From 68b71263f37b822fcf39ce9b7aa7da40f320e913 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 20 Sep 2020 13:25:07 +0000 Subject: [PATCH] Tests: Optimize some image tests to avoid checking for image editor engines availability twice. Follow-up to [49009]. See #50639, #50640. git-svn-id: https://develop.svn.wordpress.org/trunk@49014 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/image/functions.php | 71 ++++++++++++++----------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php index 99936c7d00..1daf479360 100644 --- a/tests/phpunit/tests/image/functions.php +++ b/tests/phpunit/tests/image/functions.php @@ -155,7 +155,16 @@ class Tests_Image_Functions extends WP_UnitTestCase { $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' ); } - if ( ! WP_Image_Editor_GD::test() && ! WP_Image_Editor_Imagick::test() ) { + $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); + + foreach ( $classes as $class ) { + if ( ! call_user_func( array( $class, 'test' ) ) ) { + // If the image editor isn't available, skip it. + unset( $classes[ $class ] ); + } + } + + if ( ! $classes ) { $this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) ); } @@ -169,14 +178,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { ); // Test each image editor engine. - $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); foreach ( $classes as $class ) { - - // If the image editor isn't available, skip it. - if ( ! call_user_func( array( $class, 'test' ) ) ) { - continue; - } - $img = new $class( DIR_TESTDATA . '/images/canola.jpg' ); $loaded = $img->load(); @@ -212,19 +214,21 @@ class Tests_Image_Functions extends WP_UnitTestCase { $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' ); } - if ( ! WP_Image_Editor_GD::test() && ! WP_Image_Editor_Imagick::test() ) { + $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); + + foreach ( $classes as $class ) { + if ( ! call_user_func( array( $class, 'test' ) ) ) { + // If the image editor isn't available, skip it. + unset( $classes[ $class ] ); + } + } + + if ( ! $classes ) { $this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) ); } // Test each image editor engine. - $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); foreach ( $classes as $class ) { - - // If the image editor isn't available, skip it. - if ( ! call_user_func( array( $class, 'test' ) ) ) { - continue; - } - $img = new $class( DIR_TESTDATA . '/images/canola.jpg' ); $loaded = $img->load(); @@ -255,7 +259,16 @@ class Tests_Image_Functions extends WP_UnitTestCase { $this->markTestSkipped( 'The fileinfo PHP extension is not loaded.' ); } - if ( ! WP_Image_Editor_GD::test() && ! WP_Image_Editor_Imagick::test() ) { + $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); + + foreach ( $classes as $class ) { + if ( ! call_user_func( array( $class, 'test' ) ) ) { + // If the image editor isn't available, skip it. + unset( $classes[ $class ] ); + } + } + + if ( ! $classes ) { $this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) ); } @@ -270,14 +283,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { ); // Test each image editor engine. - $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); foreach ( $classes as $class ) { - - // If the image editor isn't available, skip it. - if ( ! call_user_func( array( $class, 'test' ) ) ) { - continue; - } - $img = new $class( DIR_TESTDATA . '/images/canola.jpg' ); $loaded = $img->load(); @@ -319,18 +325,21 @@ class Tests_Image_Functions extends WP_UnitTestCase { $editor2 = wp_get_image_editor( DIR_TESTDATA ); $this->assertNotInternalType( 'resource', $editor2 ); - if ( ! WP_Image_Editor_GD::test() && ! WP_Image_Editor_Imagick::test() ) { + $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); + + foreach ( $classes as $class ) { + if ( ! call_user_func( array( $class, 'test' ) ) ) { + // If the image editor isn't available, skip it. + unset( $classes[ $class ] ); + } + } + + if ( ! $classes ) { $this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) ); } // Then, test with editors. - $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' ); foreach ( $classes as $class ) { - // If the image editor isn't available, skip it. - if ( ! call_user_func( array( $class, 'test' ) ) ) { - continue; - } - $editor = new $class( DIR_TESTDATA ); $loaded = $editor->load();