Make WordPress Core

Changeset 34255


Ignore:
Timestamp:
09/17/2015 12:36:12 AM (10 years ago)
Author:
wonderboymusic
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post-functions.php

    r34248 r34255  
    50825082
    50835083        foreach ( $matches as $match => $wilds ) {
    5084             if ( isset($types[$wilds[0]])) {
    5085                 $icon = $types[$wilds[0]];
    5086                 if ( !is_numeric($mime) )
    5087                     wp_cache_add("mime_type_icon_$mime", $icon);
    5088                 break;
     5084            foreach ( $wilds as $wild ) {
     5085                if ( ! isset( $types[ $wild ] ) ) {
     5086                    continue;
     5087                }
     5088
     5089                $icon = $types[ $wild ];
     5090                if ( ! is_numeric( $mime ) ) {
     5091                    wp_cache_add( "mime_type_icon_$mime", $icon );
     5092                }
     5093                break 2;
    50895094            }
    50905095        }
  • trunk/tests/phpunit/tests/post/attachments.php

    r33188 r34255  
    513513        $upload = wp_upload_bits( basename( $filename ), null, $contents );
    514514
     515        remove_filter( 'upload_mimes', array( $this, 'blacklist_jpg_mime_type' ) );
     516
    515517        $this->assertNotEmpty( $upload['error'] );
    516 
    517         remove_filter( 'upload_mimes', array( $this, 'blacklist_jpg_mime_type' ) );
    518518    }
    519519
     
    527527        return $mimes;
    528528    }
     529
     530    /**
     531     * @ticket 33012
     532     */
     533    public function test_wp_mime_type_icon() {
     534        $icon = wp_mime_type_icon();
     535
     536        $this->assertContains( 'images/media/default.png', $icon );
     537    }
     538
     539    /**
     540     * @ticket 33012
     541     */
     542    public function test_wp_mime_type_icon_video() {
     543        $icon = wp_mime_type_icon( 'video/mp4' );
     544
     545        $this->assertContains( 'images/media/video.png', $icon );
     546    }
    529547}
Note: See TracChangeset for help on using the changeset viewer.