From 7772da95d398235297577b664df2464ad17ba5a3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 25 Feb 2023 12:08:34 +1100 Subject: [PATCH] Testing PDF mocks --- app/Services/Pdf/PdfBuilder.php | 4 ++-- app/Services/Pdf/PdfConfiguration.php | 2 +- app/Services/Pdf/PdfMock.php | 2 +- tests/Pdf/PdfmockTest.php | 21 ++++++++++++++++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/Services/Pdf/PdfBuilder.php b/app/Services/Pdf/PdfBuilder.php index bcf8fba0d4e0..af43a120f584 100644 --- a/app/Services/Pdf/PdfBuilder.php +++ b/app/Services/Pdf/PdfBuilder.php @@ -561,9 +561,9 @@ class PdfBuilder $data[$key][$table_type.".{$_table_type}4"] = strlen($item->custom_value4) >= 1 ? $helpers->formatCustomFieldValue($this->service->company->custom_fields, "{$_table_type}4", $item->custom_value4, $this->service->config->currency_entity) : ''; if ($item->quantity > 0 || $item->cost > 0) { - $data[$key][$table_type.'.quantity'] = Number::formatValueNoTrailingZeroes($item->quantity, $this->service->config->currency_entity); + $data[$key][$table_type.'.quantity'] = $this->service->config->formatMoney($item->quantity); - $data[$key][$table_type.'.unit_cost'] = Number::formatMoneyNoRounding($item->cost, $this->service->config->currency_entity); + $data[$key][$table_type.'.unit_cost'] = $this->service->config->formatMoney($item->cost); $data[$key][$table_type.'.cost'] = $this->service->config->formatMoney($item->cost); diff --git a/app/Services/Pdf/PdfConfiguration.php b/app/Services/Pdf/PdfConfiguration.php index 93744300480f..614b1cab8b99 100644 --- a/app/Services/Pdf/PdfConfiguration.php +++ b/app/Services/Pdf/PdfConfiguration.php @@ -142,7 +142,7 @@ class PdfConfiguration * * @return self */ - private function setPdfVariables() :self + public function setPdfVariables() :self { $default = (array) CompanySettings::getEntityVariableDefaults(); diff --git a/app/Services/Pdf/PdfMock.php b/app/Services/Pdf/PdfMock.php index 740ebc2de0b5..82dc46d2a1a4 100644 --- a/app/Services/Pdf/PdfMock.php +++ b/app/Services/Pdf/PdfMock.php @@ -43,7 +43,7 @@ class PdfMock private function getTaxMap() { - return collect( ['name' => 'GST', 'total' => 10]); + return collect( [['name' => 'GST', 'total' => 10]]); } diff --git a/tests/Pdf/PdfmockTest.php b/tests/Pdf/PdfmockTest.php index be758e34b405..7b3a8d3e2eb5 100644 --- a/tests/Pdf/PdfmockTest.php +++ b/tests/Pdf/PdfmockTest.php @@ -13,9 +13,11 @@ namespace Tests\Pdf; use Tests\TestCase; +use App\Models\Design; use App\Models\Country; use App\Models\Invoice; use App\Models\Currency; +use App\Services\Pdf\PdfBuilder; use Tests\MockAccountData; use App\Services\Pdf\PdfMock; use Beganovich\Snappdf\Snappdf; @@ -71,8 +73,25 @@ class PdfmockTest extends TestCase $pdf_config->entity_design_id = 'invoice_design_id'; $pdf_config->settings_object = $mock->client; $pdf_config->entity_string = 'invoice'; - $pdf_config->settings = $pdf_config->service->company->settings; + $pdf_config->settings = (object)$pdf_config->service->company->settings; + $pdf_config->setPdfVariables(); + $pdf_config->design = Design::find(2); + $pdf_config->currency_entity = $mock->client; + + $pdf_service->config = $pdf_config; + $pdf_designer = (new \App\Services\Pdf\PdfDesigner($pdf_service))->build(); + $pdf_service->designer = $pdf_designer; + + $pdf_service->html_variables = $this->getStubVariables(); + + $pdf_builder = (new PdfBuilder($pdf_service))->build(); + $pdf_service->builder = $pdf_builder; $this->assertNotNull($pdf_config); } + + private function getStubVariables() + { + return ['values' => [], 'labels' => []]; + } }