From bd91b818221a36e32d2eb23c47abc855fc846945 Mon Sep 17 00:00:00 2001 From: hellofromtonya Date: Wed, 16 Aug 2023 10:22:07 -0500 Subject: [PATCH] WP_Fonts_Library: split tests --- .../class-wp-fonts-library-test.php | 52 ------------------- .../wpFontFamily/uninstall-test.php | 7 +-- .../wpFontsLibrary/getFontsDir-test.php | 18 +++++++ .../wpFontsLibrary/setUploadDir-test.php | 30 +++++++++++ 4 files changed, 52 insertions(+), 55 deletions(-) delete mode 100644 phpunit/fonts-library/class-wp-fonts-library-test.php 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-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/uninstall-test.php b/phpunit/fonts-library/wpFontFamily/uninstall-test.php index 0b972ed2c28dc..cd221a4b575b0 100644 --- a/phpunit/fonts-library/wpFontFamily/uninstall-test.php +++ b/phpunit/fonts-library/wpFontFamily/uninstall-test.php @@ -22,10 +22,11 @@ public function test_should_return_error_when_font_not_found() { // Test. $actual = $font->uninstall(); - $this->assertInstanceOf( WP_Error::class, $actual, 'WP_Error instance should have been returned' ); + $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 + $actual->errors, + 'WP_Error should have "fonts_must_have_same_slug" error' ); } @@ -42,7 +43,7 @@ public function test_should_return_error_when_not_able_to_uninstall( $failure_to // Test. $actual = $font->uninstall(); - $this->assertInstanceOf( WP_Error::class, $actual, 'WP_Error instance should be returned' ); + $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, diff --git a/phpunit/fonts-library/wpFontsLibrary/getFontsDir-test.php b/phpunit/fonts-library/wpFontsLibrary/getFontsDir-test.php new file mode 100644 index 0000000000000..4ed6616c813d0 --- /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..ad038260caa42 --- /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 ) ); + } +}