Skip to content

Commit

Permalink
Merge pull request #114 from albertStaalburger/main
Browse files Browse the repository at this point in the history
PDFBuilder now honours pdf name set by either name() or download() methods during download
  • Loading branch information
freekmurze authored Apr 8, 2024
2 parents 91a72d0 + d0129fb commit e9e9c13
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function footerHtml(string $html): self

public function download(?string $downloadName = null): self
{
$this->name($downloadName ?? 'download');
$this->downloadName ?? $this->name($downloadName ?? 'download');

$this->addHeaders([
'Content-Type' => 'application/pdf',
Expand Down
40 changes: 40 additions & 0 deletions tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,43 @@
->viewName->toBe('foo')
->viewData->toBe(['bar' => 'bax']);
});

test('the `pdf` function name accepts a name parameter and sets downloadName', function () {
Pdf::fake();

expect(pdf('foo', ['bar' => 'bax'])->name('baz.pdf'))
->toBeInstanceOf(FakePdfBuilder::class)
->viewName->toBe('foo')
->viewData->toBe(['bar' => 'bax'])
->downloadName->toBe('baz.pdf');
});

test('the `pdf` function download accepts a name parameter and sets downloadName', function () {
Pdf::fake();

expect(pdf('foo', ['bar' => 'bax'])->download('baz.pdf'))
->toBeInstanceOf(FakePdfBuilder::class)
->viewName->toBe('foo')
->viewData->toBe(['bar' => 'bax'])
->downloadName->toBe('baz.pdf');
});

test('the `pdf` function name accepts a name parameter and sets downloadName while calling download', function () {
Pdf::fake();

expect(pdf('foo', ['bar' => 'bax'])->name('baz.pdf')->download())
->toBeInstanceOf(FakePdfBuilder::class)
->viewName->toBe('foo')
->viewData->toBe(['bar' => 'bax'])
->downloadName->toBe('baz.pdf');
});

test('the `pdf` function download assigns the default to downloadName when no name is specified', function () {
Pdf::fake();

expect(pdf('foo', ['bar' => 'bax'])->download())
->toBeInstanceOf(FakePdfBuilder::class)
->viewName->toBe('foo')
->viewData->toBe(['bar' => 'bax'])
->downloadName->toBe('download.pdf');
});

0 comments on commit e9e9c13

Please sign in to comment.