Skip to content

Commit 5c9b321

Browse files
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: * [php/php-src#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 desrosj, jrf, costdev, SergeyBiryukov. Merges [55462] to the 5.9 branch. Fixes #56817. git-svn-id: https://develop.svn.wordpress.org/branches/5.9@55498 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 88b0e2f commit 5c9b321

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

tests/phpunit/tests/functions.php

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,11 +1443,15 @@ public function test_wp_check_filetype_and_ext_with_filtered_svg() {
14431443
'proper_filename' => false,
14441444
);
14451445

1446-
add_filter( 'upload_mimes', array( $this, 'filter_mime_types_svg' ) );
1447-
$this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) );
1446+
add_filter(
1447+
'upload_mimes',
1448+
static function( $mimes ) {
1449+
$mimes['svg'] = 'image/svg+xml';
1450+
return $mimes;
1451+
}
1452+
);
14481453

1449-
// Cleanup.
1450-
remove_filter( 'upload_mimes', array( $this, 'filter_mime_types_svg' ) );
1454+
$this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) );
14511455
}
14521456

14531457
/**
@@ -1459,27 +1463,33 @@ public function test_wp_check_filetype_and_ext_with_filtered_woff() {
14591463
$file = DIR_TESTDATA . '/uploads/dashicons.woff';
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' ) );
1469-
$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-
}
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+
);
14791491

1480-
public function filter_mime_types_woff( $mimes ) {
1481-
$mimes['woff'] = 'application/font-woff';
1482-
return $mimes;
1492+
$this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) );
14831493
}
14841494

14851495
/**

0 commit comments

Comments
 (0)