From d54b686c8d5c7b207a843cdaa81f4e34664be165 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 18 Jan 2023 16:17:41 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@55090 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/kses.php | 110 +++++++++++++++++------------------ 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/tests/phpunit/tests/kses.php b/tests/phpunit/tests/kses.php index 84787a4501..b31f477661 100644 --- a/tests/phpunit/tests/kses.php +++ b/tests/phpunit/tests/kses.php @@ -11,21 +11,21 @@ class Tests_Kses extends WP_UnitTestCase { * @dataProvider data_wp_filter_post_kses_address * @ticket 20210 * - * @param string $string Test string for kses. - * @param string $expect_string Expected result after passing through kses. + * @param string $content Test string for kses. + * @param string $expected Expected result after passing through kses. */ - public function test_wp_filter_post_kses_address( $string, $expect_string ) { + public function test_wp_filter_post_kses_address( $content, $expected ) { global $allowedposttags; - $this->assertSame( $expect_string, wp_kses( $string, $allowedposttags ) ); + $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) ); } /** * Data provider for test_wp_filter_post_kses_address. * * @return array[] Arguments { - * @type string $string Test string for kses. - * @type string $expect_string Expected result after passing through kses. + * @type string $content Test string for kses. + * @type string $expected Expected result after passing through kses. * } */ public function data_wp_filter_post_kses_address() { @@ -45,10 +45,10 @@ class Tests_Kses extends WP_UnitTestCase { foreach ( $attributes as $name => $values ) { foreach ( (array) $values as $value ) { - $string = "
1 WordPress Avenue, The Internet.
"; - $expect_string = "
1 WordPress Avenue, The Internet.
"; + $content = "
1 WordPress Avenue, The Internet.
"; + $expected = "
1 WordPress Avenue, The Internet.
"; - $data[] = array( $string, $expect_string ); + $data[] = array( $content, $expected ); } } @@ -59,21 +59,21 @@ class Tests_Kses extends WP_UnitTestCase { * @dataProvider data_wp_filter_post_kses_a * @ticket 20210 * - * @param string $string Test string for kses. - * @param string $expect_string Expected result after passing through kses. + * @param string $content Test string for kses. + * @param string $expected Expected result after passing through kses. */ - public function test_wp_filter_post_kses_a( $string, $expect_string ) { + public function test_wp_filter_post_kses_a( $content, $expected ) { global $allowedposttags; - $this->assertSame( $expect_string, wp_kses( $string, $allowedposttags ) ); + $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) ); } /** * Data provider for test_wp_filter_post_kses_a. * * @return array[] Arguments { - * @type string $string Test string for kses. - * @type string $expect_string Expected result after passing through kses. + * @type string $content Test string for kses. + * @type string $expected Expected result after passing through kses. * } */ public function data_wp_filter_post_kses_a() { @@ -100,9 +100,9 @@ class Tests_Kses extends WP_UnitTestCase { $attr = $name; $expected_attr = $name; } - $string = "I link this"; - $expect_string = "I link this"; - $data[] = array( $string, $expect_string ); + $content = "I link this"; + $expected = "I link this"; + $data[] = array( $content, $expected ); } return $data; @@ -120,8 +120,7 @@ class Tests_Kses extends WP_UnitTestCase { * @param string $expected Expected output following KSES parsing. */ public function test_wp_kses_video( $source, $context, $expected ) { - $actual = wp_kses( $source, $context ); - $this->assertSame( $expected, $actual ); + $this->assertSame( $expected, wp_kses( $source, $context ) ); } /** @@ -166,21 +165,21 @@ class Tests_Kses extends WP_UnitTestCase { * @dataProvider data_wp_filter_post_kses_abbr * @ticket 20210 * - * @param string $string Test string for kses. - * @param string $expect_string Expected result after passing through kses. + * @param string $content Test string for kses. + * @param string $expected Expected result after passing through kses. */ - public function test_wp_filter_post_kses_abbr( $string, $expect_string ) { + public function test_wp_filter_post_kses_abbr( $content, $expected ) { global $allowedposttags; - $this->assertSame( $expect_string, wp_kses( $string, $allowedposttags ) ); + $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) ); } /** * Data provider for data_wp_filter_post_kses_abbr. * * @return array[] Arguments { - * @type string $string Test string for kses. - * @type string $expect_string Expected result after passing through kses. + * @type string $content Test string for kses. + * @type string $expected Expected result after passing through kses. * } */ public function data_wp_filter_post_kses_abbr() { @@ -194,9 +193,9 @@ class Tests_Kses extends WP_UnitTestCase { $data = array(); foreach ( $attributes as $name => $value ) { - $string = "WP"; - $expect_string = "WP"; - $data[] = array( $string, $expect_string ); + $content = "WP"; + $expected = "WP"; + $data[] = array( $content, $expected ); } return $data; @@ -535,17 +534,18 @@ EOF; } public function test_hyphenated_tag() { - $string = 'Alot of hyphens.'; - $custom_tags = array( + $content = 'Alot of hyphens.'; + $custom_tags = array( 'hyphenated-tag' => array( 'attribute' => true, ), ); - $expect_stripped_string = 'Alot of hyphens.'; - $expect_valid_string = 'Alot of hyphens.'; - $this->assertSame( $expect_stripped_string, wp_kses_post( $string ) ); - $this->assertSame( $expect_valid_string, wp_kses( $string, $custom_tags ) ); + $expect_stripped_content = 'Alot of hyphens.'; + $expect_valid_content = 'Alot of hyphens.'; + + $this->assertSame( $expect_stripped_content, wp_kses_post( $content ) ); + $this->assertSame( $expect_valid_content, wp_kses( $content, $custom_tags ) ); } /** @@ -569,10 +569,10 @@ EOF; * @ticket 28506 * @dataProvider data_ctrl_removal */ - public function test_ctrl_removal( $input, $output ) { + public function test_ctrl_removal( $content, $expected ) { global $allowedposttags; - return $this->assertSame( $output, wp_kses( $input, $allowedposttags ) ); + return $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) ); } public function data_ctrl_removal() { @@ -606,10 +606,10 @@ EOF; * @ticket 28699 * @dataProvider data_slash_zero_removal */ - public function test_slash_zero_removal( $input, $output ) { + public function test_slash_zero_removal( $content, $expected ) { global $allowedposttags; - return $this->assertSame( $output, wp_kses( $input, $allowedposttags ) ); + return $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) ); } public function data_slash_zero_removal() { @@ -862,9 +862,9 @@ EOF; public function test_bdo_tag_allowed() { global $allowedposttags; - $input = '

This is a BDO tag. Weird, right?

'; + $content = '

This is a BDO tag. Weird, right?

'; - $this->assertSame( $input, wp_kses( $input, $allowedposttags ) ); + $this->assertSame( $content, wp_kses( $content, $allowedposttags ) ); } /** @@ -873,9 +873,9 @@ EOF; public function test_ruby_tag_allowed() { global $allowedposttags; - $input = ': Star, Étoile.'; + $content = ': Star, Étoile.'; - $this->assertSame( $input, wp_kses( $input, $allowedposttags ) ); + $this->assertSame( $content, wp_kses( $content, $allowedposttags ) ); } /** @@ -884,9 +884,9 @@ EOF; public function test_ol_reversed_attribute_allowed() { global $allowedposttags; - $input = '
  1. Item 1
  2. Item 2
  3. Item 3
'; + $content = '
  1. Item 1
  2. Item 2
  3. Item 3
'; - $this->assertSame( $input, wp_kses( $input, $allowedposttags ) ); + $this->assertSame( $content, wp_kses( $content, $allowedposttags ) ); } /** @@ -1306,10 +1306,10 @@ EOF; ), ); - $string = '
Malformed attributes
'; + $content = '
Malformed attributes
'; $expected = '
Malformed attributes
'; - $actual = wp_kses( $string, $allowed_html ); + $actual = wp_kses( $content, $allowed_html ); $this->assertSame( $expected, $actual ); } @@ -1326,10 +1326,10 @@ EOF; ), ); - $string = '
Well formed attribute
'; + $content = '
Well formed attribute
'; $expected = '
Well formed attribute
'; - $actual = wp_kses( $string, $allowed_html ); + $actual = wp_kses( $content, $allowed_html ); $this->assertSame( $expected, $actual ); } @@ -1844,12 +1844,12 @@ HTML; * * @dataProvider data_wp_kses_allowed_values_list * - * @param string $html A string of HTML to test. + * @param string $content A string of HTML to test. * @param string $expected The expected result from KSES. * @param array $allowed_html The allowed HTML to pass to KSES. */ - public function test_wp_kses_allowed_values_list( $html, $expected, $allowed_html ) { - $this->assertSame( $expected, wp_kses( $html, $allowed_html ) ); + public function test_wp_kses_allowed_values_list( $content, $expected, $allowed_html ) { + $this->assertSame( $expected, wp_kses( $content, $allowed_html ) ); } /** @@ -1902,12 +1902,12 @@ HTML; * * @dataProvider data_wp_kses_required_attribute * - * @param string $html A string of HTML to test. + * @param string $content A string of HTML to test. * @param string $expected The expected result from KSES. * @param array $allowed_html The allowed HTML to pass to KSES. */ - public function test_wp_kses_required_attribute( $html, $expected, $allowed_html ) { - $this->assertSame( $expected, wp_kses( $html, $allowed_html ) ); + public function test_wp_kses_required_attribute( $content, $expected, $allowed_html ) { + $this->assertSame( $expected, wp_kses( $content, $allowed_html ) ); } /**