Make WordPress Core

Changeset 53495


Ignore:
Timestamp:
06/13/2022 04:42:17 PM (3 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

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

    r53292 r53495  
    2626            unlink( $file );
    2727        }
     28    }
     29
     30    /**
     31     * Get the available image editor engine class(es).
     32     *
     33     * @return string[] Available image editor classes; empty array when none are available.
     34     */
     35    private function get_image_editor_engine_classes() {
     36        $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
     37
     38        foreach ( $classes as $key => $class ) {
     39            if ( ! call_user_func( array( $class, 'test' ) ) ) {
     40                // If the image editor isn't available, skip it.
     41                unset( $classes[ $key ] );
     42            }
     43        }
     44
     45        if ( empty( $classes ) ) {
     46            $this->markTestSkipped( 'Image editor engines WP_Image_Editor_GD and WP_Image_Editor_Imagick are not supported on this system.' );
     47        }
     48
     49        return $classes;
    2850    }
    2951
     
    322344
    323345    /**
    324      * Get the available image editor engine class(es).
    325      *
    326      * @return string[] Available image editor classes; empty array when none are avaialble.
    327      */
    328     private function get_image_editor_engine_classes() {
    329         $classes = array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
    330 
    331         foreach ( $classes as $key => $class ) {
    332             if ( ! call_user_func( array( $class, 'test' ) ) ) {
    333                 // If the image editor isn't available, skip it.
    334                 unset( $classes[ $key ] );
    335             }
    336         }
    337 
    338         if ( empty( $classes ) ) {
    339             $this->markTestSkipped( 'Image editor engines WP_Image_Editor_GD and WP_Image_Editor_Imagick are not supported on this system.' );
    340         }
    341 
    342         return $classes;
    343     }
    344 
    345     /**
    346346     * @ticket 55403
    347347     */
     
    447447    }
    448448
    449     public function mock_image_editor( $editors ) {
    450         return array( 'WP_Image_Editor_Mock' );
    451     }
    452 
    453449    /**
    454450     * @ticket 23325
     
    471467        remove_filter( 'wp_image_editors', array( $this, 'mock_image_editor' ) );
    472468        WP_Image_Editor_Mock::$save_return = array();
     469    }
     470
     471    /**
     472     * @see test_wp_crop_image_error_on_saving()
     473     */
     474    public function mock_image_editor( $editors ) {
     475        return array( 'WP_Image_Editor_Mock' );
    473476    }
    474477
Note: See TracChangeset for help on using the changeset viewer.