From a24833b0bf1643b47700f8355b62f033d566a744 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Sat, 31 Oct 2026 05:08:05 +0000 Subject: [PATCH 1/2] Tests: Cover wp_get_default_extension_for_mime_type(). Add unit tests for known mime-to-extension mapping and unknown mime types.\n\nSee #65819. --- .../wpGetDefaultExtensionForMimeType.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/phpunit/tests/functions/wpGetDefaultExtensionForMimeType.php diff --git a/tests/phpunit/tests/functions/wpGetDefaultExtensionForMimeType.php b/tests/phpunit/tests/functions/wpGetDefaultExtensionForMimeType.php new file mode 100644 index 0000000000000..67fe760b63946 --- /dev/null +++ b/tests/phpunit/tests/functions/wpGetDefaultExtensionForMimeType.php @@ -0,0 +1,48 @@ +assertSame( $expected, wp_get_default_extension_for_mime_type( $mime_type ) ); + } + + /** + * Data provider. + * + * @return array[] + */ + public static function data_known_mime_types() { + return array( + 'jpeg' => array( 'image/jpeg', 'jpg' ), + 'png' => array( 'image/png', 'png' ), + 'pdf' => array( 'application/pdf', 'pdf' ), + 'mp3' => array( 'audio/mpeg', 'mp3' ), + ); + } + + /** + * Tests that an unknown mime type returns false. + * + * @ticket 65819 + */ + public function test_returns_false_for_unknown_mime_type() { + $this->assertFalse( wp_get_default_extension_for_mime_type( 'application/x-not-a-real-type' ) ); + } +} From 437892796830c5a3fe228eeebe7d953cb251553b Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Sun, 1 Nov 2026 05:20:45 +0000 Subject: [PATCH 2/2] Tests: Extend mime default-extension coverage in Tests_Functions. Add PDF and MP3 first-extension assertions to the existing helper test and drop the dedicated class. See #65819. --- tests/phpunit/tests/functions.php | 4 ++ .../wpGetDefaultExtensionForMimeType.php | 48 ------------------- 2 files changed, 4 insertions(+), 48 deletions(-) delete mode 100644 tests/phpunit/tests/functions/wpGetDefaultExtensionForMimeType.php diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 9939678366265..4ecbdd81c554f 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -2265,11 +2265,15 @@ public static function data_wp_is_json_media_type() { /** * @ticket 53668 + * @ticket 65819 + * @covers ::wp_get_default_extension_for_mime_type */ public function test_wp_get_default_extension_for_mime_type() { $this->assertSame( 'jpg', wp_get_default_extension_for_mime_type( 'image/jpeg' ), 'jpg not returned as default extension for "image/jpeg"' ); $this->assertNotSame( 'jpeg', wp_get_default_extension_for_mime_type( 'image/jpeg' ), 'jpeg should not be returned as default extension for "image/jpeg"' ); $this->assertSame( 'png', wp_get_default_extension_for_mime_type( 'image/png' ), 'png not returned as default extension for "image/png"' ); + $this->assertSame( 'pdf', wp_get_default_extension_for_mime_type( 'application/pdf' ), 'pdf not returned as default extension for "application/pdf"' ); + $this->assertSame( 'mp3', wp_get_default_extension_for_mime_type( 'audio/mpeg' ), 'mp3 not returned as default extension for "audio/mpeg"' ); $this->assertFalse( wp_get_default_extension_for_mime_type( 'wibble/wobble' ), 'false not returned for unrecognized mime type' ); $this->assertFalse( wp_get_default_extension_for_mime_type( '' ), 'false not returned when empty string as mime type supplied' ); $this->assertFalse( wp_get_default_extension_for_mime_type( ' ' ), 'false not returned when empty string as mime type supplied' ); diff --git a/tests/phpunit/tests/functions/wpGetDefaultExtensionForMimeType.php b/tests/phpunit/tests/functions/wpGetDefaultExtensionForMimeType.php deleted file mode 100644 index 67fe760b63946..0000000000000 --- a/tests/phpunit/tests/functions/wpGetDefaultExtensionForMimeType.php +++ /dev/null @@ -1,48 +0,0 @@ -assertSame( $expected, wp_get_default_extension_for_mime_type( $mime_type ) ); - } - - /** - * Data provider. - * - * @return array[] - */ - public static function data_known_mime_types() { - return array( - 'jpeg' => array( 'image/jpeg', 'jpg' ), - 'png' => array( 'image/png', 'png' ), - 'pdf' => array( 'application/pdf', 'pdf' ), - 'mp3' => array( 'audio/mpeg', 'mp3' ), - ); - } - - /** - * Tests that an unknown mime type returns false. - * - * @ticket 65819 - */ - public function test_returns_false_for_unknown_mime_type() { - $this->assertFalse( wp_get_default_extension_for_mime_type( 'application/x-not-a-real-type' ) ); - } -}