Changeset 57720 for trunk/tests/phpunit/tests/fonts/font-face/wpFontFaceResolver/getFontsFromThemeJson.php
- Timestamp:
- 02/27/2024 12:04:55 PM (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/fonts/font-face/wpFontFaceResolver/getFontsFromThemeJson.php
r56688 r57720 39 39 40 40 /** 41 * @ticket 60605 42 */ 43 public function test_should_return_all_fonts_from_all_theme_origins() { 44 switch_theme( static::FONTS_THEME ); 45 46 $add_custom_fonts = static function ( $theme_json_data ) { 47 $data = $theme_json_data->get_data(); 48 // Add font families to the custom origin of theme json. 49 $data['settings']['typography']['fontFamilies']['custom'] = self::get_custom_font_families( 'input' ); 50 return new WP_Theme_JSON_Data( $data ); 51 }; 52 53 add_filter( 'wp_theme_json_data_theme', $add_custom_fonts ); 54 $actual = WP_Font_Face_Resolver::get_fonts_from_theme_json(); 55 remove_filter( 'wp_theme_json_data_theme', $add_custom_fonts ); 56 57 $expected = array_merge( 58 $this->get_expected_fonts_for_fonts_block_theme( 'fonts' ), 59 $this->get_custom_font_families( 'expected' ) 60 ); 61 62 $this->assertSame( $expected, $actual, 'Both the fonts from the theme and the custom origin should be returned.' ); 63 } 64 65 /** 41 66 * @dataProvider data_should_replace_src_file_placeholder 42 67 * 43 68 * @param string $font_name Font's name. 44 * @param string $font_index Font's index in the $fonts array. 69 * @param string $font_weight Font's weight. 70 * @param string $font_style Font's style. 45 71 * @param string $expected Expected src. 46 72 */ 47 public function test_should_replace_src_file_placeholder( $font_name, $font_ index, $expected ) {73 public function test_should_replace_src_file_placeholder( $font_name, $font_weight, $font_style, $expected ) { 48 74 switch_theme( static::FONTS_THEME ); 49 75 50 76 $fonts = WP_Font_Face_Resolver::get_fonts_from_theme_json(); 51 52 $actual = $fonts[ $font_name ][ $font_index ]['src'][0]; 77 $fonts = array_merge( array(), ...array_map( 'array_values', $fonts ) ); 78 79 $font = array_filter( 80 $fonts, 81 static function ( $font ) use ( $font_name, $font_weight, $font_style ) { 82 return $font['font-family'] === $font_name 83 && $font['font-weight'] === $font_weight 84 && $font['font-style'] === $font_style; 85 } 86 ); 87 88 $font = reset( $font ); 89 53 90 $expected = get_stylesheet_directory_uri() . $expected; 91 $actual = $font['src'][0]; 54 92 55 93 $this->assertStringNotContainsString( 'file:./', $actual, 'Font src should not contain the "file:./" placeholder' ); … … 66 104 // Theme's theme.json. 67 105 'DM Sans: 400 normal' => array( 68 'font_name' => 'DM Sans', 69 'font_index' => 0, 70 'expected' => '/assets/fonts/dm-sans/DMSans-Regular.woff2', 106 'font_name' => 'DM Sans', 107 'font_weight' => '400', 108 'font_style' => 'normal', 109 'expected' => '/assets/fonts/dm-sans/DMSans-Regular.woff2', 71 110 ), 72 111 'DM Sans: 400 italic' => array( 73 'font_name' => 'DM Sans', 74 'font_index' => 1, 75 'expected' => '/assets/fonts/dm-sans/DMSans-Regular-Italic.woff2', 112 'font_name' => 'DM Sans', 113 'font_weight' => '400', 114 'font_style' => 'italic', 115 'expected' => '/assets/fonts/dm-sans/DMSans-Regular-Italic.woff2', 76 116 ), 77 117 'DM Sans: 700 normal' => array( 78 'font_name' => 'DM Sans', 79 'font_index' => 2, 80 'expected' => '/assets/fonts/dm-sans/DMSans-Bold.woff2', 118 'font_name' => 'DM Sans', 119 'font_weight' => '700', 120 'font_style' => 'normal', 121 'expected' => '/assets/fonts/dm-sans/DMSans-Bold.woff2', 81 122 ), 82 123 'DM Sans: 700 italic' => array( 83 'font_name' => 'DM Sans', 84 'font_index' => 3, 85 'expected' => '/assets/fonts/dm-sans/DMSans-Bold-Italic.woff2', 124 'font_name' => 'DM Sans', 125 'font_weight' => '700', 126 'font_style' => 'italic', 127 'expected' => '/assets/fonts/dm-sans/DMSans-Bold-Italic.woff2', 86 128 ), 87 129 'Source Serif Pro: 200-900 normal' => array( 88 'font_name' => 'Source Serif Pro', 89 'font_index' => 0, 90 'expected' => '/assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2', 130 'font_name' => 'Source Serif Pro', 131 'font_weight' => '200 900', 132 'font_style' => 'normal', 133 'expected' => '/assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2', 91 134 ), 92 135 'Source Serif Pro: 200-900 italic' => array( 93 'font_name' => 'Source Serif Pro', 94 'font_index' => 1, 95 'expected' => '/assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2', 136 'font_name' => 'Source Serif Pro', 137 'font_weight' => '200 900', 138 'font_style' => 'italic', 139 'expected' => '/assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2', 96 140 ), 97 141 ); … … 119 163 remove_filter( 'wp_theme_json_data_theme', $replace_fonts ); 120 164 121 $this->assertArrayHasKey( $expected_name, $fonts ); 165 // flatten the array to make it easier to test. 166 $fonts = array_merge( array(), ...array_map( 'array_values', $fonts ) ); 167 168 $fonts_found = array_filter( 169 $fonts, 170 function ( $font ) use ( $expected_name ) { 171 return $font['font-family'] === $expected_name; 172 } 173 ); 174 175 $this->assertNotEmpty( $fonts_found, 'Expected font-family name not found in the array' ); 122 176 } 123 177
Note: See TracChangeset
for help on using the changeset viewer.