Skip to content

Commit

Permalink
Fix setOptions method (#974)
Browse files Browse the repository at this point in the history
* Fix setOptions method

* Test for `setOption`, `setOptions`
  • Loading branch information
erikn69 authored Oct 2, 2023
1 parent 90e680f commit 0918341
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $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;
}

Expand Down
18 changes: 18 additions & 0 deletions tests/PdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<h1>Test</h1>');
$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')
Expand Down

0 comments on commit 0918341

Please sign in to comment.