Skip to content

Commit

Permalink
[8.x] Fix assertDownload if testing against a filename with spaces in…
Browse files Browse the repository at this point in the history
… it (laravel#39536)

* add failing test

* fix assertDownload when filename contains spaces
  • Loading branch information
fabio-ivona authored Nov 8, 2021
1 parent b2dfaca commit 8e2d727
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public function assertDownload($filename = null)
PHPUnit::assertSame(
$filename,
isset(explode('=', $contentDisposition[1])[1])
? trim(explode('=', $contentDisposition[1])[1])
? trim(explode('=', $contentDisposition[1])[1], " \"'")
: '',
$message
);
Expand Down
15 changes: 15 additions & 0 deletions tests/Testing/TestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,21 @@ public function testAssertDownloadOfferedFailsWithInlineContentDisposition()
$files->deleteDirectory($tempDir);
}

public function testAssertDownloadOfferedWithAFileNameWithSpacesInIt()
{
$files = new Filesystem;
$tempDir = __DIR__.'/tmp';
$files->makeDirectory($tempDir, 0755, false, true);
$files->put($tempDir.'/file.txt', 'Hello World');
$testResponse = TestResponse::fromBaseResponse(new Response(
$files->get($tempDir.'/file.txt'), 200, [
'Content-Disposition' => 'attachment; filename = "test file.txt"',
]
));
$testResponse->assertDownload('test file.txt');
$files->deleteDirectory($tempDir);
}

public function testMacroable()
{
TestResponse::macro('foo', function () {
Expand Down

0 comments on commit 8e2d727

Please sign in to comment.