Make WordPress Core

Changeset 53526


Ignore:
Timestamp:
06/19/2022 03:34:21 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Refactor Tests_Image_Functions::test_is_displayable_image_negative() to use a data provider.

Using a data provider has a number of advantages:

  1. If the first test case fails, it won't prevent the other test cases from being tested.
  2. While the assertion used in this test method does have a "failure message" (👍), the output from PHPUnit itself will already be more descriptive in case of failure when using a data provider.
  3. Using named test cases in the data provider will also make the --testdox output much more descriptive and informative.

The actual cases being tested, or the test itself have not been changed.

Includes:

  • Adding a @covers annotation.

Follow-up to [184/tests], [53495], [53497], [53521], [53523], [53524], [53525].

Props jrf.
See #55652.

File:
1 edited

Legend:

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

    r53525 r53526  
    8888                $files = array(
    8989                        'test-image-cmyk.jpg',
     90                        'test-image-grayscale.jpg',
    9091                        'test-image.bmp',
    91                         'test-image-grayscale.jpg',
    9292                        'test-image.gif',
    9393                        'test-image.png',
     
    181181        }
    182182
    183         public function test_is_displayable_image_negative() {
     183        /**
     184         * @dataProvider data_is_displayable_image_negative
     185         *
     186         * @covers ::file_is_displayable_image
     187         *
     188         * @param string $file File name.
     189         */
     190        public function test_is_displayable_image_negative( $file ) {
     191                $this->assertFalse(
     192                        file_is_displayable_image( DIR_TESTDATA . '/images/' . $file ),
     193                        "file_is_displayable_image( '$file' ) should return false"
     194                );
     195        }
     196
     197        /**
     198         * Data provider.
     199         *
     200         * @return array
     201         */
     202        public function data_is_displayable_image_negative() {
    184203                // These are image files but aren't suitable for web pages because of compatibility or size issues.
    185204                $files = array(
    186205                        // 'test-image-cmyk.jpg',      Allowed in r9727.
     206                        // 'test-image-grayscale.jpg', Allowed in r9727.
    187207                        // 'test-image.bmp',           Allowed in r28589.
    188                         // 'test-image-grayscale.jpg', Allowed in r9727.
    189208                        'test-image.pct',
    190209                        'test-image.tga',
     
    197216                );
    198217
    199                 foreach ( $files as $file ) {
    200                         $this->assertFalse( file_is_displayable_image( DIR_TESTDATA . '/images/' . $file ), "file_is_valid_image($file) should return false" );
    201                 }
     218                return $this->text_array_to_dataprovider( $files );
    202219        }
    203220
Note: See TracChangeset for help on using the changeset viewer.