1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/tests/Pdf/PdfmockTest.php

112 lines
3.1 KiB
PHP
Raw Normal View History

2023-02-25 01:11:09 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace Tests\Pdf;
2023-02-25 06:11:12 +01:00
use App\DataMapper\CompanySettings;
2023-02-25 01:11:09 +01:00
use Tests\TestCase;
2023-02-25 02:08:34 +01:00
use App\Models\Design;
2023-02-25 06:11:12 +01:00
use App\Models\Company;
2023-02-25 01:53:30 +01:00
use App\Models\Country;
2023-02-25 01:11:09 +01:00
use App\Models\Invoice;
2023-02-25 01:53:30 +01:00
use App\Models\Currency;
2023-02-25 01:11:09 +01:00
use Tests\MockAccountData;
2023-02-25 01:53:30 +01:00
use App\Services\Pdf\PdfMock;
2023-02-25 01:11:09 +01:00
use Beganovich\Snappdf\Snappdf;
2023-02-25 06:11:12 +01:00
use App\Services\Pdf\PdfBuilder;
2023-02-25 01:11:09 +01:00
use App\Services\Pdf\PdfService;
use App\Services\Pdf\PdfConfiguration;
/**
* @test
* @covers App\Services\Pdf\PdfService
*/
class PdfmockTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
}
public function testPdfInstance ()
{
2023-02-25 06:11:12 +01:00
$data = [
'settings' => CompanySettings::defaults(),
'settings_type' => 'company',
'entity_type' => 'invoice',
];
2023-02-25 01:11:09 +01:00
2023-02-25 06:11:12 +01:00
$entity = (new \App\Services\Pdf\PdfMock($data, Company::factory()->make()))->build()->initEntity();
2023-02-25 01:11:09 +01:00
$this->assertInstanceOf(Invoice::class, $entity);
$this->assertNotNull($entity->client);
2023-02-25 01:53:30 +01:00
$pdf_service = new PdfService($entity->invitation);
$this->assertNotNull($pdf_service);
$pdf_config = (new PdfConfiguration($pdf_service));
$this->assertNotNull($pdf_config);
}
public function testHtmlGeneration()
{
2023-02-25 06:11:12 +01:00
$data = [
'settings' => CompanySettings::defaults(),
'settings_type' => 'company',
'entity_type' => 'invoice',
];
$pdf_mock = (new PdfMock($data, Company::factory()->make()))->build();
$mock = $pdf_mock->initEntity();
2023-02-25 01:53:30 +01:00
$pdf_service = new PdfService($mock->invitation);
$pdf_config = (new PdfConfiguration($pdf_service));
$pdf_config->entity = $mock;
$pdf_config->setTaxMap($mock->tax_map);
$pdf_config->setTotalTaxMap($mock->total_tax_map);
$pdf_config->setCurrency(Currency::find(1));
$pdf_config->setCountry(Country::find(840));
$pdf_config->client = $mock->client;
$pdf_config->entity_design_id = 'invoice_design_id';
$pdf_config->settings_object = $mock->client;
$pdf_config->entity_string = 'invoice';
2023-02-25 06:11:12 +01:00
$pdf_config->settings = $pdf_mock->getMergedSettings();
$pdf_mock->settings = $pdf_config->settings;
2023-02-25 02:08:34 +01:00
$pdf_config->setPdfVariables();
$pdf_config->design = Design::find(2);
$pdf_config->currency_entity = $mock->client;
$pdf_service->config = $pdf_config;
2023-02-25 01:53:30 +01:00
2023-02-25 02:08:34 +01:00
$pdf_designer = (new \App\Services\Pdf\PdfDesigner($pdf_service))->build();
$pdf_service->designer = $pdf_designer;
2023-02-25 02:17:08 +01:00
$pdf_service->html_variables = $pdf_mock->getStubVariables();
2023-02-25 02:08:34 +01:00
$pdf_builder = (new PdfBuilder($pdf_service))->build();
$pdf_service->builder = $pdf_builder;
2023-02-25 01:53:30 +01:00
$this->assertNotNull($pdf_config);
2023-02-25 02:08:34 +01:00
2023-02-25 02:17:08 +01:00
$html = $pdf_service->getHtml();
$this->assertNotNull($html);
2023-02-25 02:08:34 +01:00
}
2023-02-25 02:17:08 +01:00
2023-02-25 01:11:09 +01:00
}