1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/tests/Integration/HtmlGenerationTest.php

100 lines
3.0 KiB
PHP
Raw Normal View History

<?php
2020-09-14 13:11:46 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-09-14 13:11:46 +02:00
*
2022-06-08 06:25:44 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2020-09-14 13:11:46 +02:00
*/
namespace Tests\Integration;
2020-10-28 00:34:09 +01:00
use App\Models\Credit;
use App\Models\Design;
2020-10-28 00:34:09 +01:00
use App\Models\Invoice;
2022-06-08 00:27:47 +02:00
use App\Models\PurchaseOrder;
2020-10-28 00:34:09 +01:00
use App\Models\Quote;
use App\Models\RecurringInvoice;
2020-11-25 15:19:52 +01:00
use App\Services\PdfMaker\Design as PdfDesignModel;
use App\Services\PdfMaker\Design as PdfMakerDesign;
use App\Services\PdfMaker\PdfMaker as PdfMakerService;
2020-10-28 00:34:09 +01:00
use App\Utils\HtmlEngine;
use App\Utils\Traits\MakesHash;
use Tests\MockAccountData;
use Tests\TestCase;
2020-11-25 15:19:52 +01:00
/**
* @test
*/
class HtmlGenerationTest extends TestCase
{
use MockAccountData;
2020-10-28 00:34:09 +01:00
use MakesHash;
public function setUp() :void
{
parent::setUp();
$this->makeTestData();
}
public function testHtmlOutput()
{
2021-07-03 06:45:40 +02:00
$this->client->fresh();
$html = $this->generateHtml($this->invoice->fresh());
2020-10-28 00:34:09 +01:00
$this->assertNotNull($html);
}
2020-10-28 00:34:09 +01:00
private function generateHtml($entity)
{
$entity_design_id = '';
2020-11-25 15:19:52 +01:00
if ($entity instanceof Invoice || $entity instanceof RecurringInvoice) {
2020-10-28 00:34:09 +01:00
$entity_design_id = 'invoice_design_id';
2020-11-25 15:19:52 +01:00
} elseif ($entity instanceof Quote) {
2020-10-28 00:34:09 +01:00
$entity_design_id = 'quote_design_id';
2020-11-25 15:19:52 +01:00
} elseif ($entity instanceof Credit) {
2020-10-28 00:34:09 +01:00
$entity_design_id = 'credit_design_id';
2022-06-08 00:27:47 +02:00
} elseif ($entity instanceof PurchaseOrder) {
$entity_design_id = 'purchase_order_design_id';
2020-10-28 00:34:09 +01:00
}
$entity_design_id = $entity->design_id ? $entity->design_id : $this->decodePrimaryKey($entity->client->getSetting($entity_design_id));
$design = Design::find($entity_design_id);
$html = new HtmlEngine($entity->invitations->first());
if ($design->is_custom) {
2020-11-25 15:19:52 +01:00
$options = [
2020-10-28 00:34:09 +01:00
'custom_partials' => json_decode(json_encode($design->design), true)
];
2020-11-25 15:19:52 +01:00
$template = new PdfMakerDesign(PdfDesignModel::CUSTOM, $options);
2020-10-28 00:34:09 +01:00
} else {
2020-11-25 15:19:52 +01:00
$template = new PdfMakerDesign(strtolower($design->name));
2020-10-28 00:34:09 +01:00
}
$state = [
'template' => $template->elements([
'client' => $entity->client,
'entity' => $entity,
'pdf_variables' => (array) $entity->company->settings->pdf_variables,
'$product' => $design->design->product,
2020-10-28 00:34:09 +01:00
]),
'variables' => $html->generateLabelsAndValues(),
'options' => [
'all_pages_header' => $entity->client->getSetting('all_pages_header'),
'all_pages_footer' => $entity->client->getSetting('all_pages_footer'),
],
];
$maker = new PdfMakerService($state);
return $maker->design($template)
->build()
->getCompiledHTML(true);
}
}