Make WordPress Core

Changeset 55563


Ignore:
Timestamp:
03/19/2023 12:51:14 PM (13 months 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.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/formatting.php

    r55495 r55563  
    53385338
    53395339/**
    5340  * Adds a Target attribute to all links in passed content.
     5340 * Adds a target attribute to all links in passed content.
    53415341 *
    53425342 * This function by default only applies to `<a>` tags, however this can be
    5343  * modified by the 3rd param.
    5344  *
    5345  * *NOTE:* Any current target attributed will be stripped and replaced.
     5343 * modified by the `$tags` parameter.
     5344 *
     5345 * *NOTE:* Any current target attribute will be stripped and replaced.
    53465346 *
    53475347 * @since 2.7.0
     
    53505350 *
    53515351 * @param string   $content String to search for links in.
    5352  * @param string   $target  The Target to add to the links.
     5352 * @param string   $target  The target to add to the links.
    53535353 * @param string[] $tags    An array of tags to apply to.
    53545354 * @return string The processed content.
  • 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";
  • trunk/tests/phpunit/tests/formatting/getUrlInContent.php

    r55562 r55563  
    99
    1010    /**
    11      * Validate the get_url_in_content function
     11     * Tests the get_url_in_content() function.
    1212     *
    1313     * @dataProvider data_get_url_in_content
    1414     */
    15     public function test_get_url_in_content( $in_str, $exp_str ) {
    16         $this->assertSame( $exp_str, get_url_in_content( $in_str ) );
     15    public function test_get_url_in_content( $input, $expected ) {
     16        $this->assertSame( $expected, get_url_in_content( $input ) );
    1717    }
    1818
    1919    /**
    20      * URL Content Data Provider
     20     * Data provider.
    2121     *
    22      * array ( input_txt, converted_output_txt )
     22     * @return array {
     23     *     @type array {
     24     *         @type string $input    Input content.
     25     *         @type string $expected Expected output.
     26     *     }
     27     * }
    2328     */
    2429    public function data_get_url_in_content() {
  • trunk/tests/phpunit/tests/formatting/linksAddTarget.php

    r55562 r55563  
    88
    99    /**
    10      * Validate the normalize_whitespace function
     10     * Tests the links_add_target() function.
    1111     *
    1212     * @dataProvider data_links_add_target
    1313     */
    14     public function test_links_add_target( $content, $target, $tags, $exp_str ) {
    15         if ( true === is_null( $target ) ) {
    16             $this->assertSame( $exp_str, links_add_target( $content ) );
    17         } elseif ( true === is_null( $tags ) ) {
    18             $this->assertSame( $exp_str, links_add_target( $content, $target ) );
     14    public function test_links_add_target( $content, $target, $tags, $expected ) {
     15        if ( is_null( $target ) ) {
     16            $this->assertSame( $expected, links_add_target( $content ) );
     17        } elseif ( is_null( $tags ) ) {
     18            $this->assertSame( $expected, links_add_target( $content, $target ) );
    1919        } else {
    20             $this->assertSame( $exp_str, links_add_target( $content, $target, $tags ) );
     20            $this->assertSame( $expected, links_add_target( $content, $target, $tags ) );
    2121        }
    2222    }
    2323
    2424    /**
    25      * Test Content DataProvider
     25     * Data provider.
    2626     *
    27      * array ( input_txt, converted_output_txt)
     27     * @return array {
     28     *     @type array {
     29     *         @type string $content  String to search for links in.
     30     *         @type string $target   The target to add to the links.
     31     *         @type string $tags     An array of tags to apply to.
     32     *         @type string $expected Expected output.
     33     *     }
     34     * }
    2835     */
    2936    public function data_links_add_target() {
  • trunk/tests/phpunit/tests/formatting/normalizeWhitespace.php

    r55562 r55563  
    88
    99    /**
    10      * Validate the normalize_whitespace function
     10     * Tests the the normalize_whitespace() function.
    1111     *
    1212     * @dataProvider data_normalize_whitespace
    1313     */
    14     public function test_normalize_whitespace( $in_str, $exp_str ) {
    15         $this->assertSame( $exp_str, normalize_whitespace( $in_str ) );
     14    public function test_normalize_whitespace( $input, $expected ) {
     15        $this->assertSame( $expected, normalize_whitespace( $input ) );
    1616    }
    1717
    1818    /**
    19      * WhitespaceTest Content DataProvider
     19     * Data provider.
    2020     *
    21      * array( input_txt, converted_output_txt)
     21     * @return array {
     22     *     @type array {
     23     *         @type string $input    Input content.
     24     *         @type string $expected Expected output.
     25     *     }
     26     * }
    2227     */
    2328    public function data_normalize_whitespace() {
  • trunk/tests/phpunit/tests/formatting/urlencodeDeep.php

    r55562 r55563  
    1010
    1111    /**
    12      * Data Provider
     12     * Tests the urlencode_deep() function pair by pair.
     13     *
     14     * @dataProvider data_urlencode_deep
     15     *
     16     * @param string $input
     17     * @param string $expected
     18     */
     19    public function test_urlencode_deep_should_encode_individual_value( $input, $expected ) {
     20        $this->assertSame( $expected, urlencode_deep( $input ) );
     21    }
     22
     23    /**
     24     * Data provider.
    1325     */
    1426    public function data_urlencode_deep() {
     
    2335
    2436    /**
    25      * Validate the urlencode_deep function pair by pair
    26      *
    27      * @dataProvider data_urlencode_deep
    28      *
    29      * @param string $actual
    30      * @param string $expected
    31      */
    32     public function test_urlencode_deep_should_encode_individual_value( $actual, $expected ) {
    33         $this->assertSame( $expected, urlencode_deep( $actual ) );
    34     }
    35 
    36     /**
    37      * Test the whole array as input
     37     * Tests the whole array as input.
    3838     */
    3939    public function test_urlencode_deep_should_encode_all_values_in_array() {
  • trunk/tests/phpunit/tests/formatting/wpParseStr.php

    r54728 r55563  
    2525
    2626    /**
    27      * Data Provider.
     27     * Data provider.
    2828     *
    2929     * @return array
  • trunk/tests/phpunit/tests/kses.php

    r55562 r55563  
    948948
    949949    /**
    950      * Data Provider for test_safecss_filter_attr().
     950     * Data provider for test_safecss_filter_attr().
    951951     *
    952952     * @return array {
     
    15811581
    15821582    /**
    1583      * Data Provider for test_safecss_filter_attr_filtered().
     1583     * Data provider for test_safecss_filter_attr_filtered().
    15841584     *
    15851585     * @return array {
  • trunk/tests/phpunit/tests/pluggable/wpRand.php

    r54702 r55563  
    2121            0,
    2222            wp_rand( $min, $max ),
    23             'The value was not greater than or equal 0'
     23            'The value was not greater than or equal to 0'
    2424        );
    2525
Note: See TracChangeset for help on using the changeset viewer.