From 0918341c9b22329ebbe693bcc304852c000d1de3 Mon Sep 17 00:00:00 2001 From: erikn69 Date: Mon, 2 Oct 2023 02:19:56 -0500 Subject: [PATCH] Fix setOptions method (#974) * Fix setOptions method * Test for `setOption`, `setOptions` --- src/PDF.php | 6 +++--- tests/PdfTest.php | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/PDF.php b/src/PDF.php index 2b68b94..ae9f53d 100644 --- a/src/PDF.php +++ b/src/PDF.php @@ -156,13 +156,13 @@ public function setOption($attribute, $value = null): self /** * Replace all the Options from DomPDF * - * @deprecated Use setOption to override individual options. * @param array $options */ public function setOptions(array $options): self { - $options = new Options($options); - $this->dompdf->setOptions($options); + $dompdfOptions = new Options(app()->make('dompdf.options')); + $dompdfOptions->set($options); + $this->dompdf->setOptions($dompdfOptions); return $this; } diff --git a/tests/PdfTest.php b/tests/PdfTest.php index 27bbe13..75498b4 100644 --- a/tests/PdfTest.php +++ b/tests/PdfTest.php @@ -96,6 +96,24 @@ public function testSaveOnDisk(): void $this->assertEquals($content, $pdf->output()); } + public function testConfigOptions(): void + { + \Config::set('dompdf.options.default_font', 'default_font'); + \Config::set('dompdf.options.log_output_file', 'default_log'); + + $pdf = Facade\Pdf::loadHtml('

Test

'); + $this->assertEquals('default_font', $pdf->getDomPDF()->getOptions()->getDefaultFont()); + $this->assertEquals('default_log', $pdf->getDomPDF()->getOptions()->getLogOutputFile()); + + $pdf->setOption('default_font', 'custom_font'); + $this->assertEquals('custom_font', $pdf->getDomPDF()->getOptions()->getDefaultFont()); + $this->assertEquals('default_log', $pdf->getDomPDF()->getOptions()->getLogOutputFile()); + + $pdf->setOptions([]); // reset options to config/dompdf.php + $this->assertEquals('default_font', $pdf->getDomPDF()->getOptions()->getDefaultFont()); + $this->assertEquals('default_log', $pdf->getDomPDF()->getOptions()->getLogOutputFile()); + } + public function testMagicMethods(): void { $pdf = Facade\Pdf::setBaseHost('host')->setProtocol('protocol')