Skip to content

Commit

Permalink
Make the mimetypes per php version private
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Feb 5, 2024
1 parent 2613c74 commit 2d1d9b2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 97 deletions.
14 changes: 6 additions & 8 deletions src/wp-includes/fonts/class-wp-font-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
}

Expand Down Expand Up @@ -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() );
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Test WP_Font_Library::set_allowed_mime_types().
*
* @package WordPress
* @subpackage Font Library
*
* @group fonts
* @group font-library
* @group toto
*
* @covers WP_Font_Library::set_allowed_mime_types
*/
class Tests_Fonts_WpFontLibrary_SetAllowedMimeTypes extends WP_Font_Library_UnitTestCase {

public function test_should_supply_correct_mime_type_for_php_version() {
$allowed_mime_types_per_php_version = array(
0 => array(

Check warning on line 18 in tests/phpunit/tests/fonts/font-library/wpFontLibrary/setAllowedMimeTypes.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 5 space(s) between "0" and double arrow, but found 1.
'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 );
}
}

0 comments on commit 2d1d9b2

Please sign in to comment.