Make WordPress Core

Changeset 55463


Ignore:
Timestamp:
03/06/2023 12:51:40 PM (16 months ago)
Author:
SergeyBiryukov
Message:

Tests: Adjust the expected mime type for WOFF fonts on PHP 8.1.12+.

As of PHP 8.1.12, which includes libmagic/file update to version 5.42, the expected mime type for WOFF files has changed to font/woff, so the type needs to be adjusted accordingly in wp_check_filetype_and_ext() tests.

References:

Follow-up to [40124], [54508], [54509], [54724].

Props costdev, SergeyBiryukov.
Merges [55462] to the 6.1 branch.
Fixes #56817.

Location:
branches/6.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.1

  • branches/6.1/tests/phpunit/tests/functions.php

    r54732 r55463  
    13921392        );
    13931393
    1394         add_filter( 'upload_mimes', array( $this, 'filter_mime_types_svg' ) );
     1394        add_filter(
     1395            'upload_mimes',
     1396            static function( $mimes ) {
     1397                $mimes['svg'] = 'image/svg+xml';
     1398                return $mimes;
     1399            }
     1400        );
     1401
    13951402        $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) );
    1396 
    1397         // Cleanup.
    1398         remove_filter( 'upload_mimes', array( $this, 'filter_mime_types_svg' ) );
    13991403    }
    14001404
     
    14051409     */
    14061410    public function test_wp_check_filetype_and_ext_with_filtered_woff() {
    1407         if ( PHP_VERSION_ID >= 80100 ) {
    1408             /*
    1409              * For the time being, this test is marked skipped on PHP 8.1+ as a recent change introduced
    1410              * an inconsistency with how the mime-type for WOFF files are handled compared to older versions.
    1411              *
    1412              * See https://core.trac.wordpress.org/ticket/56817 for more details.
    1413              */
    1414             $this->markTestSkipped( 'This test currently fails on PHP 8.1+ and requires further investigation.' );
    1415         }
    1416 
    14171411        $file     = DIR_TESTDATA . '/uploads/dashicons.woff';
    14181412        $filename = 'dashicons.woff';
    14191413
     1414        $woff_mime_type = 'application/font-woff';
     1415
     1416        /*
     1417         * As of PHP 8.1.12, which includes libmagic/file update to version 5.42,
     1418         * the expected mime type for WOFF files is 'font/woff'.
     1419         *
     1420         * See https://github.com/php/php-src/issues/8805.
     1421         */
     1422        if ( PHP_VERSION_ID >= 80112 ) {
     1423            $woff_mime_type = 'font/woff';
     1424        }
     1425
    14201426        $expected = array(
    14211427            'ext'             => 'woff',
    1422             'type'            => 'application/font-woff',
     1428            'type'            => $woff_mime_type,
    14231429            'proper_filename' => false,
    14241430        );
    14251431
    1426         add_filter( 'upload_mimes', array( $this, 'filter_mime_types_woff' ) );
     1432        add_filter(
     1433            'upload_mimes',
     1434            static function( $mimes ) use ( $woff_mime_type ) {
     1435                $mimes['woff'] = $woff_mime_type;
     1436                return $mimes;
     1437            }
     1438        );
     1439
    14271440        $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) );
    1428 
    1429         // Cleanup.
    1430         remove_filter( 'upload_mimes', array( $this, 'filter_mime_types_woff' ) );
    1431     }
    1432 
    1433     public function filter_mime_types_svg( $mimes ) {
    1434         $mimes['svg'] = 'image/svg+xml';
    1435         return $mimes;
    1436     }
    1437 
    1438     public function filter_mime_types_woff( $mimes ) {
    1439         $mimes['woff'] = 'application/font-woff';
    1440         return $mimes;
    14411441    }
    14421442
Note: See TracChangeset for help on using the changeset viewer.