Make WordPress Core

Changeset 55090


Ignore:
Timestamp:
01/18/2023 04:17:41 PM (23 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Rename parameters that use reserved keywords in phpunit/tests/kses.php.

While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.

This commit:

  • Renames the $string parameter to $content in:
    • Tests_Kses::test_wp_filter_post_kses_address()
    • Tests_Kses::test_wp_filter_post_kses_a()
    • Tests_Kses::test_wp_filter_post_kses_abbr()
  • Amends a few parameters and variables in other tests in the same file for consistency.

Follow-up to [52946], [52996], [52997], [52998], [53003], [53014], [53029], [53039], [53116], [53117], [53137], [53174], [53184], [53185], [53192], [53193], [53198], [53203], [53207], [53215], [53216], [53220], [53230], [53232], [53236], [53239], [53240], [53242], [53243], [53245], [53246], [53257], [53269], [53270], [53271], [53272], [53273], [53274], [53275], [53276], [53277], [53281], [53283], [53284], [53285], [53287], [53364], [53365], [54927], [54929], [54930], [54931], [54932], [54933], [54938], [54943], [54944], [54945], [54946], [54947], [54948], [54950], [54951], [54952], [54956], [54959], [54960], [54961], [54962], [54964], [54965], [54969], [54970], [54971], [54972], [54996], [55000], [55011], [55013], [55014], [55015], [55016], [55017], [55020], [55021], [55023], [55027], [55028], [55034], [55036], [55037], [55038], [55039], [55049], [55050], [55060], [55062], [55064], [55065], [55076], [55077], [55078], [55081].

Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #56788.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/kses.php

    r54889 r55090  
    1212     * @ticket 20210
    1313     *
    14      * @param string $string        Test string for kses.
    15      * @param string $expect_string Expected result after passing through kses.
    16      */
    17     public function test_wp_filter_post_kses_address( $string, $expect_string ) {
     14     * @param string $content  Test string for kses.
     15     * @param string $expected Expected result after passing through kses.
     16     */
     17    public function test_wp_filter_post_kses_address( $content, $expected ) {
    1818        global $allowedposttags;
    1919
    20         $this->assertSame( $expect_string, wp_kses( $string, $allowedposttags ) );
     20        $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
    2121    }
    2222
     
    2525     *
    2626     * @return array[] Arguments {
    27      *     @type string $string        Test string for kses.
    28      *     @type string $expect_string Expected result after passing through kses.
     27     *     @type string $content  Test string for kses.
     28     *     @type string $expected Expected result after passing through kses.
    2929     * }
    3030     */
     
    4646        foreach ( $attributes as $name => $values ) {
    4747            foreach ( (array) $values as $value ) {
    48                 $string        = "<address $name='$value'>1 WordPress Avenue, The Internet.</address>";
    49                 $expect_string = "<address $name='" . str_replace( '; ', ';', trim( $value, ';' ) ) . "'>1 WordPress Avenue, The Internet.</address>";
    50 
    51                 $data[] = array( $string, $expect_string );
     48                $content  = "<address $name='$value'>1 WordPress Avenue, The Internet.</address>";
     49                $expected = "<address $name='" . str_replace( '; ', ';', trim( $value, ';' ) ) . "'>1 WordPress Avenue, The Internet.</address>";
     50
     51                $data[] = array( $content, $expected );
    5252            }
    5353        }
     
    6060     * @ticket 20210
    6161     *
    62      * @param string $string        Test string for kses.
    63      * @param string $expect_string Expected result after passing through kses.
    64      */
    65     public function test_wp_filter_post_kses_a( $string, $expect_string ) {
     62     * @param string $content  Test string for kses.
     63     * @param string $expected Expected result after passing through kses.
     64     */
     65    public function test_wp_filter_post_kses_a( $content, $expected ) {
    6666        global $allowedposttags;
    6767
    68         $this->assertSame( $expect_string, wp_kses( $string, $allowedposttags ) );
     68        $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
    6969    }
    7070
     
    7373     *
    7474     * @return array[] Arguments {
    75      *     @type string $string        Test string for kses.
    76      *     @type string $expect_string Expected result after passing through kses.
     75     *     @type string $content  Test string for kses.
     76     *     @type string $expected Expected result after passing through kses.
    7777     * }
    7878     */
     
    101101                $expected_attr = $name;
    102102            }
    103             $string        = "<a $attr>I link this</a>";
    104             $expect_string = "<a $expected_attr>I link this</a>";
    105             $data[]        = array( $string, $expect_string );
     103            $content  = "<a $attr>I link this</a>";
     104            $expected = "<a $expected_attr>I link this</a>";
     105            $data[]   = array( $content, $expected );
    106106        }
    107107
     
    121121     */
    122122    public function test_wp_kses_video( $source, $context, $expected ) {
    123         $actual = wp_kses( $source, $context );
    124         $this->assertSame( $expected, $actual );
     123        $this->assertSame( $expected, wp_kses( $source, $context ) );
    125124    }
    126125
     
    167166     * @ticket 20210
    168167     *
    169      * @param string $string        Test string for kses.
    170      * @param string $expect_string Expected result after passing through kses.
    171      */
    172     public function test_wp_filter_post_kses_abbr( $string, $expect_string ) {
     168     * @param string $content  Test string for kses.
     169     * @param string $expected Expected result after passing through kses.
     170     */
     171    public function test_wp_filter_post_kses_abbr( $content, $expected ) {
    173172        global $allowedposttags;
    174173
    175         $this->assertSame( $expect_string, wp_kses( $string, $allowedposttags ) );
     174        $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
    176175    }
    177176
     
    180179     *
    181180     * @return array[] Arguments {
    182      *     @type string $string        Test string for kses.
    183      *     @type string $expect_string Expected result after passing through kses.
     181     *     @type string $content  Test string for kses.
     182     *     @type string $expected Expected result after passing through kses.
    184183     * }
    185184     */
     
    195194
    196195        foreach ( $attributes as $name => $value ) {
    197             $string        = "<abbr $name='$value'>WP</abbr>";
    198             $expect_string = "<abbr $name='" . trim( $value, ';' ) . "'>WP</abbr>";
    199             $data[]        = array( $string, $expect_string );
     196            $content  = "<abbr $name='$value'>WP</abbr>";
     197            $expected = "<abbr $name='" . trim( $value, ';' ) . "'>WP</abbr>";
     198            $data[]   = array( $content, $expected );
    200199        }
    201200
     
    536535
    537536    public function test_hyphenated_tag() {
    538         $string                 = '<hyphenated-tag attribute="value" otherattribute="value2">Alot of hyphens.</hyphenated-tag>';
    539         $custom_tags            = array(
     537        $content     = '<hyphenated-tag attribute="value" otherattribute="value2">Alot of hyphens.</hyphenated-tag>';
     538        $custom_tags = array(
    540539            'hyphenated-tag' => array(
    541540                'attribute' => true,
    542541            ),
    543542        );
    544         $expect_stripped_string = 'Alot of hyphens.';
    545 
    546         $expect_valid_string = '<hyphenated-tag attribute="value">Alot of hyphens.</hyphenated-tag>';
    547         $this->assertSame( $expect_stripped_string, wp_kses_post( $string ) );
    548         $this->assertSame( $expect_valid_string, wp_kses( $string, $custom_tags ) );
     543
     544        $expect_stripped_content = 'Alot of hyphens.';
     545        $expect_valid_content    = '<hyphenated-tag attribute="value">Alot of hyphens.</hyphenated-tag>';
     546
     547        $this->assertSame( $expect_stripped_content, wp_kses_post( $content ) );
     548        $this->assertSame( $expect_valid_content, wp_kses( $content, $custom_tags ) );
    549549    }
    550550
     
    570570     * @dataProvider data_ctrl_removal
    571571     */
    572     public function test_ctrl_removal( $input, $output ) {
     572    public function test_ctrl_removal( $content, $expected ) {
    573573        global $allowedposttags;
    574574
    575         return $this->assertSame( $output, wp_kses( $input, $allowedposttags ) );
     575        return $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
    576576    }
    577577
     
    607607     * @dataProvider data_slash_zero_removal
    608608     */
    609     public function test_slash_zero_removal( $input, $output ) {
     609    public function test_slash_zero_removal( $content, $expected ) {
    610610        global $allowedposttags;
    611611
    612         return $this->assertSame( $output, wp_kses( $input, $allowedposttags ) );
     612        return $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) );
    613613    }
    614614
     
    863863        global $allowedposttags;
    864864
    865         $input = '<p>This is <bdo dir="rtl">a BDO tag</bdo>. Weird, <bdo dir="ltr">right?</bdo></p>';
    866 
    867         $this->assertSame( $input, wp_kses( $input, $allowedposttags ) );
     865        $content = '<p>This is <bdo dir="rtl">a BDO tag</bdo>. Weird, <bdo dir="ltr">right?</bdo></p>';
     866
     867        $this->assertSame( $content, wp_kses( $content, $allowedposttags ) );
    868868    }
    869869
     
    874874        global $allowedposttags;
    875875
    876         $input = '<ruby>✶<rp>: </rp><rt>Star</rt><rp>, </rp><rt lang="fr">Étoile</rt><rp>.</rp></ruby>';
    877 
    878         $this->assertSame( $input, wp_kses( $input, $allowedposttags ) );
     876        $content = '<ruby>✶<rp>: </rp><rt>Star</rt><rp>, </rp><rt lang="fr">Étoile</rt><rp>.</rp></ruby>';
     877
     878        $this->assertSame( $content, wp_kses( $content, $allowedposttags ) );
    879879    }
    880880
     
    885885        global $allowedposttags;
    886886
    887         $input = '<ol reversed="reversed"><li>Item 1</li><li>Item 2</li><li>Item 3</li></ol>';
    888 
    889         $this->assertSame( $input, wp_kses( $input, $allowedposttags ) );
     887        $content = '<ol reversed="reversed"><li>Item 1</li><li>Item 2</li><li>Item 3</li></ol>';
     888
     889        $this->assertSame( $content, wp_kses( $content, $allowedposttags ) );
    890890    }
    891891
     
    13071307        );
    13081308
    1309         $string   = '<div datamelformed-prefix="gone" data="gone" data-="gone" onclick="alert(1)">Malformed attributes</div>';
     1309        $content  = '<div datamelformed-prefix="gone" data="gone" data-="gone" onclick="alert(1)">Malformed attributes</div>';
    13101310        $expected = '<div>Malformed attributes</div>';
    13111311
    1312         $actual = wp_kses( $string, $allowed_html );
     1312        $actual = wp_kses( $content, $allowed_html );
    13131313
    13141314        $this->assertSame( $expected, $actual );
     
    13271327        );
    13281328
    1329         $string   = '<div data-wp-id="pens-and-pencils">Well formed attribute</div>';
     1329        $content  = '<div data-wp-id="pens-and-pencils">Well formed attribute</div>';
    13301330        $expected = '<div data-wp-id="pens-and-pencils">Well formed attribute</div>';
    13311331
    1332         $actual = wp_kses( $string, $allowed_html );
     1332        $actual = wp_kses( $content, $allowed_html );
    13331333
    13341334        $this->assertSame( $expected, $actual );
     
    18451845     * @dataProvider data_wp_kses_allowed_values_list
    18461846     *
    1847      * @param string $html         A string of HTML to test.
     1847     * @param string $content      A string of HTML to test.
    18481848     * @param string $expected     The expected result from KSES.
    18491849     * @param array  $allowed_html The allowed HTML to pass to KSES.
    18501850     */
    1851     public function test_wp_kses_allowed_values_list( $html, $expected, $allowed_html ) {
    1852         $this->assertSame( $expected, wp_kses( $html, $allowed_html ) );
     1851    public function test_wp_kses_allowed_values_list( $content, $expected, $allowed_html ) {
     1852        $this->assertSame( $expected, wp_kses( $content, $allowed_html ) );
    18531853    }
    18541854
     
    19031903     * @dataProvider data_wp_kses_required_attribute
    19041904     *
    1905      * @param string $html         A string of HTML to test.
     1905     * @param string $content      A string of HTML to test.
    19061906     * @param string $expected     The expected result from KSES.
    19071907     * @param array  $allowed_html The allowed HTML to pass to KSES.
    19081908     */
    1909     public function test_wp_kses_required_attribute( $html, $expected, $allowed_html ) {
    1910         $this->assertSame( $expected, wp_kses( $html, $allowed_html ) );
     1909    public function test_wp_kses_required_attribute( $content, $expected, $allowed_html ) {
     1910        $this->assertSame( $expected, wp_kses( $content, $allowed_html ) );
    19111911    }
    19121912
Note: See TracChangeset for help on using the changeset viewer.