Make WordPress Core


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

Tests: Improve documentation and variable names in some formatting tests.

Includes documenting data provider values using hash notation in the tests for:

  • convert_smilies()
  • get_url_in_content()
  • links_add_target()
  • normalize_whitespace()

Follow-up to [26191], [26327], [26328], [26972], [55562].

See #57841.

File:
1 edited

Legend:

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

    r55562 r55563  
    1010
    1111        /**
     12         * Basic validation test to confirm that smilies are converted to image
     13         * when use_smilies = 1 and not when use_smilies = 0.
     14         *
    1215         * @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 ) {
     16         */
     17        public function test_convert_standard_smilies( $input, $converted ) {
    1818                // Standard smilies, use_smilies: ON.
    1919                update_option( 'use_smilies', 1 );
     
    2121                smilies_init();
    2222
    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         /**
    32          * Basic Test Content DataProvider
    33          *
    34          * array ( input_txt, converted_output_txt)
     23                $this->assertSame( $converted, convert_smilies( $input ) );
     24
     25                // Standard smilies, use_smilies: OFF.
     26                update_option( 'use_smilies', 0 );
     27
     28                $this->assertSame( $input, convert_smilies( $input ) );
     29        }
     30
     31        /**
     32         * Data provider.
     33         *
     34         * @return array {
     35         *     @type array {
     36         *         @type string $input     Input content.
     37         *         @type string $converted Converted output.
     38         *     }
     39         * }
    3540         */
    3641        public function data_convert_standard_smilies() {
     
    6671
    6772        /**
     73         * Tests that custom smilies are converted to images when use_smilies = 1.
     74         *
    6875         * @dataProvider data_convert_custom_smilies
    69          *
    70          * Validate Custom Smilies are converted to images when use_smilies = 1
    71          */
    72         public function test_convert_custom_smilies( $in_txt, $converted_txt ) {
     76         */
     77        public function test_convert_custom_smilies( $input, $converted ) {
    7378                global $wpsmiliestrans;
    7479
     
    9196                smilies_init();
    9297
    93                 $this->assertSame( $converted_txt, convert_smilies( $in_txt ) );
    94 
    95                 // Standard smilies, use_smilies: OFF.
    96                 update_option( 'use_smilies', 0 );
    97 
    98                 $this->assertSame( $in_txt, convert_smilies( $in_txt ) );
     98                $this->assertSame( $converted, convert_smilies( $input ) );
     99
     100                // Standard smilies, use_smilies: OFF.
     101                update_option( 'use_smilies', 0 );
     102
     103                $this->assertSame( $input, convert_smilies( $input ) );
    99104
    100105                $wpsmiliestrans = $trans_orig; // Reset original translations array.
     
    102107
    103108        /**
    104          * Custom Smilies Test Content DataProvider
    105          *
    106          * array ( input_txt, converted_output_txt)
     109         * Data provider.
     110         *
     111         * @return array {
     112         *     @type array {
     113         *         @type string $input     Input content.
     114         *         @type string $converted Converted output.
     115         *     }
     116         * }
    107117         */
    108118        public function data_convert_custom_smilies() {
     
    126136
    127137        /**
    128          * Validate Conversion of Smilies is ignored in pre-determined tags
    129          * pre, code, script, style
     138         * Tests that conversion of smilies is ignored in pre-determined tags:
     139         * pre, code, script, style.
    130140         *
    131141         * @ticket 16448
     
    135145                $includes_path = includes_url( 'images/smilies/' );
    136146
    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>";
     147                $input    = 'Do we ignore smilies ;-) in ' . $element . ' tags <' . $element . ' class="foo">My Content Here :?: </' . $element . '>';
     148                $expected = "Do we ignore smilies \xf0\x9f\x98\x89 in $element tags <$element class=\"foo\">My Content Here :?: </$element>";
    139149
    140150                // Standard smilies, use_smilies: ON.
     
    142152                smilies_init();
    143153
    144                 $this->assertSame( $exp_str, convert_smilies( $in_str ) );
    145 
    146                 // Standard smilies, use_smilies: OFF.
    147                 update_option( 'use_smilies', 0 );
    148         }
    149 
    150         /**
    151          * DataProvider of HTML elements/tags that smilie matches should be ignored in
     154                $this->assertSame( $expected, convert_smilies( $input ) );
     155
     156                // Standard smilies, use_smilies: OFF.
     157                update_option( 'use_smilies', 0 );
     158        }
     159
     160        /**
     161         * Data provider.
     162         *
     163         * @return array {
     164         *     @type array {
     165         *         @type string $element HTML tag name.
     166         *     }
     167         * }
    152168         */
    153169        public function data_ignore_smilies_in_tags() {
     
    162178
    163179        /**
    164          * Validate Combinations of Smilies separated by single space
    165          * are converted correctly
     180         * Tests that combinations of smilies separated by a single space
     181         * are converted correctly.
    166182         *
    167183         * @ticket 20124
    168184         * @dataProvider data_smilies_combinations
    169185         */
    170         public function test_smilies_combinations( $in_txt, $converted_txt ) {
     186        public function test_smilies_combinations( $input, $converted ) {
    171187                // Custom smilies, use_smilies: ON.
    172188                update_option( 'use_smilies', 1 );
    173189                smilies_init();
    174190
    175                 $this->assertSame( $converted_txt, convert_smilies( $in_txt ) );
     191                $this->assertSame( $converted, convert_smilies( $input ) );
    176192
    177193                // Custom smilies, use_smilies: OFF.
    178194                update_option( 'use_smilies', 0 );
    179195
    180                 $this->assertSame( $in_txt, convert_smilies( $in_txt ) );
    181         }
    182 
    183         /**
    184          * DataProvider of Smilie Combinations
     196                $this->assertSame( $input, convert_smilies( $input ) );
     197        }
     198
     199        /**
     200         * Data provider.
     201         *
     202         * @return array {
     203         *     @type array {
     204         *         @type string $input     Input content.
     205         *         @type string $converted Converted output.
     206         *     }
     207         * }
    185208         */
    186209        public function data_smilies_combinations() {
     
    216239
    217240        /**
    218          * Validate Smilies are converted for single smilie in
    219          * the $wpsmiliestrans global array
     241         * Tests that smilies are converted for single smilie in
     242         * the $wpsmiliestrans global array.
    220243         *
    221244         * @ticket 25303
    222245         * @dataProvider data_single_smilies_in_wpsmiliestrans
    223246         */
    224         public function test_single_smilies_in_wpsmiliestrans( $in_txt, $converted_txt ) {
     247        public function test_single_smilies_in_wpsmiliestrans( $input, $converted ) {
    225248                global $wpsmiliestrans;
    226249
     
    240263                smilies_init();
    241264
    242                 $this->assertSame( $converted_txt, convert_smilies( $in_txt ) );
    243 
    244                 // Standard smilies, use_smilies: OFF.
    245                 update_option( 'use_smilies', 0 );
    246 
    247                 $this->assertSame( $in_txt, convert_smilies( $in_txt ) );
     265                $this->assertSame( $converted, convert_smilies( $input ) );
     266
     267                // Standard smilies, use_smilies: OFF.
     268                update_option( 'use_smilies', 0 );
     269
     270                $this->assertSame( $input, convert_smilies( $input ) );
    248271
    249272                $wpsmiliestrans = $orig_trans; // Reset original translations array.
     
    251274
    252275        /**
    253          * DataProvider of Single Smilies input and converted output
     276         * Data provider.
     277         *
     278         * @return array {
     279         *     @type array {
     280         *         @type string $input     Input content.
     281         *         @type string $converted Converted output.
     282         *     }
     283         * }
    254284         */
    255285        public function data_single_smilies_in_wpsmiliestrans() {
     
    273303
    274304        /**
    275          * Check that $wp_smiliessearch pattern will match smilies
     305         * Tests that $wp_smiliessearch pattern will match smilies
    276306         * between spaces, but never capture those spaces.
    277307         *
    278          * Further check that spaces aren't randomly deleted
     308         * Further tests that spaces aren't randomly deleted
    279309         * or added when replacing the text with an image.
    280310         *
     
    282312         * @dataProvider data_spaces_around_smilies
    283313         */
    284         public function test_spaces_around_smilies( $in_txt, $converted_txt ) {
     314        public function test_spaces_around_smilies( $input, $converted ) {
    285315                // Standard smilies, use_smilies: ON.
    286316                update_option( 'use_smilies', 1 );
     
    288318                smilies_init();
    289319
    290                 $this->assertSame( $converted_txt, convert_smilies( $in_txt ) );
    291 
    292                 // Standard smilies, use_smilies: OFF.
    293                 update_option( 'use_smilies', 0 );
    294         }
    295 
     320                $this->assertSame( $converted, convert_smilies( $input ) );
     321
     322                // Standard smilies, use_smilies: OFF.
     323                update_option( 'use_smilies', 0 );
     324        }
     325
     326        /**
     327         * Data provider.
     328         *
     329         * @return array {
     330         *     @type array {
     331         *         @type string $input     Input content.
     332         *         @type string $converted Converted output.
     333         *     }
     334         * }
     335         */
    296336        public function data_spaces_around_smilies() {
    297337                $nbsp = "\xC2\xA0";
Note: See TracChangeset for help on using the changeset viewer.