From 54d2b2413916a0fe7fc7d47fedf98b4d000a9338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Fri, 30 Sep 2022 14:41:12 +1000 Subject: [PATCH 1/7] Only accept a query as a next() method argument --- .../html/class-wp-html-tag-processor.php | 63 +++--- .../wp-html-tag-processor-standalone-test.php | 202 +++++++++--------- 2 files changed, 128 insertions(+), 137 deletions(-) diff --git a/lib/experimental/html/class-wp-html-tag-processor.php b/lib/experimental/html/class-wp-html-tag-processor.php index 41230754634c0..b4eca33819376 100644 --- a/lib/experimental/html/class-wp-html-tag-processor.php +++ b/lib/experimental/html/class-wp-html-tag-processor.php @@ -42,14 +42,14 @@ * Example: * ```php * $tags = new WP_HTML_Tag_Processor( $html ); - * if ( $tags->next_tag( [ 'tag_name' => 'option' ] ) ) { + * if ( $tags->next( [ 'tag_name' => 'option' ] ) ) { * $tags->set_attribute( 'selected', true ); * } * ``` * * ### Finding tags * - * The `next_tag()` function moves the internal cursor through + * The `next()` function moves the internal cursor through * your input HTML document until it finds a tag meeting any of * the supplied restrictions in the optional query argument. If * no argument is provided then it will find the next HTML tag, @@ -57,17 +57,17 @@ * * If you want to _find whatever the next tag is_: * ```php - * $tags->next_tag(); + * $tags->next(); * ``` * * | Goal | Query | * |-----------------------------------------------------------|----------------------------------------------------------------------------| - * | Find any tag. | `$tags->next_tag();` | - * | Find next image tag. | `$tags->next_tag( [ 'tag_name' => 'img' ] );` | - * | Find next tag containing the `fullwidth` CSS class. | `$tags->next_tag( [ 'class_name' => 'fullwidth' ] );` | - * | Find next image tag containing the `fullwidth` CSS class. | `$tags->next_tag( [ 'tag_name' => 'img', 'class_name' => 'fullwidth' ] );` | + * | Find any tag. | `$tags->next();` | + * | Find next image tag. | `$tags->next( [ 'tag_name' => 'img' ] );` | + * | Find next tag containing the `fullwidth` CSS class. | `$tags->next( [ 'class_name' => 'fullwidth' ] );` | + * | Find next image tag containing the `fullwidth` CSS class. | `$tags->next( [ 'tag_name' => 'img', 'class_name' => 'fullwidth' ] );` | * - * If a tag was found meeting your criteria then `next_tag()` + * If a tag was found meeting your criteria then `next()` * will return `true` and you can proceed to modify it. If it * returns `false`, however, it failed to find the tag and * moved the cursor to the end of the file. @@ -88,7 +88,7 @@ * ```php * // Paint up to the first five DIV or SPAN tags marked with the "jazzy" style. * $remaining_count = 5; - * while ( $remaining_count > 0 && $tags->next_tag() ) { + * while ( $remaining_count > 0 && $tags->next() ) { * if ( * ( 'DIV' === $tags->get_tag() || 'SPAN' === $tags->get_tag() ) && * 'jazzy' === $tags->get_attribute( 'data-style' ) @@ -115,7 +115,7 @@ * * Example: * ```php - * if ( $tags->next_tag( [ 'class' => 'wp-group-block' ] ) ) { + * if ( $tags->next( [ 'class' => 'wp-group-block' ] ) ) { * $tags->set_attribute( 'title', 'This groups the contained content.' ); * $tags->remove_attribute( 'data-test-id' ); * } @@ -190,7 +190,7 @@ class WP_HTML_Tag_Processor { private $html; /** - * The last query passed to next_tag(). + * The last query passed to next(). * * @since 6.2.0 * @var array|null @@ -392,7 +392,7 @@ public function __construct( $html ) { * } * @return boolean Whether a tag was matched. */ - public function next_tag( $query = null ) { + public function next( $query = null ) { $this->parse_query( $query ); $already_found = 0; @@ -402,7 +402,7 @@ public function next_tag( $query = null ) { * lead us to skip over other tags and lose track of our place. So we need to search for * _every_ tag and then check after we find one if it's the one we are looking for. */ - if ( false === $this->parse_next_tag() ) { + if ( false === $this->parse_next() ) { $this->parsed_bytes = strlen( $this->html ); return false; @@ -620,7 +620,7 @@ private function skip_script_data() { * * @since 6.2.0 */ - private function parse_next_tag() { + private function parse_next() { $this->after_tag(); $html = $this->html; @@ -1027,12 +1027,12 @@ private static function sort_start_ascending( $a, $b ) { * Example: * * $p = new WP_HTML_Tag_Processor( '
Test
' ); - * $p->next_tag( [ 'class_name' => 'test' ] ) === true; + * $p->next( [ 'class_name' => 'test' ] ) === true; * $p->get_attribute( 'data-test-id' ) === '14'; * $p->get_attribute( 'enabled' ) === true; * $p->get_attribute( 'aria-label' ) === null; * - * $p->next_tag( [] ) === false; + * $p->next( [] ) === false; * $p->get_attribute( 'class' ) === null; *
* @@ -1069,10 +1069,10 @@ public function get_attribute( $name ) { * Example: * * $p = new WP_HTML_Tag_Processor( '
Test
' ); - * $p->next_tag( [] ) === true; + * $p->next( [] ) === true; * $p->get_tag() === 'DIV'; * - * $p->next_tag( [] ) === false; + * $p->next( [] ) === false; * $p->get_tag() === null; *
* @@ -1333,7 +1333,7 @@ public function get_updated_html() { * * @since 6.2.0 * - * @param array|string $query { + * @param array $query { * Which tag name to find, having which class. * * @type string|null $tag_name Which tag to find, or `null` for "any tag." @@ -1341,8 +1341,10 @@ public function get_updated_html() { * } */ private function parse_query( $query ) { - if ( null !== $query && $query === $this->last_query ) { - return; + if ( null !== $query ) { + if ( ! is_array( $query ) || $query === $this->last_query ) { + return; + } } $this->last_query = $query; @@ -1350,23 +1352,12 @@ private function parse_query( $query ) { $this->sought_class_name = null; $this->sought_match_offset = 1; - // A single string value means "find the tag of this name". - if ( is_string( $query ) ) { - $this->sought_tag_name = $query; - return; - } - - // If not using the string interface we have to pass an associative array. - if ( ! is_array( $query ) ) { - return; - } - - if ( isset( $query['tag_name'] ) && is_string( $query['tag_name'] ) ) { - $this->sought_tag_name = $query['tag_name']; + if ( isset( $query['tag'] ) && is_string( $query['tag'] ) ) { + $this->sought_tag_name = $query['tag']; } - if ( isset( $query['class_name'] ) && is_string( $query['class_name'] ) ) { - $this->sought_class_name = $query['class_name']; + if ( isset( $query['class'] ) && is_string( $query['class'] ) ) { + $this->sought_class_name = $query['class']; } if ( isset( $query['match_offset'] ) && is_int( $query['match_offset'] ) && 0 < $query['match_offset'] ) { diff --git a/phpunit/html/wp-html-tag-processor-standalone-test.php b/phpunit/html/wp-html-tag-processor-standalone-test.php index 8079db28f52be..beca2f78fde09 100644 --- a/phpunit/html/wp-html-tag-processor-standalone-test.php +++ b/phpunit/html/wp-html-tag-processor-standalone-test.php @@ -50,24 +50,24 @@ public function test_get_tag_returns_null_before_finding_tags() { /** * @ticket 56299 * - * @covers next_tag + * @covers next * @covers get_tag */ public function test_get_tag_returns_null_when_not_in_open_tag() { $p = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertFalse( $p->next_tag( 'p' ), 'Querying a non-existing tag did not return false' ); + $this->assertFalse( $p->next( array( 'tag' => 'p' ) ), 'Querying a non-existing tag did not return false' ); $this->assertNull( $p->get_tag(), 'Accessing a non-existing tag did not return null' ); } /** * @ticket 56299 * - * @covers next_tag + * @covers next * @covers get_tag */ - public function test_get_tag_returns_open_tag_name() { + public function test_get_tag_returns_open_tag() { $p = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertTrue( $p->next_tag( 'div' ), 'Querying an existing tag did not return true' ); + $this->assertTrue( $p->next( array( 'tag' => 'div' ) ), 'Querying an existing tag did not return true' ); $this->assertSame( 'DIV', $p->get_tag(), 'Accessing an existing tag name did not return "div"' ); } @@ -84,60 +84,60 @@ public function test_get_attribute_returns_null_before_finding_tags() { /** * @ticket 56299 * - * @covers next_tag + * @covers next * @covers get_attribute */ public function test_get_attribute_returns_null_when_not_in_open_tag() { $p = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertFalse( $p->next_tag( 'p' ), 'Querying a non-existing tag did not return false' ); + $this->assertFalse( $p->next( array( 'tag' => 'p' ) ), 'Querying a non-existing tag did not return false' ); $this->assertNull( $p->get_attribute( 'class' ), 'Accessing an attribute of a non-existing tag did not return null' ); } /** * @ticket 56299 * - * @covers next_tag + * @covers next * @covers get_attribute */ public function test_get_attribute_returns_null_when_attribute_missing() { $p = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertTrue( $p->next_tag( 'div' ), 'Querying an existing tag did not return true' ); + $this->assertTrue( $p->next( array( 'tag' => 'div' ) ), 'Querying an existing tag did not return true' ); $this->assertNull( $p->get_attribute( 'test-id' ), 'Accessing a non-existing attribute did not return null' ); } /** * @ticket 56299 * - * @covers next_tag + * @covers next * @covers get_attribute */ public function test_get_attribute_returns_attribute_value() { $p = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertTrue( $p->next_tag( 'div' ), 'Querying an existing tag did not return true' ); + $this->assertTrue( $p->next( array( 'tag' => 'div' ) ), 'Querying an existing tag did not return true' ); $this->assertSame( 'test', $p->get_attribute( 'class' ), 'Accessing a class="test" attribute value did not return "test"' ); } /** * @ticket 56299 * - * @covers next_tag + * @covers next * @covers get_attribute */ public function test_get_attribute_returns_true_for_boolean_attribute() { $p = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertTrue( $p->next_tag( array( 'class_name' => 'test' ) ), 'Querying an existing tag did not return true' ); + $this->assertTrue( $p->next( array( 'class' => 'test' ) ), 'Querying an existing tag did not return true' ); $this->assertTrue( $p->get_attribute( 'enabled' ), 'Accessing a boolean "enabled" attribute value did not return true' ); } /** * @ticket 56299 * - * @covers next_tag + * @covers next * @covers get_attribute */ public function test_get_attribute_returns_string_for_truthy_attributes() { $p = new WP_HTML_Tag_Processor( '' ); - $this->assertTrue( $p->next_tag( array() ), 'Querying an existing tag did not return true' ); + $this->assertTrue( $p->next( array() ), 'Querying an existing tag did not return true' ); $this->assertSame( 'enabled', $p->get_attribute( 'enabled' ), 'Accessing a boolean "enabled" attribute value did not return true' ); $this->assertSame( '1', $p->get_attribute( 'checked' ), 'Accessing a checked=1 attribute value did not return "1"' ); $this->assertSame( 'true', $p->get_attribute( 'hidden' ), 'Accessing a hidden="true" attribute value did not return "true"' ); @@ -150,19 +150,19 @@ public function test_get_attribute_returns_string_for_truthy_attributes() { */ public function test_get_attribute_decodes_html_character_references() { $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag(); + $p->next(); $this->assertSame( 'the "grande" is < 32oz†', $p->get_attribute( 'id' ), 'HTML Attribute value was returned without decoding character references' ); } /** * @ticket 56299 * - * @covers next_tag + * @covers next * @covers get_attribute */ public function test_attributes_parser_treats_slash_as_attribute_separator() { $p = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertTrue( $p->next_tag( array() ), 'Querying an existing tag did not return true' ); + $this->assertTrue( $p->next( array() ), 'Querying an existing tag did not return true' ); $this->assertTrue( $p->get_attribute( 'a' ), 'Accessing an existing attribute did not return true' ); $this->assertTrue( $p->get_attribute( 'b' ), 'Accessing an existing attribute did not return true' ); $this->assertTrue( $p->get_attribute( 'c' ), 'Accessing an existing attribute did not return true' ); @@ -197,10 +197,10 @@ public function tostring_returns_updated_html() { */ public function test_get_updated_html_applies_the_updates_so_far_and_keeps_the_processor_on_the_current_tag() { $p = new WP_HTML_Tag_Processor( '
Test
' ); - $p->next_tag(); + $p->next(); $p->remove_attribute( 'id' ); - $p->next_tag(); + $p->next(); $p->set_attribute( 'id', 'div-id-1' ); $p->add_class( 'new_class_1' ); $this->assertSame( @@ -217,7 +217,7 @@ public function test_get_updated_html_applies_the_updates_so_far_and_keeps_the_p 'Calling get_updated_html after updating the attributes of the second tag for the second time returned different HTML than expected' ); - $p->next_tag(); + $p->next(); $p->remove_attribute( 'id' ); $this->assertSame( '
Test
', @@ -239,33 +239,33 @@ public function test_get_updated_html_without_updating_any_attributes_returns_th /** * @ticket 56299 * - * @covers next_tag + * @covers next */ - public function test_next_tag_with_no_arguments_should_find_the_next_existing_tag() { + public function test_next_with_no_arguments_should_find_the_next_existing_tag() { $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $this->assertTrue( $p->next_tag(), 'Querying an existing tag did not return true' ); + $this->assertTrue( $p->next(), 'Querying an existing tag did not return true' ); } /** * @ticket 56299 * - * @covers next_tag + * @covers next */ - public function test_next_tag_should_return_false_for_a_non_existing_tag() { + public function test_next_should_return_false_for_a_non_existing_tag() { $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $this->assertFalse( $p->next_tag( 'p' ), 'Querying a non-existing tag did not return false' ); + $this->assertFalse( $p->next( array( 'tag' => 'p' ) ), 'Querying a non-existing tag did not return false' ); } /** * @ticket 56299 * - * @covers next_tag + * @covers next * @covers get_updated_html */ public function test_set_attribute_on_a_non_existing_tag_does_not_change_the_markup() { $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $this->assertFalse( $p->next_tag( 'p' ), 'Querying a non-existing tag did not return false' ); - $this->assertFalse( $p->next_tag( 'div' ), 'Querying a non-existing tag did not return false' ); + $this->assertFalse( $p->next( array( 'tag' => 'p' ) ), 'Querying a non-existing tag did not return false' ); + $this->assertFalse( $p->next( array( 'tag' => 'div' ) ), 'Querying a non-existing tag did not return false' ); $p->set_attribute( 'id', 'primary' ); $this->assertSame( self::HTML_SIMPLE, @@ -279,7 +279,7 @@ public function test_set_attribute_on_a_non_existing_tag_does_not_change_the_mar * * * $p = new WP_HTML_Tag_Processor( '
' ); - * $p->next_tag(); + * $p->next(); * $p->set_attribute('class', '" onclick="alert'); * echo $p; * //
@@ -298,7 +298,7 @@ public function test_set_attribute_on_a_non_existing_tag_does_not_change_the_mar */ public function test_set_attribute_prevents_xss( $attribute_value ) { $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag(); + $p->next(); $p->set_attribute( 'test', $attribute_value ); /* @@ -344,7 +344,7 @@ public function data_set_attribute_escapable_values() { */ public function test_set_attribute_with_a_non_existing_attribute_adds_a_new_attribute_to_the_markup() { $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); + $p->next(); $p->set_attribute( 'test-attribute', 'test-value' ); $this->assertSame( '
Text
', $p->get_updated_html() ); } @@ -360,7 +360,7 @@ public function test_set_attribute_with_a_non_existing_attribute_adds_a_new_attr */ public function test_update_first_when_duplicated_attribute() { $p = new WP_HTML_Tag_Processor( '
Text
' ); - $p->next_tag(); + $p->next(); $p->set_attribute( 'id', 'updated-id' ); $this->assertSame( '
Text
', $p->get_updated_html() ); } @@ -373,7 +373,7 @@ public function test_update_first_when_duplicated_attribute() { */ public function test_set_attribute_with_an_existing_attribute_name_updates_its_value_in_the_markup() { $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); + $p->next(); $p->set_attribute( 'id', 'new-id' ); $this->assertSame( '
Text
', $p->get_updated_html() ); } @@ -384,9 +384,9 @@ public function test_set_attribute_with_an_existing_attribute_name_updates_its_v * @covers set_attribute * @covers get_updated_html */ - public function test_next_tag_and_set_attribute_in_a_loop_update_all_tags_in_the_markup() { + public function test_next_and_set_attribute_in_a_loop_update_all_tags_in_the_markup() { $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - while ( $p->next_tag() ) { + while ( $p->next() ) { $p->set_attribute( 'data-foo', 'bar' ); } @@ -410,7 +410,7 @@ public function test_next_tag_and_set_attribute_in_a_loop_update_all_tags_in_the */ public function test_remove_first_when_duplicated_attribute() { $p = new WP_HTML_Tag_Processor( '
Text
' ); - $p->next_tag(); + $p->next(); $p->remove_attribute( 'id' ); $this->assertSame( '
Text
', $p->get_updated_html() ); } @@ -423,7 +423,7 @@ public function test_remove_first_when_duplicated_attribute() { */ public function test_remove_attribute_with_an_existing_attribute_name_removes_it_from_the_markup() { $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); + $p->next(); $p->remove_attribute( 'id' ); $this->assertSame( '
Text
', $p->get_updated_html() ); } @@ -436,7 +436,7 @@ public function test_remove_attribute_with_an_existing_attribute_name_removes_it */ public function test_remove_attribute_with_a_non_existing_attribute_name_does_not_change_the_markup() { $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); + $p->next(); $p->remove_attribute( 'no-such-attribute' ); $this->assertSame( self::HTML_SIMPLE, $p->get_updated_html() ); } @@ -449,7 +449,7 @@ public function test_remove_attribute_with_a_non_existing_attribute_name_does_no */ public function test_add_class_creates_a_class_attribute_when_there_is_none() { $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); + $p->next(); $p->add_class( 'foo-class' ); $this->assertSame( '
Text
', $p->get_updated_html() ); } @@ -460,9 +460,9 @@ public function test_add_class_creates_a_class_attribute_when_there_is_none() { * @covers add_class * @covers get_updated_html */ - public function test_calling_add_class_twice_creates_a_class_attribute_with_both_class_names_when_there_is_no_class_attribute() { + public function test_calling_add_class_twice_creates_a_class_attribute_with_both_classs_when_there_is_no_class_attribute() { $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); + $p->next(); $p->add_class( 'foo-class' ); $p->add_class( 'bar-class' ); $this->assertSame( '
Text
', $p->get_updated_html() ); @@ -476,7 +476,7 @@ public function test_calling_add_class_twice_creates_a_class_attribute_with_both */ public function test_remove_class_does_not_change_the_markup_when_there_is_no_class_attribute() { $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); + $p->next(); $p->remove_class( 'foo-class' ); $this->assertSame( self::HTML_SIMPLE, $p->get_updated_html() ); } @@ -487,9 +487,9 @@ public function test_remove_class_does_not_change_the_markup_when_there_is_no_cl * @covers add_class * @covers get_updated_html */ - public function test_add_class_appends_class_names_to_the_existing_class_attribute_when_one_already_exists() { + public function test_add_class_appends_classs_to_the_existing_class_attribute_when_one_already_exists() { $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); + $p->next(); $p->add_class( 'foo-class' ); $p->add_class( 'bar-class' ); $this->assertSame( @@ -506,7 +506,7 @@ public function test_add_class_appends_class_names_to_the_existing_class_attribu */ public function test_remove_class_removes_a_single_class_from_the_class_attribute_when_one_exists() { $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); + $p->next(); $p->remove_class( 'main' ); $this->assertSame( '
Text
', @@ -520,9 +520,9 @@ public function test_remove_class_removes_a_single_class_from_the_class_attribut * @covers remove_class * @covers get_updated_html */ - public function test_calling_remove_class_with_all_listed_class_names_removes_the_existing_class_attribute_from_the_markup() { + public function test_calling_remove_class_with_all_listed_classs_removes_the_existing_class_attribute_from_the_markup() { $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); + $p->next(); $p->remove_class( 'main' ); $p->remove_class( 'with-border' ); $this->assertSame( @@ -537,9 +537,9 @@ public function test_calling_remove_class_with_all_listed_class_names_removes_th * @covers add_class * @covers get_updated_html */ - public function test_add_class_does_not_add_duplicate_class_names() { + public function test_add_class_does_not_add_duplicate_classs() { $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); + $p->next(); $p->add_class( 'with-border' ); $this->assertSame( '
Text
', @@ -553,9 +553,9 @@ public function test_add_class_does_not_add_duplicate_class_names() { * @covers add_class * @covers get_updated_html */ - public function test_add_class_preserves_class_name_order_when_a_duplicate_class_name_is_added() { + public function test_add_class_preserves_class_order_when_a_duplicate_class_is_added() { $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); + $p->next(); $p->add_class( 'main' ); $this->assertSame( '
Text
', @@ -573,7 +573,7 @@ public function test_add_class_when_there_is_a_class_attribute_with_excessive_wh $p = new WP_HTML_Tag_Processor( '
Text
' ); - $p->next_tag(); + $p->next(); $p->add_class( 'foo-class' ); $this->assertSame( '
Text
', @@ -591,7 +591,7 @@ public function test_remove_class_preserves_whitespaces_when_there_is_a_class_at $p = new WP_HTML_Tag_Processor( '
Text
' ); - $p->next_tag(); + $p->next(); $p->remove_class( 'with-border' ); $this->assertSame( '
Text
', @@ -609,7 +609,7 @@ public function test_removing_all_classes_removes_the_existing_class_attribute_f $p = new WP_HTML_Tag_Processor( '
Text
' ); - $p->next_tag(); + $p->next(); $p->remove_class( 'main' ); $p->remove_class( 'with-border' ); $this->assertSame( @@ -632,7 +632,7 @@ public function test_removing_all_classes_removes_the_existing_class_attribute_f */ public function test_set_attribute_takes_priority_over_add_class() { $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); + $p->next(); $p->add_class( 'add_class' ); $p->set_attribute( 'class', 'set_attribute' ); $this->assertSame( @@ -642,7 +642,7 @@ public function test_set_attribute_takes_priority_over_add_class() { ); $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); + $p->next(); $p->set_attribute( 'class', 'set_attribute' ); $p->add_class( 'add_class' ); $this->assertSame( @@ -709,14 +709,14 @@ public function test_advanced_use_case() { HTML; $p = new WP_HTML_Tag_Processor( $input ); - $this->assertTrue( $p->next_tag( 'div' ), 'Querying an existing tag did not return true' ); + $this->assertTrue( $p->next( array( 'tag' => 'div' ) ), 'Querying an existing tag did not return true' ); $p->set_attribute( 'data-details', '{ "key": "value" }' ); $p->add_class( 'is-processed' ); $this->assertTrue( - $p->next_tag( + $p->next( array( - 'tag_name' => 'div', - 'class_name' => 'BtnGroup', + 'tag' => 'div', + 'class' => 'BtnGroup', ) ), 'Querying an existing tag did not return true' @@ -725,10 +725,10 @@ public function test_advanced_use_case() { $p->add_class( 'button-group' ); $p->add_class( 'Another-Mixed-Case' ); $this->assertTrue( - $p->next_tag( + $p->next( array( - 'tag_name' => 'div', - 'class_name' => 'BtnGroup', + 'tag' => 'div', + 'class' => 'BtnGroup', ) ), 'Querying an existing tag did not return true' @@ -737,17 +737,17 @@ public function test_advanced_use_case() { $p->add_class( 'button-group' ); $p->add_class( 'Another-Mixed-Case' ); $this->assertTrue( - $p->next_tag( + $p->next( array( - 'tag_name' => 'button', - 'class_name' => 'btn', + 'tag' => 'button', + 'class' => 'btn', 'match_offset' => 3, ) ), 'Querying an existing tag did not return true' ); $p->remove_attribute( 'class' ); - $this->assertFalse( $p->next_tag( 'non-existent' ), 'Querying a non-existing tag did not return false' ); + $this->assertFalse( $p->next( 'non-existent' ), 'Querying a non-existing tag did not return false' ); $p->set_attribute( 'class', 'test' ); $this->assertSame( $expected_output, $p->get_updated_html(), 'Calling get_updated_html after updating the attributes did not return the expected HTML' ); } @@ -763,17 +763,17 @@ public function test_correctly_parses_html_attributes_wrapped_in_single_quotatio $p = new WP_HTML_Tag_Processor( '
Text
' ); - $p->next_tag( + $p->next( array( - 'tag_name' => 'div', - 'id' => 'first', + 'tag' => 'div', + 'id' => 'first', ) ); $p->remove_attribute( 'id' ); - $p->next_tag( + $p->next( array( - 'tag_name' => 'span', - 'id' => 'second', + 'tag' => 'span', + 'id' => 'second', ) ); $p->set_attribute( 'id', 'single-quote' ); @@ -793,7 +793,7 @@ public function test_set_attribute_with_value_equals_to_true_adds_a_boolean_html $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag( 'input' ); + $p->next( array( 'tag' => 'input' ) ); $p->set_attribute( 'checked', true ); $this->assertSame( '
', @@ -811,7 +811,7 @@ public function test_setting_a_boolean_attribute_to_false_removes_it_from_the_ma $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag( 'input' ); + $p->next( array( 'tag' => 'input' ) ); $p->set_attribute( 'checked', false ); $this->assertSame( '
', @@ -828,7 +828,7 @@ public function test_setting_a_boolean_attribute_to_false_removes_it_from_the_ma public function test_setting_a_missing_attribute_to_false_does_not_change_the_markup() { $html_input = '
'; $p = new WP_HTML_Tag_Processor( $html_input ); - $p->next_tag( 'input' ); + $p->next( array( 'tag' => 'input' ) ); $p->set_attribute( 'checked', false ); $this->assertSame( $html_input, $p->get_updated_html() ); } @@ -843,7 +843,7 @@ public function test_setting_a_boolean_attribute_to_a_string_value_adds_explicit $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag( 'input' ); + $p->next( array( 'tag' => 'input' ) ); $p->set_attribute( 'checked', 'checked' ); $this->assertSame( '
', @@ -855,27 +855,27 @@ public function test_setting_a_boolean_attribute_to_a_string_value_adds_explicit * @ticket 56299 * * @covers get_tag - * @covers next_tag + * @covers next */ public function test_unclosed_script_tag_should_not_cause_an_infinite_loop() { $p = new WP_HTML_Tag_Processor( '