From fc85cb93b16ba1264007f2a96bafec914fb62190 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Mon, 15 Sep 2025 12:37:58 -0400 Subject: [PATCH 1/2] Dynamically load the correct WP Importer version --- tools/local-env/scripts/install.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/local-env/scripts/install.js b/tools/local-env/scripts/install.js index 891d43cc42cab..032aed77f1e90 100644 --- a/tools/local-env/scripts/install.js +++ b/tools/local-env/scripts/install.js @@ -55,6 +55,11 @@ function wp_cli( cmd ) { function install_wp_importer() { const testPluginDirectory = 'tests/phpunit/data/plugins/wordpress-importer'; + + // The final version of the WordPress Importer plugin with support for PHP < 7.2 is 0.9.0. + const phpVersion = parseFloat(process.env.LOCAL_PHP.split('-')[0]); + const branchFlag = phpVersion < 7.2 ? '--branch 0.9.0' : ''; + execSync( `docker compose exec -T php rm -rf ${testPluginDirectory}`, { stdio: 'inherit' } ); - execSync( `docker compose exec -T php git clone https://github.com/WordPress/wordpress-importer.git ${testPluginDirectory} --depth=1`, { stdio: 'inherit' } ); + execSync( `docker compose exec -T php git clone ${branchFlag} https://github.com/WordPress/wordpress-importer.git ${testPluginDirectory} --depth=1`, { stdio: 'inherit' } ); } From 56459974f5d03422bb5a4b7babb2d68d3832c25d Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Mon, 15 Sep 2025 14:28:41 -0400 Subject: [PATCH 2/2] Backport fixes for new PHP images and ImageMagick --- tests/phpunit/tests/image/editorImagick.php | 5 +++++ tests/phpunit/tests/image/resize.php | 22 +++++++++++++++++++++ tests/phpunit/tests/media.php | 3 +++ tools/local-env/scripts/install.js | 2 +- 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/image/editorImagick.php b/tests/phpunit/tests/image/editorImagick.php index 30747f69f1b62..956ea0772d7a8 100644 --- a/tests/phpunit/tests/image/editorImagick.php +++ b/tests/phpunit/tests/image/editorImagick.php @@ -656,6 +656,11 @@ public function test_remove_pdf_alpha_channel_should_remove_the_alpha_channel_in $this->markTestSkipped( 'Rendering PDFs is not supported on this system.' ); } + $version = Imagick::getVersion(); + if ( $version['versionNumber'] < 0x675 ) { + $this->markTestSkipped( 'The version of ImageMagick does not support removing alpha channels from PDFs.' ); + } + $test_file = DIR_TESTDATA . '/images/test-alpha.pdf'; $attachment_id = $this->factory->attachment->create_upload_object( $test_file ); $this->assertNotEmpty( $attachment_id, 'The attachment was not created before testing.' ); diff --git a/tests/phpunit/tests/image/resize.php b/tests/phpunit/tests/image/resize.php index e82dd3d2e6b2a..1f78d5a9fc9ca 100644 --- a/tests/phpunit/tests/image/resize.php +++ b/tests/phpunit/tests/image/resize.php @@ -23,6 +23,8 @@ public function wp_image_editors() { public function test_resize_jpg() { $image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.jpg', 25, 25 ); + $this->assertNotWPError( $image ); + list( $w, $h, $type ) = getimagesize( $image ); unlink( $image ); @@ -78,6 +80,8 @@ public function test_resize_webp() { $image = $this->resize_helper( $file, 25, 25 ); + $this->assertNotWPError( $image ); + list( $w, $h, $type ) = wp_getimagesize( $image ); unlink( $image ); @@ -92,6 +96,10 @@ public function test_resize_webp() { * Test resizing AVIF image. * * @ticket 51228 + * + * Temporarily disabled until we can figure out why it fails on the Trixie based PHP container. + * See https://core.trac.wordpress.org/ticket/63932. + * @requires PHP < 8.3 */ public function test_resize_avif() { $file = DIR_TESTDATA . '/images/avif-lossy.avif'; @@ -104,6 +112,8 @@ public function test_resize_avif() { $image = $this->resize_helper( $file, 25, 25 ); + $this->assertNotWPError( $image ); + list( $w, $h, $type ) = wp_getimagesize( $image ); unlink( $image ); @@ -125,6 +135,8 @@ public function test_resize_larger() { public function test_resize_thumb_128x96() { $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 96 ); + $this->assertNotWPError( $image ); + list( $w, $h, $type ) = getimagesize( $image ); unlink( $image ); @@ -138,6 +150,8 @@ public function test_resize_thumb_128x96() { public function test_resize_thumb_128x0() { $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 0 ); + $this->assertNotWPError( $image ); + list( $w, $h, $type ) = getimagesize( $image ); unlink( $image ); @@ -151,6 +165,8 @@ public function test_resize_thumb_128x0() { public function test_resize_thumb_0x96() { $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 0, 96 ); + $this->assertNotWPError( $image ); + list( $w, $h, $type ) = getimagesize( $image ); unlink( $image ); @@ -164,6 +180,8 @@ public function test_resize_thumb_0x96() { public function test_resize_thumb_150x150_crop() { $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 150, 150, true ); + $this->assertNotWPError( $image ); + list( $w, $h, $type ) = getimagesize( $image ); unlink( $image ); @@ -190,6 +208,8 @@ public function test_resize_thumb_150x100_crop() { public function test_resize_thumb_50x150_crop() { $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 50, 150, true ); + $this->assertNotWPError( $image ); + list( $w, $h, $type ) = getimagesize( $image ); unlink( $image ); @@ -214,6 +234,8 @@ public function test_resize_non_existent_image() { /** * Function to help out the tests + * + * @return string|WP_Error The path to the resized image file or a WP_Error on failure. */ protected function resize_helper( $file, $width, $height, $crop = false ) { $editor = wp_get_image_editor( $file ); diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 7cc9f5470f754..f1fe1631ba165 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -5284,6 +5284,9 @@ public function test_quality_with_image_conversion_file_sizes() { // Sub-sizes: for each size, the JPEGs should be smaller than the WebP. $sizes_to_compare = array_intersect_key( $jpeg_sizes['sizes'], $webp_sizes['sizes'] ); + + $this->assertNotWPError( $sizes_to_compare ); + foreach ( $sizes_to_compare as $size => $size_data ) { $this->assertLessThan( $webp_sizes['sizes'][ $size ]['filesize'], $jpeg_sizes['sizes'][ $size ]['filesize'] ); } diff --git a/tools/local-env/scripts/install.js b/tools/local-env/scripts/install.js index 032aed77f1e90..220b2eda68070 100644 --- a/tools/local-env/scripts/install.js +++ b/tools/local-env/scripts/install.js @@ -36,7 +36,7 @@ writeFileSync( 'wp-tests-config.php', testConfig ); // Once the site is available, install WordPress! wait_on( { resources: [ `tcp:localhost:${process.env.LOCAL_PORT}`] } ) .then( () => { - wp_cli( 'db reset --yes' ); + wp_cli( 'db reset --yes --defaults' ); wp_cli( `core install --title="WordPress Develop" --admin_user=admin --admin_password=password --admin_email=test@test.com --skip-email --url=http://localhost:${process.env.LOCAL_PORT}` ); } );