Tests: Improve Tests_Image_Functions::test_wp_crop_image*() tests.

Includes:
* Adding `@covers` annotations.
* Adding a failure message to each assertion when multiple assertions are used in the test.

Follow-up to [1126/tests], [53495], [53497], [53521], [53523], [53524], [53525], [53526], [53529], [53530], [53531], [53537].

Props jrf.
See #55652.

git-svn-id: https://develop.svn.wordpress.org/trunk@53538 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2022-06-20 21:35:03 +00:00
parent 1e48121fd6
commit 1ce3d79729

View File

@@ -484,6 +484,7 @@ class Tests_Image_Functions extends WP_UnitTestCase {
/**
* @ticket 55403
* @covers ::wp_crop_image
*/
public function test_wp_crop_image_with_filtered_extension() {
add_filter( 'image_editor_output_format', array( $this, 'filter_image_editor_output_format' ) );
@@ -508,6 +509,7 @@ class Tests_Image_Functions extends WP_UnitTestCase {
}
/**
* @covers ::wp_crop_image
* @requires function imagejpeg
*/
public function test_wp_crop_image_file() {
@@ -520,17 +522,20 @@ class Tests_Image_Functions extends WP_UnitTestCase {
100,
100
);
$this->assertNotWPError( $file );
$this->assertFileExists( $file );
$this->assertNotWPError( $file, 'Cropping the image resulted in a WP_Error.' );
$this->assertFileExists( $file, "The file $file does not exist." );
$image = wp_get_image_editor( $file );
$size = $image->get_size();
$this->assertSame( 100, $size['height'] );
$this->assertSame( 100, $size['width'] );
$this->assertSame( 100, $size['height'], 'Cropped image height does not match expectation.' );
$this->assertSame( 100, $size['width'], 'Cropped image width does not match expectation.' );
unlink( $file );
}
/**
* @covers ::wp_crop_image
* @requires function imagejpeg
* @requires extension openssl
*/
@@ -551,17 +556,22 @@ class Tests_Image_Functions extends WP_UnitTestCase {
$this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url() cannot access remote image.' );
}
$this->assertNotWPError( $file );
$this->assertFileExists( $file );
$this->assertNotWPError( $file, 'Cropping the image resulted in a WP_Error.' );
$this->assertFileExists( $file, "The file $file does not exist." );
$image = wp_get_image_editor( $file );
$size = $image->get_size();
$this->assertSame( 100, $size['height'] );
$this->assertSame( 100, $size['width'] );
$this->assertSame( 100, $size['height'], 'Cropped image height does not match expectation.' );
$this->assertSame( 100, $size['width'], 'Cropped image width does not match expectation.' );
unlink( $file );
}
public function test_wp_crop_image_file_not_exist() {
/**
* @covers ::wp_crop_image
*/
public function test_wp_crop_image_file_not_exists() {
$file = wp_crop_image(
DIR_TESTDATA . '/images/canoladoesnotexist.jpg',
0,
@@ -575,9 +585,10 @@ class Tests_Image_Functions extends WP_UnitTestCase {
}
/**
* @covers ::wp_crop_image
* @requires extension openssl
*/
public function test_wp_crop_image_url_not_exist() {
public function test_wp_crop_image_url_not_exists() {
$file = wp_crop_image(
'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg',
0,
@@ -592,6 +603,7 @@ class Tests_Image_Functions extends WP_UnitTestCase {
/**
* @ticket 23325
* @covers ::wp_crop_image
*/
public function test_wp_crop_image_error_on_saving() {
WP_Image_Editor_Mock::$save_return = new WP_Error();