Make WordPress Core

Changeset 49014


Ignore:
Timestamp:
09/20/2020 01:25:07 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Tests: Optimize some image tests to avoid checking for image editor engines availability twice.

Follow-up to [49009].

See #50639, #50640.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/functions.php

    r49009 r49014  
    156156                }
    157157
    158                 if ( ! WP_Image_Editor_GD::test() && ! WP_Image_Editor_Imagick::test() ) {
     158                $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
     159
     160                foreach ( $classes as $class ) {
     161                        if ( ! call_user_func( array( $class, 'test' ) ) ) {
     162                                // If the image editor isn't available, skip it.
     163                                unset( $classes[ $class ] );
     164                        }
     165                }
     166
     167                if ( ! $classes ) {
    159168                        $this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) );
    160169                }
    … …  
    170179
    171180                // Test each image editor engine.
    172                 $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
    173181                foreach ( $classes as $class ) {
    174 
    175                         // If the image editor isn't available, skip it.
    176                         if ( ! call_user_func( array( $class, 'test' ) ) ) {
    177                                 continue;
    178                         }
    179 
    180182                        $img    = new $class( DIR_TESTDATA . '/images/canola.jpg' );
    181183                        $loaded = $img->load();
    … …  
    213215                }
    214216
    215                 if ( ! WP_Image_Editor_GD::test() && ! WP_Image_Editor_Imagick::test() ) {
     217                $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
     218
     219                foreach ( $classes as $class ) {
     220                        if ( ! call_user_func( array( $class, 'test' ) ) ) {
     221                                // If the image editor isn't available, skip it.
     222                                unset( $classes[ $class ] );
     223                        }
     224                }
     225
     226                if ( ! $classes ) {
    216227                        $this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) );
    217228                }
    218229
    219230                // Test each image editor engine.
    220                 $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
    221231                foreach ( $classes as $class ) {
    222 
    223                         // If the image editor isn't available, skip it.
    224                         if ( ! call_user_func( array( $class, 'test' ) ) ) {
    225                                 continue;
    226                         }
    227 
    228232                        $img    = new $class( DIR_TESTDATA . '/images/canola.jpg' );
    229233                        $loaded = $img->load();
    … …  
    256260                }
    257261
    258                 if ( ! WP_Image_Editor_GD::test() && ! WP_Image_Editor_Imagick::test() ) {
     262                $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
     263
     264                foreach ( $classes as $class ) {
     265                        if ( ! call_user_func( array( $class, 'test' ) ) ) {
     266                                // If the image editor isn't available, skip it.
     267                                unset( $classes[ $class ] );
     268                        }
     269                }
     270
     271                if ( ! $classes ) {
    259272                        $this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) );
    260273                }
    … …  
    271284
    272285                // Test each image editor engine.
    273                 $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
    274286                foreach ( $classes as $class ) {
    275 
    276                         // If the image editor isn't available, skip it.
    277                         if ( ! call_user_func( array( $class, 'test' ) ) ) {
    278                                 continue;
    279                         }
    280 
    281287                        $img    = new $class( DIR_TESTDATA . '/images/canola.jpg' );
    282288                        $loaded = $img->load();
    … …  
    320326                $this->assertNotInternalType( 'resource', $editor2 );
    321327
    322                 if ( ! WP_Image_Editor_GD::test() && ! WP_Image_Editor_Imagick::test() ) {
     328                $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
     329
     330                foreach ( $classes as $class ) {
     331                        if ( ! call_user_func( array( $class, 'test' ) ) ) {
     332                                // If the image editor isn't available, skip it.
     333                                unset( $classes[ $class ] );
     334                        }
     335                }
     336
     337                if ( ! $classes ) {
    323338                        $this->markTestSkipped( sprintf( 'The image editor engine %s is not supported on this system.', 'WP_Image_Editor_GD' ) );
    324339                }
    325340
    326341                // Then, test with editors.
    327                 $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
    328342                foreach ( $classes as $class ) {
    329                         // If the image editor isn't available, skip it.
    330                         if ( ! call_user_func( array( $class, 'test' ) ) ) {
    331                                 continue;
    332                         }
    333 
    334343                        $editor = new $class( DIR_TESTDATA );
    335344                        $loaded = $editor->load();
Note: See TracChangeset for help on using the changeset viewer.