From 3a63ed2939092ceeccbfd5733d009f1252eca1e6 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 15 Jan 2023 13:36:10 +0000 Subject: [PATCH] Tests: Use more specific assertions in image saving tests. When passed a `WP_Image_Editor` instance as the `$image` parameter, `wp_save_image_file()` returns an array on success, so we can specifically check for an array instead of any non-empty result. Likewise, in PDF tests, when creating an attachment is expected to return an integer ID and not a `WP_Error` object, we can specifically check for that. Follow-up to [1061/tests], [38949], [39617], [42792], [53529], [53530], [53531], [55019], [55066]. See #56793. git-svn-id: https://develop.svn.wordpress.org/trunk@55070 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/image/functions.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php index 7ed944b439..82988c5f6b 100644 --- a/tests/phpunit/tests/image/functions.php +++ b/tests/phpunit/tests/image/functions.php @@ -283,8 +283,8 @@ class Tests_Image_Functions extends WP_UnitTestCase { $ret = wp_save_image_file( $file, $img, $mime_type, 1 ); // Make assertions. - $this->assertNotEmpty( $ret, 'Image failed to save - "empty" response returned.' ); $this->assertNotWPError( $ret, 'Image failed to save - WP_Error returned.' ); + $this->assertIsArray( $ret, 'Image failed to save - non-array response returned.' ); $this->assertSame( $mime_type, $this->get_mime_type( $ret['path'] ), 'Mime type of the saved image does not match.' ); // Clean up. @@ -374,8 +374,8 @@ class Tests_Image_Functions extends WP_UnitTestCase { $ret = $img->save( $file, $mime_type ); // Make assertions. - $this->assertNotEmpty( $ret, 'Image failed to save - "empty" response returned.' ); $this->assertNotWPError( $ret, 'Image failed to save - WP_Error returned.' ); + $this->assertIsArray( $ret, 'Image failed to save - non-array response returned.' ); $this->assertSame( $mime_type, $this->get_mime_type( $ret['path'] ), 'Mime type of the saved image did not override file name.' ); // Clean up. @@ -420,8 +420,8 @@ class Tests_Image_Functions extends WP_UnitTestCase { $ret = $img->save( trailingslashit( $temp ) . $file ); // Make assertions. - $this->assertNotEmpty( $ret, 'Image failed to save - "empty" response returned.' ); $this->assertNotWPError( $ret, 'Image failed to save - WP Error returned.' ); + $this->assertIsArray( $ret, 'Image failed to save - non-array response returned.' ); $this->assertSame( $mime_type, $this->get_mime_type( $ret['path'] ), 'Mime type of the saved image was not inferred correctly.' ); // Clean up. @@ -679,7 +679,8 @@ class Tests_Image_Functions extends WP_UnitTestCase { ) ); - $this->assertNotEmpty( $attachment_id ); + $this->assertNotWPError( $attachment_id, 'Could not create attachment - WP_Error returned.' ); + $this->assertIsInt( $attachment_id, 'Could not create attachment - non-integer response returned.' ); $temp_dir = get_temp_dir(); @@ -756,7 +757,8 @@ class Tests_Image_Functions extends WP_UnitTestCase { ) ); - $this->assertNotEmpty( $attachment_id ); + $this->assertNotWPError( $attachment_id, 'Could not create attachment - WP_Error returned.' ); + $this->assertIsInt( $attachment_id, 'Could not create attachment - non-integer response returned.' ); $temp_dir = get_temp_dir(); @@ -829,7 +831,8 @@ class Tests_Image_Functions extends WP_UnitTestCase { ) ); - $this->assertNotEmpty( $attachment_id ); + $this->assertNotWPError( $attachment_id, 'Could not create attachment - WP_Error returned.' ); + $this->assertIsInt( $attachment_id, 'Could not create attachment - non-integer response returned.' ); add_image_size( 'test-size', 100, 100 ); add_filter( 'fallback_intermediate_image_sizes', array( $this, 'filter_fallback_intermediate_image_sizes' ), 10, 2 );