Skip to content

Commit 7ad924f

Browse files
committed
Fix Importer and ImageMagic tests
1 parent 79a5f9e commit 7ad924f

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

tests/phpunit/tests/image/editorImagick.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,11 @@ public function test_remove_pdf_alpha_channel_should_remove_the_alpha_channel_in
656656
$this->markTestSkipped( 'Rendering PDFs is not supported on this system.' );
657657
}
658658

659+
$version = Imagick::getVersion();
660+
if ( $version['versionNumber'] < 0x675 ) {
661+
$this->markTestSkipped( 'The version of ImageMagick does not support removing alpha channels from PDFs.' );
662+
}
663+
659664
$test_file = DIR_TESTDATA . '/images/test-alpha.pdf';
660665
$attachment_id = $this->factory->attachment->create_upload_object( $test_file );
661666
$this->assertNotEmpty( $attachment_id, 'The attachment was not created before testing.' );

tests/phpunit/tests/image/resize.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function wp_image_editors() {
2323
public function test_resize_jpg() {
2424
$image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.jpg', 25, 25 );
2525

26+
$this->assertNotWPError( $image );
27+
2628
list( $w, $h, $type ) = getimagesize( $image );
2729

2830
unlink( $image );
@@ -78,6 +80,8 @@ public function test_resize_webp() {
7880

7981
$image = $this->resize_helper( $file, 25, 25 );
8082

83+
$this->assertNotWPError( $image );
84+
8185
list( $w, $h, $type ) = wp_getimagesize( $image );
8286

8387
unlink( $image );
@@ -99,6 +103,8 @@ public function test_resize_larger() {
99103
public function test_resize_thumb_128x96() {
100104
$image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 96 );
101105

106+
$this->assertNotWPError( $image );
107+
102108
list( $w, $h, $type ) = getimagesize( $image );
103109

104110
unlink( $image );
@@ -112,6 +118,8 @@ public function test_resize_thumb_128x96() {
112118
public function test_resize_thumb_128x0() {
113119
$image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 0 );
114120

121+
$this->assertNotWPError( $image );
122+
115123
list( $w, $h, $type ) = getimagesize( $image );
116124

117125
unlink( $image );
@@ -125,6 +133,8 @@ public function test_resize_thumb_128x0() {
125133
public function test_resize_thumb_0x96() {
126134
$image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 0, 96 );
127135

136+
$this->assertNotWPError( $image );
137+
128138
list( $w, $h, $type ) = getimagesize( $image );
129139

130140
unlink( $image );
@@ -138,6 +148,8 @@ public function test_resize_thumb_0x96() {
138148
public function test_resize_thumb_150x150_crop() {
139149
$image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 150, 150, true );
140150

151+
$this->assertNotWPError( $image );
152+
141153
list( $w, $h, $type ) = getimagesize( $image );
142154

143155
unlink( $image );
@@ -164,6 +176,8 @@ public function test_resize_thumb_150x100_crop() {
164176
public function test_resize_thumb_50x150_crop() {
165177
$image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 50, 150, true );
166178

179+
$this->assertNotWPError( $image );
180+
167181
list( $w, $h, $type ) = getimagesize( $image );
168182

169183
unlink( $image );
@@ -188,6 +202,8 @@ public function test_resize_non_existent_image() {
188202

189203
/**
190204
* Function to help out the tests
205+
*
206+
* @return string|WP_Error The path to the resized image file or a WP_Error on failure.
191207
*/
192208
protected function resize_helper( $file, $width, $height, $crop = false ) {
193209
$editor = wp_get_image_editor( $file );

tests/phpunit/tests/media.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5284,6 +5284,9 @@ public function test_quality_with_image_conversion_file_sizes() {
52845284

52855285
// Sub-sizes: for each size, the JPEGs should be smaller than the WebP.
52865286
$sizes_to_compare = array_intersect_key( $jpeg_sizes['sizes'], $webp_sizes['sizes'] );
5287+
5288+
$this->assertNotWPError( $sizes_to_compare );
5289+
52875290
foreach ( $sizes_to_compare as $size => $size_data ) {
52885291
$this->assertLessThan( $webp_sizes['sizes'][ $size ]['filesize'], $jpeg_sizes['sizes'][ $size ]['filesize'] );
52895292
}

tools/local-env/scripts/install.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ writeFileSync( 'wp-tests-config.php', testConfig );
3636
// Once the site is available, install WordPress!
3737
wait_on( { resources: [ `tcp:localhost:${process.env.LOCAL_PORT}`] } )
3838
.then( () => {
39-
wp_cli( 'db reset --yes' );
39+
wp_cli( 'db reset --yes --defaults' );
4040
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}` );
4141
} );
4242

@@ -55,6 +55,11 @@ function wp_cli( cmd ) {
5555
function install_wp_importer() {
5656
const testPluginDirectory = 'tests/phpunit/data/plugins/wordpress-importer';
5757

58+
59+
// The final version of the WordPress Importer plugin with support for PHP < 7.2 is 0.9.0.
60+
const phpVersion = parseFloat(process.env.LOCAL_PHP.split('-')[0]);
61+
const branchFlag = phpVersion < 7.2 ? '--branch 0.9.0' : '';
62+
5863
execSync( `docker compose exec -T php rm -rf ${testPluginDirectory}`, { stdio: 'inherit' } );
59-
execSync( `docker compose exec -T php git clone https://github.com/WordPress/wordpress-importer.git ${testPluginDirectory} --depth=1`, { stdio: 'inherit' } );
64+
execSync( `docker compose exec -T php git clone ${branchFlag} https://github.com/WordPress/wordpress-importer.git ${testPluginDirectory} --depth=1`, { stdio: 'inherit' } );
6065
}

0 commit comments

Comments
 (0)