From 7ad924f0e26a9d927c722c48a011a9dbce825647 Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Mon, 15 Sep 2025 14:36:46 -0400 Subject: [PATCH] Fix Importer and ImageMagic tests --- tests/phpunit/tests/image/editorImagick.php | 5 +++++ tests/phpunit/tests/image/resize.php | 16 ++++++++++++++++ tests/phpunit/tests/media.php | 3 +++ tools/local-env/scripts/install.js | 9 +++++++-- 4 files changed, 31 insertions(+), 2 deletions(-) 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 5b302ce2958b8..825c73a9cb204 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 ); @@ -99,6 +103,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 ); @@ -112,6 +118,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 ); @@ -125,6 +133,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 ); @@ -138,6 +148,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 ); @@ -164,6 +176,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 ); @@ -188,6 +202,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 8d91517b1fcd6..d3a78ce8a4b94 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 891d43cc42cab..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}` ); } ); @@ -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' } ); }