Improve testability and coverage of wp_ext2type().

* Following pattern of `wp_get_mime_types()`, introduce `wp_get_ext_types()` function. New function returns a filtered list of file types with their extensions.
* Use this function in new tests for `wp_ext2type()`.

Props borgesbruno.
Fixes #35987.

git-svn-id: https://develop.svn.wordpress.org/trunk@37189 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2016-04-13 03:11:25 +00:00
parent c1913d5ad3
commit 26a5e78d94
2 changed files with 69 additions and 22 deletions

View File

@@ -813,4 +813,39 @@ class Tests_Functions extends WP_UnitTestCase {
array( '2016-03-02T19:13:00', '16-03-02 19:13' )
);
}
/**
* @ticket 35987
*/
public function test_wp_get_ext_types() {
$extensions = wp_get_ext_types();
$this->assertInternalType( 'array', $extensions );
$this->assertNotEmpty( $extensions );
add_filter( 'ext2type', '__return_empty_array' );
$extensions = wp_get_ext_types();
$this->assertSame( array(), $extensions );
remove_filter( 'ext2type', '__return_empty_array' );
$extensions = wp_get_ext_types();
$this->assertInternalType( 'array', $extensions );
$this->assertNotEmpty( $extensions );
}
/**
* @ticket 35987
*/
public function test_wp_ext2type() {
$extensions = wp_get_ext_types();
foreach ( $extensions as $type => $extensionList ) {
foreach ( $extensionList as $extension ) {
$this->assertEquals( $type, wp_ext2type( $extension ) );
$this->assertEquals( $type, wp_ext2type( strtoupper( $extension ) ) );
}
}
$this->assertNull( wp_ext2type( 'unknown_format' ) );
}
}