Make WordPress Core


Ignore:
Timestamp:
03/19/2023 12:03:30 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use the data_ prefix for various data provider methods.

This aims to bring more consistency to the test suite, as the vast majority of data providers already use that prefix.

Includes moving some data providers next to the tests they are used in.

Follow-up to [55464].

See #57841.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/balanceTags.php

    r54727 r55562  
    88class Tests_Formatting_BalanceTags extends WP_UnitTestCase {
    99
    10         public function nestable_tags() {
    11                 return array(
    12                         array( 'article' ),
    13                         array( 'aside' ),
    14                         array( 'blockquote' ),
    15                         array( 'details' ),
    16                         array( 'div' ),
    17                         array( 'figure' ),
    18                         array( 'object' ),
    19                         array( 'q' ),
    20                         array( 'section' ),
    21                         array( 'span' ),
    22                 );
    23         }
    24 
    25         // This is a complete(?) listing of valid single/self-closing tags.
    26         public function single_tags() {
    27                 return array(
    28                         array( 'area' ),
    29                         array( 'base' ),
    30                         array( 'basefont' ),
    31                         array( 'br' ),
    32                         array( 'col' ),
    33                         array( 'command' ),
    34                         array( 'embed' ),
    35                         array( 'frame' ),
    36                         array( 'hr' ),
    37                         array( 'img' ),
    38                         array( 'input' ),
    39                         array( 'isindex' ),
    40                         array( 'link' ),
    41                         array( 'meta' ),
    42                         array( 'param' ),
    43                         array( 'source' ),
    44                         array( 'track' ),
    45                         array( 'wbr' ),
    46                 );
    47         }
    48 
    49         public function supported_traditional_tag_names() {
     10        /**
     11         * @ticket 47014
     12         * @dataProvider data_supported_traditional_tag_names
     13         */
     14        public function test_detects_traditional_tag_names( $tag ) {
     15                $normalized = strtolower( $tag );
     16
     17                $this->assertSame( "<$normalized>inside</$normalized>", balanceTags( "<$tag>inside", true ) );
     18        }
     19
     20        public function data_supported_traditional_tag_names() {
    5021                return array(
    5122                        array( 'a' ),
     
    5930        }
    6031
    61         public function supported_custom_element_tag_names() {
     32        /**
     33         * @ticket 47014
     34         * @dataProvider data_supported_custom_element_tag_names
     35         */
     36        public function test_detects_supported_custom_element_tag_names( $tag ) {
     37                $this->assertSame( "<$tag>inside</$tag>", balanceTags( "<$tag>inside", true ) );
     38        }
     39
     40        public function data_supported_custom_element_tag_names() {
    6241                return array(
    6342                        array( 'custom-element' ),
     
    7150        }
    7251
    73         public function invalid_tag_names() {
     52        /**
     53         * @ticket 47014
     54         * @dataProvider data_invalid_tag_names
     55         */
     56        public function test_ignores_invalid_tag_names( $input, $output ) {
     57                $this->assertSame( $output, balanceTags( $input, true ) );
     58        }
     59
     60        public function data_invalid_tag_names() {
    7461                return array(
    7562                        array( '<0-day>inside', '&lt;0-day>inside' ), // Can't start with a number - handled by the "<3" fix.
     
    7966
    8067        /**
     68         * @ticket 47014
     69         * @dataProvider data_unsupported_valid_tag_names
     70         */
     71        public function test_ignores_unsupported_custom_tag_names( $tag ) {
     72                $this->assertSame( "<$tag>inside", balanceTags( "<$tag>inside", true ) );
     73        }
     74
     75        /**
    8176         * These are valid custom elements but we don't support them yet.
    8277         *
    8378         * @see https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
    8479         */
    85         public function unsupported_valid_tag_names() {
     80        public function data_unsupported_valid_tag_names() {
    8681                return array(
    8782                        // We don't allow ending in a dash.
     
    139134
    140135        /**
     136         * @ticket 47014
     137         * @dataProvider data_supported_invalid_tag_names
     138         */
     139        public function test_detects_supported_invalid_tag_names( $tag ) {
     140                $this->assertSame( "<$tag>inside</$tag>", balanceTags( "<$tag>inside", true ) );
     141        }
     142
     143        /**
    141144         * These are invalid custom elements but we support them right now in order to keep the parser simpler.
    142145         *
    143146         * @see https://w3c.github.io/webcomponents/spec/custom/#valid-custom-element-name
    144147         */
    145         public function supported_invalid_tag_names() {
     148        public function data_supported_invalid_tag_names() {
    146149                return array(
    147150                        // Reserved names for custom elements.
     
    158161
    159162        /**
    160          * @ticket 47014
    161          * @dataProvider supported_traditional_tag_names
    162          */
    163         public function test_detects_traditional_tag_names( $tag ) {
    164                 $normalized = strtolower( $tag );
    165 
    166                 $this->assertSame( "<$normalized>inside</$normalized>", balanceTags( "<$tag>inside", true ) );
    167         }
    168 
    169         /**
    170          * @ticket 47014
    171          * @dataProvider supported_custom_element_tag_names
    172          */
    173         public function test_detects_supported_custom_element_tag_names( $tag ) {
    174                 $this->assertSame( "<$tag>inside</$tag>", balanceTags( "<$tag>inside", true ) );
    175         }
    176 
    177         /**
    178          * @ticket 47014
    179          * @dataProvider invalid_tag_names
    180          */
    181         public function test_ignores_invalid_tag_names( $input, $output ) {
    182                 $this->assertSame( $output, balanceTags( $input, true ) );
    183         }
    184 
    185         /**
    186          * @ticket 47014
    187          * @dataProvider unsupported_valid_tag_names
    188          */
    189         public function test_ignores_unsupported_custom_tag_names( $tag ) {
    190                 $this->assertSame( "<$tag>inside", balanceTags( "<$tag>inside", true ) );
    191         }
    192 
    193         /**
    194          * @ticket 47014
    195          * @dataProvider supported_invalid_tag_names
    196          */
    197         public function test_detects_supported_invalid_tag_names( $tag ) {
    198                 $this->assertSame( "<$tag>inside</$tag>", balanceTags( "<$tag>inside", true ) );
    199         }
    200 
    201         /**
    202163         * If a recognized valid single tag appears unclosed, it should get self-closed
    203164         *
    204165         * @ticket 1597
    205          * @dataProvider single_tags
     166         * @dataProvider data_single_tags
    206167         */
    207168        public function test_selfcloses_unclosed_known_single_tags( $tag ) {
     
    214175         *
    215176         * @ticket 1597
    216          * @dataProvider single_tags
     177         * @dataProvider data_single_tags
    217178         */
    218179        public function test_selfcloses_known_single_tags_having_closing_tag( $tag ) {
    219180                $this->assertSame( "<$tag />", balanceTags( "<$tag></$tag>", true ) );
     181        }
     182
     183        // This is a complete(?) listing of valid single/self-closing tags.
     184        public function data_single_tags() {
     185                return array(
     186                        array( 'area' ),
     187                        array( 'base' ),
     188                        array( 'basefont' ),
     189                        array( 'br' ),
     190                        array( 'col' ),
     191                        array( 'command' ),
     192                        array( 'embed' ),
     193                        array( 'frame' ),
     194                        array( 'hr' ),
     195                        array( 'img' ),
     196                        array( 'input' ),
     197                        array( 'isindex' ),
     198                        array( 'link' ),
     199                        array( 'meta' ),
     200                        array( 'param' ),
     201                        array( 'source' ),
     202                        array( 'track' ),
     203                        array( 'wbr' ),
     204                );
    220205        }
    221206
     
    275260
    276261        /**
    277          * @dataProvider nestable_tags
     262         * @dataProvider data_nestable_tags
    278263         */
    279264        public function test_balances_nestable_tags( $tag ) {
     
    292277                        $this->assertSame( $expected[ $key ], balanceTags( $inputs[ $key ], true ) );
    293278                }
     279        }
     280
     281        public function data_nestable_tags() {
     282                return array(
     283                        array( 'article' ),
     284                        array( 'aside' ),
     285                        array( 'blockquote' ),
     286                        array( 'details' ),
     287                        array( 'div' ),
     288                        array( 'figure' ),
     289                        array( 'object' ),
     290                        array( 'q' ),
     291                        array( 'section' ),
     292                        array( 'span' ),
     293                );
    294294        }
    295295
Note: See TracChangeset for help on using the changeset viewer.