From 3496f8b0b4f54e5e5e4bf83e01d9682db6301633 Mon Sep 17 00:00:00 2001 From: Dhrupo Nil Date: Tue, 21 Apr 2026 12:51:49 +0600 Subject: [PATCH 1/2] Media: guard attachment icon size lookup --- tests/phpunit/tests/media.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 060a7295f6bb4..121d43d9b7bcd 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -1732,6 +1732,31 @@ public function test_wp_get_attachment_image_url() { $this->assertSame( $image[0], wp_get_attachment_image_url( $attachment_id ) ); } + /** + * @ticket 64742 + */ + public function test_wp_get_attachment_image_src_with_icon_when_icon_file_size_cannot_be_read() { + $post_id = self::factory()->post->create(); + $attachment_id = self::factory()->attachment->create_object( + 'test.pdf', + $post_id, + array( + 'post_mime_type' => 'application/pdf', + 'post_type' => 'attachment', + ) + ); + + $filter = static function () { + return 'https://example.org/wp-includes/images/media/missing-icon.png'; + }; + + add_filter( 'wp_mime_type_icon', $filter ); + + $this->assertFalse( wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ) ); + + remove_filter( 'wp_mime_type_icon', $filter ); + } + /** * @ticket 12235 */ From 47ce51ea7c8b5fc44d8c3fd76efc6e3dd6f9c04e Mon Sep 17 00:00:00 2001 From: Dhrupo Nil Date: Sat, 27 Jun 2026 09:43:20 +0600 Subject: [PATCH 2/2] Media: address review feedback on icon size lookup test Apply review suggestions: add void return type, inline the filter closure, and drop the manual remove_filter() teardown. --- tests/phpunit/tests/media.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 121d43d9b7bcd..6782bfc01b1c7 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -1735,7 +1735,7 @@ public function test_wp_get_attachment_image_url() { /** * @ticket 64742 */ - public function test_wp_get_attachment_image_src_with_icon_when_icon_file_size_cannot_be_read() { + public function test_wp_get_attachment_image_src_with_icon_when_icon_file_size_cannot_be_read(): void { $post_id = self::factory()->post->create(); $attachment_id = self::factory()->attachment->create_object( 'test.pdf', @@ -1746,15 +1746,14 @@ public function test_wp_get_attachment_image_src_with_icon_when_icon_file_size_c ) ); - $filter = static function () { - return 'https://example.org/wp-includes/images/media/missing-icon.png'; - }; - - add_filter( 'wp_mime_type_icon', $filter ); + add_filter( + 'wp_mime_type_icon', + static function () { + return 'https://example.org/wp-includes/images/media/missing-icon.png'; + } + ); $this->assertFalse( wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ) ); - - remove_filter( 'wp_mime_type_icon', $filter ); } /**