From 67454a06c2fcddebe90b5ffafab52535651589db Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Wed, 16 Aug 2023 13:17:09 -0500 Subject: [PATCH] Font Library: Test improvements (#53702) * Splits the tests into 1 test file per public method. * Adds tests where needed for improved coverage. * Splits happy and unhappy paths into separate test methods and data providers. --------- Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- .../class-wp-font-family-test.php | 340 ------------------ .../class-wp-fonts-library-test.php | 52 --- .../wpFontFamily/__construct-test.php | 62 ++++ phpunit/fonts-library/wpFontFamily/base.php | 75 ++++ .../wpFontFamily/getData-test.php | 94 +++++ .../wpFontFamily/getDataAsJson-test.php | 67 ++++ .../wpFontFamily/getFontPost-test.php | 42 +++ .../wpFontFamily/hasFontFaces-test.php | 78 ++++ .../wpFontFamily/install-test.php | 248 +++++++++++++ .../wpFontFamily/uninstall-test.php | 194 ++++++++++ .../getFilenameFromFontFace-test.php | 64 ++++ .../hasFontMimeType-test.php | 61 ++++ .../mergeFontsData-test.php} | 188 +++------- .../wpFontsLibrary/getFontsDir-test.php | 18 + .../wpFontsLibrary/setUploadDir-test.php | 30 ++ 15 files changed, 1084 insertions(+), 529 deletions(-) delete mode 100644 phpunit/fonts-library/class-wp-font-family-test.php delete mode 100644 phpunit/fonts-library/class-wp-fonts-library-test.php create mode 100644 phpunit/fonts-library/wpFontFamily/__construct-test.php create mode 100644 phpunit/fonts-library/wpFontFamily/base.php create mode 100644 phpunit/fonts-library/wpFontFamily/getData-test.php create mode 100644 phpunit/fonts-library/wpFontFamily/getDataAsJson-test.php create mode 100644 phpunit/fonts-library/wpFontFamily/getFontPost-test.php create mode 100644 phpunit/fonts-library/wpFontFamily/hasFontFaces-test.php create mode 100644 phpunit/fonts-library/wpFontFamily/install-test.php create mode 100644 phpunit/fonts-library/wpFontFamily/uninstall-test.php create mode 100644 phpunit/fonts-library/wpFontFamilyUtils/getFilenameFromFontFace-test.php create mode 100644 phpunit/fonts-library/wpFontFamilyUtils/hasFontMimeType-test.php rename phpunit/fonts-library/{class-wp-font-family-utils-test.php => wpFontFamilyUtils/mergeFontsData-test.php} (59%) create mode 100644 phpunit/fonts-library/wpFontsLibrary/getFontsDir-test.php create mode 100644 phpunit/fonts-library/wpFontsLibrary/setUploadDir-test.php diff --git a/phpunit/fonts-library/class-wp-font-family-test.php b/phpunit/fonts-library/class-wp-font-family-test.php deleted file mode 100644 index 85e5c2c6e5fde..0000000000000 --- a/phpunit/fonts-library/class-wp-font-family-test.php +++ /dev/null @@ -1,340 +0,0 @@ - 'Piazzolla', - 'name' => 'Piazzolla', - ); - $this->expectException( 'Exception' ); - $this->expectExceptionMessage( 'Font family data is missing the slug.' ); - new WP_Font_Family( $font_data ); - } - - /** - * Tests that data is set by the constructor and retrieved by the get_data() method. - * - * @covers ::__construct - * @covers ::get_data - * - * @dataProvider data_font_fixtures - * - * @param array $font_data Font family data in theme.json format. - */ - public function test_get_data( $font_data ) { - $font = new WP_Font_Family( $font_data ); - $this->assertSame( $font_data, $font->get_data() ); - } - - /** - * Tests that the get_data_as_json() method returns the expected data in JSON format. - * - * @covers ::get_data_as_json - * - * @dataProvider data_get_data_as_json - * - * @param array $font_data Font family data in theme.json format. - * @param string $expected Expected font family data as JSON string. - */ - public function test_get_data_as_json( $font_data, $expected ) { - $font = new WP_Font_Family( $font_data ); - $this->assertSame( $expected, $font->get_data_as_json() ); - } - - /** - * Data provider. - * - * @return array[] - */ - public function data_get_data_as_json() { - return array( - 'piazzolla' => array( - 'font_data' => array( - 'slug' => 'piazzolla', - 'fontFamily' => 'Piazzolla', - 'name' => 'Piazzolla', - 'fontFace' => array( - array( - 'fontFamily' => 'Piazzolla', - 'src' => 'https://example.com/fonts/piazzolla_italic_400.ttf', - 'fontStyle' => 'italic', - 'fontWeight' => '400', - ), - ), - ), - 'expected' => '{"slug":"piazzolla","fontFamily":"Piazzolla","name":"Piazzolla","fontFace":[{"fontFamily":"Piazzolla","src":"https:\/\/example.com\/fonts\/piazzolla_italic_400.ttf","fontStyle":"italic","fontWeight":"400"}]}', - ), - 'piazzolla2' => array( - 'font_data' => array( - 'slug' => 'piazzolla', - 'fontFamily' => 'Piazzolla', - 'name' => 'Piazzolla', - 'fontFace' => array( - array( - 'fontFamily' => 'Piazzolla', - 'src' => 'https://example.com/fonts/piazzolla_italic_400.ttf', - 'fontStyle' => 'italic', - 'fontWeight' => '400', - ), - ), - ), - 'expected' => '{"slug":"piazzolla","fontFamily":"Piazzolla","name":"Piazzolla","fontFace":[{"fontFamily":"Piazzolla","src":"https:\/\/example.com\/fonts\/piazzolla_italic_400.ttf","fontStyle":"italic","fontWeight":"400"}]}', - ), - ); - } - - /** - * Tests that the has_font_faces() method correctly determines whether a font family has font faces. - * - * @covers ::has_font_faces - * - * @dataProvider data_has_font_faces - * - * @param array $font_data Font family data in theme.json format. - * @param bool $expected Expected result. - */ - public function test_has_font_faces( $font_data, $expected ) { - $font = new WP_Font_Family( $font_data ); - $this->assertSame( $expected, $font->has_font_faces() ); - } - - /** - * Data provider. - * - * @return array[] - */ - public function data_has_font_faces() { - return array( - 'with font faces' => array( - 'font_data' => array( - 'slug' => 'piazzolla', - 'fontFace' => array( - array( - 'fontFamily' => 'Piazzolla', - 'fontStyle' => 'italic', - 'fontWeight' => '400', - ), - ), - ), - 'expected' => true, - ), - - 'empty font faces' => array( - 'font_data' => array( - 'slug' => 'piazzolla', - 'fontFace' => array(), - ), - 'expected' => false, - ), - - 'without font faces' => array( - 'font_data' => array( - 'slug' => 'piazzolla', - ), - 'expected' => false, - ), - ); - } - - /** - * Tests that the install() and uninstall() methods work as expected - * It uses different types of font families: with local, remote or no files. - * - * @covers ::install - * @covers ::uninstall - * @covers ::get_font_post - * - * @dataProvider data_font_fixtures - * - * @param array $font_data Font family data in theme.json format. - * @param array $installed_font_data Font family data in theme.json format expected data after installation. - * @param array $files_data Optional. Files data in $_FILES format (Used only if the font has local files). Default: empty array. - */ - public function test_install_and_uninstall( $font_data, $installed_font_data, $files_data = array() ) { - $font = new WP_Font_Family( $font_data ); - $font->install( $files_data ); - - // Check that the post was created. - $post = $font->get_font_post(); - $this->assertInstanceof( 'WP_Post', $post, 'The font post was not created.' ); - - // Check that the post has the correct data. - $this->assertSame( $installed_font_data['name'], $post->post_title, 'The font post has the wrong title.' ); - $this->assertSame( $installed_font_data['slug'], $post->post_name, 'The font post has the wrong slug.' ); - - $content = json_decode( $post->post_content, true ); - $this->assertSame( $installed_font_data['fontFamily'], $content['fontFamily'], 'The font post content has the wrong font family.' ); - $this->assertSame( $installed_font_data['slug'], $content['slug'], 'The font post content has the wrong slug.' ); - - $this->assertArrayNotHasKey( 'download_from_url', $content, 'The installed font should not have the url from where it was downloaded.' ); - $this->assertArrayNotHasKey( 'uploaded_file', $content, 'The installed font should not have the reference to the file from it was installed.' ); - - $this->assertCount( count( $installed_font_data['fontFace'] ), $content['fontFace'], 'One or more font faces could not be installed.' ); - - $font->uninstall(); - - // Check that the post was deleted. - $post = $font->get_font_post(); - $this->assertNull( $post, 'The font post was not deleted' ); - } - - /** - * Data provider. - * - * @return array[] - */ - public function data_font_fixtures() { - $temp_file_path1 = wp_tempnam( 'Inter-' ); - file_put_contents( $temp_file_path1, 'Mocking file content' ); - $temp_file_path2 = wp_tempnam( 'Inter-' ); - file_put_contents( $temp_file_path2, 'Mocking file content' ); - - return array( - 'with_one_google_font_face_to_be_downloaded' => array( - 'font_data' => array( - 'name' => 'Piazzolla', - 'slug' => 'piazzolla', - 'fontFamily' => 'Piazzolla', - 'fontFace' => array( - array( - 'fontFamily' => 'Piazzolla', - 'fontStyle' => 'italic', - 'fontWeight' => '400', - 'src' => 'http://fonts.gstatic.com/s/piazzolla/v33/N0b72SlTPu5rIkWIZjVgI-TckS03oGpPETyEJ88Rbvi0_TzOzKcQhZqx3gX9BRy5m5M.ttf', - 'download_from_url' => 'http://fonts.gstatic.com/s/piazzolla/v33/N0b72SlTPu5rIkWIZjVgI-TckS03oGpPETyEJ88Rbvi0_TzOzKcQhZqx3gX9BRy5m5M.ttf', - ), - ), - ), - 'installed_font_data' => array( - 'name' => 'Piazzolla', - 'slug' => 'piazzolla', - 'fontFamily' => 'Piazzolla', - 'fontFace' => array( - array( - 'fontFamily' => 'Piazzolla', - 'fontStyle' => 'italic', - 'fontWeight' => '400', - 'src' => 'piazzolla_italic_400.ttf', // This is just filename of the font asset and not the entire URL because we can't know the URL of the asset in the test. - ), - ), - ), - 'files_data' => null, - ), - 'with_one_google_font_face_to_not_be_downloaded' => array( - 'font_data' => array( - 'name' => 'Piazzolla', - 'slug' => 'piazzolla', - 'fontFamily' => 'Piazzolla', - 'fontFace' => array( - array( - 'fontFamily' => 'Piazzolla', - 'fontStyle' => 'italic', - 'fontWeight' => '400', - 'src' => 'http://fonts.gstatic.com/s/piazzolla/v33/N0b72SlTPu5rIkWIZjVgI-TckS03oGpPETyEJ88Rbvi0_TzOzKcQhZqx3gX9BRy5m5M.ttf', - ), - ), - ), - 'installed_font_data' => array( - 'name' => 'Piazzolla', - 'slug' => 'piazzolla', - 'fontFamily' => 'Piazzolla', - 'fontFace' => array( - array( - 'fontFamily' => 'Piazzolla', - 'fontStyle' => 'italic', - 'fontWeight' => '400', - 'src' => 'piazzolla_italic_400.ttf', // This is just filename of the font asset and not the entire URL because we can't know the URL of the asset in the test. - ), - ), - ), - 'files_data' => null, - ), - 'without_font_faces' => array( - 'font_data' => array( - 'name' => 'Arial', - 'slug' => 'arial', - 'fontFamily' => 'Arial', - 'fontFace' => array(), - ), - 'installed_font_data' => array( - 'name' => 'Arial', - 'slug' => 'arial', - 'fontFamily' => 'Arial', - 'fontFace' => array(), - ), - 'files_data' => null, - ), - 'with_local_files' => array( - 'font_data' => array( - 'name' => 'Inter', - 'slug' => 'inter', - 'fontFamily' => 'Inter', - 'fontFace' => array( - array( - 'fontFamily' => 'Inter', - 'fontStyle' => 'normal', - 'fontWeight' => '400', - 'uploaded_file' => 'files0', - ), - array( - 'fontFamily' => 'Inter', - 'fontStyle' => 'normal', - 'fontWeight' => '500', - 'uploaded_file' => 'files1', - ), - ), - ), - 'installed_font_data' => array( - 'name' => 'Inter', - 'slug' => 'inter', - 'fontFamily' => 'Inter', - 'fontFace' => array( - array( - 'fontFamily' => 'Inter', - 'fontStyle' => 'normal', - 'fontWeight' => '400', - 'src' => 'inter_normal_400.ttf', - ), - array( - 'fontFamily' => 'Inter', - 'fontStyle' => 'normal', - 'fontWeight' => '500', - 'src' => 'inter_normal_500.ttf', - ), - ), - ), - 'files_data' => array( - 'files0' => array( - 'name' => 'inter1.ttf', - 'type' => 'font/ttf', - 'tmp_name' => $temp_file_path1, - 'error' => 0, - 'size' => 123, - ), - 'files1' => array( - 'name' => 'inter2.ttf', - 'type' => 'font/ttf', - 'tmp_name' => $temp_file_path2, - 'error' => 0, - 'size' => 123, - ), - ), - ), - ); - } -} diff --git a/phpunit/fonts-library/class-wp-fonts-library-test.php b/phpunit/fonts-library/class-wp-fonts-library-test.php deleted file mode 100644 index 5e802fb6e3685..0000000000000 --- a/phpunit/fonts-library/class-wp-fonts-library-test.php +++ /dev/null @@ -1,52 +0,0 @@ -assertStringEndsWith( '/wp-content/uploads/fonts', WP_Fonts_Library::get_fonts_dir() ); - } - - /** - * @covers ::set_upload_dir - * - * @dataProvider data_set_upload_dir - * - * @param array $defaults Default upload directory data. - * @param array $expected Modified upload directory data. - */ - public function test_set_upload_dir( $defaults, $expected ) { - $this->assertSame( $expected, WP_Fonts_Library::set_upload_dir( $defaults ) ); - } - - public function data_set_upload_dir() { - return array( - 'fonts_subdir' => array( - 'defaults' => array( - 'subdir' => '/abc', - 'basedir' => '/var/www/html/wp-content/uploads', - 'baseurl' => 'http://example.com/wp-content/uploads', - ), - 'expected' => array( - 'subdir' => '/fonts', - 'basedir' => '/var/www/html/wp-content/uploads', - 'baseurl' => 'http://example.com/wp-content/uploads', - 'path' => '/var/www/html/wp-content/uploads/fonts', - 'url' => 'http://example.com/wp-content/uploads/fonts', - ), - ), - ); - } - -} diff --git a/phpunit/fonts-library/wpFontFamily/__construct-test.php b/phpunit/fonts-library/wpFontFamily/__construct-test.php new file mode 100644 index 0000000000000..1b1e8706f1c68 --- /dev/null +++ b/phpunit/fonts-library/wpFontFamily/__construct-test.php @@ -0,0 +1,62 @@ +setAccessible( true ); + + $font_data = array( + 'fontFamily' => 'Piazzolla', + 'name' => 'Piazzolla', + 'slug' => 'piazzolla', + ); + $font_family = new WP_Font_Family( $font_data ); + + $actual = $property->getValue( $font_family ); + $property->setAccessible( false ); + + $this->assertSame( $font_data, $actual ); + } + + /** + * @dataProvider data_should_throw_exception + * + * @param mixed $font_data Data to test. + */ + public function test_should_throw_exception( $font_data ) { + $this->expectException( 'Exception' ); + $this->expectExceptionMessage( 'Font family data is missing the slug.' ); + + new WP_Font_Family( $font_data ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_should_throw_exception() { + return array( + 'no slug' => array( + array( + 'fontFamily' => 'Piazzolla', + 'name' => 'Piazzolla', + ), + ), + 'empty array' => array( array() ), + 'boolean instead of array' => array( false ), + 'null instead of array' => array( null ), + ); + } +} diff --git a/phpunit/fonts-library/wpFontFamily/base.php b/phpunit/fonts-library/wpFontFamily/base.php new file mode 100644 index 0000000000000..f823fea6c8093 --- /dev/null +++ b/phpunit/fonts-library/wpFontFamily/base.php @@ -0,0 +1,75 @@ + array(), + 'files_data' => array(), + 'font_filename' => '', + ); + + public static function set_up_before_class() { + parent::set_up_before_class(); + + $uploads_dir = wp_upload_dir(); + static::$fonts_dir = $uploads_dir['basedir'] . '/fonts/'; + } + + public function set_up() { + parent::set_up(); + + $merriweather_tmp_name = wp_tempnam( 'Merriweather-' ); + file_put_contents( $merriweather_tmp_name, 'Mocking file content' ); + $this->merriweather = array( + 'font_data' => array( + 'name' => 'Merriweather', + 'slug' => 'merriweather', + 'fontFamily' => 'Merriweather', + 'fontFace' => array( + array( + 'fontFamily' => 'Merriweather', + 'fontStyle' => 'normal', + 'fontWeight' => '400', + 'uploaded_file' => 'files0', + ), + ), + ), + 'files_data' => array( + 'files0' => array( + 'name' => 'merriweather.ttf', + 'type' => 'font/ttf', + 'tmp_name' => $merriweather_tmp_name, + 'error' => 0, + 'size' => 123, + ), + ), + 'font_filename' => static::$fonts_dir . 'merriweather_normal_400.ttf', + ); + } + + public function tear_down() { + // Clean up the /fonts directory. + foreach ( $this->files_in_dir( static::$fonts_dir ) as $file ) { + @unlink( $file ); + } + + parent::tear_down(); + } +} diff --git a/phpunit/fonts-library/wpFontFamily/getData-test.php b/phpunit/fonts-library/wpFontFamily/getData-test.php new file mode 100644 index 0000000000000..eccb1d7d7ad92 --- /dev/null +++ b/phpunit/fonts-library/wpFontFamily/getData-test.php @@ -0,0 +1,94 @@ +assertSame( $font_data, $font->get_data() ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_get_data() { + return array( + 'with one google font face to be downloaded' => array( + array( + 'name' => 'Piazzolla', + 'slug' => 'piazzolla', + 'fontFamily' => 'Piazzolla', + 'fontFace' => array( + array( + 'fontFamily' => 'Piazzolla', + 'fontStyle' => 'italic', + 'fontWeight' => '400', + 'src' => 'http://fonts.gstatic.com/s/piazzolla/v33/N0b72SlTPu5rIkWIZjVgI-TckS03oGpPETyEJ88Rbvi0_TzOzKcQhZqx3gX9BRy5m5M.ttf', + 'download_from_url' => 'http://fonts.gstatic.com/s/piazzolla/v33/N0b72SlTPu5rIkWIZjVgI-TckS03oGpPETyEJ88Rbvi0_TzOzKcQhZqx3gX9BRy5m5M.ttf', + ), + ), + ), + ), + 'with one google font face to not be downloaded' => array( + array( + 'name' => 'Piazzolla', + 'slug' => 'piazzolla', + 'fontFamily' => 'Piazzolla', + 'fontFace' => array( + array( + 'fontFamily' => 'Piazzolla', + 'fontStyle' => 'italic', + 'fontWeight' => '400', + 'src' => 'http://fonts.gstatic.com/s/piazzolla/v33/N0b72SlTPu5rIkWIZjVgI-TckS03oGpPETyEJ88Rbvi0_TzOzKcQhZqx3gX9BRy5m5M.ttf', + ), + ), + ), + ), + 'without font faces' => array( + array( + 'name' => 'Arial', + 'slug' => 'arial', + 'fontFamily' => 'Arial', + 'fontFace' => array(), + ), + ), + 'with local files' => array( + array( + 'name' => 'Inter', + 'slug' => 'inter', + 'fontFamily' => 'Inter', + 'fontFace' => array( + array( + 'fontFamily' => 'Inter', + 'fontStyle' => 'normal', + 'fontWeight' => '400', + 'uploaded_file' => 'files0', + ), + array( + 'fontFamily' => 'Inter', + 'fontStyle' => 'normal', + 'fontWeight' => '500', + 'uploaded_file' => 'files1', + ), + ), + ), + ), + ); + } +} diff --git a/phpunit/fonts-library/wpFontFamily/getDataAsJson-test.php b/phpunit/fonts-library/wpFontFamily/getDataAsJson-test.php new file mode 100644 index 0000000000000..06408bb325b6d --- /dev/null +++ b/phpunit/fonts-library/wpFontFamily/getDataAsJson-test.php @@ -0,0 +1,67 @@ +assertSame( $expected, $font->get_data_as_json() ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_get_data_as_json() { + return array( + 'piazzolla' => array( + 'font_data' => array( + 'slug' => 'piazzolla', + 'fontFamily' => 'Piazzolla', + 'name' => 'Piazzolla', + 'fontFace' => array( + array( + 'fontFamily' => 'Piazzolla', + 'src' => 'https://example.com/fonts/piazzolla_italic_400.ttf', + 'fontStyle' => 'italic', + 'fontWeight' => '400', + ), + ), + ), + 'expected' => '{"slug":"piazzolla","fontFamily":"Piazzolla","name":"Piazzolla","fontFace":[{"fontFamily":"Piazzolla","src":"https:\/\/example.com\/fonts\/piazzolla_italic_400.ttf","fontStyle":"italic","fontWeight":"400"}]}', + ), + 'piazzolla2' => array( + 'font_data' => array( + 'slug' => 'piazzolla', + 'fontFamily' => 'Piazzolla', + 'name' => 'Piazzolla', + 'fontFace' => array( + array( + 'fontFamily' => 'Piazzolla', + 'src' => 'https://example.com/fonts/piazzolla_italic_400.ttf', + 'fontStyle' => 'italic', + 'fontWeight' => '400', + ), + ), + ), + 'expected' => '{"slug":"piazzolla","fontFamily":"Piazzolla","name":"Piazzolla","fontFace":[{"fontFamily":"Piazzolla","src":"https:\/\/example.com\/fonts\/piazzolla_italic_400.ttf","fontStyle":"italic","fontWeight":"400"}]}', + ), + ); + } +} diff --git a/phpunit/fonts-library/wpFontFamily/getFontPost-test.php b/phpunit/fonts-library/wpFontFamily/getFontPost-test.php new file mode 100644 index 0000000000000..e3a1c9f49e739 --- /dev/null +++ b/phpunit/fonts-library/wpFontFamily/getFontPost-test.php @@ -0,0 +1,42 @@ + $this->merriweather['font_data']['name'], + 'post_name' => $this->merriweather['font_data']['slug'], + 'post_type' => 'wp_font_family', + 'post_content' => '', + 'post_status' => 'publish', + ); + $post_id = wp_insert_post( $post ); + $font = new WP_Font_Family( $this->merriweather['font_data'] ); + + // Test. + $actual = $font->get_font_post(); + $this->assertInstanceOf( WP_Post::class, $actual, 'Font post should exist' ); + $this->assertSame( $post_id, $actual->ID, 'Font post ID should match' ); + } + + public function test_should_return_null_when_post_does_not_exist() { + $font = new WP_Font_Family( $this->merriweather['font_data'] ); + + $this->assertNull( $font->get_font_post() ); + } +} diff --git a/phpunit/fonts-library/wpFontFamily/hasFontFaces-test.php b/phpunit/fonts-library/wpFontFamily/hasFontFaces-test.php new file mode 100644 index 0000000000000..d7d4fedce24c6 --- /dev/null +++ b/phpunit/fonts-library/wpFontFamily/hasFontFaces-test.php @@ -0,0 +1,78 @@ + 'piazzolla', + 'fontFace' => array( + array( + 'fontFamily' => 'Piazzolla', + 'fontStyle' => 'italic', + 'fontWeight' => '400', + ), + ), + ); + $font = new WP_Font_Family( $font_data ); + $this->assertTrue( $font->has_font_faces() ); + } + + /** + * @dataProvider data_should_return_false_when_check_fails + * + * @param array $font_data Font family data in theme.json format. + */ + public function test_should_return_false_when_check_fails( $font_data ) { + $font = new WP_Font_Family( $font_data ); + $this->assertFalse( $font->has_font_faces() ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_return_false_when_check_fails() { + return array( + 'wrong fontFace key' => array( + array( + 'slug' => 'piazzolla', + 'fontFaces' => array( + array( + 'fontFamily' => 'Piazzolla', + 'fontStyle' => 'italic', + 'fontWeight' => '400', + ), + ), + ), + ), + 'without font faces' => array( + array( + 'slug' => 'piazzolla', + ), + ), + 'empty array' => array( + array( + 'slug' => 'piazzolla', + 'fontFace' => array(), + ), + ), + 'null' => array( + array( + 'slug' => 'piazzolla', + 'fontFace' => null, + ), + ), + ); + } +} diff --git a/phpunit/fonts-library/wpFontFamily/install-test.php b/phpunit/fonts-library/wpFontFamily/install-test.php new file mode 100644 index 0000000000000..e16ce7571838e --- /dev/null +++ b/phpunit/fonts-library/wpFontFamily/install-test.php @@ -0,0 +1,248 @@ +install(); + $this->assertEmpty( $this->files_in_dir( static::$fonts_dir ), 'Font directory should be empty' ); + $this->assertInstanceOf( WP_Post::class, $font->get_font_post(), 'Font post should exist after install' ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_not_download_when_no_fontface() { + return array( + 'wrong fontFace key' => array( + array( + 'name' => 'Piazzolla', + 'slug' => 'piazzolla', + 'fontFamily' => 'Piazzolla', + 'fontFaces' => array( + array( + 'fontFamily' => 'Piazzolla', + 'fontStyle' => 'italic', + 'fontWeight' => '400', + ), + ), + ), + ), + 'without font faces' => array( + array( + 'name' => 'Piazzolla', + 'slug' => 'piazzolla', + 'fontFamily' => 'Piazzolla', + ), + ), + 'empty array' => array( + array( + 'name' => 'Piazzolla', + 'slug' => 'piazzolla', + 'fontFamily' => 'Piazzolla', + 'fontFace' => array(), + ), + ), + 'null' => array( + array( + 'name' => 'Piazzolla', + 'slug' => 'piazzolla', + 'fontFamily' => 'Piazzolla', + 'fontFace' => null, + ), + ), + ); + } + + /** + * @dataProvider data_should_download_fontfaces + * + * @param array $font_data Font family data in theme.json format. + * @param array $expected Expected font filename(s). + */ + public function test_should_download_fontfaces_and_create_post( $font_data, array $expected ) { + // Pre-checks to ensure starting conditions. + foreach ( $expected as $font_file ) { + $font_file = static::$fonts_dir . $font_file; + $this->assertFileDoesNotExist( $font_file, "Font file [{$font_file}] should not exist in the uploads/fonts/ directory after installing" ); + } + $font = new WP_Font_Family( $font_data ); + + // Test. + $font->install(); + foreach ( $expected as $font_file ) { + $font_file = static::$fonts_dir . $font_file; + $this->assertFileExists( $font_file, "Font file [{$font_file}] should exists in the uploads/fonts/ directory after installing" ); + } + $this->assertInstanceOf( WP_Post::class, $font->get_font_post(), 'Font post should exist after install' ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_download_fontfaces() { + return array( + '1 font face to download' => array( + 'font_data' => array( + 'name' => 'Piazzolla', + 'slug' => 'piazzolla', + 'fontFamily' => 'Piazzolla', + 'fontFace' => array( + array( + 'fontFamily' => 'Piazzolla', + 'fontStyle' => 'italic', + 'fontWeight' => '400', + 'src' => 'http://fonts.gstatic.com/s/piazzolla/v33/N0b72SlTPu5rIkWIZjVgI-TckS03oGpPETyEJ88Rbvi0_TzOzKcQhZqx3gX9BRy5m5M.ttf', + 'download_from_url' => 'http://fonts.gstatic.com/s/piazzolla/v33/N0b72SlTPu5rIkWIZjVgI-TckS03oGpPETyEJ88Rbvi0_TzOzKcQhZqx3gX9BRy5m5M.ttf', + ), + ), + ), + 'expected' => array( 'piazzolla_italic_400.ttf' ), + ), + '2 font faces to download' => array( + 'font_data' => array( + 'name' => 'Lato', + 'slug' => 'lato', + 'fontFamily' => 'Lato', + 'fontFace' => array( + array( + 'fontFamily' => 'Lato', + 'fontStyle' => 'normal', + 'fontWeight' => '400', + 'src' => 'http://fonts.gstatic.com/s/lato/v24/S6uyw4BMUTPHvxk6XweuBCY.ttf', + 'download_from_url' => 'http://fonts.gstatic.com/s/lato/v24/S6uyw4BMUTPHvxk6XweuBCY.ttf', + ), + array( + 'fontFamily' => 'Lato', + 'fontStyle' => 'italic', + 'fontWeight' => '400', + 'src' => 'http://fonts.gstatic.com/s/lato/v24/S6u8w4BMUTPHjxswWyWrFCbw7A.ttf', + 'download_from_url' => 'http://fonts.gstatic.com/s/lato/v24/S6u8w4BMUTPHjxswWyWrFCbw7A.ttf', + ), + ), + ), + 'expected' => array( 'lato_normal_400.ttf', 'lato_italic_400.ttf' ), + ), + ); + } + + /** + * @dataProvider data_should_move_local_fontfaces + * + * @param array $font_data Font family data in theme.json format. + * @param array $files_data Files data in $_FILES format. + * @param array $expected Expected font filename(s). + */ + public function test_should_move_local_fontfaces( $font_data, array $files_data, array $expected ) { + // Set up the temporary files. + foreach ( $files_data as $file ) { + file_put_contents( $file['tmp_name'], 'Mocking file content' ); + } + + $font = new WP_Font_Family( $font_data ); + $font->install( $files_data ); + + foreach ( $expected as $font_file ) { + $font_file = static::$fonts_dir . $font_file; + $this->assertFileExists( $font_file, "Font file [{$font_file}] should exists in the uploads/fonts/ directory after installing" ); + } + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_move_local_fontfaces() { + return array( + '1 local font' => array( + 'font_data' => array( + 'name' => 'Inter', + 'slug' => 'inter', + 'fontFamily' => 'Inter', + 'fontFace' => array( + array( + 'fontFamily' => 'Inter', + 'fontStyle' => 'italic', + 'fontWeight' => '900', + 'uploaded_file' => 'files0', + ), + ), + ), + 'files_data' => array( + 'files0' => array( + 'name' => 'inter1.ttf', + 'type' => 'font/ttf', + 'tmp_name' => wp_tempnam( 'Inter-' ), + 'error' => 0, + 'size' => 123, + ), + ), + 'expected' => array( 'inter_italic_900.ttf' ), + ), + '2 local fonts' => array( + 'font_data' => array( + 'name' => 'Lato', + 'slug' => 'lato', + 'fontFamily' => 'Lato', + 'fontFace' => array( + array( + 'fontFamily' => 'Lato', + 'fontStyle' => 'normal', + 'fontWeight' => '400', + 'uploaded_file' => 'files1', + ), + array( + 'fontFamily' => 'Lato', + 'fontStyle' => 'normal', + 'fontWeight' => '500', + 'uploaded_file' => 'files2', + ), + ), + ), + 'files_data' => array( + 'files1' => array( + 'name' => 'lato1.ttf', + 'type' => 'font/ttf', + 'tmp_name' => wp_tempnam( 'Lato-' ), + 'error' => 0, + 'size' => 123, + ), + 'files2' => array( + 'name' => 'lato2.ttf', + 'type' => 'font/ttf', + 'tmp_name' => wp_tempnam( 'Lato-' ), + 'error' => 0, + 'size' => 123, + ), + ), + 'expected' => array( 'lato_normal_400.ttf', 'lato_normal_500.ttf' ), + ), + ); + } +} diff --git a/phpunit/fonts-library/wpFontFamily/uninstall-test.php b/phpunit/fonts-library/wpFontFamily/uninstall-test.php new file mode 100644 index 0000000000000..8b2b79e78cbdf --- /dev/null +++ b/phpunit/fonts-library/wpFontFamily/uninstall-test.php @@ -0,0 +1,194 @@ +merriweather['font_data'] ); + + // Test. + $actual = $font->uninstall(); + $this->assertWPError( $actual, 'WP_Error should have been returned' ); + $this->assertSame( + array( 'font_family_not_found' => array( 'The font family could not be found.' ) ), + $actual->errors, + 'WP_Error should have "fonts_must_have_same_slug" error' + ); + } + + /** + * @dataProvider data_should_return_error_when_not_able_to_uninstall + * + * @param string $failure_to_mock The filter name to mock the failure. + */ + public function test_should_return_error_when_not_able_to_uninstall( $failure_to_mock ) { + // Set up the font. + add_filter( $failure_to_mock, '__return_empty_string' ); + $font = new WP_Font_Family( $this->merriweather['font_data'] ); + $font->install( $this->merriweather['files_data'] ); + + // Test. + $actual = $font->uninstall(); + $this->assertWPError( $actual, 'WP_Error should be returned' ); + $this->assertSame( + array( 'font_family_not_deleted' => array( 'The font family could not be deleted.' ) ), + $actual->errors, + 'WP_Error should have "font_family_not_deleted" error' + ); + } + + /** + * Data provider. + * + * @return string[][] + */ + public function data_should_return_error_when_not_able_to_uninstall() { + return array( + 'When delete file fails' => array( 'wp_delete_file' ), + 'when delete post fails' => array( 'pre_delete_post' ), + ); + } + + /** + * @dataProvider data_should_uninstall + * + * @param array $font_data Font family data in theme.json format. + * @param array $files_data Files data in $_FILES format. + */ + public function test_should_uninstall( $font_data, array $files_data ) { + // Set up. + foreach ( $files_data as $file ) { + file_put_contents( $file['tmp_name'], 'Mocking file content' ); + } + $font = new WP_Font_Family( $font_data ); + $font->install( $files_data ); + + // Pre-checks to ensure the starting point is as expected. + $this->assertInstanceOf( WP_Post::class, $font->get_font_post(), 'Font post should exist' ); + $this->assertNotEmpty( $this->files_in_dir( static::$fonts_dir ), 'Fonts should be installed' ); + + // Uninstall. + $this->assertTrue( $font->uninstall() ); + + // Test the post and font file(s) were uninstalled. + $this->assertNull( $font->get_font_post(), 'Font post should be deleted after uninstall' ); + $this->assertEmpty( $this->files_in_dir( static::$fonts_dir ), 'Fonts should be uninstalled' ); + } + + /** + * @dataProvider data_should_uninstall + * + * @param array $font_data Font family data in theme.json format. + * @param array $files_data Files data in $_FILES format. + * @param array $files_to_uninstall Files to uninstall. + */ + public function test_should_uninstall_only_its_font_family( $font_data, array $files_data, array $files_to_uninstall ) { + // Set up a different font family instance. This font family should not be uninstalled. + $merriweather = new WP_Font_Family( $this->merriweather['font_data'] ); + $merriweather->install( $this->merriweather['files_data'] ); + + // Set up the font family to be uninstalled. + foreach ( $files_data as $file ) { + file_put_contents( $file['tmp_name'], 'Mocking file content' ); + } + $font = new WP_Font_Family( $font_data ); + $font->install( $files_data ); + + $this->assertTrue( $font->uninstall() ); + + // Check that the files were uninstalled. + foreach ( $files_to_uninstall as $font_file ) { + $font_file = static::$fonts_dir . $font_file; + $this->assertFileDoesNotExist( $font_file, "Font file [{$font_file}] should not exists in the uploads/fonts/ directory after uninstalling" ); + } + // Check that the Merriweather file was not uninstalled. + $this->assertFileExists( $this->merriweather['font_filename'], 'The other font family [Merriweather] should not have been uninstalled.' ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_uninstall() { + return array( + '1 local font' => array( + 'font_data' => array( + 'name' => 'Inter', + 'slug' => 'inter', + 'fontFamily' => 'Inter', + 'fontFace' => array( + array( + 'fontFamily' => 'Inter', + 'fontStyle' => 'italic', + 'fontWeight' => '900', + 'uploaded_file' => 'files0', + ), + ), + ), + 'files_data' => array( + 'files0' => array( + 'name' => 'inter1.ttf', + 'type' => 'font/ttf', + 'tmp_name' => wp_tempnam( 'Inter-' ), + 'error' => 0, + 'size' => 123, + ), + ), + 'files_to_uninstall' => array( 'inter_italic_900.ttf' ), + ), + '2 local fonts' => array( + 'font_data' => array( + 'name' => 'Lato', + 'slug' => 'lato', + 'fontFamily' => 'Lato', + 'fontFace' => array( + array( + 'fontFamily' => 'Lato', + 'fontStyle' => 'normal', + 'fontWeight' => '400', + 'uploaded_file' => 'files1', + ), + array( + 'fontFamily' => 'Lato', + 'fontStyle' => 'normal', + 'fontWeight' => '500', + 'uploaded_file' => 'files2', + ), + ), + ), + 'files_data' => array( + 'files1' => array( + 'name' => 'lato1.ttf', + 'type' => 'font/ttf', + 'tmp_name' => wp_tempnam( 'Lato-' ), + 'error' => 0, + 'size' => 123, + ), + 'files2' => array( + 'name' => 'lato2.ttf', + 'type' => 'font/ttf', + 'tmp_name' => wp_tempnam( 'Lato-' ), + 'error' => 0, + 'size' => 123, + ), + ), + 'files_to_uninstall' => array( 'lato_normal_400.ttf', 'lato_normal_500.ttf' ), + ), + ); + } +} diff --git a/phpunit/fonts-library/wpFontFamilyUtils/getFilenameFromFontFace-test.php b/phpunit/fonts-library/wpFontFamilyUtils/getFilenameFromFontFace-test.php new file mode 100644 index 0000000000000..99467c42451be --- /dev/null +++ b/phpunit/fonts-library/wpFontFamilyUtils/getFilenameFromFontFace-test.php @@ -0,0 +1,64 @@ +assertSame( + $expected, + WP_Font_Family_Utils::get_filename_from_font_face( + $slug, + $font_face, + $font_face['src'], + $suffix + ) + ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_get_filename() { + return array( + 'piazzolla' => array( + 'slug' => 'piazzolla', + 'font_face' => array( + 'fontStyle' => 'italic', + 'fontWeight' => '400', + 'src' => 'http://example.com/fonts/font_file.ttf', + ), + 'suffix' => '', + 'expected_file_name' => 'piazzolla_italic_400.ttf', + ), + 'inter' => array( + 'slug' => 'inter', + 'font_face' => array( + 'fontStyle' => 'normal', + 'fontWeight' => '600', + 'src' => 'http://example.com/fonts/font_file.otf', + ), + 'suffix' => '', + 'expected_file_name' => 'inter_normal_600.otf', + ), + ); + } +} diff --git a/phpunit/fonts-library/wpFontFamilyUtils/hasFontMimeType-test.php b/phpunit/fonts-library/wpFontFamilyUtils/hasFontMimeType-test.php new file mode 100644 index 0000000000000..623dae4937bd9 --- /dev/null +++ b/phpunit/fonts-library/wpFontFamilyUtils/hasFontMimeType-test.php @@ -0,0 +1,61 @@ +assertTrue( WP_Font_Family_Utils::has_font_mime_type( $font_file ) ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_succeed_when_has_mime_type() { + return array( + 'ttf' => array( '/temp/piazzolla_400_italic.ttf' ), + 'otf' => array( '/temp/piazzolla_400_italic.otf' ), + 'woff' => array( '/temp/piazzolla_400_italic.woff' ), + 'woff2' => array( '/temp/piazzolla_400_italic.woff2' ), + ); + } + + /** + * @dataProvider data_should_fail_when_mime_not_supported + * + * @param string $font_file Font file path. + */ + public function test_should_fail_when_mime_not_supported( $font_file ) { + $this->assertFalse( WP_Font_Family_Utils::has_font_mime_type( $font_file ) ); + } + + /** + * Data provider. + * + * @return array[] + */ + public function data_should_fail_when_mime_not_supported() { + return array( + 'exe' => array( '/temp/test.exe' ), + 'md' => array( '/temp/license.md' ), + 'php' => array( '/temp/test.php' ), + 'txt' => array( '/temp/test.txt' ), + 'zip' => array( '/temp/lato.zip' ), + ); + } +} diff --git a/phpunit/fonts-library/class-wp-font-family-utils-test.php b/phpunit/fonts-library/wpFontFamilyUtils/mergeFontsData-test.php similarity index 59% rename from phpunit/fonts-library/class-wp-font-family-utils-test.php rename to phpunit/fonts-library/wpFontFamilyUtils/mergeFontsData-test.php index 775c88ce8b596..29e7eff1dac97 100644 --- a/phpunit/fonts-library/class-wp-font-family-utils-test.php +++ b/phpunit/fonts-library/wpFontFamilyUtils/mergeFontsData-test.php @@ -1,82 +1,31 @@ assertSame( $expected, WP_Font_Family_Utils::has_font_mime_type( $font_file ) ); - } +class Tests_FontsLibrary_WpFontsFamilyUtils_MergeFontsData extends WP_UnitTestCase { /** - * Data provider. + * @dataProvider data_should_fail_merge * - * @return array[] + * @param array $font1 First font data in theme.json format. + * @param array $font2 Second font data in theme.json format. */ - public function data_has_font_mime_type_fixtures() { - return array( - 'ttf' => array( - 'font_file' => '/temp/piazzolla_400_italic.ttf', - 'expected' => true, - ), - 'otf' => array( - 'font_file' => '/temp/piazzolla_400_italic.otf', - 'expected' => true, - ), - 'woff' => array( - 'font_file' => '/temp/piazzolla_400_italic.woff', - 'expected' => true, - ), - 'woff2' => array( - 'font_file' => '/temp/piazzolla_400_italic.woff2', - 'expected' => true, - ), - 'exe' => array( - 'font_file' => '/temp/piazzolla_400_italic.exe', - 'expected' => false, - ), - 'php' => array( - 'font_file' => '/temp/piazzolla_400_italic.php', - 'expected' => false, - ), - ); - } - - /** - * @covers ::get_filename_from_font_face - * - * @dataProvider data_get_filename_from_font_face_fixtures - * - * @param string $slug Font slug. - * @param array $font_face Font face data in theme.json format. - * @param string $suffix Suffix added to the resulting filename. Default empty string. - * @param string $expected_file_name Expected file name. - */ - public function test_get_filename_from_font_face( $slug, $font_face, $suffix, $expected_file_name ) { + public function test_should_fail_merge( $font1, $font2 ) { + $actual = WP_Font_Family_Utils::merge_fonts_data( $font1, $font2 ); + $this->assertWPError( $actual, 'WP_Error should have been returned' ); $this->assertSame( - $expected_file_name, - WP_Font_Family_Utils::get_filename_from_font_face( - $slug, - $font_face, - $font_face['src'], - $suffix - ) + array( 'fonts_must_have_same_slug' => array( 'Fonts must have the same slug to be merged.' ) ), + $actual->errors, + 'WP_Error should have "fonts_must_have_same_slug" error' ); } @@ -85,51 +34,51 @@ public function test_get_filename_from_font_face( $slug, $font_face, $suffix, $e * * @return array[] */ - public function data_get_filename_from_font_face_fixtures() { + public function data_should_fail_merge() { return array( - 'piazzolla' => array( - 'slug' => 'piazzolla', - 'font_face' => array( - 'fontStyle' => 'italic', - 'fontWeight' => '400', - 'src' => 'http://example.com/fonts/font_file.ttf', + 'different slugs' => array( + 'font1' => array( + 'slug' => 'piazzolla', + 'name' => 'Piazzolla', + 'fontFamily' => 'Piazzolla', + 'fontFace' => array( + array( + 'fontFamily' => 'Piazzolla', + 'fontStyle' => 'italic', + 'fontWeight' => '400', + 'src' => 'http://example.com/fonts/piazzolla_400_italic.ttf', + ), + ), ), - 'suffix' => '', - 'expected_file_name' => 'piazzolla_italic_400.ttf', - ), - 'inter' => array( - 'slug' => 'inter', - 'font_face' => array( - 'fontStyle' => 'normal', - 'fontWeight' => '600', - 'src' => 'http://example.com/fonts/font_file.otf', + 'font2' => array( + 'slug' => 'inter', + 'fontFamily' => 'Inter', + 'fontFace' => array( + array( + 'fontFamily' => 'Inter', + 'fontStyle' => 'normal', + 'fontWeight' => '700', + 'src' => 'http://example.com/fonts/inter_700_normal.ttf', + ), + ), ), - 'suffix' => '', - 'expected_file_name' => 'inter_normal_600.otf', + 'expected_result' => 'WP_Error', ), ); } + /** - * @covers ::merge_fonts_data - * - * @dataProvider data_merge_fonts_data_fixtures + * @dataProvider data_should_merge * - * @param bool $are_mergeable Whether the fonts are mergeable. * @param array $font1 First font data in theme.json format. * @param array $font2 Second font data in theme.json format. * @param array $expected_result Expected result. */ - public function test_merge_fonts_data( $are_mergeable, $font1, $font2, $expected_result ) { - // Fonts with same slug should be merged. - $merged_font = WP_Font_Family_Utils::merge_fonts_data( $font1, $font2 ); + public function test_should_merge( array $font1, array $font2, array $expected_result ) { + $actual = WP_Font_Family_Utils::merge_fonts_data( $font1, $font2 ); - if ( $are_mergeable ) { - $this->assertNotWPError( $merged_font, 'Fonts could not be merged' ); - $this->assertSame( $expected_result, $merged_font, 'The font family data and font faces merged not as expected' ); - } else { - $this->assertWPError( $merged_font, 'Merging non mergeable fonts (diifferent slug) should have failed.' ); - } + $this->assertSame( $expected_result, $actual ); } /** @@ -137,11 +86,9 @@ public function test_merge_fonts_data( $are_mergeable, $font1, $font2, $expected * * @return array[] */ - public function data_merge_fonts_data_fixtures() { + public function data_should_merge() { return array( - - 'mergeable_fonts' => array( - 'are_mergeable' => true, + 'with different font faces' => array( 'font1' => array( 'slug' => 'piazzolla', 'name' => 'Piazzolla', @@ -212,8 +159,7 @@ public function data_merge_fonts_data_fixtures() { ), ), - 'mergeable_fonts_with_repeated_font_faces' => array( - 'are_mergeable' => true, + 'repeated font faces' => array( 'font1' => array( 'slug' => 'piazzolla', 'name' => 'Piazzolla', @@ -283,38 +229,6 @@ public function data_merge_fonts_data_fixtures() { ), ), ), - - 'non_mergeable_fonts' => array( - 'are_mergeable' => false, - 'font1' => array( - 'slug' => 'piazzolla', - 'name' => 'Piazzolla', - 'fontFamily' => 'Piazzolla', - 'fontFace' => array( - array( - 'fontFamily' => 'Piazzolla', - 'fontStyle' => 'italic', - 'fontWeight' => '400', - 'src' => 'http://example.com/fonts/piazzolla_400_italic.ttf', - ), - ), - ), - 'font2' => array( - 'slug' => 'inter', - 'fontFamily' => 'Inter', - 'fontFace' => array( - array( - 'fontFamily' => 'Inter', - 'fontStyle' => 'normal', - 'fontWeight' => '700', - 'src' => 'http://example.com/fonts/inter_700_normal.ttf', - ), - ), - ), - 'expected_result' => 'WP_Error', - ), - ); } - } diff --git a/phpunit/fonts-library/wpFontsLibrary/getFontsDir-test.php b/phpunit/fonts-library/wpFontsLibrary/getFontsDir-test.php new file mode 100644 index 0000000000000..dd64a4a3ba60a --- /dev/null +++ b/phpunit/fonts-library/wpFontsLibrary/getFontsDir-test.php @@ -0,0 +1,18 @@ +assertStringEndsWith( '/wp-content/uploads/fonts', WP_Fonts_Library::get_fonts_dir() ); + } +} diff --git a/phpunit/fonts-library/wpFontsLibrary/setUploadDir-test.php b/phpunit/fonts-library/wpFontsLibrary/setUploadDir-test.php new file mode 100644 index 0000000000000..65d1612659fa8 --- /dev/null +++ b/phpunit/fonts-library/wpFontsLibrary/setUploadDir-test.php @@ -0,0 +1,30 @@ + '/abc', + 'basedir' => '/var/www/html/wp-content/uploads', + 'baseurl' => 'http://example.com/wp-content/uploads', + ); + $expected = array( + 'subdir' => '/fonts', + 'basedir' => '/var/www/html/wp-content/uploads', + 'baseurl' => 'http://example.com/wp-content/uploads', + 'path' => '/var/www/html/wp-content/uploads/fonts', + 'url' => 'http://example.com/wp-content/uploads/fonts', + ); + $this->assertSame( $expected, WP_Fonts_Library::set_upload_dir( $defaults ) ); + } +}