Skip to content

Commit

Permalink
Add test for generate_and_enqueue_editor_styles
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyip authored and zaguiini committed Mar 15, 2022
1 parent 74dd564 commit 7b4900a
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions phpunit/class-wp-webfonts-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,51 @@ public function test_generate_styles() {

$expected = <<<EOF
@font-face{font-family:"Source Serif Pro";font-style:normal;font-weight:200 900;font-display:fallback;font-stretch:normal;src:local("Source Serif Pro"), url('https://example.com/assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2') format('woff2');}
EOF;

$this->assertContains(
$expected,
get_echo( 'wp_print_styles' )
);
}

/**
* Test generate_and_enqueue_editor_styles outputs registered and enqueued webfonts.
* Both are necessary so the editor correctly loads webfonts picked while in the editor.
*
* @covers WP_Webfonts::generate_and_enqueue_editor_styles
*/
public function test_generate_and_enqueue_editor_styles() {
wp_register_webfont(
'source-serif-pro-200-900-italic-local',
array(
'provider' => 'local',
'font-family' => 'Source Serif Pro',
'font-style' => 'italic',
'font-weight' => '200 900',
'font-stretch' => 'normal',
'src' => 'https://example.com/assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2',
'font-display' => 'fallback',
)
);

wp_enqueue_webfont(
'source-serif-pro-200-900-normal-local', // This is different from the webfont registered above.
array(
'provider' => 'local',
'font-family' => 'Source Serif Pro',
'font-style' => 'normal',
'font-weight' => '200 900',
'font-stretch' => 'normal',
'src' => 'https://example.com/assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2',
'font-display' => 'fallback',
)
);

wp_webfonts()->generate_and_enqueue_editor_styles();

$expected = <<<EOF
@font-face{font-family:"Source Serif Pro";font-style:italic;font-weight:200 900;font-display:fallback;font-stretch:normal;src:local("Source Serif Pro"), url('https://example.com/assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2') format('woff2');}@font-face{font-family:"Source Serif Pro";font-style:normal;font-weight:200 900;font-display:fallback;font-stretch:normal;src:local("Source Serif Pro"), url('https://example.com/assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2') format('woff2');}
EOF;

$this->assertContains(
Expand Down

0 comments on commit 7b4900a

Please sign in to comment.