Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,29 @@
"test-e2e:debug": "wp-scripts test-playwright --config tools/e2e/playwright.config.ts --ui",
"test-e2e:auto-sizes": "wp-scripts test-playwright --config tools/e2e/playwright.config.ts --project=auto-sizes",
"lint-php": "composer lint:all",
"test-php": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:plugins",
"test-php": "npm-run-all -s --continue-on-error test-php:performance-lab test-php:auto-sizes test-php:dominant-color-images test-php:embed-optimizer test-php:image-prioritizer test-php:optimization-detective test-php:speculation-rules test-php:view-transitions test-php:web-worker-offloading test-php:webp-uploads",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you elaborate on this change?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, right, it's because we have the same test command in both package.json and composer.json, but only here do we control where it is run.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Alternatively, this could be just the following, if we move all execution from cli:

Suggested change
"test-php": "npm-run-all -s --continue-on-error test-php:performance-lab test-php:auto-sizes test-php:dominant-color-images test-php:embed-optimizer test-php:image-prioritizer test-php:optimization-detective test-php:speculation-rules test-php:view-transitions test-php:web-worker-offloading test-php:webp-uploads",
"test-php": "wp-env --config=.wp-env.test.json run wordpress --env-cwd=/var/www/html/wp-content/plugins/performance composer test:plugins",

@b1ink0 b1ink0 Jun 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in b509cb1.

"test-php-watch": "./bin/test-php-watch.sh",
"test-php-multisite": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:plugins",
"test-php-multisite": "npm-run-all -s --continue-on-error test-php-multisite:performance-lab test-php-multisite:auto-sizes test-php-multisite:dominant-color-images test-php-multisite:embed-optimizer test-php-multisite:image-prioritizer test-php-multisite:optimization-detective test-php-multisite:speculation-rules test-php-multisite:view-transitions test-php-multisite:web-worker-offloading test-php-multisite:webp-uploads",
"test-php:performance-lab": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:performance-lab",
"test-php:auto-sizes": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:auto-sizes",
"test-php:dominant-color-images": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:dominant-color-images",
"test-php:dominant-color-images": "wp-env --config=.wp-env.test.json run wordpress --env-cwd=/var/www/html/wp-content/plugins/performance composer test:dominant-color-images",

Copy link
Copy Markdown
Member

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 wordpress instead of cli for all of the plugins?

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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-cli was introduced in PR #544 before it was phpunit. However, I could not find any discussion explaining the decision to use tests-cli instead of tests-wordpress.

Also, @thelovekesh commented on the issue:

wp-env generates the Dockerfile, builds it, and runs it, so it's wp-env specific. Also, tests should run in the tests WordPress image and not the CLI image.

Reference: #2521 (comment)

I think we should move everything to the wordpress image now, as that would simplify a lot of the setup and maintenance.

updated in b509cb1.

"test-php:embed-optimizer": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:embed-optimizer",
"test-php:image-prioritizer": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:image-prioritizer",
"test-php:optimization-detective": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:optimization-detective",
"test-php:speculation-rules": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:speculation-rules",
"test-php:view-transitions": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:view-transitions",
"test-php:web-worker-offloading": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:web-worker-offloading",
"test-php:webp-uploads": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test:webp-uploads",
"test-php:webp-uploads": "wp-env --config=.wp-env.test.json run wordpress --env-cwd=/var/www/html/wp-content/plugins/performance composer test:webp-uploads",
"test-php-multisite:performance-lab": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:performance-lab",
"test-php-multisite:auto-sizes": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:auto-sizes",
"test-php-multisite:dominant-color-images": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:dominant-color-images",
"test-php-multisite:dominant-color-images": "wp-env --config=.wp-env.test.json run wordpress --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:dominant-color-images",
"test-php-multisite:embed-optimizer": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:embed-optimizer",
"test-php-multisite:image-prioritizer": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:image-prioritizer",
"test-php-multisite:optimization-detective": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:optimization-detective",
"test-php-multisite:speculation-rules": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:speculation-rules",
"test-php-multisite:view-transitions": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:view-transitions",
"test-php-multisite:web-worker-offloading": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:web-worker-offloading",
"test-php-multisite:webp-uploads": "wp-env --config=.wp-env.test.json run cli --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:webp-uploads",
"test-php-multisite:webp-uploads": "wp-env --config=.wp-env.test.json run wordpress --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:webp-uploads",
"update-test-case-snapshots": "bin/update-test-case-snapshots.sh",
"wp-env": "wp-env",
"wp-env-test": "wp-env --config=.wp-env.test.json",
Expand Down
6 changes: 3 additions & 3 deletions plugins/dominant-color-images/tests/data/class-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ public function provider_get_dominant_color(): array {
),
'balloons_webp' => array(
'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/balloons.webp',
'expected_color' => array( 'c1bbb9', 'c0bbb9', 'c0bab8', 'c3bdbd', 'bfbab8' ),
'expected_color' => array( 'c1bbb9', 'c0bbb9', 'c0bab8', 'c3bdbd', 'bfbab8', 'c2bdbc' ),
'expected_transparency' => false,
),
'half_opaque' => array(
'image_path' => TESTS_PLUGIN_DIR . '/tests/data/images/half-opaque.png',
'expected_color' => array( '7e7e7e' ),
'expected_color' => array( '7e7e7e', 'ffffff' ),
'expected_transparency' => true,
),
);
Expand Down Expand Up @@ -214,7 +214,7 @@ public function test_get_dominant_color_invalid( string $image_path ): void {
$dominant_color_data = dominant_color_get_dominant_color_data( $attachment_id );

$this->assertWPError( $dominant_color_data );
$this->assertStringContainsString( 'image_no_editor', $dominant_color_data->get_error_code() );
$this->assertStringContainsString( 'unsupported_attachment_type', $dominant_color_data->get_error_code() );
}

/**
Expand Down
54 changes: 49 additions & 5 deletions plugins/webp-uploads/tests/test-load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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' );
Expand Down Expand Up @@ -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 {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is still required due to following:

The tests are now passing for PHP 8.1+ and PHP 7.2+ versions due to the upstream fix, but PHP 8.1 and PHP 7.2 will not be fixed because support for this Docker image has been dropped (see docker-library/wordpress#992.

We have the option to skip these failing tests for this specific version, or we can remove PHP 8.1 from testing.

For now, I will skip these failing tests on these version.

#2245 (comment)

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;
}
}
Loading