mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Editor: Load all style variation fonts within the editors.
Loads the font family files from style variations defined within a theme for user in the site and post editors. This is to ensure the fonts are shown while editing without the need for a reload after switching styles. Props ironprogrammer, mmaattiiaass. Fixes #62231. git-svn-id: https://develop.svn.wordpress.org/trunk@59260 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
1 parent
281a68f
commit ba47208
Showing
7 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
tests/phpunit/tests/fonts/font-face/wpFontFaceResolver/getFontsFromStyleVariations.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* Test case for WP_Font_Face_Resolver::get_fonts_from_style_variations(). | ||
* | ||
* @package WordPress | ||
* @subpackage Fonts | ||
* | ||
* @since 6.7.0 | ||
* | ||
* @group fonts | ||
* @group fontface | ||
* | ||
* @covers WP_Font_Face_Resolver::get_fonts_from_style_variations | ||
*/ | ||
class Tests_Fonts_WPFontFaceResolver_GetFontsFromStyleVariations extends WP_Font_Face_UnitTestCase { | ||
const FONTS_THEME = 'fonts-block-theme'; | ||
|
||
public static function set_up_before_class() { | ||
self::$requires_switch_theme_fixtures = true; | ||
|
||
parent::set_up_before_class(); | ||
} | ||
|
||
/** | ||
* Ensure that an empty array is returned when the theme has no style variations. | ||
* | ||
* @ticket 62231 | ||
*/ | ||
public function test_should_return_empty_array_when_theme_has_no_style_variations() { | ||
switch_theme( 'block-theme' ); | ||
|
||
$fonts = WP_Font_Face_Resolver::get_fonts_from_style_variations(); | ||
$this->assertIsArray( $fonts, 'Should return an array data type' ); | ||
$this->assertEmpty( $fonts, 'Should return an empty array' ); | ||
} | ||
|
||
/** | ||
* Ensure that all variations are loaded from a theme. | ||
* | ||
* @ticket 62231 | ||
*/ | ||
public function test_should_return_all_fonts_from_all_style_variations() { | ||
switch_theme( static::FONTS_THEME ); | ||
|
||
$actual = WP_Font_Face_Resolver::get_fonts_from_style_variations(); | ||
$expected = self::get_custom_style_variations( 'expected' ); | ||
|
||
$this->assertSame( $expected, $actual, 'All the fonts from the theme variations should be returned.' ); | ||
} | ||
|
||
/** | ||
* Ensure that file:./ is replaced in the src list. | ||
* | ||
* @ticket 62231 | ||
*/ | ||
public function test_should_replace_src_file_placeholder() { | ||
switch_theme( static::FONTS_THEME ); | ||
|
||
$fonts = WP_Font_Face_Resolver::get_fonts_from_style_variations(); | ||
|
||
// Check that the there is no theme relative url in the src list. | ||
foreach ( $fonts as $family ) { | ||
foreach ( $family as $font ) { | ||
foreach ( $font['src'] as $src ) { | ||
$src_basename = basename( $src ); | ||
$this->assertStringNotContainsString( 'file:./', $src, "Font $src_basename should not contain the 'file:./' placeholder" ); | ||
} | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
tests/phpunit/tests/fonts/font-face/wpPrintFontFacesFromStyleVariations.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* Test case for wp_print_font_faces_from_style_variations(). | ||
* | ||
* @package WordPress | ||
* @subpackage Fonts | ||
* | ||
* @since 6.7.0 | ||
* | ||
* @group fonts | ||
* @group fontface | ||
* | ||
* @covers wp_print_font_faces_from_style_variations | ||
*/ | ||
class Tests_Fonts_WpPrintFontFacesFromStyleVariations extends WP_Font_Face_UnitTestCase { | ||
const FONTS_THEME = 'fonts-block-theme'; | ||
|
||
public static function set_up_before_class() { | ||
parent::set_up_before_class(); | ||
self::$requires_switch_theme_fixtures = true; | ||
} | ||
|
||
/** | ||
* Ensure that no fonts are printed when the theme has no fonts. | ||
* | ||
* @ticket 62231 | ||
*/ | ||
public function test_should_not_print_when_no_fonts() { | ||
switch_theme( 'block-theme' ); | ||
|
||
$this->expectOutputString( '' ); | ||
wp_print_font_faces_from_style_variations(); | ||
} | ||
|
||
/** | ||
* Ensure that all fonts are printed from the theme style variations. | ||
* | ||
* @ticket 62231 | ||
*/ | ||
public function test_should_print_fonts_in_style_variations() { | ||
switch_theme( static::FONTS_THEME ); | ||
|
||
$expected = $this->get_custom_style_variations( 'expected_styles' ); | ||
$expected_output = $this->get_expected_styles_output( $expected ); | ||
|
||
$this->expectOutputString( $expected_output ); | ||
wp_print_font_faces_from_style_variations(); | ||
} | ||
|
||
private function get_expected_styles_output( $styles ) { | ||
$style_element = "<style class='wp-fonts-local' type='text/css'>\n%s\n</style>\n"; | ||
return sprintf( $style_element, $styles ); | ||
} | ||
} |