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

Fixes for tests

This commit is contained in:
David Bomba 2020-10-28 10:34:09 +11:00
parent d211fb3afa
commit 0b16b2ac9c
2 changed files with 62 additions and 8 deletions

View File

@ -154,7 +154,7 @@ class CompanyTransformer extends EntityTransformer
'invoice_task_timelog' => (bool) $company->invoice_task_timelog,
'auto_start_tasks' => (bool) $company->auto_start_tasks,
'invoice_task_documents' => (bool) $company->invoice_task_documents,
'use_credits_payment' => 'always', //todo remove
// 'use_credits_payment' => 'always', //todo remove
];
}

View File

@ -12,18 +12,26 @@ namespace Tests\Integration;
use App\Designs\Bold;
use App\Designs\Designer;
use App\Models\Credit;
use App\Models\Design;
use App\Models\Invoice;
use App\Models\Quote;
use App\Models\RecurringInvoice;
use App\Utils\HtmlEngine;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceHtml;
use Tests\MockAccountData;
use Tests\TestCase;
use App\Services\PdfMaker\Design as PdfDesignModel;
use App\Services\PdfMaker\Design as PdfMakerDesign;
use App\Services\PdfMaker\PdfMaker as PdfMakerService;
/**
* @test
*/
class HtmlGenerationTest extends TestCase
{
use MockAccountData;
use MakesInvoiceHtml;
use MakesHash;
public function setUp() :void
{
@ -34,12 +42,58 @@ class HtmlGenerationTest extends TestCase
public function testHtmlOutput()
{
$design = Design::find(3);
$designer = new Designer($this->invoice, $design, $this->invoice->client->getSetting('pdf_variables'), 'invoice');
$html = $this->generateEntityHtml($designer, $this->invoice);
$html = $this->generateHtml($this->invoice);
$this->assertNotNull($html);
}
private function generateHtml($entity)
{
$entity_design_id = '';
if($entity instanceof Invoice || $entity instanceof RecurringInvoice){
$entity_design_id = 'invoice_design_id';
}
elseif($entity instanceof Quote){
$entity_design_id = 'quote_design_id';
}
elseif($entity instanceof Credit){
$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) {
$options = [
'custom_partials' => json_decode(json_encode($design->design), true)
];
$template = new PdfMakerDesign(PdfDesignModel::CUSTOM, $options);
} else {
$template = new PdfMakerDesign(strtolower($design->name));
}
$state = [
'template' => $template->elements([
'client' => $entity->client,
'entity' => $entity,
'pdf_variables' => (array) $entity->company->settings->pdf_variables,
'products' => $design->design->product,
]),
'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);
}
}