Set content-disposition 'attachment' for both local and S3 downloads. Added a bunch of tests. Fixes #1148.

This commit is contained in:
Andrew Herron
2026-07-30 17:21:51 +10:00
committed by Gregor Vostrak
parent ed3ba0135b
commit 453d5ed066
7 changed files with 287 additions and 3 deletions

View File

@@ -4,6 +4,9 @@ declare(strict_types=1);
namespace Tests\Unit\Endpoint\Api\V1;
use Closure;
use DateTimeInterface;
use Illuminate\Support\Facades\Storage;
use Illuminate\Testing\TestResponse;
use Tests\TestCaseWithDatabase;
@@ -16,4 +19,26 @@ class ApiEndpointTestAbstract extends TestCaseWithDatabase
}
$response->assertStatus($statusCode);
}
/**
* Replaces the temporary URL builder of the private disk to capture the options
* passed to temporaryUrl. Returns a closure that yields the captured options.
*
* @return Closure(): (array<string, mixed>|null)
*/
protected function captureTemporaryUrlOptions(): Closure
{
$captured = null;
Storage::disk(config('filesystems.private'))->buildTemporaryUrlsUsing(
function (string $path, DateTimeInterface $expiration, array $options) use (&$captured): string {
$captured = $options;
return 'https://storage.fake/'.$path;
}
);
return function () use (&$captured): ?array {
return $captured;
};
}
}