Tests: Move helper functions in Tests_Image_Functions to more appropriate places.

* Move a non-test specific helper function used by multiple tests up to the top of the class to make it more easily discoverable.
* Move a test-specific helper function used by only one test to be directly below the test using the helper function and make the link with the test explicit by adding a `@see` tag.

Follow-up to [1201/tests], [51415].

Props jrf.
See #55652.

git-svn-id: https://develop.svn.wordpress.org/trunk@53495 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2022-06-13 16:42:17 +00:00
parent c33e34d8a5
commit 2aa8e490e0

View File

@ -27,6 +27,28 @@ class Tests_Image_Functions extends WP_UnitTestCase {
}
}
/**
* Get the available image editor engine class(es).
*
* @return string[] Available image editor classes; empty array when none are available.
*/
private function get_image_editor_engine_classes() {
$classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
foreach ( $classes as $key => $class ) {
if ( ! call_user_func( array( $class, 'test' ) ) ) {
// If the image editor isn't available, skip it.
unset( $classes[ $key ] );
}
}
if ( empty( $classes ) ) {
$this->markTestSkipped( 'Image editor engines WP_Image_Editor_GD and WP_Image_Editor_Imagick are not supported on this system.' );
}
return $classes;
}
/**
* Get the MIME type of a file
*
@ -320,28 +342,6 @@ class Tests_Image_Functions extends WP_UnitTestCase {
}
}
/**
* Get the available image editor engine class(es).
*
* @return string[] Available image editor classes; empty array when none are avaialble.
*/
private function get_image_editor_engine_classes() {
$classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
foreach ( $classes as $key => $class ) {
if ( ! call_user_func( array( $class, 'test' ) ) ) {
// If the image editor isn't available, skip it.
unset( $classes[ $key ] );
}
}
if ( empty( $classes ) ) {
$this->markTestSkipped( 'Image editor engines WP_Image_Editor_GD and WP_Image_Editor_Imagick are not supported on this system.' );
}
return $classes;
}
/**
* @ticket 55403
*/
@ -446,10 +446,6 @@ class Tests_Image_Functions extends WP_UnitTestCase {
$this->assertInstanceOf( 'WP_Error', $file );
}
public function mock_image_editor( $editors ) {
return array( 'WP_Image_Editor_Mock' );
}
/**
* @ticket 23325
*/
@ -472,6 +468,13 @@ class Tests_Image_Functions extends WP_UnitTestCase {
WP_Image_Editor_Mock::$save_return = array();
}
/**
* @see test_wp_crop_image_error_on_saving()
*/
public function mock_image_editor( $editors ) {
return array( 'WP_Image_Editor_Mock' );
}
/**
* @ticket 31050
*/