-
Notifications
You must be signed in to change notification settings - Fork 152
Fix skipped tests in Image Placeholders and Modern Image Formats #2523
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
Changes from all commits
c284697
68a36a3
a0d719d
b509cb1
14171aa
ced9d4e
1f22821
43a1f05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -774,10 +774,15 @@ public function test_it_should_replace_the_featured_image_to_webp_when_requestin | |
| * @return array<string, array<string>> An array of valid image types. | ||
| */ | ||
| public function data_provider_supported_image_types(): array { | ||
| return array( | ||
| $data = array( | ||
| 'webp' => array( 'webp' ), | ||
| 'avif' => array( 'avif' ), | ||
| ); | ||
|
|
||
| if ( $this->check_avif_encoding_support() ) { | ||
| $data['avif'] = array( 'avif' ); | ||
| } | ||
|
|
||
| return $data; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -786,12 +791,17 @@ public function data_provider_supported_image_types(): array { | |
| * @return array<string, array<int, string|true>> An array of valid image types. | ||
| */ | ||
| public function data_provider_supported_image_types_with_threshold(): array { | ||
| return array( | ||
| $data = array( | ||
| 'webp' => array( 'webp' ), | ||
| 'webp with 850 threshold' => array( 'webp', true ), | ||
| 'avif' => array( 'avif' ), | ||
| 'avif with 850 threshold' => array( 'avif', true ), | ||
| ); | ||
|
|
||
| if ( $this->check_avif_encoding_support() ) { | ||
| $data['avif'] = array( 'avif' ); | ||
| $data['avif with 850 threshold'] = array( 'avif', true ); | ||
| } | ||
|
|
||
| return $data; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1094,6 +1104,10 @@ public function test_that_it_should_convert_webp_to_avif_on_upload(): void { | |
| $this->markTestSkipped( 'Mime type image/avif is not supported.' ); | ||
| } | ||
|
|
||
| if ( ! $this->check_avif_encoding_support() ) { | ||
| $this->markTestSkipped( 'AVIF encoding is not supported.' ); | ||
| } | ||
|
|
||
| $this->set_image_output_type( 'avif' ); | ||
|
|
||
| $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/data/images/balloons.webp' ); | ||
|
|
@@ -1310,4 +1324,34 @@ public function test_webp_uploads_update_featured_image_picture_element_enabled( | |
| $featured_image = get_the_post_thumbnail( $post_id ); | ||
| $this->assertStringStartsWith( '<picture ', $featured_image ); | ||
| } | ||
|
|
||
| /** | ||
| * Check if AVIF encoding is supported. | ||
| * | ||
| * This is required due to false positive given by Imagick::queryFormats() for AVIF support, | ||
| * where it returns true for AVIF support even if only decoding is supported but not encoding. | ||
| * | ||
| * @return bool True if AVIF encoding is supported, false otherwise. | ||
| */ | ||
| public function check_avif_encoding_support(): bool { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still required due to following:
|
||
| static $encoding_support = null; | ||
| if ( null === $encoding_support ) { | ||
| if ( extension_loaded( 'imagick' ) && class_exists( 'Imagick' ) && class_exists( 'ImagickException' ) ) { | ||
| // Only reliable way to check for AVIF encoding support is to attempt to encode an image and catch the exception if it fails. | ||
| try { | ||
| $i = new Imagick(); | ||
| $i->newImage( 10, 10, 'white' ); | ||
| $i->setImageFormat( 'avif' ); | ||
| $i->getImageBlob(); | ||
| $encoding_support = true; | ||
| } catch ( ImagickException $e ) { | ||
| $encoding_support = false; | ||
| } | ||
| } else { | ||
| $encoding_support = false; | ||
| } | ||
| } | ||
|
|
||
| return $encoding_support; | ||
| } | ||
| } | ||
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.
Any reason to not use the
wordpressinstead ofclifor all of the plugins?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 had this question/thought as well, and even confirmed that the tests all pass after changing them all to wordpress.
I assume the thought was that WordPress is perhaps heavier?
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.
@westonruter, after some investigation, I found that the
tests-cliwas introduced in PR #544 before it wasphpunit. However, I could not find any discussion explaining the decision to usetests-cliinstead oftests-wordpress.Also, @thelovekesh commented on the issue:
Reference: #2521 (comment)
I think we should move everything to the
wordpressimage now, as that would simplify a lot of the setup and maintenance.updated in b509cb1.