-
Notifications
You must be signed in to change notification settings - Fork 101
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
Conversation
Interesting. There are PHPUnit test failures in most PHP versions related to Image Placeholders. I don't get this error locally. Instead I get a fatal error:
|
@westonruter The current trunk doesn't work for multisite unit tests; it shows Additionally, I debugged the unit test failures for the current PR and found that Additionally, I occasionally encounter a |
If we want to solve the unit tests issue then we have to skip
|
That's why this PR was opened, to fix this :-)
Sounds reasonable 👍 |
@mukeshpanchal27 Would you amend this PR with your suggestion? |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
$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." ); | ||
} |
There was a problem hiding this comment.
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 ) );
}
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Co-authored-by: Lovekesh Kumar <lovekesh.kumar@rtcamp.com>
7dbe3ad
to
eef6f62
Compare
I just got this error again when running non-multisite tests locally:
It's happening each time I do |
Maybe it's a wp-env thing? PL is loaded in wp-env by default. And then the When I run the tests locally without wp-env, I don't get such an error. |
Yes, it is possible if the test cases don't delete the drop-in. @westonruter and I discussed this a while ago. It seems to be a side effect that occurs after running the test cases. If we halt the server timing test cases, we might be able to replicate this issue. |
Summary
Fixes #1326
Relevant technical choices