Skip to content

Commit

Permalink
Add test for generate_and_enqueue_styles
Browse files Browse the repository at this point in the history
  • Loading branch information
zaguiini committed Mar 15, 2022
1 parent fc3c8e9 commit 74dd564
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions phpunit/class-wp-webfonts-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,24 +308,46 @@ public function test_validate_font() {
}

/**
* Test generate_and_enqueue_styles outputs only enqueued webfonts.
*
* @covers WP_Webfonts::generate_styles
*/
public function test_generate_styles() {
$font = 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_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_register_webfont( $font );
wp_webfonts()->generate_and_enqueue_styles();

$this->assertEquals(
'@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\');}',
wp_webfonts()->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' )
);
}
}

0 comments on commit 74dd564

Please sign in to comment.