Skip to content

Commit

Permalink
Tests for wp_print_font_faces().
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-vlasenko committed Jun 29, 2023
1 parent b699043 commit 72d3ecf
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 2 deletions.
4 changes: 2 additions & 2 deletions phpunit/fonts/wpFontFace/generateAndPrint-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public function set_up() {
/**
* @dataProvider data_test_generate_and_print
*
* @param array $fonts Prepared fonts (to store in WP_Fonts_Provider_Local::$fonts property).
* @param array $fonts Prepared fonts.
* @param string $expected Expected CSS.
*/
public function test_generate_and_print( array $fonts, $expected ) {
public function test_should_generate_and_print_passed_fonts( array $fonts, $expected ) {
$style_element = "<style id='wp-fonts-local' type='text/css'>\n%s\n</style>\n";
$expected_output = sprintf( $style_element, $expected );
$this->expectOutputString( $expected_output );
Expand Down
201 changes: 201 additions & 0 deletions phpunit/fonts/wpPrintFontFaces-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,205 @@
*/
class Tests_Fonts_WPPrintFontFaces extends WP_UnitTestCase {

/**
* @dataProvider data_test_wp_print_font_faces
*
* @param array $fonts Prepared fonts (to store in WP_Fonts_Provider_Local::$fonts property).
* @param string $expected Expected CSS.
*/
public function test_should_print_passed_fonts( array $fonts, $expected ) {
$style_element = "<style id='wp-fonts-local' type='text/css'>\n%s\n</style>\n";
$expected_output = sprintf( $style_element, $expected );
$this->expectOutputString( $expected_output );
wp_print_font_faces( $fonts );
}

/**
* Data provider.
*
* @return array
*/
public function data_test_wp_print_font_faces() {
return array(
'single truetype format font' => array(
'fonts' => array(
'Inter' =>
array(
array(
'src' =>
array(
'https://example.org/assets/fonts/inter/Inter-VariableFont_slnt,wght.ttf',
),
'font-family' => 'Inter',
'font-stretch' => 'normal',
'font-style' => 'normal',
'font-weight' => '200',
),
),
),
'expected' => <<<CSS
@font-face{font-family:Inter;font-style:normal;font-weight:200;font-display:fallback;src:url('https://example.org/assets/fonts/inter/Inter-VariableFont_slnt,wght.ttf') format('truetype');font-stretch:normal;}
CSS
,
),
'multiple truetype format fonts' => array(
'fonts' => array(
'Inter' =>
array(
array(
'src' =>
array(
'https://example.org/assets/fonts/inter/Inter-VariableFont_slnt,wght.ttf',
),
'font-family' => 'Inter',
'font-stretch' => 'normal',
'font-style' => 'normal',
'font-weight' => '200',
),
array(
'src' =>
array(
'https://example.org/assets/fonts/inter/Inter-VariableFont_slnt-Italic,wght.ttf',
),
'font-family' => 'Inter',
'font-stretch' => 'normal',
'font-style' => 'italic',
'font-weight' => '900',
),
),
),
'expected' => <<<CSS
@font-face{font-family:Inter;font-style:normal;font-weight:200;font-display:fallback;src:url('https://example.org/assets/fonts/inter/Inter-VariableFont_slnt,wght.ttf') format('truetype');font-stretch:normal;}
@font-face{font-family:Inter;font-style:italic;font-weight:900;font-display:fallback;src:url('https://example.org/assets/fonts/inter/Inter-VariableFont_slnt-Italic,wght.ttf') format('truetype');font-stretch:normal;}
CSS
,
),
'single woff2 format font' => array(
'fonts' => array(
'DM Sans' =>
array(
array(
'src' =>
array(
'https://example.org/assets/fonts/dm-sans/DMSans-Regular.woff2',
),
'font-family' => 'DM Sans',
'font-stretch' => 'normal',
'font-style' => 'normal',
'font-weight' => '400',
),
),
),
'expected' => <<<CSS
@font-face{font-family:"DM Sans";font-style:normal;font-weight:400;font-display:fallback;src:url('https://example.org/assets/fonts/dm-sans/DMSans-Regular.woff2') format('woff2');font-stretch:normal;}
CSS
,
),
'multiple woff2 format fonts' => array(
'fonts' => array(
'DM Sans' =>
array(
array(
'src' =>
array(
'https://example.org/assets/fonts/dm-sans/DMSans-Regular.woff2',
),
'font-family' => 'DM Sans',
'font-stretch' => 'normal',
'font-style' => 'normal',
'font-weight' => '400',
),
array(
'src' =>
array(
'https://example.org/assets/fonts/dm-sans/DMSans-Regular-Italic.woff2',
),
'font-family' => 'DM Sans',
'font-stretch' => 'normal',
'font-style' => 'italic',
'font-weight' => '400',
),
array(
'src' =>
array(
'https://example.org/assets/fonts/dm-sans/DMSans-Bold.woff2',
),
'font-family' => 'DM Sans',
'font-stretch' => 'normal',
'font-style' => 'normal',
'font-weight' => '700',
),
array(
'src' =>
array(
'https://example.org/assets/fonts/dm-sans/DMSans-Bold-Italic.woff2',
),
'font-family' => 'DM Sans',
'font-stretch' => 'normal',
'font-style' => 'italic',
'font-weight' => '700',
),
),
'IBM Plex Mono' =>
array(
array(
'src' =>
array(
'https://example.org/assets/fonts/ibm-plex-mono/IBMPlexMono-Light.woff2',
),
'font-family' => 'IBM Plex Mono',
'font-display' => 'block',
'font-stretch' => 'normal',
'font-style' => 'normal',
'font-weight' => '300',
),
array(
'src' =>
array(
'https://example.org/assets/fonts/ibm-plex-mono/IBMPlexMono-Regular.woff2',
),
'font-family' => 'IBM Plex Mono',
'font-display' => 'block',
'font-stretch' => 'normal',
'font-style' => 'normal',
'font-weight' => '400',
),
array(
'src' =>
array(
'https://example.org/assets/fonts/ibm-plex-mono/IBMPlexMono-Italic.woff2',
),
'font-family' => 'IBM Plex Mono',
'font-display' => 'block',
'font-stretch' => 'normal',
'font-style' => 'italic',
'font-weight' => '400',
),
array(
'src' =>
array(
'https://example.org/assets/fonts/ibm-plex-mono/IBMPlexMono-Bold.woff2',
),
'font-family' => 'IBM Plex Mono',
'font-display' => 'block',
'font-stretch' => 'normal',
'font-style' => 'normal',
'font-weight' => '700',
),
),
),
'expected' => <<<CSS
@font-face{font-family:"DM Sans";font-style:normal;font-weight:400;font-display:fallback;src:url('https://example.org/assets/fonts/dm-sans/DMSans-Regular.woff2') format('woff2');font-stretch:normal;}
@font-face{font-family:"DM Sans";font-style:italic;font-weight:400;font-display:fallback;src:url('https://example.org/assets/fonts/dm-sans/DMSans-Regular-Italic.woff2') format('woff2');font-stretch:normal;}
@font-face{font-family:"DM Sans";font-style:normal;font-weight:700;font-display:fallback;src:url('https://example.org/assets/fonts/dm-sans/DMSans-Bold.woff2') format('woff2');font-stretch:normal;}
@font-face{font-family:"DM Sans";font-style:italic;font-weight:700;font-display:fallback;src:url('https://example.org/assets/fonts/dm-sans/DMSans-Bold-Italic.woff2') format('woff2');font-stretch:normal;}
@font-face{font-family:"IBM Plex Mono";font-style:normal;font-weight:300;font-display:block;src:url('https://example.org/assets/fonts/ibm-plex-mono/IBMPlexMono-Light.woff2') format('woff2');font-stretch:normal;}
@font-face{font-family:"IBM Plex Mono";font-style:normal;font-weight:400;font-display:block;src:url('https://example.org/assets/fonts/ibm-plex-mono/IBMPlexMono-Regular.woff2') format('woff2');font-stretch:normal;}
@font-face{font-family:"IBM Plex Mono";font-style:italic;font-weight:400;font-display:block;src:url('https://example.org/assets/fonts/ibm-plex-mono/IBMPlexMono-Italic.woff2') format('woff2');font-stretch:normal;}
@font-face{font-family:"IBM Plex Mono";font-style:normal;font-weight:700;font-display:block;src:url('https://example.org/assets/fonts/ibm-plex-mono/IBMPlexMono-Bold.woff2') format('woff2');font-stretch:normal;}
CSS
,
),
);
}
}

0 comments on commit 72d3ecf

Please sign in to comment.