From ce73de3685774e98a641d177c8c4179a50ad17a8 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Sat, 31 Oct 2026 05:05:57 +0000 Subject: [PATCH 1/2] Tests: Cover wp_ext2type(). Add unit tests for known extension type mapping and unknown extensions.\n\nSee #65819. --- tests/phpunit/tests/functions/wpExt2type.php | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/phpunit/tests/functions/wpExt2type.php diff --git a/tests/phpunit/tests/functions/wpExt2type.php b/tests/phpunit/tests/functions/wpExt2type.php new file mode 100644 index 0000000000000..9d1c081289059 --- /dev/null +++ b/tests/phpunit/tests/functions/wpExt2type.php @@ -0,0 +1,49 @@ +assertSame( $expected, wp_ext2type( $ext ) ); + } + + /** + * Data provider. + * + * @return array[] + */ + public static function data_known_extensions() { + return array( + 'image lowercase' => array( 'jpg', 'image' ), + 'image uppercase' => array( 'PNG', 'image' ), + 'audio' => array( 'mp3', 'audio' ), + 'video' => array( 'mp4', 'video' ), + 'document' => array( 'pdf', 'document' ), + ); + } + + /** + * Tests that an unknown extension returns null. + * + * @ticket 65819 + */ + public function test_returns_null_for_unknown_extension() { + $this->assertNull( wp_ext2type( 'notarealext' ) ); + } +} From 232359825cfba7ffdd226b8c3ae38bd5c3061f89 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Sun, 1 Nov 2026 05:22:39 +0000 Subject: [PATCH 2/2] Tests: Strengthen wp_ext2type() coverage in Tests_Functions. Add literal extension mappings to the existing helper test and drop the dedicated class. See #65819. --- tests/phpunit/tests/functions.php | 9 ++++ tests/phpunit/tests/functions/wpExt2type.php | 49 -------------------- 2 files changed, 9 insertions(+), 49 deletions(-) delete mode 100644 tests/phpunit/tests/functions/wpExt2type.php diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 9939678366265..41ce50e90e575 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -1147,12 +1147,21 @@ public function test_wp_get_ext_types() { /** * @ticket 35987 + * @ticket 65819 + * @covers ::wp_ext2type */ public function test_wp_ext2type() { $extensions = wp_get_ext_types(); $this->assertNotEmpty( $extensions ); + // Literal mappings stay independent of the current registry contents. + $this->assertSame( 'image', wp_ext2type( 'jpg' ) ); + $this->assertSame( 'image', wp_ext2type( 'PNG' ) ); + $this->assertSame( 'audio', wp_ext2type( 'mp3' ) ); + $this->assertSame( 'video', wp_ext2type( 'mp4' ) ); + $this->assertSame( 'document', wp_ext2type( 'pdf' ) ); + foreach ( $extensions as $type => $extension_list ) { foreach ( $extension_list as $extension ) { $this->assertSame( $type, wp_ext2type( $extension ) ); diff --git a/tests/phpunit/tests/functions/wpExt2type.php b/tests/phpunit/tests/functions/wpExt2type.php deleted file mode 100644 index 9d1c081289059..0000000000000 --- a/tests/phpunit/tests/functions/wpExt2type.php +++ /dev/null @@ -1,49 +0,0 @@ -assertSame( $expected, wp_ext2type( $ext ) ); - } - - /** - * Data provider. - * - * @return array[] - */ - public static function data_known_extensions() { - return array( - 'image lowercase' => array( 'jpg', 'image' ), - 'image uppercase' => array( 'PNG', 'image' ), - 'audio' => array( 'mp3', 'audio' ), - 'video' => array( 'mp4', 'video' ), - 'document' => array( 'pdf', 'document' ), - ); - } - - /** - * Tests that an unknown extension returns null. - * - * @ticket 65819 - */ - public function test_returns_null_for_unknown_extension() { - $this->assertNull( wp_ext2type( 'notarealext' ) ); - } -}