WordPress.org

Make WordPress Core

Ticket #40017: exif.2.diff

File exif.2.diff, 1.5 KB (added by blobfolio, 3 years ago)

remove false !==, add unit test

  • src/wp-includes/functions.php

    diff --git src/wp-includes/functions.php src/wp-includes/functions.php
    index ee214e9..966dcd8 100644
    function wp_get_image_mime( $file ) { 
    23672367         */
    23682368        try {
    23692369                if ( is_callable( 'exif_imagetype' ) ) {
    2370                         $mime = image_type_to_mime_type( exif_imagetype( $file ) );
     2370                        $imagetype = exif_imagetype( $file );
     2371                        $mime = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
    23712372                } elseif ( function_exists( 'getimagesize' ) ) {
    23722373                        $imagesize = getimagesize( $file );
    23732374                        $mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
  • new file tests/phpunit/tests/functions/wpGetImageMime.php

    diff --git tests/phpunit/tests/functions/wpGetImageMime.php tests/phpunit/tests/functions/wpGetImageMime.php
    new file mode 100644
    index 0000000..dcb4b63
    - +  
     1<?php
     2
     3/**
     4 * Tests for wp_get_image_mime()
     5 *
     6 * @group functions.php
     7 * @ticket 40017
     8 */
     9class Tests_Functions_Wp_Get_Image_Mime extends WP_UnitTestCase {
     10        function setUp() {
     11                if ( ! is_callable( 'exif_imagetype' ) && ! function_exists( 'getimagesize' ) )
     12                        $this->markTestSkipped( 'The exif PHP extension is not loaded.' );
     13                parent::setUp();
     14        }
     15
     16        public function test_wp_get_image_mime() {
     17                // Test a valid image.
     18                $out = wp_get_image_mime( DIR_TESTDATA.'/images/2004-07-22-DSC_0008.jpg' );
     19                $this->assertEquals( 'image/jpeg', $out );
     20
     21                // Test a non-image file.
     22                $out = wp_get_image_mime( DIR_TESTDATA.'/uploads/dashicons.woff' );
     23                $this->assertEquals( false, $out );
     24        }
     25}