From 3e962723ff06d674e309e11304d63102dd8f7c91 Mon Sep 17 00:00:00 2001 From: Steve Williamson Date: Tue, 9 Jun 2026 15:34:35 -0400 Subject: [PATCH] Fix download preview test for Filament href escaping. Filament 5.6+ HTML-escapes signed URLs in href attributes, so assert the decoded href matches rather than expecting raw ampersands in the rendered HTML. Co-authored-by: Cursor --- tests/Unit/LibraryFilePreviewResolverTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/Unit/LibraryFilePreviewResolverTest.php b/tests/Unit/LibraryFilePreviewResolverTest.php index 44e564e..36de5bb 100644 --- a/tests/Unit/LibraryFilePreviewResolverTest.php +++ b/tests/Unit/LibraryFilePreviewResolverTest.php @@ -194,7 +194,7 @@ function previewMedia(array $attributes, ?string $diskPath = null, ?string $cont ->and($html)->toContain('Paragraph text.'); }); -it('renders download preview button with unescaped signed url query params', function (): void { +it('renders download preview button with a valid signed url href', function (): void { $signedUrl = 'https://example.test/file.txt?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Signature=abc123'; $html = view('filament-library::infolists.components.previews.download', [ @@ -202,6 +202,9 @@ function previewMedia(array $attributes, ?string $diskPath = null, ?string $cont 'message' => 'This file type cannot be previewed. Please download to view.', ])->render(); - expect($html)->toContain('href="' . $signedUrl . '"') + preg_match('/href="([^"]+)"/', $html, $matches); + + expect($matches)->not->toBeEmpty() + ->and(html_entity_decode($matches[1], ENT_QUOTES))->toBe($signedUrl) ->and($html)->not->toContain('&'); });