diff --git a/tests/Feature/PdfMaker/PdfMaker.php b/tests/Feature/PdfMaker/PdfMaker.php index 84ec1c92a47a..fd13b78013dc 100644 --- a/tests/Feature/PdfMaker/PdfMaker.php +++ b/tests/Feature/PdfMaker/PdfMaker.php @@ -2,8 +2,6 @@ namespace Tests\Feature\PdfMaker; -use DOMDocument; - class PdfMaker { use PdfMakerUtilities; @@ -42,9 +40,7 @@ class PdfMaker } } - foreach ($this->data['variables'] as $entry) { - $this->updateVariable($entry['id'], $entry['variable'], $entry['value']); - } + $this->updateVariables($this->data['variables']); return $this; } diff --git a/tests/Feature/PdfMaker/PdfMakerTest.php b/tests/Feature/PdfMaker/PdfMakerTest.php index b220cce7a88f..5602fa8c0272 100644 --- a/tests/Feature/PdfMaker/PdfMakerTest.php +++ b/tests/Feature/PdfMaker/PdfMakerTest.php @@ -95,7 +95,7 @@ class PdfMakerTest extends TestCase ], ], 'variables' => [ - ['id' => 'header', 'variable' => '$title', 'value' => 'Invoice Ninja'], + '$title' => 'Invoice Ninja', ], ]; diff --git a/tests/Feature/PdfMaker/PdfMakerUtilities.php b/tests/Feature/PdfMaker/PdfMakerUtilities.php index 4931072f5178..5274be7e619c 100644 --- a/tests/Feature/PdfMaker/PdfMakerUtilities.php +++ b/tests/Feature/PdfMaker/PdfMakerUtilities.php @@ -13,7 +13,7 @@ trait PdfMakerUtilities $document->validateOnParse = true; @$document->loadHTML($this->design->html()); - + $this->document = $document; $this->xpath = new DOMXPath($document); } @@ -49,6 +49,15 @@ trait PdfMakerUtilities return $element; } + public function updateVariables(array $variables) + { + $html = strtr($this->getCompiledHTML(), $variables); + + $this->document->loadHTML($html); + + $this->document->saveHTML(); + } + public function updateVariable(string $element, string $variable, string $value) { $element = $this->document->getElementById($element); @@ -56,7 +65,7 @@ trait PdfMakerUtilities $original = $element->nodeValue; info([$variable => $value]); - + $element->nodeValue = ''; $replaced = strtr($original, [$variable => $value]); @@ -67,4 +76,4 @@ trait PdfMakerUtilities return $element; } -} \ No newline at end of file +}