diff --git a/src/wp-includes/fonts/class-wp-font-library.php b/src/wp-includes/fonts/class-wp-font-library.php index 3e48a1d797b6b..c863ca1c7ca5c 100644 --- a/src/wp-includes/fonts/class-wp-font-library.php +++ b/src/wp-includes/fonts/class-wp-font-library.php @@ -23,19 +23,17 @@ class WP_Font_Library { * * @since 6.5.0 * - * @param array $php_version_id The version of PHP to provide mime types for. The default is the current PHP version. - * * @return Array A collection of mime types keyed by file extension. */ - public static function get_expected_font_mime_types_per_php_version( $php_version_id = PHP_VERSION_ID ) { + private static function get_expected_font_mime_types_for_php_version() { - $php_7_ttf_mime_type = $php_version_id >= 70300 ? 'application/font-sfnt' : 'application/x-font-ttf'; + $php_7_ttf_mime_type = PHP_VERSION_ID >= 70300 ? 'application/font-sfnt' : 'application/x-font-ttf'; return array( 'otf' => 'application/vnd.ms-opentype', - 'ttf' => $php_version_id >= 70400 ? 'font/sfnt' : $php_7_ttf_mime_type, - 'woff' => $php_version_id >= 80100 ? 'font/woff' : 'application/font-woff', - 'woff2' => $php_version_id >= 80100 ? 'font/woff2' : 'application/font-woff2', + 'ttf' => PHP_VERSION_ID >= 70400 ? 'font/sfnt' : $php_7_ttf_mime_type, + 'woff' => PHP_VERSION_ID >= 80100 ? 'font/woff' : 'application/font-woff', + 'woff2' => PHP_VERSION_ID >= 80100 ? 'font/woff2' : 'application/font-woff2', ); } @@ -150,6 +148,6 @@ public static function get_font_collection( $slug ) { * @return array Modified upload directory. */ public static function set_allowed_mime_types( $mime_types ) { - return array_merge( $mime_types, self::get_expected_font_mime_types_per_php_version() ); + return array_merge( $mime_types, self::get_expected_font_mime_types_for_php_version() ); } } diff --git a/tests/phpunit/tests/fonts/font-library/wpFontLibrary/getMimeTypes.php b/tests/phpunit/tests/fonts/font-library/wpFontLibrary/getMimeTypes.php deleted file mode 100644 index 4fb97e754611f..0000000000000 --- a/tests/phpunit/tests/fonts/font-library/wpFontLibrary/getMimeTypes.php +++ /dev/null @@ -1,89 +0,0 @@ -assertSame( $expected, $mimes ); - } - - /** - * Data provider. - * - * @return array - */ - public function data_should_supply_correct_mime_type_for_php_version() { - return array( - 'version 7.2' => array( - 'php_version_id' => 70200, - 'expected' => array( - 'otf' => 'application/vnd.ms-opentype', - 'ttf' => 'application/x-font-ttf', - 'woff' => 'application/font-woff', - 'woff2' => 'application/font-woff2', - ), - ), - 'version 7.3' => array( - 'php_version_id' => 70300, - 'expected' => array( - 'otf' => 'application/vnd.ms-opentype', - 'ttf' => 'application/font-sfnt', - 'woff' => 'application/font-woff', - 'woff2' => 'application/font-woff2', - ), - ), - 'version 7.4' => array( - 'php_version_id' => 70400, - 'expected' => array( - 'otf' => 'application/vnd.ms-opentype', - 'ttf' => 'font/sfnt', - 'woff' => 'application/font-woff', - 'woff2' => 'application/font-woff2', - ), - ), - 'version 8.0' => array( - 'php_version_id' => 80000, - 'expected' => array( - 'otf' => 'application/vnd.ms-opentype', - 'ttf' => 'font/sfnt', - 'woff' => 'application/font-woff', - 'woff2' => 'application/font-woff2', - ), - ), - 'version 8.1' => array( - 'php_version_id' => 80100, - 'expected' => array( - 'otf' => 'application/vnd.ms-opentype', - 'ttf' => 'font/sfnt', - 'woff' => 'font/woff', - 'woff2' => 'font/woff2', - ), - ), - 'version 8.2' => array( - 'php_version_id' => 80200, - 'expected' => array( - 'otf' => 'application/vnd.ms-opentype', - 'ttf' => 'font/sfnt', - 'woff' => 'font/woff', - 'woff2' => 'font/woff2', - ), - ), - ); - } -} diff --git a/tests/phpunit/tests/fonts/font-library/wpFontLibrary/setAllowedMimeTypes.php b/tests/phpunit/tests/fonts/font-library/wpFontLibrary/setAllowedMimeTypes.php new file mode 100644 index 0000000000000..a4542b06a2453 --- /dev/null +++ b/tests/phpunit/tests/fonts/font-library/wpFontLibrary/setAllowedMimeTypes.php @@ -0,0 +1,52 @@ + array( + 'otf' => 'application/vnd.ms-opentype', + 'ttf' => 'application/x-font-ttf', + 'woff' => 'application/font-woff', + 'woff2' => 'application/font-woff2', + ), + 70300 => array( + 'otf' => 'application/vnd.ms-opentype', + 'ttf' => 'application/font-sfnt', + 'woff' => 'application/font-woff', + 'woff2' => 'application/font-woff2', + ), + 70400 => array( + 'otf' => 'application/vnd.ms-opentype', + 'ttf' => 'font/sfnt', + 'woff' => 'application/font-woff', + 'woff2' => 'application/font-woff2', + ), + 80100 => array( + 'otf' => 'application/vnd.ms-opentype', + 'ttf' => 'font/sfnt', + 'woff' => 'font/woff', + 'woff2' => 'font/woff2', + ), + ); + foreach ( $allowed_mime_types_per_php_version as $php_version => $current_mime_types ) { + if ( $php_version < PHP_VERSION_ID ) { + $expected = $current_mime_types; + } + } + + $mimes = WP_Font_Library::set_allowed_mime_types( array() ); + $this->assertSame( $expected, $mimes ); + } +}