Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests for multisite #1327

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@
"lint:webp-uploads": "@lint -- ./plugins/webp-uploads --standard=./plugins/webp-uploads/phpcs.xml.dist",
"phpstan": "phpstan analyse --memory-limit=2048M",
"test": "phpunit",
"test-multisite": "@test -c tests/multisite.xml",
"test-multisite": [
"WP_MULTISITE=1 phpunit --exclude-group=ms-excluded"
],
"test-multisite:plugins": [
"@test-multisite:auto-sizes",
"@test-multisite:dominant-color-images",
Expand Down
8 changes: 8 additions & 0 deletions plugins/dominant-color-images/tests/data/class-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ public function test_get_dominant_color_valid( string $image_path, array $expect
* @dataProvider provider_get_dominant_color_invalid_images
*/
public function test_get_dominant_color_invalid( string $image_path ): void {
$mime_type = wp_check_filetype( $image_path )['type'];
// Old WP does not support ".tiff" and ".bmp" so return false.
if ( ! $mime_type ) {
$this->markTestSkipped( 'Mime type is not supported.' );
}
if ( ! wp_image_editor_supports( array( 'mime_type' => $mime_type ) ) ) {
$this->markTestSkipped( "Mime type $mime_type is not supported." );
}
Comment on lines +178 to +185
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was discovered previously as well when I added support for running PHPUnit tests using a custom setup.

As a fix, I didn't skip these tests rather I added tiff and bmp in supported mime types in multisite.

/**
 * Setup before class.
 */
public static function wpSetUpBeforeClass() {
	// Setup site options if it's a multisite network.
	if ( is_multisite() ) {
		$site_exts = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) );

		// Add `tiff` and `bmp` to the list of allowed file types.
		// These are removed by default in multisite.
		$site_exts[] = 'tiff';
		$site_exts[] = 'bmp';

		update_site_option( 'upload_filetypes', implode( ' ', $site_exts ) );
	}
}

See https://github.com/WordPress/performance/pull/1065/files#diff-670d6c64aed0f0b20a7a5971711c80e3d2b739a57e12b41044ee268010f01a13

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not in favor of adding support in multisite as it's a hacky solution. If WordPress itself doesn't support it, we should skip those tests to accurately reflect the lack of support in multisites.

As of WordPress 6.6, support for these features has been added in core, as seen in changeset 58400. These changes are already in trunk, so the tests are passing as seen in this run ✅.

From 6.6 onwards, the tests will work without needing to be skipped.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't call it a hacky solution, as WordPress allows this extensibility of adding more mime types. Also, since tests are running with these MIME types on a single site, testing them on a multisite setup looks good to me. However, it was just a suggestion, and I'm perfectly fine with either approach.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can go with either approach.

I think the unit tests for dominant-color-images need to be revisited. The valid and invalid MIME type tests seem to be skipped somehow, as they are meant to test functionality based on the MIME type. We should ensure these tests are correctly executed to verify the implementation accurately.

Single site skipped tests

There were 24 skipped tests:

1) Test_Dominant_Color_Image_Editor_GD::test_get_dominant_color_invalid with data set "tiff" ('/var/www/html/wp-content/plug...e.tiff')
Mime type image/tiff is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:184

2) Test_Dominant_Color_Image_Editor_GD::test_get_dominant_color_invalid with data set "bmp" ('/var/www/html/wp-content/plug...ge.bmp')
Mime type image/bmp is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:184

3) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "animated_gif" ('/var/www/html/wp-content/plug...ed.gif', array('874e4e', '864e4e', 'df7f7f'), true)
Mime type image/gif is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:1[56](https://github.com/WordPress/performance/actions/runs/9812767245/job/27097470441?pr=1327#step:9:57)

4) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "red_jpg" ('/var/www/html/wp-content/plug...ed.jpg', array('ff0000', 'fe0000'), false)
Mime type image/jpeg is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

5) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "green_jpg" ('/var/www/html/wp-content/plug...en.jpg', array('00ff00', '00ff01', '02ff01'), false)
Mime type image/jpeg is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

6) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "white_jpg" ('/var/www/html/wp-content/plug...te.jpg', array('ffffff'), false)
Mime type image/jpeg is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

7) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "red_gif" ('/var/www/html/wp-content/plug...ed.gif', array('ff0000'), false)
Mime type image/gif is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

8) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "green_gif" ('/var/www/html/wp-content/plug...en.gif', array('00ff00'), false)
Mime type image/gif is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

9) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "white_gif" ('/var/www/html/wp-content/plug...te.gif', array('ffffff'), false)
Mime type image/gif is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

10) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "trans_gif" ('/var/www/html/wp-content/plug...ns.gif', array('5a5a5a', '020202'), true)
Mime type image/gif is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

11) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "red_png" ('/var/www/html/wp-content/plug...ed.png', array('ff0000'), false)
Mime type image/png is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

12) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "green_png" ('/var/www/html/wp-content/plug...en.png', array('00ff00'), false)
Mime type image/png is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

13) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "white_png" ('/var/www/html/wp-content/plug...te.png', array('ffffff'), false)
Mime type image/png is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

14) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "trans_png" ('/var/www/html/wp-content/plug...ns.png', array('000000'), true)
Mime type image/png is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

15) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "red_webp" ('/var/www/html/wp-content/plug...d.webp', array('ff0000'), false)
Mime type image/webp is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

16) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "green_webp" ('/var/www/html/wp-content/plug...n.webp', array('00ff00'), false)
Mime type image/webp is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

17) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "white_webp" ('/var/www/html/wp-content/plug...e.webp', array('ffffff'), false)
Mime type image/webp is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

18) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "trans_webp" ('/var/www/html/wp-content/plug...s.webp', array('000000'), true)
Mime type image/webp is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

19) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "balloons_webp" ('/var/www/html/wp-content/plug...s.webp', array('c1bbb9', 'c0bbb9', 'c0bab8', 'c3bdbd', 'bfbab8'), false)
Mime type image/webp is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

20) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "half_opaque" ('/var/www/html/wp-content/plug...ue.png', array('7e7e7e'), true)
Mime type image/png is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

21) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_invalid with data set "tiff" ('/var/www/html/wp-content/plug...e.tiff')
Mime type image/tiff is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:1[84](https://github.com/WordPress/performance/actions/runs/9812767245/job/27097470441?pr=1327#step:9:85)

22) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_invalid with data set "bmp" ('/var/www/html/wp-content/plug...ge.bmp')
Mime type image/bmp is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:184

23) Test_Dominant_Color::test_get_dominant_color_invalid with data set "tiff" ('/var/www/html/wp-content/plug...e.tiff')
Mime type image/tiff is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:184

24) Test_Dominant_Color::test_get_dominant_color_invalid with data set "bmp" ('/var/www/html/wp-content/plug...ge.bmp')
Mime type image/bmp is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:184
Multisite site skipped tests

There were 24 skipped tests:

1) Test_Dominant_Color_Image_Editor_GD::test_get_dominant_color_invalid with data set "tiff" ('/var/www/html/wp-content/plug...e.tiff')
Mime type is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:181

2) Test_Dominant_Color_Image_Editor_GD::test_get_dominant_color_invalid with data set "bmp" ('/var/www/html/wp-content/plug...ge.bmp')
Mime type is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:181

3) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "animated_gif" ('/var/www/html/wp-content/plug...ed.gif', array('874e4e', '864e4e', 'df7f7f'), true)
Mime type image/gif is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:1[56](https://github.com/WordPress/performance/actions/runs/9812767245/job/27097470441?pr=1327#step:10:57)

4) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "red_jpg" ('/var/www/html/wp-content/plug...ed.jpg', array('ff0000', 'fe0000'), false)
Mime type image/jpeg is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

5) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "green_jpg" ('/var/www/html/wp-content/plug...en.jpg', array('00ff00', '00ff01', '02ff01'), false)
Mime type image/jpeg is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

6) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "white_jpg" ('/var/www/html/wp-content/plug...te.jpg', array('ffffff'), false)
Mime type image/jpeg is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

7) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "red_gif" ('/var/www/html/wp-content/plug...ed.gif', array('ff0000'), false)
Mime type image/gif is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

8) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "green_gif" ('/var/www/html/wp-content/plug...en.gif', array('00ff00'), false)
Mime type image/gif is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

9) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "white_gif" ('/var/www/html/wp-content/plug...te.gif', array('ffffff'), false)
Mime type image/gif is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

10) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_valid with data set "trans_gif" ('/var/www/html/wp-content/plug...ns.gif', array('5a5a5a', '020202'), true)
Mime type image/gif is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:156

21) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_invalid with data set "tiff" ('/var/www/html/wp-content/plug...e.tiff')
Mime type is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:1[81](https://github.com/WordPress/performance/actions/runs/9812767245/job/27097470441?pr=1327#step:10:82)

22) Test_Dominant_Color_Image_Editor_Imagick::test_get_dominant_color_invalid with data set "bmp" ('/var/www/html/wp-content/plug...ge.bmp')
Mime type is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:181

23) Test_Dominant_Color::test_get_dominant_color_invalid with data set "tiff" ('/var/www/html/wp-content/plug...e.tiff')
Mime type is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:181

24) Test_Dominant_Color::test_get_dominant_color_invalid with data set "bmp" ('/var/www/html/wp-content/plug...ge.bmp')
Mime type is not supported.

/var/www/html/wp-content/plugins/performance/plugins/dominant-color-images/tests/data/class-testcase.php:181

$attachment_id = self::factory()->attachment->create_upload_object( $image_path );
wp_maybe_generate_attachment_metadata( get_post( $attachment_id ) );

Expand Down
30 changes: 0 additions & 30 deletions tests/multisite.xml

This file was deleted.

Loading