WordPress.org

Make WordPress Core

Ticket #40017: exif.3.diff

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

move unit test to function.php

  • 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;
  • tests/phpunit/tests/functions.php

    diff --git tests/phpunit/tests/functions.php tests/phpunit/tests/functions.php
    index a3aba79..50ea235 100644
    class Tests_Functions extends WP_UnitTestCase { 
    916916        }
    917917
    918918        /**
     919         * @ticket 40017
     920         */
     921        public function test_wp_get_image_mime() {
     922                if ( ! is_callable( 'exif_imagetype' ) && ! function_exists( 'getimagesize' ) ) {
     923                        $this->markTestSkipped( 'The exif PHP extension is not loaded.' );
     924                }
     925
     926                // Test a valid image.
     927                $out = wp_get_image_mime( DIR_TESTDATA.'/images/2004-07-22-DSC_0008.jpg' );
     928                $this->assertEquals( 'image/jpeg', $out );
     929
     930                // Test a non-image file.
     931                $out = wp_get_image_mime( DIR_TESTDATA.'/uploads/dashicons.woff' );
     932                $this->assertEquals( false, $out );
     933        }
     934
     935        /**
    919936         * @ticket 39550
    920937         * @dataProvider _wp_check_filetype_and_ext_data
    921938         */