mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-03 14:17:06 +00:00
Tests: Clean up skipping conditions and requirements for various tests.
This improves the consistency of test skipping and ensures that: * The `@requires` annotations use the right condition and format, and are on the right level (class vs. function). * Inline conditions with a `markTestSkipped()` call are only used when annotations cannot be used. * All `markTestSkipped()` calls contain a verbose explanation of why the test is being skipped. Props jrf, hellofromTonya. Fixes #53009. git-svn-id: https://develop.svn.wordpress.org/trunk@51415 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -172,18 +172,7 @@ class Tests_Image_Functions extends WP_UnitTestCase {
|
||||
* @requires extension fileinfo
|
||||
*/
|
||||
public function test_wp_save_image_file() {
|
||||
$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 ( ! $classes ) {
|
||||
$this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) );
|
||||
}
|
||||
$classes = $this->get_image_editor_engine_classes();
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/image-edit.php';
|
||||
|
||||
@@ -233,18 +222,7 @@ class Tests_Image_Functions extends WP_UnitTestCase {
|
||||
* @requires extension fileinfo
|
||||
*/
|
||||
public function test_mime_overrides_filename() {
|
||||
$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 ( ! $classes ) {
|
||||
$this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) );
|
||||
}
|
||||
$classes = $this->get_image_editor_engine_classes();
|
||||
|
||||
// Test each image editor engine.
|
||||
foreach ( $classes as $class ) {
|
||||
@@ -275,18 +253,7 @@ class Tests_Image_Functions extends WP_UnitTestCase {
|
||||
* @requires extension fileinfo
|
||||
*/
|
||||
public function test_inferred_mime_types() {
|
||||
$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 ( ! $classes ) {
|
||||
$this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) );
|
||||
}
|
||||
$classes = $this->get_image_editor_engine_classes();
|
||||
|
||||
// Mime types.
|
||||
$mime_types = array(
|
||||
@@ -342,18 +309,7 @@ class Tests_Image_Functions extends WP_UnitTestCase {
|
||||
$editor2 = wp_get_image_editor( DIR_TESTDATA );
|
||||
$this->assertInstanceOf( 'WP_Error', $editor2 );
|
||||
|
||||
$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 ( ! $classes ) {
|
||||
$this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) );
|
||||
}
|
||||
$classes = $this->get_image_editor_engine_classes();
|
||||
|
||||
// Then, test with editors.
|
||||
foreach ( $classes as $class ) {
|
||||
@@ -365,6 +321,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 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires function imagejpeg
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user