From d7c458f866e844227f2199e61bcf238cb38ac6d1 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 6 Mar 2023 12:39:18 +0000 Subject: [PATCH] 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: * [https://github.com/php/php-src/issues/8805 php-src: #8805: finfo returns wrong mime type for woff/woff2 files] * [https://www.php.net/ChangeLog-8.php#8.1.12 PHP 8.1.12 changelog] Follow-up to [40124], [54508], [54509], [54724]. Props costdev, SergeyBiryukov. Fixes #56817. git-svn-id: https://develop.svn.wordpress.org/trunk@55462 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/functions.php | 58 +++++++++++++++---------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 7e4a9189f5..79cb9c233d 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -1391,11 +1391,15 @@ class Tests_Functions extends WP_UnitTestCase { 'proper_filename' => false, ); - add_filter( 'upload_mimes', array( $this, 'filter_mime_types_svg' ) ); - $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); + add_filter( + 'upload_mimes', + static function( $mimes ) { + $mimes['svg'] = 'image/svg+xml'; + return $mimes; + } + ); - // Cleanup. - remove_filter( 'upload_mimes', array( $this, 'filter_mime_types_svg' ) ); + $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); } /** @@ -1404,40 +1408,36 @@ class Tests_Functions extends WP_UnitTestCase { * @requires extension fileinfo */ public function test_wp_check_filetype_and_ext_with_filtered_woff() { - if ( PHP_VERSION_ID >= 80100 ) { - /* - * For the time being, this test is marked skipped on PHP 8.1+ as a recent change introduced - * an inconsistency with how the mime-type for WOFF files are handled compared to older versions. - * - * See https://core.trac.wordpress.org/ticket/56817 for more details. - */ - $this->markTestSkipped( 'This test currently fails on PHP 8.1+ and requires further investigation.' ); - } - $file = DIR_TESTDATA . '/uploads/dashicons.woff'; $filename = 'dashicons.woff'; + $woff_mime_type = 'application/font-woff'; + + /* + * As of PHP 8.1.12, which includes libmagic/file update to version 5.42, + * the expected mime type for WOFF files is 'font/woff'. + * + * See https://github.com/php/php-src/issues/8805. + */ + if ( PHP_VERSION_ID >= 80112 ) { + $woff_mime_type = 'font/woff'; + } + $expected = array( 'ext' => 'woff', - 'type' => 'application/font-woff', + 'type' => $woff_mime_type, 'proper_filename' => false, ); - add_filter( 'upload_mimes', array( $this, 'filter_mime_types_woff' ) ); + add_filter( + 'upload_mimes', + static function( $mimes ) use ( $woff_mime_type ) { + $mimes['woff'] = $woff_mime_type; + return $mimes; + } + ); + $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); - - // Cleanup. - remove_filter( 'upload_mimes', array( $this, 'filter_mime_types_woff' ) ); - } - - public function filter_mime_types_svg( $mimes ) { - $mimes['svg'] = 'image/svg+xml'; - return $mimes; - } - - public function filter_mime_types_woff( $mimes ) { - $mimes['woff'] = 'application/font-woff'; - return $mimes; } /**