Skip to content

Commit

Permalink
Move tests into existing test.
Browse files Browse the repository at this point in the history
To avoid reflection issues on different PHP versions and
potential contributor confusion, merging the new tests into
the existing test.
  • Loading branch information
hellofromtonya committed Sep 19, 2023
1 parent 5689b53 commit 370caf0
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 140 deletions.
140 changes: 0 additions & 140 deletions phpunit/tests/fonts/font-face/wpFontFaceResolver/getFontFamilyName.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,108 @@ public function data_should_replace_src_file_placeholder() {
),
);
}

/**
* @dataProvider data_should_get_font_family_name
*
* @param array $fonts Fonts to test.
* @param string $expected_name Expected font-family name.
*/
public function test_should_get_font_family_name( $fonts, $expected_name ) {
switch_theme( static::FONTS_THEME );

$replace_fonts = static function ( $theme_json_data ) use ( $fonts ) {
$data = $theme_json_data->get_data();

// Replace typography.fontFamilies.
$data['settings']['typography']['fontFamilies']['theme'] = $fonts;

return new WP_Theme_JSON_Data_Gutenberg( $data );
};
add_filter( 'wp_theme_json_data_theme', $replace_fonts );
$fonts = WP_Font_Face_Resolver::get_fonts_from_theme_json();
remove_filter( 'wp_theme_json_data_theme', $replace_fonts );

$this->assertArrayHasKey( $expected_name, $fonts );
}

/**
* Data provider.
*
* @return array
*/
public function data_should_get_font_family_name() {
$font_face = array(
array(
'fontFamily' => 'DM Sans',
'fontStretch' => 'normal',
'fontStyle' => 'normal',
'fontWeight' => '400',
'src' => array(
'file:./assets/fonts/dm-sans/DMSans-Regular.woff2',
),
),
array(
'fontFamily' => 'DM Sans',
'fontStretch' => 'normal',
'fontStyle' => 'italic',
'fontWeight' => '400',
'src' => array(
'file:./assets/fonts/dm-sans/DMSans-Regular-Italic.woff2',
),
),
array(
'fontFamily' => 'DM Sans',
'fontStretch' => 'normal',
'fontStyle' => 'italic',
'fontWeight' => '700',
'src' => array(
'file:./assets/fonts/dm-sans/DMSans-Bold.woff2',
),
),
array(
'fontFamily' => 'DM Sans',
'fontStretch' => 'normal',
'fontStyle' => 'italic',
'fontWeight' => '700',
'src' => array(
'file:./assets/fonts/dm-sans/DMSans-Bold-Italic.woff2',
),
),
);

return array(
'name declared' => array(
'fonts' => array(
array(
'fontFamily' => 'DM Sans',
'name' => 'DM Sans',
'slug' => 'dm-sans',
'fontFace' => $font_face,
),
),
'expected_name' => 'DM Sans',
),
'name not declared' => array(
'fonts' => array(
array(
'fontFamily' => 'DM Sans',
'slug' => 'dm-sans',
'fontFace' => $font_face,
),
),
'expected_name' => 'DM Sans',
),
'fontFamily comma-separated list' => array(
'fonts' => array(
array(
'fontFamily' => 'DM Sans, sans-serif',
'slug' => 'dm-sans',
'fontFace' => $font_face,
),
),
'expected_name' => 'DM Sans',
),
);
}
}

0 comments on commit 370caf0

Please sign in to comment.