Make WordPress Core

Changeset 49024


Ignore:
Timestamp:
09/21/2020 11:34:06 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Tests: Convert the checks for imagejpeg() function availability to use the @requires annotation.

This better utilizes the PHPUnit native functionality.

Props ayeshrajans, jrf, johnbillion.
Fixes #50639. See #50640.

Location:
trunk/tests/phpunit/tests
Files:
4 edited

Legend:

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

    r49006 r49024  
    144144         * @ticket 6821
    145145         * @expectedDeprecated wp_save_image_file
     146         * @requires function imagejpeg
    146147         *
    147148         * @covers ::wp_save_image_file
    148149         */
    149150        public function test_wp_save_image_file_deprecated_with_gd_resource() {
    150                 if ( ! function_exists( 'imagejpeg' ) ) {
    151                         $this->fail( 'jpeg support unavailable' );
    152                 }
    153 
    154151                // Call wp_save_image_file().
    155152                require_once ABSPATH . 'wp-admin/includes/image-edit.php';
     
    169166         *
    170167         * @ticket 6821
     168         * @requires function imagejpeg
    171169         *
    172170         * @covers ::wp_save_image_file
    173171         */
    174172        public function test_wp_save_image_file_not_deprecated_with_wp_image_editor() {
    175                 if ( ! function_exists( 'imagejpeg' ) ) {
    176                         $this->fail( 'jpeg support unavailable' );
    177                 }
    178 
    179173                // Call wp_save_image_file().
    180174                require_once ABSPATH . 'wp-admin/includes/image-edit.php';
  • trunk/tests/phpunit/tests/image/functions.php

    r49018 r49024  
    349349        }
    350350
     351        /**
     352         * @requires function imagejpeg
     353         */
    351354        public function test_wp_crop_image_file() {
    352                 if ( ! function_exists( 'imagejpeg' ) ) {
    353                         $this->fail( 'jpeg support unavailable' );
    354                 }
    355 
    356355                $file = wp_crop_image(
    357356                        DIR_TESTDATA . '/images/canola.jpg',
     
    373372        }
    374373
     374        /**
     375         * @requires function imagejpeg
     376         */
    375377        public function test_wp_crop_image_url() {
    376                 if ( ! function_exists( 'imagejpeg' ) ) {
    377                         $this->fail( 'jpeg support unavailable' );
    378                 }
    379 
    380378                if ( ! extension_loaded( 'openssl' ) ) {
    381379                        $this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url() requires openssl.' );
  • trunk/tests/phpunit/tests/image/intermediateSize.php

    r49010 r49024  
    2929        }
    3030
     31        /**
     32         * @requires function imagejpeg
     33         */
    3134        function test_make_intermediate_size_width() {
    32                 if ( ! function_exists( 'imagejpeg' ) ) {
    33                         $this->fail( 'jpeg support unavailable' );
    34                 }
    35 
    3635                $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 100, 0, false );
    3736
     
    3938        }
    4039
     40        /**
     41         * @requires function imagejpeg
     42         */
    4143        function test_make_intermediate_size_height() {
    42                 if ( ! function_exists( 'imagejpeg' ) ) {
    43                         $this->fail( 'jpeg support unavailable' );
    44                 }
    45 
    4644                $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 0, 75, false );
    4745
     
    4947        }
    5048
     49        /**
     50         * @requires function imagejpeg
     51         */
    5152        function test_make_intermediate_size_successful() {
    52                 if ( ! function_exists( 'imagejpeg' ) ) {
    53                         $this->fail( 'jpeg support unavailable' );
    54                 }
    55 
    5653                $image = image_make_intermediate_size( DIR_TESTDATA . '/images/a2-small.jpg', 100, 75, true );
    5754
     
    6865        /**
    6966         * @ticket 17626
     67         * @requires function imagejpeg
    7068         */
    7169        function test_get_intermediate_sizes_by_name() {
    72                 if ( ! function_exists( 'imagejpeg' ) ) {
    73                         $this->fail( 'jpeg support unavailable' );
    74                 }
    75 
    7670                add_image_size( 'test-size', 330, 220, true );
    7771
     
    9286        /**
    9387         * @ticket 17626
     88         * @requires function imagejpeg
    9489         */
    9590        function test_get_intermediate_sizes_by_array_exact() {
    96                 if ( ! function_exists( 'imagejpeg' ) ) {
    97                         $this->fail( 'jpeg support unavailable' );
    98                 }
    99 
    10091                // Only one dimention match shouldn't return false positive (see: #17626).
    10192                add_image_size( 'test-size', 330, 220, true );
     
    117108        /**
    118109         * @ticket 17626
     110         * @requires function imagejpeg
    119111         */
    120112        function test_get_intermediate_sizes_by_array_nearest() {
    121                 if ( ! function_exists( 'imagejpeg' ) ) {
    122                         $this->fail( 'jpeg support unavailable' );
    123                 }
    124 
    125113                // If an exact size is not found, it should be returned.
    126114                // If not, find nearest size that is larger (see: #17626).
     
    164152        /**
    165153         * @ticket 17626
     154         * @requires function imagejpeg
    166155         */
    167156        function test_get_intermediate_sizes_by_array_zero_height() {
    168                 if ( ! function_exists( 'imagejpeg' ) ) {
    169                         $this->fail( 'jpeg support unavailable' );
    170                 }
    171 
    172157                // Generate random width.
    173158                $random_w = rand( 300, 400 );
     
    196181         * @ticket 17626
    197182         * @ticket 34087
     183         * @requires function imagejpeg
    198184         */
    199185        function test_get_intermediate_sizes_by_array_zero_width() {
    200                 if ( ! function_exists( 'imagejpeg' ) ) {
    201                         $this->fail( 'jpeg support unavailable' );
    202                 }
    203 
    204186                // 202 is the smallest height that will trigger a miss for 'false-height'.
    205187                $height = 202;
     
    228210         * @ticket 17626
    229211         * @ticket 34087
     212         * @requires function imagejpeg
    230213         */
    231214        public function test_get_intermediate_sizes_should_match_size_with_off_by_one_aspect_ratio() {
    232                 if ( ! function_exists( 'imagejpeg' ) ) {
    233                         $this->fail( 'jpeg support unavailable' );
    234                 }
    235 
    236215                // Original is 600x400. 300x201 is close enough to match.
    237216                $width  = 300;
     
    255234        /**
    256235         * @ticket 34384
     236         * @requires function imagejpeg
    257237         */
    258238        public function test_get_intermediate_size_with_small_size_array() {
    259                 if ( ! function_exists( 'imagejpeg' ) ) {
    260                         $this->fail( 'jpeg support unavailable' );
    261                 }
    262 
    263239                // Add a hard cropped size that matches the aspect ratio we're going to test.
    264240                add_image_size( 'test-size', 200, 100, true );
     
    276252        /**
    277253         * @ticket 34384
     254         * @requires function imagejpeg
    278255         */
    279256        public function test_get_intermediate_size_with_small_size_array_fallback() {
    280                 if ( ! function_exists( 'imagejpeg' ) ) {
    281                         $this->fail( 'jpeg support unavailable' );
    282                 }
    283 
    284257                $file = DIR_TESTDATA . '/images/waffles.jpg';
    285258                $id   = $this->_make_attachment( $file, 0 );
  • trunk/tests/phpunit/tests/post/attachments.php

    r48937 r49024  
    5555        }
    5656
     57        /**
     58         * @requires function imagejpeg
     59         */
    5760        function test_insert_image_thumb_only() {
    58                 if ( ! function_exists( 'imagejpeg' ) ) {
    59                         $this->fail( 'jpeg support unavailable' );
    60                 }
    61 
    6261                update_option( 'medium_size_w', 0 );
    6362                update_option( 'medium_size_h', 0 );
     
    107106        }
    108107
     108        /**
     109         * @requires function imagejpeg
     110         */
    109111        function test_insert_image_medium_sizes() {
    110                 if ( ! function_exists( 'imagejpeg' ) ) {
    111                         $this->fail( 'jpeg support unavailable' );
    112                 }
    113 
    114112                update_option( 'medium_size_w', 400 );
    115113                update_option( 'medium_size_h', 0 );
     
    165163        }
    166164
    167 
     165        /**
     166         * @requires function imagejpeg
     167         */
    168168        function test_insert_image_delete() {
    169                 if ( ! function_exists( 'imagejpeg' ) ) {
    170                         $this->fail( 'jpeg support unavailable' );
    171                 }
    172 
    173169                update_option( 'medium_size_w', 400 );
    174170                update_option( 'medium_size_h', 0 );
Note: See TracChangeset for help on using the changeset viewer.