From 25710ecc67f1a1e73fcdb64726851df1e79446f1 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 17 Sep 2015 00:36:12 +0000 Subject: [PATCH] In `wp_mime_type_icon()`, the length of the `$wilds` array varies depending on what is passed as `$mime`. Loop over `$wilds` instead of arbitrarily checking `$wilds[0]`. Adds unit tests. Fixes #33012. git-svn-id: https://develop.svn.wordpress.org/trunk@34255 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post-functions.php | 15 ++++++++++----- tests/phpunit/tests/post/attachments.php | 22 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/post-functions.php b/src/wp-includes/post-functions.php index c4640d5fe7..04f888a055 100644 --- a/src/wp-includes/post-functions.php +++ b/src/wp-includes/post-functions.php @@ -5081,11 +5081,16 @@ function wp_mime_type_icon( $mime = 0 ) { $matches['default'] = array('default'); foreach ( $matches as $match => $wilds ) { - if ( isset($types[$wilds[0]])) { - $icon = $types[$wilds[0]]; - if ( !is_numeric($mime) ) - wp_cache_add("mime_type_icon_$mime", $icon); - break; + foreach ( $wilds as $wild ) { + if ( ! isset( $types[ $wild ] ) ) { + continue; + } + + $icon = $types[ $wild ]; + if ( ! is_numeric( $mime ) ) { + wp_cache_add( "mime_type_icon_$mime", $icon ); + } + break 2; } } } diff --git a/tests/phpunit/tests/post/attachments.php b/tests/phpunit/tests/post/attachments.php index 7633fd1f89..7459c6ae4c 100644 --- a/tests/phpunit/tests/post/attachments.php +++ b/tests/phpunit/tests/post/attachments.php @@ -512,9 +512,9 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $upload = wp_upload_bits( basename( $filename ), null, $contents ); - $this->assertNotEmpty( $upload['error'] ); - remove_filter( 'upload_mimes', array( $this, 'blacklist_jpg_mime_type' ) ); + + $this->assertNotEmpty( $upload['error'] ); } public function whitelist_psd_mime_type( $mimes ) { @@ -526,4 +526,22 @@ class Tests_Post_Attachments extends WP_UnitTestCase { unset( $mimes['jpg|jpeg|jpe'] ); return $mimes; } + + /** + * @ticket 33012 + */ + public function test_wp_mime_type_icon() { + $icon = wp_mime_type_icon(); + + $this->assertContains( 'images/media/default.png', $icon ); + } + + /** + * @ticket 33012 + */ + public function test_wp_mime_type_icon_video() { + $icon = wp_mime_type_icon( 'video/mp4' ); + + $this->assertContains( 'images/media/video.png', $icon ); + } }