From 655fbb26ab593e436146672b92208fbb4084d0e1 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 22 May 2021 12:58:46 +0000 Subject: [PATCH] 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 --- src/wp-includes/class-wp-image-editor.php | 19 +++++++++---------- .../phpunit/tests/image/intermediateSize.php | 13 ++++++++----- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/wp-includes/class-wp-image-editor.php b/src/wp-includes/class-wp-image-editor.php index d322d6a7cb..37b65ca8d1 100644 --- a/src/wp-includes/class-wp-image-editor.php +++ b/src/wp-includes/class-wp-image-editor.php @@ -322,29 +322,28 @@ abstract class WP_Image_Editor { * Enables filtering the mime type used to save images. By default, * the mapping array is empty, so the mime type matches the source image. * - * @see src/wp-includes/class-wp-image-editor.php -> get_output_format() + * @see WP_Image_Editor::get_output_format() * * @since 5.8.0 * - * @param array $wp_image_editor_output_format { + * @param array $output_format { * An array of mime type mappings. Maps a source mime type to a new - * destination mime type. Empty by default. + * destination mime type. Default empty array. * * @type array $mime_type The source mime type { * @type string $mime_type The new mime type. * } - * @param string $filename Path to the image. + * @param string $filename Path to the image. * @param string $mime_type The source image mime type. * } */ - $wp_image_editor_output_format = apply_filters( 'image_editor_output_format', array(), $filename, $mime_type ); + $output_format = apply_filters( 'image_editor_output_format', array(), $filename, $mime_type ); - if ( - isset( $wp_image_editor_output_format[ $mime_type ] ) && - $this->supports_mime_type( $wp_image_editor_output_format[ $mime_type ] ) + if ( isset( $output_format[ $mime_type ] ) + && $this->supports_mime_type( $output_format[ $mime_type ] ) ) { - $mime_type = $wp_image_editor_output_format[ $mime_type ]; - $new_ext = $this->get_extension( $mime_type ); + $mime_type = $output_format[ $mime_type ]; + $new_ext = $this->get_extension( $mime_type ); } // Double-check that the mime-type selected is supported by the editor. diff --git a/tests/phpunit/tests/image/intermediateSize.php b/tests/phpunit/tests/image/intermediateSize.php index 28ccb220a6..86e2c87323 100644 --- a/tests/phpunit/tests/image/intermediateSize.php +++ b/tests/phpunit/tests/image/intermediateSize.php @@ -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' ); } /**