2020-03-07 07:31:26 +01:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-14 13:11:46 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2020-03-07 07:31:26 +01:00
|
|
|
namespace Tests\Integration;
|
|
|
|
|
2020-10-28 00:34:09 +01:00
|
|
|
use App\Models\Credit;
|
2020-03-07 07:31:26 +01:00
|
|
|
use App\Models\Design;
|
2020-10-28 00:34:09 +01:00
|
|
|
use App\Models\Invoice;
|
|
|
|
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;
|
2020-03-07 07:31:26 +01:00
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
2020-11-25 15:19:52 +01:00
|
|
|
|
2020-03-07 07:31:26 +01:00
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
class HtmlGenerationTest extends TestCase
|
|
|
|
{
|
|
|
|
use MockAccountData;
|
2020-10-28 00:34:09 +01:00
|
|
|
use MakesHash;
|
2020-03-07 07:31:26 +01:00
|
|
|
|
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testHtmlOutput()
|
|
|
|
{
|
2020-10-28 00:34:09 +01:00
|
|
|
$html = $this->generateHtml($this->invoice);
|
|
|
|
|
|
|
|
$this->assertNotNull($html);
|
|
|
|
}
|
2020-03-07 07:31:26 +01:00
|
|
|
|
2020-10-28 00:34:09 +01:00
|
|
|
private function generateHtml($entity)
|
|
|
|
{
|
|
|
|
$entity_design_id = '';
|
2020-03-07 07:31:26 +01:00
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
|
|
|
$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,
|
2020-11-04 14:56:08 +01:00
|
|
|
'$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);
|
2020-03-07 07:31:26 +01:00
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|