Media: Some documentation and test improvements for the image_editor_output_format filter:

* Update the filter DocBlock per the documentation standards.
* Use a shorter variable name for consistency with the surrounding code.
* Delete the test file before performing assertions to avoid leftovers in case the test fails.

Follow-up to [50943].

See #52867.

git-svn-id: https://develop.svn.wordpress.org/trunk@50951 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2021-05-22 12:58:46 +00:00
parent 2fc2afb107
commit 655fbb26ab
2 changed files with 17 additions and 15 deletions

View File

@@ -52,19 +52,19 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
function test_make_intermediate_size_successful() {
$image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 100, 75, true );
unlink( DIR_TESTDATA . '/images/a2-small-100x75.jpg' );
$this->assertInternalType( 'array', $image );
$this->assertSame( 100, $image['width'] );
$this->assertSame( 75, $image['height'] );
$this->assertSame( 'image/jpeg', $image['mime-type'] );
$this->assertFalse( isset( $image['path'] ) );
unlink( DIR_TESTDATA . '/images/a2-small-100x75.jpg' );
}
/**
* @requires function imagejpeg
* @ticket 52867
* @requires function imagejpeg
*/
function test_image_editor_output_format_filter() {
add_filter(
@@ -73,16 +73,19 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase {
return array( 'image/jpeg' => 'image/webp' );
}
);
$file = DIR_TESTDATA . '/images/waffles.jpg';
$image = image_make_intermediate_size( $file, 100, 75, true );
$editor = wp_get_image_editor( $file );
unlink( DIR_TESTDATA . '/images/' . $image['file'] );
remove_all_filters( 'image_editor_output_format' );
if ( is_wp_error( $editor ) || ! $editor->supports_mime_type( 'image/webp' ) ) {
$this->assertSame( 'image/jpeg', $image['mime-type'] );
} else {
$this->assertSame( 'image/webp', $image['mime-type'] );
}
unlink( DIR_TESTDATA . '/images/' . $image['file'] );
remove_all_filters( 'image_editor_output_format' );
}
/**