Make WordPress Core

Changeset 55498


Ignore:
Timestamp:
03/09/2023 02:04:51 PM (3 years 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 desrosj, jrf, costdev, SergeyBiryukov.
Merges [55462] to the 5.9 branch.
Fixes #56817.

Location:
branches/5.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.9

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

    r52328 r55498  
    14441444                );
    14451445
    1446                 add_filter( 'upload_mimes', array( $this, 'filter_mime_types_svg' ) );
     1446                add_filter(
     1447                        'upload_mimes',
     1448                        static function( $mimes ) {
     1449                                $mimes['svg'] = 'image/svg+xml';
     1450                                return $mimes;
     1451                        }
     1452                );
     1453
    14471454                $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) );
    1448 
    1449                 // Cleanup.
    1450                 remove_filter( 'upload_mimes', array( $this, 'filter_mime_types_svg' ) );
    14511455        }
    14521456
     
    14601464                $filename = 'dashicons.woff';
    14611465
     1466                $woff_mime_type = 'application/font-woff';
     1467
     1468                /*
     1469                 * As of PHP 8.1.12, which includes libmagic/file update to version 5.42,
     1470                 * the expected mime type for WOFF files is 'font/woff'.
     1471                 *
     1472                 * See https://github.com/php/php-src/issues/8805.
     1473                 */
     1474                if ( PHP_VERSION_ID >= 80112 ) {
     1475                        $woff_mime_type = 'font/woff';
     1476                }
     1477
    14621478                $expected = array(
    14631479                        'ext'             => 'woff',
    1464                         'type'            => 'application/font-woff',
     1480                        'type'            => $woff_mime_type,
    14651481                        'proper_filename' => false,
    14661482                );
    14671483
    1468                 add_filter( 'upload_mimes', array( $this, 'filter_mime_types_woff' ) );
     1484                add_filter(
     1485                        'upload_mimes',
     1486                        static function( $mimes ) use ( $woff_mime_type ) {
     1487                                $mimes['woff'] = $woff_mime_type;
     1488                                return $mimes;
     1489                        }
     1490                );
     1491
    14691492                $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) );
    1470 
    1471                 // Cleanup.
    1472                 remove_filter( 'upload_mimes', array( $this, 'filter_mime_types_woff' ) );
    1473         }
    1474 
    1475         public function filter_mime_types_svg( $mimes ) {
    1476                 $mimes['svg'] = 'image/svg+xml';
    1477                 return $mimes;
    1478         }
    1479 
    1480         public function filter_mime_types_woff( $mimes ) {
    1481                 $mimes['woff'] = 'application/font-woff';
    1482                 return $mimes;
    14831493        }
    14841494
Note: See TracChangeset for help on using the changeset viewer.