Changeset 55090
- Timestamp:
- 01/18/2023 04:17:41 PM (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/kses.php
r54889 r55090 12 12 * @ticket 20210 13 13 * 14 * @param string $ stringTest string for kses.15 * @param string $expect _stringExpected 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 ) { 18 18 global $allowedposttags; 19 19 20 $this->assertSame( $expect _string, wp_kses( $string, $allowedposttags ) );20 $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) ); 21 21 } 22 22 … … 25 25 * 26 26 * @return array[] Arguments { 27 * @type string $ stringTest string for kses.28 * @type string $expect _stringExpected result after passing through kses.27 * @type string $content Test string for kses. 28 * @type string $expected Expected result after passing through kses. 29 29 * } 30 30 */ … … 46 46 foreach ( $attributes as $name => $values ) { 47 47 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 ); 52 52 } 53 53 } … … 60 60 * @ticket 20210 61 61 * 62 * @param string $ stringTest string for kses.63 * @param string $expect _stringExpected 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 ) { 66 66 global $allowedposttags; 67 67 68 $this->assertSame( $expect _string, wp_kses( $string, $allowedposttags ) );68 $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) ); 69 69 } 70 70 … … 73 73 * 74 74 * @return array[] Arguments { 75 * @type string $ stringTest string for kses.76 * @type string $expect _stringExpected result after passing through kses.75 * @type string $content Test string for kses. 76 * @type string $expected Expected result after passing through kses. 77 77 * } 78 78 */ … … 101 101 $expected_attr = $name; 102 102 } 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 ); 106 106 } 107 107 … … 121 121 */ 122 122 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 ) ); 125 124 } 126 125 … … 167 166 * @ticket 20210 168 167 * 169 * @param string $ stringTest string for kses.170 * @param string $expect _stringExpected 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 ) { 173 172 global $allowedposttags; 174 173 175 $this->assertSame( $expect _string, wp_kses( $string, $allowedposttags ) );174 $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) ); 176 175 } 177 176 … … 180 179 * 181 180 * @return array[] Arguments { 182 * @type string $ stringTest string for kses.183 * @type string $expect _stringExpected result after passing through kses.181 * @type string $content Test string for kses. 182 * @type string $expected Expected result after passing through kses. 184 183 * } 185 184 */ … … 195 194 196 195 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 ); 200 199 } 201 200 … … 536 535 537 536 public function test_hyphenated_tag() { 538 $ string= '<hyphenated-tag attribute="value" otherattribute="value2">Alot of hyphens.</hyphenated-tag>';539 $custom_tags 537 $content = '<hyphenated-tag attribute="value" otherattribute="value2">Alot of hyphens.</hyphenated-tag>'; 538 $custom_tags = array( 540 539 'hyphenated-tag' => array( 541 540 'attribute' => true, 542 541 ), 543 542 ); 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 ) ); 549 549 } 550 550 … … 570 570 * @dataProvider data_ctrl_removal 571 571 */ 572 public function test_ctrl_removal( $ input, $output) {572 public function test_ctrl_removal( $content, $expected ) { 573 573 global $allowedposttags; 574 574 575 return $this->assertSame( $ output, wp_kses( $input, $allowedposttags ) );575 return $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) ); 576 576 } 577 577 … … 607 607 * @dataProvider data_slash_zero_removal 608 608 */ 609 public function test_slash_zero_removal( $ input, $output) {609 public function test_slash_zero_removal( $content, $expected ) { 610 610 global $allowedposttags; 611 611 612 return $this->assertSame( $ output, wp_kses( $input, $allowedposttags ) );612 return $this->assertSame( $expected, wp_kses( $content, $allowedposttags ) ); 613 613 } 614 614 … … 863 863 global $allowedposttags; 864 864 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 ) ); 868 868 } 869 869 … … 874 874 global $allowedposttags; 875 875 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 ) ); 879 879 } 880 880 … … 885 885 global $allowedposttags; 886 886 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 ) ); 890 890 } 891 891 … … 1307 1307 ); 1308 1308 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>'; 1310 1310 $expected = '<div>Malformed attributes</div>'; 1311 1311 1312 $actual = wp_kses( $ string, $allowed_html );1312 $actual = wp_kses( $content, $allowed_html ); 1313 1313 1314 1314 $this->assertSame( $expected, $actual ); … … 1327 1327 ); 1328 1328 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>'; 1330 1330 $expected = '<div data-wp-id="pens-and-pencils">Well formed attribute</div>'; 1331 1331 1332 $actual = wp_kses( $ string, $allowed_html );1332 $actual = wp_kses( $content, $allowed_html ); 1333 1333 1334 1334 $this->assertSame( $expected, $actual ); … … 1845 1845 * @dataProvider data_wp_kses_allowed_values_list 1846 1846 * 1847 * @param string $ htmlA string of HTML to test.1847 * @param string $content A string of HTML to test. 1848 1848 * @param string $expected The expected result from KSES. 1849 1849 * @param array $allowed_html The allowed HTML to pass to KSES. 1850 1850 */ 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 ) ); 1853 1853 } 1854 1854 … … 1903 1903 * @dataProvider data_wp_kses_required_attribute 1904 1904 * 1905 * @param string $ htmlA string of HTML to test.1905 * @param string $content A string of HTML to test. 1906 1906 * @param string $expected The expected result from KSES. 1907 1907 * @param array $allowed_html The allowed HTML to pass to KSES. 1908 1908 */ 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 ) ); 1911 1911 } 1912 1912
Note: See TracChangeset
for help on using the changeset viewer.