Skip to content

Commit

Permalink
Add test for duplicate font face files.
Browse files Browse the repository at this point in the history
  • Loading branch information
jffng committed Sep 14, 2023
1 parent 9f9ca19 commit 83bff3d
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,60 @@ public function data_install_with_improper_inputs() {
),
);
}

/**
* Tests that duplicate font faces with same font style and weight but different file extensions are merged.
*
* @dataProvider data_install_with_duplicate_font_faces
* @param array $font_families Font families to install in theme.json format.
* @param array $files Font files to install.
*/
public function test_install_with_duplicate_font_faces( $font_families, $files = array() ) {
$install_request = new WP_REST_Request( 'POST', '/wp/v2/fonts' );
$font_families_json = json_encode( $font_families );
$install_request->set_param( 'fontFamilies', $font_families_json );
$install_request->set_file_params( $files );

$response = rest_get_server()->dispatch( $install_request );
$this->assertSame( 200, $response->get_status() );
$data = $response->get_data();

$this->assertCount( 1, $data[0]['fontFace'], 'Duplicate font faces were not removed / added incorrectly.' );
$this->assertSame( 'http://example.com/fonts/piazzolla_400_italic.ttf', $data[0]['fontFace'][0]['src'], 'The src attribute does not match the expected font file' );
}

/**
* Data provider for test_install_with_duplicate_font_faces
*/
public function data_install_with_duplicate_font_faces() {
return array(
'with duplicate font faces' => array(
'font_families' => array(
array(
'fontFamily' => 'Piazzolla',
'slug' => 'piazzolla',
'name' => 'Piazzolla',
'fontFace' => array(
array(
'fontFamily' => 'Piazzolla',
'fontStyle' => 'italic',
'fontWeight' => '400',
'src' => 'http://example.com/fonts/piazzolla_400_italic.ttf',
'downloadFromUrl' => 'http://example.com/fonts/piazzolla_400_italic.ttf',
),
array(
'fontFamily' => 'Piazzolla',
'fontStyle' => 'italic',
'fontWeight' => '400',
'src' => 'http://example.com/fonts/piazzolla_400_italic.woff',
'downloadFromUrl' => 'http://example.com/fonts/piazzolla_400_italic.woff',
),
),
),
),
'files' => array(),
),
);
}
}

0 comments on commit 83bff3d

Please sign in to comment.