diff --git a/phpunit/tests/fonts/font-library/wpRestFontLibraryController/installFonts.php b/phpunit/tests/fonts/font-library/wpRestFontLibraryController/installFonts.php index 8b8ec28406ac1d..5edcf054e2d025 100644 --- a/phpunit/tests/fonts/font-library/wpRestFontLibraryController/installFonts.php +++ b/phpunit/tests/fonts/font-library/wpRestFontLibraryController/installFonts.php @@ -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(), + ), + ); + } }