Make WordPress Core


Ignore:
Timestamp:
03/19/2023 12:03:30 PM (21 months 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/convertSmilies.php

    r54134 r55562  
    1010
    1111    /**
     12     * @dataProvider data_convert_standard_smilies
     13     *
     14     * Basic Validation Test to confirm that smilies are converted to image
     15     * when use_smilies = 1 and not when use_smilies = 0
     16     */
     17    public function test_convert_standard_smilies( $in_txt, $converted_txt ) {
     18        // Standard smilies, use_smilies: ON.
     19        update_option( 'use_smilies', 1 );
     20
     21        smilies_init();
     22
     23        $this->assertSame( $converted_txt, convert_smilies( $in_txt ) );
     24
     25        // Standard smilies, use_smilies: OFF.
     26        update_option( 'use_smilies', 0 );
     27
     28        $this->assertSame( $in_txt, convert_smilies( $in_txt ) );
     29    }
     30
     31    /**
    1232     * Basic Test Content DataProvider
    1333     *
    1434     * array ( input_txt, converted_output_txt)
    1535     */
    16     public function get_smilies_input_output() {
     36    public function data_convert_standard_smilies() {
    1737        $includes_path = includes_url( 'images/smilies/' );
    1838
     
    4666
    4767    /**
    48      * @dataProvider get_smilies_input_output
    49      *
    50      * Basic Validation Test to confirm that smilies are converted to image
    51      * when use_smilies = 1 and not when use_smilies = 0
    52      */
    53     public function test_convert_standard_smilies( $in_txt, $converted_txt ) {
    54         // Standard smilies, use_smilies: ON.
    55         update_option( 'use_smilies', 1 );
    56 
    57         smilies_init();
    58 
    59         $this->assertSame( $converted_txt, convert_smilies( $in_txt ) );
    60 
    61         // Standard smilies, use_smilies: OFF.
    62         update_option( 'use_smilies', 0 );
    63 
    64         $this->assertSame( $in_txt, convert_smilies( $in_txt ) );
    65     }
    66 
    67     /**
    68      * Custom Smilies Test Content DataProvider
    69      *
    70      * array ( input_txt, converted_output_txt)
    71      */
    72     public function get_custom_smilies_input_output() {
    73         $includes_path = includes_url( 'images/smilies/' );
    74 
    75         return array(
    76             array(
    77                 'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. :monkey:',
    78                 'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. <img src="' . $includes_path . 'icon_shock_the_monkey.gif" alt=":monkey:" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
    79             ),
    80             array(
    81                 'Star Wars Jedi Knight :arrow: Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. :nervou:',
    82                 'Star Wars Jedi Knight <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. <img src="' . $includes_path . 'icon_nervou.gif" alt=":nervou:" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
    83             ),
    84             array(
    85                 ':arrow: monkey: Lorem ipsum dolor sit amet enim. Etiam ullam :PP <br />corper. Suspendisse a pellentesque dui, non felis.<a> :arrow: :arrow</a>',
    86                 '<img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> monkey: Lorem ipsum dolor sit amet enim. Etiam ullam <img src="' . $includes_path . 'icon_tongue.gif" alt=":PP" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <br />corper. Suspendisse a pellentesque dui, non felis.<a> <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> :arrow</a>',
    87             ),
    88         );
    89     }
    90 
    91     /**
    92      * @dataProvider get_custom_smilies_input_output
     68     * @dataProvider data_convert_custom_smilies
    9369     *
    9470     * Validate Custom Smilies are converted to images when use_smilies = 1
     
    125101    }
    126102
     103    /**
     104     * Custom Smilies Test Content DataProvider
     105     *
     106     * array ( input_txt, converted_output_txt)
     107     */
     108    public function data_convert_custom_smilies() {
     109        $includes_path = includes_url( 'images/smilies/' );
     110
     111        return array(
     112            array(
     113                'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. :monkey:',
     114                'Peter Brian Gabriel (born 13 February 1950) is a British singer, musician, and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. <img src="' . $includes_path . 'icon_shock_the_monkey.gif" alt=":monkey:" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
     115            ),
     116            array(
     117                'Star Wars Jedi Knight :arrow: Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. :nervou:',
     118                'Star Wars Jedi Knight <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> Jedi Academy is a first and third-person shooter action game set in the Star Wars universe. It was developed by Raven Software and published, distributed and marketed by LucasArts in North America and by Activision in the rest of the world. <img src="' . $includes_path . 'icon_nervou.gif" alt=":nervou:" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
     119            ),
     120            array(
     121                ':arrow: monkey: Lorem ipsum dolor sit amet enim. Etiam ullam :PP <br />corper. Suspendisse a pellentesque dui, non felis.<a> :arrow: :arrow</a>',
     122                '<img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> monkey: Lorem ipsum dolor sit amet enim. Etiam ullam <img src="' . $includes_path . 'icon_tongue.gif" alt=":PP" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <br />corper. Suspendisse a pellentesque dui, non felis.<a> <img src="' . $includes_path . 'icon_arrow.gif" alt=":arrow:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> :arrow</a>',
     123            ),
     124        );
     125    }
     126
     127    /**
     128     * Validate Conversion of Smilies is ignored in pre-determined tags
     129     * pre, code, script, style
     130     *
     131     * @ticket 16448
     132     * @dataProvider data_ignore_smilies_in_tags
     133     */
     134    public function test_ignore_smilies_in_tags( $element ) {
     135        $includes_path = includes_url( 'images/smilies/' );
     136
     137        $in_str  = 'Do we ingore smilies ;-) in ' . $element . ' tags <' . $element . ' class="foo">My Content Here :?: </' . $element . '>';
     138        $exp_str = "Do we ingore smilies \xf0\x9f\x98\x89 in $element tags <$element class=\"foo\">My Content Here :?: </$element>";
     139
     140        // Standard smilies, use_smilies: ON.
     141        update_option( 'use_smilies', 1 );
     142        smilies_init();
     143
     144        $this->assertSame( $exp_str, convert_smilies( $in_str ) );
     145
     146        // Standard smilies, use_smilies: OFF.
     147        update_option( 'use_smilies', 0 );
     148    }
    127149
    128150    /**
    129151     * DataProvider of HTML elements/tags that smilie matches should be ignored in
    130152     */
    131     public function get_smilies_ignore_tags() {
     153    public function data_ignore_smilies_in_tags() {
    132154        return array(
    133155            array( 'pre' ),
     
    140162
    141163    /**
    142      * Validate Conversion of Smilies is ignored in pre-determined tags
    143      * pre, code, script, style
    144      *
    145      * @ticket 16448
    146      * @dataProvider get_smilies_ignore_tags
    147      */
    148     public function test_ignore_smilies_in_tags( $element ) {
    149         $includes_path = includes_url( 'images/smilies/' );
    150 
    151         $in_str  = 'Do we ingore smilies ;-) in ' . $element . ' tags <' . $element . ' class="foo">My Content Here :?: </' . $element . '>';
    152         $exp_str = "Do we ingore smilies \xf0\x9f\x98\x89 in $element tags <$element class=\"foo\">My Content Here :?: </$element>";
    153 
    154         // Standard smilies, use_smilies: ON.
    155         update_option( 'use_smilies', 1 );
    156         smilies_init();
    157 
    158         $this->assertSame( $exp_str, convert_smilies( $in_str ) );
    159 
    160         // Standard smilies, use_smilies: OFF.
    161         update_option( 'use_smilies', 0 );
     164     * Validate Combinations of Smilies separated by single space
     165     * are converted correctly
     166     *
     167     * @ticket 20124
     168     * @dataProvider data_smilies_combinations
     169     */
     170    public function test_smilies_combinations( $in_txt, $converted_txt ) {
     171        // Custom smilies, use_smilies: ON.
     172        update_option( 'use_smilies', 1 );
     173        smilies_init();
     174
     175        $this->assertSame( $converted_txt, convert_smilies( $in_txt ) );
     176
     177        // Custom smilies, use_smilies: OFF.
     178        update_option( 'use_smilies', 0 );
     179
     180        $this->assertSame( $in_txt, convert_smilies( $in_txt ) );
    162181    }
    163182
     
    165184     * DataProvider of Smilie Combinations
    166185     */
    167     public function get_smilies_combinations() {
     186    public function data_smilies_combinations() {
    168187        $includes_path = includes_url( 'images/smilies/' );
    169188
     
    197216
    198217    /**
    199      * Validate Combinations of Smilies separated by single space
    200      * are converted correctly
    201      *
    202      * @ticket 20124
    203      * @dataProvider get_smilies_combinations
    204      */
    205     public function test_smilies_combinations( $in_txt, $converted_txt ) {
    206         // Custom smilies, use_smilies: ON.
    207         update_option( 'use_smilies', 1 );
    208         smilies_init();
    209 
    210         $this->assertSame( $converted_txt, convert_smilies( $in_txt ) );
    211 
    212         // Custom smilies, use_smilies: OFF.
    213         update_option( 'use_smilies', 0 );
    214 
    215         $this->assertSame( $in_txt, convert_smilies( $in_txt ) );
    216     }
    217 
    218     /**
    219      * DataProvider of Single Smilies input and converted output
    220      */
    221     public function get_single_smilies_input_output() {
    222         $includes_path = includes_url( 'images/smilies/' );
    223 
    224         return array(
    225             array(
    226                 '8-O :-(',
    227                 '8-O :-(',
    228             ),
    229             array(
    230                 '8O :) additional text here :)',
    231                 '8O <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> additional text here <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
    232             ),
    233             array(
    234                 ':) :) :) :)',
    235                 '<img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
    236             ),
    237         );
    238     }
    239 
    240     /**
    241218     * Validate Smilies are converted for single smilie in
    242219     * the $wpsmiliestrans global array
    243220     *
    244221     * @ticket 25303
    245      * @dataProvider get_single_smilies_input_output
     222     * @dataProvider data_single_smilies_in_wpsmiliestrans
    246223     */
    247224    public function test_single_smilies_in_wpsmiliestrans( $in_txt, $converted_txt ) {
     
    273250    }
    274251
    275     public function get_spaces_around_smilies() {
     252    /**
     253     * DataProvider of Single Smilies input and converted output
     254     */
     255    public function data_single_smilies_in_wpsmiliestrans() {
     256        $includes_path = includes_url( 'images/smilies/' );
     257
     258        return array(
     259            array(
     260                '8-O :-(',
     261                '8-O :-(',
     262            ),
     263            array(
     264                '8O :) additional text here :)',
     265                '8O <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> additional text here <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
     266            ),
     267            array(
     268                ':) :) :) :)',
     269                '<img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <img src="' . $includes_path . 'simple-smile.png" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" />',
     270            ),
     271        );
     272    }
     273
     274    /**
     275     * Check that $wp_smiliessearch pattern will match smilies
     276     * between spaces, but never capture those spaces.
     277     *
     278     * Further check that spaces aren't randomly deleted
     279     * or added when replacing the text with an image.
     280     *
     281     * @ticket 22692
     282     * @dataProvider data_spaces_around_smilies
     283     */
     284    public function test_spaces_around_smilies( $in_txt, $converted_txt ) {
     285        // Standard smilies, use_smilies: ON.
     286        update_option( 'use_smilies', 1 );
     287
     288        smilies_init();
     289
     290        $this->assertSame( $converted_txt, convert_smilies( $in_txt ) );
     291
     292        // Standard smilies, use_smilies: OFF.
     293        update_option( 'use_smilies', 0 );
     294    }
     295
     296    public function data_spaces_around_smilies() {
    276297        $nbsp = "\xC2\xA0";
    277298
     
    290311            ),
    291312        );
    292     }
    293 
    294     /**
    295      * Check that $wp_smiliessearch pattern will match smilies
    296      * between spaces, but never capture those spaces.
    297      *
    298      * Further check that spaces aren't randomly deleted
    299      * or added when replacing the text with an image.
    300      *
    301      * @ticket 22692
    302      * @dataProvider get_spaces_around_smilies
    303      */
    304     public function test_spaces_around_smilies( $in_txt, $converted_txt ) {
    305         // Standard smilies, use_smilies: ON.
    306         update_option( 'use_smilies', 1 );
    307 
    308         smilies_init();
    309 
    310         $this->assertSame( $converted_txt, convert_smilies( $in_txt ) );
    311 
    312         // Standard smilies, use_smilies: OFF.
    313         update_option( 'use_smilies', 0 );
    314313    }
    315314
Note: See TracChangeset for help on using the changeset viewer.