Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/php-test-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
npm run wp-env-test start
fi
- name: Composer Install
run: npm run wp-env-test run cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction --no-progress
run: npm run wp-env-test run wordpress -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction --no-progress
- name: Update Composer Dependencies
run: composer update --with-all-dependencies --no-interaction --no-progress
- name: Install PHPUnit
Expand Down Expand Up @@ -136,7 +136,7 @@ jobs:
fi
- name: Upload single site coverage reports to Codecov
if: ${{ matrix.coverage == true }}
uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6.0.1
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v6.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./single-site-reports
Expand All @@ -145,7 +145,7 @@ jobs:
fail_ci_if_error: true
- name: Upload multisite coverage reports to Codecov
if: ${{ matrix.coverage == true }}
uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6.0.1
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v6.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./multisite-reports
Expand Down
2 changes: 1 addition & 1 deletion bin/test-php-watch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ while true; do
echo "Running phpunit tests for $(tput bold)$plugin_slug$(tput sgr0):"
# TODO: Interrupt when a change is made while running tests or re-run if change made since tests started running.
# Note: This is calling phpunit directly and not the composer script due to extra noise it outputs.
npm run wp-env-test --silent -- run cli --env-cwd=/var/www/html/wp-content/plugins/performance -- vendor/bin/phpunit --testsuite "$plugin_slug" "$@"
npm run wp-env-test --silent -- run wordpress --env-cwd=/var/www/html/wp-content/plugins/performance -- vendor/bin/phpunit --testsuite "$plugin_slug" "$@"
done
44 changes: 22 additions & 22 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": "wp-env --config=.wp-env.test.json run wordpress --env-cwd=/var/www/html/wp-content/plugins/performance composer test:plugins",
"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: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: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-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: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": "wp-env --config=.wp-env.test.json run wordpress --env-cwd=/var/www/html/wp-content/plugins/performance composer test-multisite:plugins",
"test-php:performance-lab": "wp-env --config=.wp-env.test.json run wordpress --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 wordpress --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 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 wordpress --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 wordpress --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 wordpress --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 wordpress --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 wordpress --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 wordpress --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 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 wordpress --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 wordpress --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 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 wordpress --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 wordpress --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 wordpress --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 wordpress --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 wordpress --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 wordpress --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 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