diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessor.php b/tests/phpunit/tests/html-api/wpHtmlProcessor.php index 109f384e25e3c..120cf354e9b0b 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessor.php @@ -52,12 +52,12 @@ public function test_warns_that_the_static_creator_methods_should_be_called_inst * @covers WP_HTML_Processor::get_tag */ public function test_get_tag_is_null_once_document_is_finished() { - $p = WP_HTML_Processor::create_fragment( '
Test
' ); - $p->next_tag(); - $this->assertSame( 'DIV', $p->get_tag() ); + $processor = WP_HTML_Processor::create_fragment( '
Test
' ); + $processor->next_tag(); + $this->assertSame( 'DIV', $processor->get_tag() ); - $this->assertFalse( $p->next_tag() ); - $this->assertNull( $p->get_tag() ); + $this->assertFalse( $processor->next_tag() ); + $this->assertNull( $processor->get_tag() ); } /** @@ -77,44 +77,44 @@ public function test_get_tag_is_null_once_document_is_finished() { * @covers WP_HTML_Processor::seek */ public function test_clear_to_navigate_after_seeking() { - $p = WP_HTML_Processor::create_fragment( '

' ); + $processor = WP_HTML_Processor::create_fragment( '

' ); - while ( $p->next_tag() ) { + while ( $processor->next_tag() ) { // Create a bookmark before entering a stack of elements and formatting elements. - if ( null !== $p->get_attribute( 'one' ) ) { - $this->assertTrue( $p->set_bookmark( 'one' ) ); + if ( null !== $processor->get_attribute( 'one' ) ) { + $this->assertTrue( $processor->set_bookmark( 'one' ) ); continue; } // Create a bookmark inside of that stack. - if ( null !== $p->get_attribute( 'two' ) ) { - $p->set_bookmark( 'two' ); + if ( null !== $processor->get_attribute( 'two' ) ) { + $processor->set_bookmark( 'two' ); break; } } // Ensure that it's possible to seek back to the outside location. - $this->assertTrue( $p->seek( 'one' ), 'Could not seek to earlier-seen location.' ); - $this->assertSame( 'DIV', $p->get_tag(), "Should have jumped back to DIV but found {$p->get_tag()} instead." ); + $this->assertTrue( $processor->seek( 'one' ), 'Could not seek to earlier-seen location.' ); + $this->assertSame( 'DIV', $processor->get_tag(), "Should have jumped back to DIV but found {$processor->get_tag()} instead." ); /* * Ensure that the P element from the inner location isn't still on the stack of open elements. * If it were, then the first STRONG element, inside the outer DIV would match the next call. */ - $this->assertTrue( $p->next_tag( array( 'breadcrumbs' => array( 'P', 'STRONG' ) ) ), 'Failed to find given location after seeking.' ); + $this->assertTrue( $processor->next_tag( array( 'breadcrumbs' => array( 'P', 'STRONG' ) ) ), 'Failed to find given location after seeking.' ); // Only if the stack is properly managed will the processor advance to the inner STRONG element. - $this->assertTrue( $p->get_attribute( 'two' ), "Found the wrong location given the breadcrumbs, at {$p->get_tag()}." ); + $this->assertTrue( $processor->get_attribute( 'two' ), "Found the wrong location given the breadcrumbs, at {$processor->get_tag()}." ); // Ensure that in seeking backwards the processor reports the correct full set of breadcrumbs. - $this->assertTrue( $p->seek( 'one' ), 'Failed to jump back to first bookmark.' ); - $this->assertSame( array( 'HTML', 'BODY', 'DIV' ), $p->get_breadcrumbs(), 'Found wrong set of breadcrumbs navigating to node "one".' ); + $this->assertTrue( $processor->seek( 'one' ), 'Failed to jump back to first bookmark.' ); + $this->assertSame( array( 'HTML', 'BODY', 'DIV' ), $processor->get_breadcrumbs(), 'Found wrong set of breadcrumbs navigating to node "one".' ); // Ensure that in seeking forwards the processor reports the correct full set of breadcrumbs. - $this->assertTrue( $p->seek( 'two' ), 'Failed to jump forward to second bookmark.' ); - $this->assertTrue( $p->get_attribute( 'two' ), "Found the wrong location given the bookmark, at {$p->get_tag()}." ); + $this->assertTrue( $processor->seek( 'two' ), 'Failed to jump forward to second bookmark.' ); + $this->assertTrue( $processor->get_attribute( 'two' ), "Found the wrong location given the bookmark, at {$processor->get_tag()}." ); - $this->assertSame( array( 'HTML', 'BODY', 'P', 'STRONG' ), $p->get_breadcrumbs(), 'Found wrong set of bookmarks navigating to node "two".' ); + $this->assertSame( array( 'HTML', 'BODY', 'P', 'STRONG' ), $processor->get_breadcrumbs(), 'Found wrong set of bookmarks navigating to node "two".' ); } /** @@ -126,10 +126,10 @@ public function test_clear_to_navigate_after_seeking() { * @covers WP_HTML_Processor::reconstruct_active_formatting_elements */ public function test_fails_to_reconstruct_formatting_elements() { - $p = WP_HTML_Processor::create_fragment( '

One

Two

Three

Four' ); + $processor = WP_HTML_Processor::create_fragment( '

One

Two

Three

Four' ); - $this->assertTrue( $p->next_tag( 'EM' ), 'Could not find first EM.' ); - $this->assertFalse( $p->next_tag( 'EM' ), 'Should have aborted before finding second EM as it required reconstructing the first EM.' ); + $this->assertTrue( $processor->next_tag( 'EM' ), 'Could not find first EM.' ); + $this->assertFalse( $processor->next_tag( 'EM' ), 'Should have aborted before finding second EM as it required reconstructing the first EM.' ); } /** diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php b/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php index 857684041550a..06576ba1e6123 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php @@ -23,10 +23,10 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase { * @param string $tag_name Name of first tag in HTML (because HTML treats IMAGE as IMG this may not match the HTML). */ public function test_navigates_into_normative_html_for_supported_elements( $html, $tag_name ) { - $p = WP_HTML_Processor::create_fragment( $html ); + $processor = WP_HTML_Processor::create_fragment( $html ); - $this->assertTrue( $p->step(), "Failed to step into supported {$tag_name} element." ); - $this->assertSame( $tag_name, $p->get_tag(), "Misread {$tag_name} as a {$p->get_tag()} element." ); + $this->assertTrue( $processor->step(), "Failed to step into supported {$tag_name} element." ); + $this->assertSame( $tag_name, $processor->get_tag(), "Misread {$tag_name} as a {$processor->get_tag()} element." ); } /** @@ -155,9 +155,9 @@ public function data_single_tag_of_supported_elements() { * @param string $html HTML string containing unsupported elements. */ public function test_fails_when_encountering_unsupported_tag( $html ) { - $p = WP_HTML_Processor::create_fragment( $html ); + $processor = WP_HTML_Processor::create_fragment( $html ); - $this->assertFalse( $p->step(), "Should not have stepped into unsupported {$p->get_tag()} element." ); + $this->assertFalse( $processor->step(), "Should not have stepped into unsupported {$processor->get_tag()} element." ); } /** @@ -229,14 +229,14 @@ public function data_unsupported_elements() { * @param string $html HTML containing unsupported markup. */ public function test_fails_when_encountering_unsupported_markup( $html, $description ) { - $p = WP_HTML_Processor::create_fragment( $html ); + $processor = WP_HTML_Processor::create_fragment( $html ); - while ( $p->step() && null === $p->get_attribute( 'supported' ) ) { + while ( $processor->step() && null === $processor->get_attribute( 'supported' ) ) { continue; } - $this->assertTrue( $p->get_attribute( 'supported' ), 'Did not find required supported element.' ); - $this->assertFalse( $p->step(), "Didn't properly reject unsupported markup: {$description}" ); + $this->assertTrue( $processor->get_attribute( 'supported' ), 'Did not find required supported element.' ); + $this->assertFalse( $processor->step(), "Didn't properly reject unsupported markup: {$description}" ); } /** @@ -270,17 +270,17 @@ public function data_unsupported_markup() { * @param int $n How many breadcrumb matches to scan through in order to find "target" element. */ public function test_finds_correct_tag_given_breadcrumbs( $html, $breadcrumbs, $n ) { - $p = WP_HTML_Processor::create_fragment( $html ); + $processor = WP_HTML_Processor::create_fragment( $html ); - $p->next_tag( + $processor->next_tag( array( 'breadcrumbs' => $breadcrumbs, 'match_offset' => $n, ) ); - $this->assertNotNull( $p->get_tag(), 'Failed to find target node.' ); - $this->assertTrue( $p->get_attribute( 'target' ), "Found {$p->get_tag()} element didn't contain the necessary 'target' attribute." ); + $this->assertNotNull( $processor->get_tag(), 'Failed to find target node.' ); + $this->assertTrue( $processor->get_attribute( 'target' ), "Found {$processor->get_tag()} element didn't contain the necessary 'target' attribute." ); } /** @@ -295,14 +295,14 @@ public function test_finds_correct_tag_given_breadcrumbs( $html, $breadcrumbs, $ * @param int $ignored_n Not used in this test but provided in the dataset for other tests. */ public function test_reports_correct_breadcrumbs_for_html( $html, $breadcrumbs, $ignored_n ) { - $p = WP_HTML_Processor::create_fragment( $html ); + $processor = WP_HTML_Processor::create_fragment( $html ); - while ( $p->next_tag() && null === $p->get_attribute( 'target' ) ) { + while ( $processor->next_tag() && null === $processor->get_attribute( 'target' ) ) { continue; } - $this->assertNotNull( $p->get_tag(), 'Failed to find the target node.' ); - $this->assertSame( $breadcrumbs, $p->get_breadcrumbs(), 'Found the wrong path from the root of the HTML document to the target node.' ); + $this->assertNotNull( $processor->get_tag(), 'Failed to find the target node.' ); + $this->assertSame( $breadcrumbs, $processor->get_breadcrumbs(), 'Found the wrong path from the root of the HTML document to the target node.' ); } /** @@ -433,38 +433,38 @@ public function data_html_with_breadcrumbs_of_various_specificity() { * @covers WP_HTML_Tag_Processor::get_updated_html */ public function test_remains_stable_when_editing_attributes() { - $p = WP_HTML_Processor::create_fragment( '

' ); + $processor = WP_HTML_Processor::create_fragment( '
Test
' ); - $p->step(); - $this->assertSame( 'DIV', $p->get_tag(), 'Did not stop at initial DIV tag.' ); - $this->assertFalse( $p->is_tag_closer(), 'Did not find that initial DIV tag is an opener.' ); + $processor->step(); + $this->assertSame( 'DIV', $processor->get_tag(), 'Did not stop at initial DIV tag.' ); + $this->assertFalse( $processor->is_tag_closer(), 'Did not find that initial DIV tag is an opener.' ); /* * When encountering the BUTTON closing tag, there is no BUTTON in the stack of open elements. * It should be ignored as there's no BUTTON to close. */ - $this->assertTrue( $p->step(), 'Found no further tags when it should have found the closing DIV' ); - $this->assertSame( 'DIV', $p->get_tag(), "Did not skip unexpected BUTTON; stopped at {$p->get_tag()}." ); - $this->assertTrue( $p->is_tag_closer(), 'Did not find that the terminal DIV tag is a closer.' ); + $this->assertTrue( $processor->step(), 'Found no further tags when it should have found the closing DIV' ); + $this->assertSame( 'DIV', $processor->get_tag(), "Did not skip unexpected BUTTON; stopped at {$processor->get_tag()}." ); + $this->assertTrue( $processor->is_tag_closer(), 'Did not find that the terminal DIV tag is a closer.' ); } /** @@ -143,20 +143,20 @@ public function test_in_body_skips_unexpected_button_closer() { * @ticket 58961 */ public function test_in_body_button_with_no_button_in_scope() { - $p = WP_HTML_Processor::create_fragment( '

Click the button !

' ); + $processor = WP_HTML_Processor::create_fragment( '

Click the button !

' ); - $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected first button.' ); - $this->assertTrue( $p->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' ); - $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' ); + $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected first button.' ); + $this->assertTrue( $processor->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' ); + $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' ); /* * There's nothing special about this HTML construction, but it's important to verify that * the HTML Processor can find a BUTTON under normal and normative scenarios, not just the * malformed and unexpected ones. */ - $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected second button.' ); - $this->assertTrue( $p->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' ); - $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' ); + $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected second button.' ); + $this->assertTrue( $processor->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' ); + $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' ); } /** @@ -168,27 +168,27 @@ public function test_in_body_button_with_no_button_in_scope() { * @since 6.4.0 */ public function test_in_body_button_with_button_in_scope_as_parent() { - $p = WP_HTML_Processor::create_fragment( '

Click the button !

' ); + $processor = WP_HTML_Processor::create_fragment( '

Click the button !

' ); - $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected first button.' ); - $this->assertTrue( $p->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' ); - $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' ); + $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected first button.' ); + $this->assertTrue( $processor->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' ); + $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' ); /* * A naive parser might skip the second BUTTON because it's looking for the close of the first one, * or it may place it as a child of the first one, but it implicitly closes the open BUTTON. */ - $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected second button.' ); - $this->assertTrue( $p->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' ); - $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' ); + $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected second button.' ); + $this->assertTrue( $processor->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' ); + $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'P', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' ); /* * This is another form of the test for the second button, but from a different side. The test is * looking for proper handling of the open and close sequence for the BUTTON tags. */ - $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected third button.' ); - $this->assertTrue( $p->get_attribute( 'three' ), 'Failed to match expected attribute on third button.' ); - $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' ); + $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected third button.' ); + $this->assertTrue( $processor->get_attribute( 'three' ), 'Failed to match expected attribute on third button.' ); + $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' ); } /** @@ -201,12 +201,12 @@ public function test_in_body_button_with_button_in_scope_as_parent() { * @since 6.4.0 */ public function test_in_body_button_with_button_in_scope_as_ancestor() { - $p = WP_HTML_Processor::create_fragment( '
!

' ); + $processor = WP_HTML_Processor::create_fragment( '
!

' ); // This button finds itself normally nesting inside the DIV. - $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected first button.' ); - $this->assertTrue( $p->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' ); - $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' ); + $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected first button.' ); + $this->assertTrue( $processor->get_attribute( 'one' ), 'Failed to match expected attribute on first button.' ); + $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for first button.' ); /* * Because the second button appears while a BUTTON is in scope, it generates implied end tags and closes @@ -214,14 +214,14 @@ public function test_in_body_button_with_button_in_scope_as_ancestor() { * of an unexpected closing SPAN tag because the SPAN was closed by the second BUTTON. This element finds * itself a child of the most-recent open element above the most-recent BUTTON, or the DIV. */ - $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected second button.' ); - $this->assertTrue( $p->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' ); - $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' ); + $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected second button.' ); + $this->assertTrue( $processor->get_attribute( 'two' ), 'Failed to match expected attribute on second button.' ); + $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for second button.' ); // The third button is back to normal, because everything has been implicitly or explicitly closed by now. - $this->assertTrue( $p->next_tag( 'BUTTON' ), 'Could not find expected third button.' ); - $this->assertTrue( $p->get_attribute( 'three' ), 'Failed to match expected attribute on third button.' ); - $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' ); + $this->assertTrue( $processor->next_tag( 'BUTTON' ), 'Could not find expected third button.' ); + $this->assertTrue( $processor->get_attribute( 'three' ), 'Failed to match expected attribute on third button.' ); + $this->assertSame( array( 'HTML', 'BODY', 'BUTTON' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting for third button.' ); } /** @@ -355,15 +355,15 @@ public function data_heading_combinations() { * @since 6.4.0 */ public function test_in_body_any_other_end_tag_with_unclosed_special_element() { - $p = WP_HTML_Processor::create_fragment( '

' ); + $processor = WP_HTML_Processor::create_fragment( '

' ); - $p->next_tag( 'P' ); - $this->assertSame( 'P', $p->get_tag(), "Expected to start test on P element but found {$p->get_tag()} instead." ); - $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'P' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting.' ); + $processor->next_tag( 'P' ); + $this->assertSame( 'P', $processor->get_tag(), "Expected to start test on P element but found {$processor->get_tag()} instead." ); + $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'P' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting.' ); - $this->assertTrue( $p->next_tag(), 'Failed to advance past P tag to expected DIV opener.' ); - $this->assertSame( 'DIV', $p->get_tag(), "Expected to find DIV element, but found {$p->get_tag()} instead." ); - $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'DIV' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should still be open and DIV should be its child.' ); + $this->assertTrue( $processor->next_tag(), 'Failed to advance past P tag to expected DIV opener.' ); + $this->assertSame( 'DIV', $processor->get_tag(), "Expected to find DIV element, but found {$processor->get_tag()} instead." ); + $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'DIV' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should still be open and DIV should be its child.' ); } /** @@ -378,19 +378,19 @@ public function test_in_body_any_other_end_tag_with_unclosed_special_element() { * @since 6.4.0 */ public function test_in_body_any_other_end_tag_with_unclosed_non_special_element() { - $p = WP_HTML_Processor::create_fragment( '
' ); + $processor = WP_HTML_Processor::create_fragment( '
' ); - $p->next_tag( 'CODE' ); - $this->assertSame( 'CODE', $p->get_tag(), "Expected to start test on CODE element but found {$p->get_tag()} instead." ); - $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'CODE' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting.' ); + $processor->next_tag( 'CODE' ); + $this->assertSame( 'CODE', $processor->get_tag(), "Expected to start test on CODE element but found {$processor->get_tag()} instead." ); + $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'SPAN', 'CODE' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting.' ); - $this->assertTrue( $p->step(), 'Failed to advance past CODE tag to expected SPAN closer.' ); - $this->assertTrue( $p->is_tag_closer(), 'Expected to find closing SPAN, but found opener instead.' ); - $this->assertSame( array( 'HTML', 'BODY', 'DIV' ), $p->get_breadcrumbs(), 'Failed to advance past CODE tag to expected DIV opener.' ); + $this->assertTrue( $processor->step(), 'Failed to advance past CODE tag to expected SPAN closer.' ); + $this->assertTrue( $processor->is_tag_closer(), 'Expected to find closing SPAN, but found opener instead.' ); + $this->assertSame( array( 'HTML', 'BODY', 'DIV' ), $processor->get_breadcrumbs(), 'Failed to advance past CODE tag to expected DIV opener.' ); - $this->assertTrue( $p->next_tag(), 'Failed to advance past SPAN closer to expected DIV opener.' ); - $this->assertSame( 'DIV', $p->get_tag(), "Expected to find DIV element, but found {$p->get_tag()} instead." ); - $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'DIV' ), $p->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should be closed and DIV should be its sibling.' ); + $this->assertTrue( $processor->next_tag(), 'Failed to advance past SPAN closer to expected DIV opener.' ); + $this->assertSame( 'DIV', $processor->get_tag(), "Expected to find DIV element, but found {$processor->get_tag()} instead." ); + $this->assertSame( array( 'HTML', 'BODY', 'DIV', 'DIV' ), $processor->get_breadcrumbs(), 'Failed to produce expected DOM nesting: SPAN should be closed and DIV should be its sibling.' ); } /** @@ -412,9 +412,9 @@ public function test_in_body_any_other_end_tag_with_unclosed_non_special_element * @ticket 60283 */ public function test_br_end_tag_unsupported() { - $p = WP_HTML_Processor::create_fragment( '
' ); + $processor = WP_HTML_Processor::create_fragment( '
' ); - $this->assertFalse( $p->next_tag(), 'Found a BR tag that should not be handled.' ); - $this->assertSame( WP_HTML_Processor::ERROR_UNSUPPORTED, $p->get_last_error() ); + $this->assertFalse( $processor->next_tag(), 'Found a BR tag that should not be handled.' ); + $this->assertSame( WP_HTML_Processor::ERROR_UNSUPPORTED, $processor->get_last_error() ); } } diff --git a/tests/phpunit/tests/html-api/wpHtmlSupportRequiredHtmlProcessor.php b/tests/phpunit/tests/html-api/wpHtmlSupportRequiredHtmlProcessor.php index 2770acb7360df..2d3cd21ce461b 100644 --- a/tests/phpunit/tests/html-api/wpHtmlSupportRequiredHtmlProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlSupportRequiredHtmlProcessor.php @@ -42,9 +42,9 @@ class Tests_HtmlApi_WpHtmlSupportRequiredHtmlProcessor extends WP_UnitTestCase { * @param string $tag_name the HTML Processor should abort when encountering this tag, e.g. "BUTTON". */ private function ensure_support_is_added_everywhere( $tag_name ) { - $p = WP_HTML_Processor::create_fragment( "<$tag_name>" ); + $processor = WP_HTML_Processor::create_fragment( "<$tag_name>" ); - $this->assertFalse( $p->step(), "Must support terminating elements in specific scope check before adding support for the {$tag_name} element." ); + $this->assertFalse( $processor->step(), "Must support terminating elements in specific scope check before adding support for the {$tag_name} element." ); } /** diff --git a/tests/phpunit/tests/html-api/wpHtmlSupportRequiredOpenElements.php b/tests/phpunit/tests/html-api/wpHtmlSupportRequiredOpenElements.php index 0a05629e024bd..c2e8c697e8156 100644 --- a/tests/phpunit/tests/html-api/wpHtmlSupportRequiredOpenElements.php +++ b/tests/phpunit/tests/html-api/wpHtmlSupportRequiredOpenElements.php @@ -44,9 +44,9 @@ class Tests_HtmlApi_WpHtmlSupportRequiredOpenElements extends WP_UnitTestCase { * @param string $tag_name the HTML Processor should abort when encountering this tag, e.g. "BUTTON". */ private function ensure_support_is_added_everywhere( $tag_name ) { - $p = WP_HTML_Processor::create_fragment( "<$tag_name>" ); + $processor = WP_HTML_Processor::create_fragment( "<$tag_name>" ); - $this->assertFalse( $p->step(), "Must support terminating elements in specific scope check before adding support for the {$tag_name} element." ); + $this->assertFalse( $processor->step(), "Must support terminating elements in specific scope check before adding support for the {$tag_name} element." ); } /** diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessor-bookmark.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessor-bookmark.php index 90adfb20be955..1041dabd439d8 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessor-bookmark.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessor-bookmark.php @@ -19,12 +19,12 @@ class Tests_HtmlApi_WpHtmlTagProcessor_Bookmark extends WP_UnitTestCase { * @covers WP_HTML_Tag_Processor::set_bookmark */ public function test_set_bookmark() { - $p = new WP_HTML_Tag_Processor( '
  • One
  • Two
  • Three
' ); - $p->next_tag( 'li' ); - $this->assertTrue( $p->set_bookmark( 'first li' ), 'Could not allocate a "first li" bookmark' ); - $p->next_tag( 'li' ); - $this->assertTrue( $p->set_bookmark( 'second li' ), 'Could not allocate a "second li" bookmark' ); - $this->assertTrue( $p->set_bookmark( 'first li' ), 'Could not move the "first li" bookmark' ); + $processor = new WP_HTML_Tag_Processor( '
  • One
  • Two
  • Three
' ); + $processor->next_tag( 'li' ); + $this->assertTrue( $processor->set_bookmark( 'first li' ), 'Could not allocate a "first li" bookmark' ); + $processor->next_tag( 'li' ); + $this->assertTrue( $processor->set_bookmark( 'second li' ), 'Could not allocate a "second li" bookmark' ); + $this->assertTrue( $processor->set_bookmark( 'first li' ), 'Could not move the "first li" bookmark' ); } /** @@ -33,11 +33,11 @@ public function test_set_bookmark() { * @covers WP_HTML_Tag_Processor::release_bookmark */ public function test_release_bookmark() { - $p = new WP_HTML_Tag_Processor( '
  • One
  • Two
  • Three
' ); - $p->next_tag( 'li' ); - $this->assertFalse( $p->release_bookmark( 'first li' ), 'Released a non-existing bookmark' ); - $p->set_bookmark( 'first li' ); - $this->assertTrue( $p->release_bookmark( 'first li' ), 'Could not release a bookmark' ); + $processor = new WP_HTML_Tag_Processor( '
  • One
  • Two
  • Three
' ); + $processor->next_tag( 'li' ); + $this->assertFalse( $processor->release_bookmark( 'first li' ), 'Released a non-existing bookmark' ); + $processor->set_bookmark( 'first li' ); + $this->assertTrue( $processor->release_bookmark( 'first li' ), 'Could not release a bookmark' ); } /** @@ -46,8 +46,8 @@ public function test_release_bookmark() { * @covers WP_HTML_Tag_Processor::has_bookmark */ public function test_has_bookmark_returns_false_if_bookmark_does_not_exist() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertFalse( $p->has_bookmark( 'my-bookmark' ) ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $this->assertFalse( $processor->has_bookmark( 'my-bookmark' ) ); } /** @@ -56,10 +56,10 @@ public function test_has_bookmark_returns_false_if_bookmark_does_not_exist() { * @covers WP_HTML_Tag_Processor::has_bookmark */ public function test_has_bookmark_returns_true_if_bookmark_exists() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); - $p->next_tag(); - $p->set_bookmark( 'my-bookmark' ); - $this->assertTrue( $p->has_bookmark( 'my-bookmark' ) ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $processor->next_tag(); + $processor->set_bookmark( 'my-bookmark' ); + $this->assertTrue( $processor->has_bookmark( 'my-bookmark' ) ); } /** @@ -68,11 +68,11 @@ public function test_has_bookmark_returns_true_if_bookmark_exists() { * @covers WP_HTML_Tag_Processor::has_bookmark */ public function test_has_bookmark_returns_false_if_bookmark_has_been_released() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); - $p->next_tag(); - $p->set_bookmark( 'my-bookmark' ); - $p->release_bookmark( 'my-bookmark' ); - $this->assertFalse( $p->has_bookmark( 'my-bookmark' ) ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $processor->next_tag(); + $processor->set_bookmark( 'my-bookmark' ); + $processor->release_bookmark( 'my-bookmark' ); + $this->assertFalse( $processor->has_bookmark( 'my-bookmark' ) ); } /** @@ -81,19 +81,19 @@ public function test_has_bookmark_returns_false_if_bookmark_has_been_released() * @covers WP_HTML_Tag_Processor::seek */ public function test_seek() { - $p = new WP_HTML_Tag_Processor( '
  • One
  • Two
  • Three
' ); - $p->next_tag( 'li' ); - $p->set_bookmark( 'first li' ); + $processor = new WP_HTML_Tag_Processor( '
  • One
  • Two
  • Three
' ); + $processor->next_tag( 'li' ); + $processor->set_bookmark( 'first li' ); - $p->next_tag( 'li' ); - $p->set_attribute( 'foo-2', 'bar-2' ); + $processor->next_tag( 'li' ); + $processor->set_attribute( 'foo-2', 'bar-2' ); - $p->seek( 'first li' ); - $p->set_attribute( 'foo-1', 'bar-1' ); + $processor->seek( 'first li' ); + $processor->set_attribute( 'foo-1', 'bar-1' ); $this->assertSame( '
  • One
  • Two
  • Three
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Did not seek to the intended bookmark locations' ); } @@ -104,18 +104,18 @@ public function test_seek() { * @covers WP_HTML_Tag_Processor::seek */ public function test_seeks_to_tag_closer_bookmark() { - $p = new WP_HTML_Tag_Processor( '
First
Second' ); - $p->next_tag( array( 'tag_closers' => 'visit' ) ); - $p->set_bookmark( 'first' ); - $p->next_tag( array( 'tag_closers' => 'visit' ) ); - $p->set_bookmark( 'second' ); + $processor = new WP_HTML_Tag_Processor( '
First
Second' ); + $processor->next_tag( array( 'tag_closers' => 'visit' ) ); + $processor->set_bookmark( 'first' ); + $processor->next_tag( array( 'tag_closers' => 'visit' ) ); + $processor->set_bookmark( 'second' ); - $p->seek( 'first' ); - $p->seek( 'second' ); + $processor->seek( 'first' ); + $processor->seek( 'second' ); $this->assertSame( 'DIV', - $p->get_tag(), + $processor->get_tag(), 'Did not seek to the intended bookmark location' ); } @@ -159,24 +159,24 @@ public function test_seeks_to_tag_closer_bookmark() { * @covers WP_HTML_Tag_Processor::set_bookmark */ public function test_removing_long_attributes_doesnt_break_seek() { - $input = << HTML; - $p = new WP_HTML_Tag_Processor( $input ); - $p->next_tag( 'button' ); - $p->set_bookmark( 'first' ); - $p->next_tag( 'button' ); - $p->set_bookmark( 'second' ); + $processor = new WP_HTML_Tag_Processor( $input ); + $processor->next_tag( 'button' ); + $processor->set_bookmark( 'first' ); + $processor->next_tag( 'button' ); + $processor->set_bookmark( 'second' ); $this->assertTrue( - $p->seek( 'first' ), + $processor->seek( 'first' ), 'Seek() to the first button has failed' ); - $p->remove_attribute( 'twenty_one_characters' ); - $p->remove_attribute( '7_chars' ); + $processor->remove_attribute( 'twenty_one_characters' ); + $processor->remove_attribute( '7_chars' ); $this->assertTrue( - $p->seek( 'second' ), + $processor->seek( 'second' ), 'Seek() to the second button has failed' ); } @@ -232,61 +232,61 @@ public function test_bookmarks_complex_use_case() {
HTML; - $p = new WP_HTML_Tag_Processor( $input ); - $p->next_tag( 'div' ); - $p->next_tag( 'div' ); - $p->next_tag( 'div' ); - $p->set_bookmark( 'first div' ); - $p->next_tag( 'button' ); - $p->set_bookmark( 'first button' ); - $p->next_tag( 'button' ); - $p->set_bookmark( 'second button' ); - $p->next_tag( 'button' ); - $p->set_bookmark( 'third button' ); - $p->next_tag( 'button' ); - $p->set_bookmark( 'fourth button' ); - - $p->seek( 'first button' ); - $p->set_attribute( 'type', 'submit' ); + $processor = new WP_HTML_Tag_Processor( $input ); + $processor->next_tag( 'div' ); + $processor->next_tag( 'div' ); + $processor->next_tag( 'div' ); + $processor->set_bookmark( 'first div' ); + $processor->next_tag( 'button' ); + $processor->set_bookmark( 'first button' ); + $processor->next_tag( 'button' ); + $processor->set_bookmark( 'second button' ); + $processor->next_tag( 'button' ); + $processor->set_bookmark( 'third button' ); + $processor->next_tag( 'button' ); + $processor->set_bookmark( 'fourth button' ); + + $processor->seek( 'first button' ); + $processor->set_attribute( 'type', 'submit' ); $this->assertTrue( - $p->seek( 'third button' ), + $processor->seek( 'third button' ), 'Seek() to the third button failed' ); - $p->remove_attribute( 'class' ); - $p->remove_attribute( 'type' ); - $p->remove_attribute( 'aria-expanded' ); - $p->set_attribute( 'id', 'rebase-and-merge' ); - $p->remove_attribute( 'data-details-container' ); + $processor->remove_attribute( 'class' ); + $processor->remove_attribute( 'type' ); + $processor->remove_attribute( 'aria-expanded' ); + $processor->set_attribute( 'id', 'rebase-and-merge' ); + $processor->remove_attribute( 'data-details-container' ); $this->assertTrue( - $p->seek( 'first div' ), + $processor->seek( 'first div' ), 'Seek() to the first div failed' ); - $p->set_attribute( 'checked', false ); + $processor->set_attribute( 'checked', false ); $this->assertTrue( - $p->seek( 'fourth button' ), + $processor->seek( 'fourth button' ), 'Seek() to the fourth button failed' ); - $p->set_attribute( 'id', 'last-button' ); - $p->remove_attribute( 'class' ); - $p->remove_attribute( 'type' ); - $p->remove_attribute( 'checked' ); - $p->remove_attribute( 'aria-label' ); - $p->remove_attribute( 'disabled' ); - $p->remove_attribute( 'data-view-component' ); + $processor->set_attribute( 'id', 'last-button' ); + $processor->remove_attribute( 'class' ); + $processor->remove_attribute( 'type' ); + $processor->remove_attribute( 'checked' ); + $processor->remove_attribute( 'aria-label' ); + $processor->remove_attribute( 'disabled' ); + $processor->remove_attribute( 'data-view-component' ); $this->assertTrue( - $p->seek( 'second button' ), + $processor->seek( 'second button' ), 'Seek() to the second button failed' ); - $p->remove_attribute( 'type' ); - $p->set_attribute( 'class', 'hx_create-pr-button' ); + $processor->remove_attribute( 'type' ); + $processor->set_attribute( 'class', 'hx_create-pr-button' ); $this->assertSame( $expected_output, - $p->get_updated_html(), + $processor->get_updated_html(), 'Performing several attribute updates on different tags does not produce the expected HTML snippet' ); } @@ -297,18 +297,18 @@ public function test_bookmarks_complex_use_case() { * @covers WP_HTML_Tag_Processor::seek */ public function test_updates_bookmark_for_additions_after_both_sides() { - $p = new WP_HTML_Tag_Processor( '
First
Second
' ); - $p->next_tag(); - $p->set_bookmark( 'first' ); - $p->next_tag(); - $p->add_class( 'second' ); + $processor = new WP_HTML_Tag_Processor( '
First
Second
' ); + $processor->next_tag(); + $processor->set_bookmark( 'first' ); + $processor->next_tag(); + $processor->add_class( 'second' ); - $p->seek( 'first' ); - $p->add_class( 'first' ); + $processor->seek( 'first' ); + $processor->add_class( 'first' ); $this->assertSame( '
First
Second
', - $p->get_updated_html(), + $processor->get_updated_html(), 'The bookmark was updated incorrectly in response to HTML markup updates' ); } @@ -319,21 +319,21 @@ public function test_updates_bookmark_for_additions_after_both_sides() { * @covers WP_HTML_Tag_Processor::seek */ public function test_updates_bookmark_for_additions_before_both_sides() { - $p = new WP_HTML_Tag_Processor( '
First
Second
' ); - $p->next_tag(); - $p->set_bookmark( 'first' ); - $p->next_tag(); - $p->set_bookmark( 'second' ); + $processor = new WP_HTML_Tag_Processor( '
First
Second
' ); + $processor->next_tag(); + $processor->set_bookmark( 'first' ); + $processor->next_tag(); + $processor->set_bookmark( 'second' ); - $p->seek( 'first' ); - $p->add_class( 'first' ); + $processor->seek( 'first' ); + $processor->add_class( 'first' ); - $p->seek( 'second' ); - $p->add_class( 'second' ); + $processor->seek( 'second' ); + $processor->add_class( 'second' ); $this->assertSame( '
First
Second
', - $p->get_updated_html(), + $processor->get_updated_html(), 'The bookmark was updated incorrectly in response to HTML markup updates' ); } @@ -344,14 +344,14 @@ public function test_updates_bookmark_for_additions_before_both_sides() { * @covers WP_HTML_Tag_Processor::seek */ public function test_updates_bookmark_for_deletions_after_both_sides() { - $p = new WP_HTML_Tag_Processor( '
First
Second
' ); - $p->next_tag(); - $p->set_bookmark( 'first' ); - $p->next_tag(); - $p->remove_attribute( 'disabled' ); + $processor = new WP_HTML_Tag_Processor( '
First
Second
' ); + $processor->next_tag(); + $processor->set_bookmark( 'first' ); + $processor->next_tag(); + $processor->remove_attribute( 'disabled' ); - $p->seek( 'first' ); - $p->set_attribute( 'untouched', true ); + $processor->seek( 'first' ); + $processor->set_attribute( 'untouched', true ); $this->assertSame( /* @@ -363,7 +363,7 @@ public function test_updates_bookmark_for_deletions_after_both_sides() { * is not required. */ '
First
Second
', - $p->get_updated_html(), + $processor->get_updated_html(), 'The bookmark was incorrectly in response to HTML markup updates' ); } @@ -374,17 +374,17 @@ public function test_updates_bookmark_for_deletions_after_both_sides() { * @covers WP_HTML_Tag_Processor::seek */ public function test_updates_bookmark_for_deletions_before_both_sides() { - $p = new WP_HTML_Tag_Processor( '
First
Second
' ); - $p->next_tag(); - $p->set_bookmark( 'first' ); - $p->next_tag(); - $p->set_bookmark( 'second' ); + $processor = new WP_HTML_Tag_Processor( '
First
Second
' ); + $processor->next_tag(); + $processor->set_bookmark( 'first' ); + $processor->next_tag(); + $processor->set_bookmark( 'second' ); - $p->seek( 'first' ); - $p->remove_attribute( 'disabled' ); + $processor->seek( 'first' ); + $processor->remove_attribute( 'disabled' ); - $p->seek( 'second' ); - $p->set_attribute( 'safe', true ); + $processor->seek( 'second' ); + $processor->set_attribute( 'safe', true ); $this->assertSame( /* @@ -396,7 +396,7 @@ public function test_updates_bookmark_for_deletions_before_both_sides() { * is not required. */ '
First
Second
', - $p->get_updated_html(), + $processor->get_updated_html(), 'The bookmark was updated incorrectly in response to HTML markup updates' ); } @@ -407,15 +407,15 @@ public function test_updates_bookmark_for_deletions_before_both_sides() { * @covers WP_HTML_Tag_Processor::set_bookmark */ public function test_limits_the_number_of_bookmarks() { - $p = new WP_HTML_Tag_Processor( '
  • One
  • Two
  • Three
' ); - $p->next_tag( 'li' ); + $processor = new WP_HTML_Tag_Processor( '
  • One
  • Two
  • Three
' ); + $processor->next_tag( 'li' ); for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_BOOKMARKS; $i++ ) { - $this->assertTrue( $p->set_bookmark( "bookmark $i" ), "Could not allocate the bookmark #$i" ); + $this->assertTrue( $processor->set_bookmark( "bookmark $i" ), "Could not allocate the bookmark #$i" ); } $this->setExpectedIncorrectUsage( 'WP_HTML_Tag_Processor::set_bookmark' ); - $this->assertFalse( $p->set_bookmark( 'final bookmark' ), "Allocated $i bookmarks, which is one above the limit" ); + $this->assertFalse( $processor->set_bookmark( 'final bookmark' ), "Allocated $i bookmarks, which is one above the limit" ); } /** @@ -424,15 +424,15 @@ public function test_limits_the_number_of_bookmarks() { * @covers WP_HTML_Tag_Processor::seek */ public function test_limits_the_number_of_seek_calls() { - $p = new WP_HTML_Tag_Processor( '
  • One
  • Two
  • Three
' ); - $p->next_tag( 'li' ); - $p->set_bookmark( 'bookmark' ); + $processor = new WP_HTML_Tag_Processor( '
  • One
  • Two
  • Three
' ); + $processor->next_tag( 'li' ); + $processor->set_bookmark( 'bookmark' ); for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_SEEK_OPS; $i++ ) { - $this->assertTrue( $p->seek( 'bookmark' ), 'Could not seek to the "bookmark"' ); + $this->assertTrue( $processor->seek( 'bookmark' ), 'Could not seek to the "bookmark"' ); } $this->setExpectedIncorrectUsage( 'WP_HTML_Tag_Processor::seek' ); - $this->assertFalse( $p->seek( 'bookmark' ), "$i-th seek() to the bookmark succeeded, even though it should exceed the allowed limit" ); + $this->assertFalse( $processor->seek( 'bookmark' ), "$i-th seek() to the bookmark succeeded, even though it should exceed the allowed limit" ); } } diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php index dda0872408a29..2121ffa221fc9 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php @@ -22,9 +22,9 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @covers WP_HTML_Tag_Processor::get_tag */ public function test_get_tag_returns_null_before_finding_tags() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertNull( $p->get_tag(), 'Calling get_tag() without selecting a tag did not return null' ); + $this->assertNull( $processor->get_tag(), 'Calling get_tag() without selecting a tag did not return null' ); } /** @@ -33,10 +33,10 @@ public function test_get_tag_returns_null_before_finding_tags() { * @covers WP_HTML_Tag_Processor::get_tag */ public function test_get_tag_returns_null_when_not_in_open_tag() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertFalse( $p->next_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' ); + $this->assertFalse( $processor->next_tag( 'p' ), 'Querying a non-existing tag did not return false' ); + $this->assertNull( $processor->get_tag(), 'Accessing a non-existing tag did not return null' ); } /** @@ -45,10 +45,10 @@ public function test_get_tag_returns_null_when_not_in_open_tag() { * @covers WP_HTML_Tag_Processor::get_tag */ public function test_get_tag_returns_open_tag_name() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertTrue( $p->next_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"' ); + $this->assertTrue( $processor->next_tag( 'div' ), 'Querying an existing tag did not return true' ); + $this->assertSame( 'DIV', $processor->get_tag(), 'Accessing an existing tag name did not return "div"' ); } /** @@ -62,13 +62,13 @@ public function test_get_tag_returns_open_tag_name() { * @param bool $flag_is_set Whether the input HTML's first tag contains the self-closing flag. */ public function test_has_self_closing_flag_matches_input_html( $html, $flag_is_set ) { - $p = new WP_HTML_Tag_Processor( $html ); - $p->next_tag( array( 'tag_closers' => 'visit' ) ); + $processor = new WP_HTML_Tag_Processor( $html ); + $processor->next_tag( array( 'tag_closers' => 'visit' ) ); if ( $flag_is_set ) { - $this->assertTrue( $p->has_self_closing_flag(), 'Did not find the self-closing tag when it was present.' ); + $this->assertTrue( $processor->has_self_closing_flag(), 'Did not find the self-closing tag when it was present.' ); } else { - $this->assertFalse( $p->has_self_closing_flag(), 'Found the self-closing tag when it was absent.' ); + $this->assertFalse( $processor->has_self_closing_flag(), 'Found the self-closing tag when it was absent.' ); } } @@ -107,9 +107,9 @@ public function data_has_self_closing_flag() { * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_returns_null_before_finding_tags() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertNull( $p->get_attribute( 'class' ), 'Accessing an attribute without selecting a tag did not return null' ); + $this->assertNull( $processor->get_attribute( 'class' ), 'Accessing an attribute without selecting a tag did not return null' ); } /** @@ -118,10 +118,10 @@ public function test_get_attribute_returns_null_before_finding_tags() { * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_returns_null_when_not_in_open_tag() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertFalse( $p->next_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' ); + $this->assertFalse( $processor->next_tag( 'p' ), 'Querying a non-existing tag did not return false' ); + $this->assertNull( $processor->get_attribute( 'class' ), 'Accessing an attribute of a non-existing tag did not return null' ); } /** @@ -130,11 +130,11 @@ public function test_get_attribute_returns_null_when_not_in_open_tag() { * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_returns_null_when_in_closing_tag() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertTrue( $p->next_tag( 'div' ), 'Querying an existing tag did not return true' ); - $this->assertTrue( $p->next_tag( array( 'tag_closers' => 'visit' ) ), 'Querying an existing closing tag did not return true' ); - $this->assertNull( $p->get_attribute( 'class' ), 'Accessing an attribute of a closing tag did not return null' ); + $this->assertTrue( $processor->next_tag( 'div' ), 'Querying an existing tag did not return true' ); + $this->assertTrue( $processor->next_tag( array( 'tag_closers' => 'visit' ) ), 'Querying an existing closing tag did not return true' ); + $this->assertNull( $processor->get_attribute( 'class' ), 'Accessing an attribute of a closing tag did not return null' ); } /** @@ -143,10 +143,10 @@ public function test_get_attribute_returns_null_when_in_closing_tag() { * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_returns_null_when_attribute_missing() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertTrue( $p->next_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' ); + $this->assertTrue( $processor->next_tag( 'div' ), 'Querying an existing tag did not return true' ); + $this->assertNull( $processor->get_attribute( 'test-id' ), 'Accessing a non-existing attribute did not return null' ); } /** @@ -155,10 +155,10 @@ public function test_get_attribute_returns_null_when_attribute_missing() { * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_returns_attribute_value() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertTrue( $p->next_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"' ); + $this->assertTrue( $processor->next_tag( 'div' ), 'Querying an existing tag did not return true' ); + $this->assertSame( 'test', $processor->get_attribute( 'class' ), 'Accessing a class="test" attribute value did not return "test"' ); } /** @@ -167,10 +167,10 @@ public function test_get_attribute_returns_attribute_value() { * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_returns_true_for_boolean_attribute() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); + $processor = 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->get_attribute( 'enabled' ), 'Accessing a boolean "enabled" attribute value did not return true' ); + $this->assertTrue( $processor->next_tag( array( 'class_name' => 'test' ) ), 'Querying an existing tag did not return true' ); + $this->assertTrue( $processor->get_attribute( 'enabled' ), 'Accessing a boolean "enabled" attribute value did not return true' ); } /** @@ -179,12 +179,12 @@ public function test_get_attribute_returns_true_for_boolean_attribute() { * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_returns_string_for_truthy_attributes() { - $p = new WP_HTML_Tag_Processor( '' ); + $processor = new WP_HTML_Tag_Processor( '' ); - $this->assertTrue( $p->next_tag(), '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"' ); + $this->assertTrue( $processor->next_tag(), 'Querying an existing tag did not return true' ); + $this->assertSame( 'enabled', $processor->get_attribute( 'enabled' ), 'Accessing a boolean "enabled" attribute value did not return true' ); + $this->assertSame( '1', $processor->get_attribute( 'checked' ), 'Accessing a checked=1 attribute value did not return "1"' ); + $this->assertSame( 'true', $processor->get_attribute( 'hidden' ), 'Accessing a hidden="true" attribute value did not return "true"' ); } /** @@ -193,10 +193,10 @@ public function test_get_attribute_returns_string_for_truthy_attributes() { * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_decodes_html_character_references() { - $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( '
' ); + $processor->next_tag(); - $this->assertSame( 'the "grande" is < 32oz†', $p->get_attribute( 'id' ), 'HTML Attribute value was returned without decoding character references' ); + $this->assertSame( 'the "grande" is < 32oz†', $processor->get_attribute( 'id' ), 'HTML Attribute value was returned without decoding character references' ); } /** @@ -205,14 +205,14 @@ public function test_get_attribute_decodes_html_character_references() { * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_attributes_parser_treats_slash_as_attribute_separator() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); - $this->assertTrue( $p->next_tag(), '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' ); - $this->assertTrue( $p->get_attribute( 'd' ), 'Accessing an existing attribute did not return true' ); - $this->assertSame( 'test', $p->get_attribute( 'e' ), 'Accessing an existing e="test" did not return "test"' ); + $this->assertTrue( $processor->next_tag(), 'Querying an existing tag did not return true' ); + $this->assertTrue( $processor->get_attribute( 'a' ), 'Accessing an existing attribute did not return true' ); + $this->assertTrue( $processor->get_attribute( 'b' ), 'Accessing an existing attribute did not return true' ); + $this->assertTrue( $processor->get_attribute( 'c' ), 'Accessing an existing attribute did not return true' ); + $this->assertTrue( $processor->get_attribute( 'd' ), 'Accessing an existing attribute did not return true' ); + $this->assertSame( 'test', $processor->get_attribute( 'e' ), 'Accessing an existing e="test" did not return "test"' ); } /** @@ -225,12 +225,12 @@ public function test_attributes_parser_treats_slash_as_attribute_separator() { * @param string $attribute_name Name of data-enabled attribute with case variations. */ public function test_get_attribute_is_case_insensitive_for_attributes_with_values( $attribute_name ) { - $p = new WP_HTML_Tag_Processor( '
Test
' ); - $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $processor->next_tag(); $this->assertSame( 'true', - $p->get_attribute( $attribute_name ), + $processor->get_attribute( $attribute_name ), 'Accessing an attribute by a differently-cased name did not return its value' ); } @@ -245,11 +245,11 @@ public function test_get_attribute_is_case_insensitive_for_attributes_with_value * @param string $attribute_name Name of data-enabled attribute with case variations. */ public function test_attributes_parser_is_case_insensitive_for_attributes_without_values( $attribute_name ) { - $p = new WP_HTML_Tag_Processor( '
Test
' ); - $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $processor->next_tag(); $this->assertTrue( - $p->get_attribute( $attribute_name ), + $processor->get_attribute( $attribute_name ), 'Accessing an attribute by a differently-cased name did not return its value' ); } @@ -274,11 +274,11 @@ public function data_attribute_name_case_variants() { * @covers WP_HTML_Tag_Processor::remove_attribute */ public function test_remove_attribute_is_case_insensitive() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); - $p->next_tag(); - $p->remove_attribute( 'data-enabled' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $processor->next_tag(); + $processor->remove_attribute( 'data-enabled' ); - $this->assertSame( '
Test
', $p->get_updated_html(), 'A case-insensitive remove_attribute call did not remove the attribute' ); + $this->assertSame( '
Test
', $processor->get_updated_html(), 'A case-insensitive remove_attribute call did not remove the attribute' ); } /** @@ -287,11 +287,11 @@ public function test_remove_attribute_is_case_insensitive() { * @covers WP_HTML_Tag_Processor::set_attribute */ public function test_set_attribute_is_case_insensitive() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); - $p->next_tag(); - $p->set_attribute( 'data-enabled', 'abc' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $processor->next_tag(); + $processor->set_attribute( 'data-enabled', 'abc' ); - $this->assertSame( '
Test
', $p->get_updated_html(), 'A case-insensitive set_attribute call did not update the existing attribute' ); + $this->assertSame( '
Test
', $processor->get_updated_html(), 'A case-insensitive set_attribute call did not update the existing attribute' ); } /** @@ -300,9 +300,9 @@ public function test_set_attribute_is_case_insensitive() { * @covers WP_HTML_Tag_Processor::get_attribute_names_with_prefix */ public function test_get_attribute_names_with_prefix_returns_null_before_finding_tags() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); $this->assertNull( - $p->get_attribute_names_with_prefix( 'data-' ), + $processor->get_attribute_names_with_prefix( 'data-' ), 'Accessing attributes by their prefix did not return null when no tag was selected' ); } @@ -313,9 +313,9 @@ public function test_get_attribute_names_with_prefix_returns_null_before_finding * @covers WP_HTML_Tag_Processor::get_attribute_names_with_prefix */ public function test_get_attribute_names_with_prefix_returns_null_when_not_in_open_tag() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); - $p->next_tag( 'p' ); - $this->assertNull( $p->get_attribute_names_with_prefix( 'data-' ), 'Accessing attributes of a non-existing tag did not return null' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $processor->next_tag( 'p' ); + $this->assertNull( $processor->get_attribute_names_with_prefix( 'data-' ), 'Accessing attributes of a non-existing tag did not return null' ); } /** @@ -324,11 +324,11 @@ public function test_get_attribute_names_with_prefix_returns_null_when_not_in_op * @covers WP_HTML_Tag_Processor::get_attribute_names_with_prefix */ public function test_get_attribute_names_with_prefix_returns_null_when_in_closing_tag() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); - $p->next_tag( 'div' ); - $p->next_tag( array( 'tag_closers' => 'visit' ) ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $processor->next_tag( 'div' ); + $processor->next_tag( array( 'tag_closers' => 'visit' ) ); - $this->assertNull( $p->get_attribute_names_with_prefix( 'data-' ), 'Accessing attributes of a closing tag did not return null' ); + $this->assertNull( $processor->get_attribute_names_with_prefix( 'data-' ), 'Accessing attributes of a closing tag did not return null' ); } /** @@ -337,10 +337,10 @@ public function test_get_attribute_names_with_prefix_returns_null_when_in_closin * @covers WP_HTML_Tag_Processor::get_attribute_names_with_prefix */ public function test_get_attribute_names_with_prefix_returns_empty_array_when_no_attributes_present() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); - $p->next_tag( 'div' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $processor->next_tag( 'div' ); - $this->assertSame( array(), $p->get_attribute_names_with_prefix( 'data-' ), 'Accessing the attributes on a tag without any did not return an empty array' ); + $this->assertSame( array(), $processor->get_attribute_names_with_prefix( 'data-' ), 'Accessing the attributes on a tag without any did not return an empty array' ); } /** @@ -349,12 +349,12 @@ public function test_get_attribute_names_with_prefix_returns_empty_array_when_no * @covers WP_HTML_Tag_Processor::get_attribute_names_with_prefix */ public function test_get_attribute_names_with_prefix_returns_matching_attribute_names_in_lowercase() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); - $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $processor->next_tag(); $this->assertSame( array( 'data-enabled', 'data-test-id' ), - $p->get_attribute_names_with_prefix( 'data-' ), + $processor->get_attribute_names_with_prefix( 'data-' ), 'Accessing attributes by their prefix did not return their lowercase names' ); } @@ -365,18 +365,18 @@ public function test_get_attribute_names_with_prefix_returns_matching_attribute_ * @covers WP_HTML_Tag_Processor::get_attribute_names_with_prefix */ public function test_get_attribute_names_with_prefix_returns_attribute_added_by_set_attribute() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); - $p->next_tag(); - $p->set_attribute( 'data-test-id', '14' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $processor->next_tag(); + $processor->set_attribute( 'data-test-id', '14' ); $this->assertSame( '
Test
', - $p->get_updated_html(), + $processor->get_updated_html(), "Updated HTML doesn't include attribute added via set_attribute" ); $this->assertSame( array( 'data-test-id', 'data-foo' ), - $p->get_attribute_names_with_prefix( 'data-' ), + $processor->get_attribute_names_with_prefix( 'data-' ), "Accessing attribute names doesn't find attribute added via set_attribute" ); } @@ -387,17 +387,17 @@ public function test_get_attribute_names_with_prefix_returns_attribute_added_by_ * @covers WP_HTML_Tag_Processor::__toString */ public function test_to_string_returns_updated_html() { - $p = new WP_HTML_Tag_Processor( '
Test
' ); - $p->next_tag(); - $p->remove_attribute( 'id' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $processor->next_tag(); + $processor->remove_attribute( 'id' ); - $p->next_tag(); - $p->set_attribute( 'id', 'div-id-1' ); - $p->add_class( 'new_class_1' ); + $processor->next_tag(); + $processor->set_attribute( 'id', 'div-id-1' ); + $processor->add_class( 'new_class_1' ); $this->assertSame( - $p->get_updated_html(), - (string) $p, + $processor->get_updated_html(), + (string) $processor, 'get_updated_html() returned a different value than __toString()' ); } @@ -408,35 +408,35 @@ public function test_to_string_returns_updated_html() { * @covers WP_HTML_Tag_Processor::get_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->remove_attribute( 'id' ); + $processor = new WP_HTML_Tag_Processor( '
Test
' ); + $processor->next_tag(); + $processor->remove_attribute( 'id' ); - $p->next_tag(); - $p->set_attribute( 'id', 'div-id-1' ); - $p->add_class( 'new_class_1' ); + $processor->next_tag(); + $processor->set_attribute( 'id', 'div-id-1' ); + $processor->add_class( 'new_class_1' ); $this->assertSame( '
Test
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Calling get_updated_html after updating the attributes of the second tag returned different HTML than expected' ); - $p->set_attribute( 'id', 'div-id-2' ); - $p->add_class( 'new_class_2' ); + $processor->set_attribute( 'id', 'div-id-2' ); + $processor->add_class( 'new_class_2' ); $this->assertSame( '
Test
', - $p->get_updated_html(), + $processor->get_updated_html(), '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->remove_attribute( 'id' ); + $processor->next_tag(); + $processor->remove_attribute( 'id' ); $this->assertSame( '
Test
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Calling get_updated_html after removing the id attribute of the third tag returned different HTML than expected' ); } @@ -447,11 +447,11 @@ public function test_get_updated_html_applies_the_updates_so_far_and_keeps_the_p * @covers WP_HTML_Tag_Processor::get_updated_html */ public function test_get_updated_html_without_updating_any_attributes_returns_the_original_html() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); $this->assertSame( self::HTML_SIMPLE, - $p->get_updated_html(), + $processor->get_updated_html(), 'Casting WP_HTML_Tag_Processor to a string without performing any updates did not return the initial HTML snippet' ); } @@ -463,17 +463,17 @@ public function test_get_updated_html_without_updating_any_attributes_returns_th * @ticket 58160 */ public function test_get_updated_html_applies_updates_to_content_after_seeking_to_before_parsed_bytes() { - $p = new WP_HTML_Tag_Processor( '
' ); + $processor = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag(); - $p->set_attribute( 'wonky', true ); - $p->next_tag(); - $p->set_bookmark( 'here' ); + $processor->next_tag(); + $processor->set_attribute( 'wonky', true ); + $processor->next_tag(); + $processor->set_bookmark( 'here' ); - $p->next_tag( array( 'tag_closers' => 'visit' ) ); - $p->seek( 'here' ); + $processor->next_tag( array( 'tag_closers' => 'visit' ) ); + $processor->seek( 'here' ); - $this->assertSame( '
', $p->get_updated_html() ); + $this->assertSame( '
', $processor->get_updated_html() ); } /** @@ -482,9 +482,9 @@ public function test_get_updated_html_applies_updates_to_content_after_seeking_t * @covers WP_HTML_Tag_Processor::next_tag */ public function test_next_tag_with_no_arguments_should_find_the_next_existing_tag() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $this->assertTrue( $p->next_tag(), 'Querying an existing tag did not return true' ); + $this->assertTrue( $processor->next_tag(), 'Querying an existing tag did not return true' ); } /** @@ -493,9 +493,9 @@ public function test_next_tag_with_no_arguments_should_find_the_next_existing_ta * @covers WP_HTML_Tag_Processor::next_tag */ public function test_next_tag_should_return_false_for_a_non_existing_tag() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor = 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( $processor->next_tag( 'p' ), 'Querying a non-existing tag did not return false' ); } /** @@ -504,9 +504,9 @@ public function test_next_tag_should_return_false_for_a_non_existing_tag() { * @covers WP_HTML_Tag_Processor::next_tag */ public function test_next_tag_matches_decoded_class_names() { - $p = new WP_HTML_Tag_Processor( '
' ); + $processor = new WP_HTML_Tag_Processor( '
' ); - $this->assertTrue( $p->next_tag( array( 'class_name' => '' ) ), 'Failed to find tag with HTML-encoded class name.' ); + $this->assertTrue( $processor->next_tag( array( 'class_name' => '' ) ), 'Failed to find tag with HTML-encoded class name.' ); } /** @@ -517,22 +517,22 @@ public function test_next_tag_matches_decoded_class_names() { * @covers WP_HTML_Tag_Processor::is_tag_closer */ public function test_next_tag_should_stop_on_closers_only_when_requested() { - $p = new WP_HTML_Tag_Processor( '
' ); + $processor = new WP_HTML_Tag_Processor( '
' ); - $this->assertTrue( $p->next_tag( array( 'tag_name' => 'div' ) ), 'Did not find desired tag opener' ); - $this->assertFalse( $p->next_tag( array( 'tag_name' => 'div' ) ), 'Visited an unwanted tag, a tag closer' ); + $this->assertTrue( $processor->next_tag( array( 'tag_name' => 'div' ) ), 'Did not find desired tag opener' ); + $this->assertFalse( $processor->next_tag( array( 'tag_name' => 'div' ) ), 'Visited an unwanted tag, a tag closer' ); - $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag( + $processor = new WP_HTML_Tag_Processor( '
' ); + $processor->next_tag( array( 'tag_name' => 'div', 'tag_closers' => 'visit', ) ); - $this->assertFalse( $p->is_tag_closer(), 'Indicated a tag opener is a tag closer' ); + $this->assertFalse( $processor->is_tag_closer(), 'Indicated a tag opener is a tag closer' ); $this->assertTrue( - $p->next_tag( + $processor->next_tag( array( 'tag_name' => 'div', 'tag_closers' => 'visit', @@ -540,11 +540,11 @@ public function test_next_tag_should_stop_on_closers_only_when_requested() { ), 'Did not stop at desired tag closer' ); - $this->assertTrue( $p->is_tag_closer(), 'Indicated a tag closer is a tag opener' ); + $this->assertTrue( $processor->is_tag_closer(), 'Indicated a tag closer is a tag opener' ); - $p = new WP_HTML_Tag_Processor( '
' ); - $this->assertTrue( $p->next_tag( array( 'tag_closers' => 'visit' ) ), "Did not find a tag opener when tag_closers was set to 'visit'" ); - $this->assertFalse( $p->next_tag( array( 'tag_closers' => 'visit' ) ), "Found a closer where there wasn't one" ); + $processor = new WP_HTML_Tag_Processor( '
' ); + $this->assertTrue( $processor->next_tag( array( 'tag_closers' => 'visit' ) ), "Did not find a tag opener when tag_closers was set to 'visit'" ); + $this->assertFalse( $processor->next_tag( array( 'tag_closers' => 'visit' ) ), "Found a closer where there wasn't one" ); } /** @@ -554,38 +554,38 @@ public function test_next_tag_should_stop_on_closers_only_when_requested() { * @covers WP_HTML_Tag_Processor::is_tag_closer */ public function test_next_tag_should_stop_on_rcdata_and_script_tag_closers_when_requested() { - $p = new WP_HTML_Tag_Processor( '' ); + $processor = new WP_HTML_Tag_Processor( '' ); - $p->next_tag(); + $processor->next_tag(); $this->assertFalse( - $p->next_tag( array( 'tag_closers' => 'visit' ) ), + $processor->next_tag( array( 'tag_closers' => 'visit' ) ), 'Should not have found closing SCRIPT tag when closing an opener.' ); - $p = new WP_HTML_Tag_Processor( 'abc' ); - $this->assertTrue( $p->next_tag( array( 'tag_closers' => 'visit' ) ), 'Did not find the tag closer when there was no tag opener' ); + $processor = new WP_HTML_Tag_Processor( 'abc' ); + $this->assertTrue( $processor->next_tag( array( 'tag_closers' => 'visit' ) ), 'Did not find the tag closer when there was no tag opener' ); - $p = new WP_HTML_Tag_Processor( '' ); + $processor = new WP_HTML_Tag_Processor( '' ); - $p->next_tag(); + $processor->next_tag(); $this->assertFalse( - $p->next_tag( array( 'tag_closers' => 'visit' ) ), + $processor->next_tag( array( 'tag_closers' => 'visit' ) ), 'Should not have found closing TEXTAREA when closing an opener.' ); - $p = new WP_HTML_Tag_Processor( 'abc' ); - $this->assertTrue( $p->next_tag( array( 'tag_closers' => 'visit' ) ), 'Did not find the tag closer when there was no tag opener' ); + $processor = new WP_HTML_Tag_Processor( 'abc' ); + $this->assertTrue( $processor->next_tag( array( 'tag_closers' => 'visit' ) ), 'Did not find the tag closer when there was no tag opener' ); - $p = new WP_HTML_Tag_Processor( 'abc' ); + $processor = new WP_HTML_Tag_Processor( 'abc' ); - $p->next_tag(); + $processor->next_tag(); $this->assertFalse( - $p->next_tag( array( 'tag_closers' => 'visit' ) ), + $processor->next_tag( array( 'tag_closers' => 'visit' ) ), 'Should not have found closing TITLE when closing an opener.' ); - $p = new WP_HTML_Tag_Processor( 'abc' ); - $this->assertTrue( $p->next_tag( array( 'tag_closers' => 'visit' ) ), 'Did not find the tag closer when there was no tag opener' ); + $processor = new WP_HTML_Tag_Processor( 'abc' ); + $this->assertTrue( $processor->next_tag( array( 'tag_closers' => 'visit' ) ), 'Did not find the tag closer when there was no tag opener' ); } /** @@ -620,16 +620,16 @@ public function test_internal_pointer_returns_to_original_spot_after_inserting_c * @covers WP_HTML_Tag_Processor::set_attribute */ public function test_set_attribute_on_a_non_existing_tag_does_not_change_the_markup() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor = 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( $processor->next_tag( 'p' ), 'Querying a non-existing tag did not return false' ); + $this->assertFalse( $processor->next_tag( 'div' ), 'Querying a non-existing tag did not return false' ); - $p->set_attribute( 'id', 'primary' ); + $processor->set_attribute( 'id', 'primary' ); $this->assertSame( self::HTML_SIMPLE, - $p->get_updated_html(), + $processor->get_updated_html(), 'Calling get_updated_html after updating a non-existing tag returned an HTML that was different from the original HTML' ); } @@ -643,31 +643,31 @@ public function test_set_attribute_on_a_non_existing_tag_does_not_change_the_mar * @covers WP_HTML_Tag_Processor::remove_class */ public function test_attribute_ops_on_tag_closer_do_not_change_the_markup() { - $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag( + $processor = new WP_HTML_Tag_Processor( '
' ); + $processor->next_tag( array( 'tag_name' => 'div', 'tag_closers' => 'visit', ) ); - $this->assertFalse( $p->is_tag_closer(), 'Skipped tag opener' ); + $this->assertFalse( $processor->is_tag_closer(), 'Skipped tag opener' ); - $p->next_tag( + $processor->next_tag( array( 'tag_name' => 'div', 'tag_closers' => 'visit', ) ); - $this->assertTrue( $p->is_tag_closer(), 'Skipped tag closer' ); - $this->assertFalse( $p->set_attribute( 'id', 'test' ), "Allowed setting an attribute on a tag closer when it shouldn't have" ); - $this->assertFalse( $p->remove_attribute( 'invalid-id' ), "Allowed removing an attribute on a tag closer when it shouldn't have" ); - $this->assertFalse( $p->add_class( 'sneaky' ), "Allowed adding a class on a tag closer when it shouldn't have" ); - $this->assertFalse( $p->remove_class( 'not-appearing-in-this-test' ), "Allowed removing a class on a tag closer when it shouldn't have" ); + $this->assertTrue( $processor->is_tag_closer(), 'Skipped tag closer' ); + $this->assertFalse( $processor->set_attribute( 'id', 'test' ), "Allowed setting an attribute on a tag closer when it shouldn't have" ); + $this->assertFalse( $processor->remove_attribute( 'invalid-id' ), "Allowed removing an attribute on a tag closer when it shouldn't have" ); + $this->assertFalse( $processor->add_class( 'sneaky' ), "Allowed adding a class on a tag closer when it shouldn't have" ); + $this->assertFalse( $processor->remove_class( 'not-appearing-in-this-test' ), "Allowed removing a class on a tag closer when it shouldn't have" ); $this->assertSame( '
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Calling get_updated_html after updating a non-existing tag returned an HTML that was different from the original HTML' ); } @@ -676,9 +676,9 @@ public function test_attribute_ops_on_tag_closer_do_not_change_the_markup() { * Passing a double quote inside of an attribute value could lead to an XSS attack as follows: * * ```php - * $p = new WP_HTML_Tag_Processor( '
' ); - * $p->next_tag(); - * $p->set_attribute('class', '" onclick="alert'); + * $processor = new WP_HTML_Tag_Processor( '
' ); + * $processor->next_tag(); + * $processor->set_attribute('class', '" onclick="alert'); * echo $p; * //
* ``` @@ -697,9 +697,9 @@ public function test_attribute_ops_on_tag_closer_do_not_change_the_markup() { * @param string $attribute_value A value with potential XSS exploit. */ public function test_set_attribute_prevents_xss( $attribute_value ) { - $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag(); - $p->set_attribute( 'test', $attribute_value ); + $processor = new WP_HTML_Tag_Processor( '
' ); + $processor->next_tag(); + $processor->set_attribute( 'test', $attribute_value ); /* * Testing the escaping is hard using tools that properly parse @@ -713,7 +713,7 @@ public function test_set_attribute_prevents_xss( $attribute_value ) { * content and (b) looks at the raw values. */ $match = null; - preg_match( '~^
$~', $p->get_updated_html(), $match ); + preg_match( '~^
$~', $processor->get_updated_html(), $match ); list( , $actual_value ) = $match; $this->assertSame( '"' . esc_attr( $attribute_value ) . '"', $actual_value, 'Entities were not properly escaped in the attribute value' ); @@ -744,18 +744,18 @@ public function data_set_attribute_prevents_xss() { * @covers WP_HTML_Tag_Processor::set_attribute */ 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->set_attribute( 'test-attribute', 'test-value' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->set_attribute( 'test-attribute', 'test-value' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not include attribute added via set_attribute()' ); $this->assertSame( 'test-value', - $p->get_attribute( 'test-attribute' ), + $processor->get_attribute( 'test-attribute' ), 'get_attribute() (called after get_updated_html()) did not return attribute added via set_attribute()' ); } @@ -766,18 +766,18 @@ public function test_set_attribute_with_a_non_existing_attribute_adds_a_new_attr * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_returns_updated_values_before_they_are_applied() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); - $p->set_attribute( 'test-attribute', 'test-value' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->set_attribute( 'test-attribute', 'test-value' ); $this->assertSame( 'test-value', - $p->get_attribute( 'test-attribute' ), + $processor->get_attribute( 'test-attribute' ), 'get_attribute() (called before get_updated_html()) did not return attribute added via set_attribute()' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not include attribute added via set_attribute()' ); } @@ -788,18 +788,18 @@ public function test_get_attribute_returns_updated_values_before_they_are_applie * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_returns_updated_values_before_they_are_applied_with_different_name_casing() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); - $p->set_attribute( 'test-ATTribute', 'test-value' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->set_attribute( 'test-ATTribute', 'test-value' ); $this->assertSame( 'test-value', - $p->get_attribute( 'test-attribute' ), + $processor->get_attribute( 'test-attribute' ), 'get_attribute() (called before get_updated_html()) did not return attribute added via set_attribute()' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not include attribute added via set_attribute()' ); } @@ -810,18 +810,18 @@ public function test_get_attribute_returns_updated_values_before_they_are_applie * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_reflects_added_class_names_before_they_are_applied() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); - $p->add_class( 'my-class' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->add_class( 'my-class' ); $this->assertSame( 'my-class', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), 'get_attribute() (called before get_updated_html()) did not return class name added via add_class()' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not include class name added via add_class()' ); } @@ -832,26 +832,26 @@ public function test_get_attribute_reflects_added_class_names_before_they_are_ap * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_reflects_added_class_names_before_they_are_applied_and_retains_classes_from_previous_add_class_calls() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); - $p->add_class( 'my-class' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->add_class( 'my-class' ); $this->assertSame( 'my-class', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), 'get_attribute() (called before get_updated_html()) did not return class name added via add_class()' ); - $p->add_class( 'my-other-class' ); + $processor->add_class( 'my-other-class' ); $this->assertSame( 'my-class my-other-class', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), 'get_attribute() (called before get_updated_html()) did not return class names added via subsequent add_class() calls' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not include class names added via subsequent add_class() calls' ); } @@ -862,17 +862,17 @@ public function test_get_attribute_reflects_added_class_names_before_they_are_ap * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_reflects_removed_attribute_before_it_is_applied() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); - $p->remove_attribute( 'id' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->remove_attribute( 'id' ); $this->assertNull( - $p->get_attribute( 'id' ), + $processor->get_attribute( 'id' ), 'get_attribute() (called before get_updated_html()) returned attribute that was removed by remove_attribute()' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML includes attribute that was removed by remove_attribute()' ); } @@ -883,18 +883,18 @@ public function test_get_attribute_reflects_removed_attribute_before_it_is_appli * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_reflects_adding_and_then_removing_an_attribute_before_those_updates_are_applied() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); - $p->set_attribute( 'test-attribute', 'test-value' ); - $p->remove_attribute( 'test-attribute' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->set_attribute( 'test-attribute', 'test-value' ); + $processor->remove_attribute( 'test-attribute' ); $this->assertNull( - $p->get_attribute( 'test-attribute' ), + $processor->get_attribute( 'test-attribute' ), 'get_attribute() (called before get_updated_html()) returned attribute that was added via set_attribute() and then removed by remove_attribute()' ); $this->assertSame( self::HTML_SIMPLE, - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML includes attribute that was added via set_attribute() and then removed by remove_attribute()' ); } @@ -905,18 +905,18 @@ public function test_get_attribute_reflects_adding_and_then_removing_an_attribut * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_reflects_setting_and_then_removing_an_existing_attribute_before_those_updates_are_applied() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); - $p->set_attribute( 'id', 'test-value' ); - $p->remove_attribute( 'id' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->set_attribute( 'id', 'test-value' ); + $processor->remove_attribute( 'id' ); $this->assertNull( - $p->get_attribute( 'id' ), + $processor->get_attribute( 'id' ), 'get_attribute() (called before get_updated_html()) returned attribute that was overwritten by set_attribute() and then removed by remove_attribute()' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML includes attribute that was overwritten by set_attribute() and then removed by remove_attribute()' ); } @@ -927,18 +927,18 @@ public function test_get_attribute_reflects_setting_and_then_removing_an_existin * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_reflects_removed_class_names_before_they_are_applied() { - $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); - $p->remove_class( 'with-border' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); + $processor->next_tag(); + $processor->remove_class( 'with-border' ); $this->assertSame( 'main', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), 'get_attribute() (called before get_updated_html()) returned the wrong attribute after calling remove_attribute()' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML includes wrong attribute after calling remove_attribute()' ); } @@ -949,19 +949,19 @@ public function test_get_attribute_reflects_removed_class_names_before_they_are_ * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_reflects_setting_and_then_removing_a_class_name_before_those_updates_are_applied() { - $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); - $p->add_class( 'foo-class' ); - $p->remove_class( 'foo-class' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); + $processor->next_tag(); + $processor->add_class( 'foo-class' ); + $processor->remove_class( 'foo-class' ); $this->assertSame( 'main with-border', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), 'get_attribute() (called before get_updated_html()) returned class name that was added via add_class() and then removed by remove_class()' ); $this->assertSame( self::HTML_WITH_CLASSES, - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML includes class that was added via add_class() and then removed by remove_class()' ); } @@ -972,19 +972,19 @@ public function test_get_attribute_reflects_setting_and_then_removing_a_class_na * @covers WP_HTML_Tag_Processor::get_attribute */ public function test_get_attribute_reflects_duplicating_and_then_removing_an_existing_class_name_before_those_updates_are_applied() { - $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); - $p->add_class( 'with-border' ); - $p->remove_class( 'with-border' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); + $processor->next_tag(); + $processor->add_class( 'with-border' ); + $processor->remove_class( 'with-border' ); $this->assertSame( 'main', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), 'get_attribute() (called before get_updated_html()) returned class name that was duplicated via add_class() and then removed by remove_class()' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML includes class that was duplicated via add_class() and then removed by remove_class()' ); } @@ -998,13 +998,13 @@ public function test_get_attribute_reflects_duplicating_and_then_removing_an_exi * @covers WP_HTML_Tag_Processor::set_attribute */ public function test_update_first_attribute_when_duplicated_attributes_exist() { - $p = new WP_HTML_Tag_Processor( '
Text
' ); - $p->next_tag(); - $p->set_attribute( 'id', 'updated-id' ); + $processor = new WP_HTML_Tag_Processor( '
Text
' ); + $processor->next_tag(); + $processor->set_attribute( 'id', 'updated-id' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Proper (first) appearance of attribute was not updated when duplicates exist' ); } @@ -1015,12 +1015,12 @@ public function test_update_first_attribute_when_duplicated_attributes_exist() { * @covers WP_HTML_Tag_Processor::set_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->set_attribute( 'id', 'new-id' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->set_attribute( 'id', 'new-id' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Existing attribute was not updated' ); } @@ -1034,13 +1034,13 @@ public function test_set_attribute_with_an_existing_attribute_name_updates_its_v * @covers WP_HTML_Tag_Processor::set_attribute */ public function test_set_attribute_with_case_variants_updates_only_the_original_first_copy() { - $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag(); - $p->set_attribute( 'DATA-ENABLED', 'canary' ); - $p->set_attribute( 'Data-Enabled', 'canary' ); - $p->set_attribute( 'dATa-EnABled', 'canary' ); + $processor = new WP_HTML_Tag_Processor( '
' ); + $processor->next_tag(); + $processor->set_attribute( 'DATA-ENABLED', 'canary' ); + $processor->set_attribute( 'Data-Enabled', 'canary' ); + $processor->set_attribute( 'dATa-EnABled', 'canary' ); - $this->assertSame( '
', strtolower( $p->get_updated_html() ) ); + $this->assertSame( '
', strtolower( $processor->get_updated_html() ) ); } /** @@ -1050,14 +1050,14 @@ public function test_set_attribute_with_case_variants_updates_only_the_original_ * @covers WP_HTML_Tag_Processor::set_attribute */ public function test_next_tag_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() ) { - $p->set_attribute( 'data-foo', 'bar' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + while ( $processor->next_tag() ) { + $processor->set_attribute( 'data-foo', 'bar' ); } $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Not all tags were updated when looping with next_tag() and set_attribute()' ); } @@ -1073,13 +1073,13 @@ public function test_next_tag_and_set_attribute_in_a_loop_update_all_tags_in_the * @covers WP_HTML_Tag_Processor::remove_attribute */ public function test_remove_first_when_duplicated_attribute() { - $p = new WP_HTML_Tag_Processor( '
Text
' ); - $p->next_tag(); - $p->remove_attribute( 'id' ); + $processor = new WP_HTML_Tag_Processor( '
Text
' ); + $processor->next_tag(); + $processor->remove_attribute( 'id' ); $this->assertStringNotContainsString( 'update-me', - $p->get_updated_html(), + $processor->get_updated_html(), 'First attribute (when duplicates exist) was not removed' ); } @@ -1090,13 +1090,13 @@ public function test_remove_first_when_duplicated_attribute() { * @covers WP_HTML_Tag_Processor::remove_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->remove_attribute( 'id' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->remove_attribute( 'id' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Attribute was not removed' ); } @@ -1111,16 +1111,16 @@ public function test_remove_attribute_with_an_existing_attribute_name_removes_it * @dataProvider data_html_with_duplicated_attributes */ public function test_remove_attribute_with_duplicated_attributes_removes_all_of_them( $html_with_duplicate_attributes, $attribute_to_remove ) { - $p = new WP_HTML_Tag_Processor( $html_with_duplicate_attributes ); - $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( $html_with_duplicate_attributes ); + $processor->next_tag(); - $p->remove_attribute( $attribute_to_remove ); - $this->assertNull( $p->get_attribute( $attribute_to_remove ), 'Failed to remove all copies of an attribute when duplicated in modified source.' ); + $processor->remove_attribute( $attribute_to_remove ); + $this->assertNull( $processor->get_attribute( $attribute_to_remove ), 'Failed to remove all copies of an attribute when duplicated in modified source.' ); // Recreate a tag processor with the updated HTML after removing the attribute. - $p = new WP_HTML_Tag_Processor( $p->get_updated_html() ); - $p->next_tag(); - $this->assertNull( $p->get_attribute( $attribute_to_remove ), 'Failed to remove all copies of duplicated attributes when getting updated HTML.' ); + $processor = new WP_HTML_Tag_Processor( $processor->get_updated_html() ); + $processor->next_tag(); + $this->assertNull( $processor->get_attribute( $attribute_to_remove ), 'Failed to remove all copies of duplicated attributes when getting updated HTML.' ); } /** @@ -1131,12 +1131,12 @@ public function test_remove_attribute_with_duplicated_attributes_removes_all_of_ * @covers WP_HTML_Tag_Processor::remove_attribute */ public function test_previous_duplicated_attributes_are_not_removed_on_successive_tag_removal() { - $p = new WP_HTML_Tag_Processor( '' ); - $p->next_tag(); - $p->next_tag(); - $p->remove_attribute( 'id' ); + $processor = new WP_HTML_Tag_Processor( '' ); + $processor->next_tag(); + $processor->next_tag(); + $processor->remove_attribute( 'id' ); - $this->assertSame( '', $p->get_updated_html() ); + $this->assertSame( '', $processor->get_updated_html() ); } /** @@ -1162,13 +1162,13 @@ public function data_html_with_duplicated_attributes() { * @covers WP_HTML_Tag_Processor::remove_attribute */ 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->remove_attribute( 'no-such-attribute' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->remove_attribute( 'no-such-attribute' ); $this->assertSame( self::HTML_SIMPLE, - $p->get_updated_html(), + $processor->get_updated_html(), 'Content was changed when attempting to remove an attribute that did not exist' ); } @@ -1179,18 +1179,18 @@ public function test_remove_attribute_with_a_non_existing_attribute_name_does_no * @covers WP_HTML_Tag_Processor::add_class */ 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->add_class( 'foo-class' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->add_class( 'foo-class' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not include class name added via add_class()' ); $this->assertSame( 'foo-class', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "get_attribute( 'class' ) did not return class name added via add_class()" ); } @@ -1201,19 +1201,19 @@ public function test_add_class_creates_a_class_attribute_when_there_is_none() { * @covers WP_HTML_Tag_Processor::add_class */ public function test_calling_add_class_twice_creates_a_class_attribute_with_both_class_names_when_there_is_no_class_attribute() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); - $p->add_class( 'foo-class' ); - $p->add_class( 'bar-class' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->add_class( 'foo-class' ); + $processor->add_class( 'bar-class' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not include class names added via subsequent add_class() calls' ); $this->assertSame( 'foo-class bar-class', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "get_attribute( 'class' ) did not return class names added via subsequent add_class() calls" ); } @@ -1224,17 +1224,17 @@ public function test_calling_add_class_twice_creates_a_class_attribute_with_both * @covers WP_HTML_Tag_Processor::remove_class */ 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->remove_class( 'foo-class' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->remove_class( 'foo-class' ); $this->assertSame( self::HTML_SIMPLE, - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML includes class name that was removed by remove_class()' ); $this->assertNull( - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "get_attribute( 'class' ) did not return null for class name that was removed by remove_class()" ); } @@ -1245,19 +1245,19 @@ public function test_remove_class_does_not_change_the_markup_when_there_is_no_cl * @covers WP_HTML_Tag_Processor::add_class */ public function test_add_class_appends_class_names_to_the_existing_class_attribute_when_one_already_exists() { - $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); - $p->add_class( 'foo-class' ); - $p->add_class( 'bar-class' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); + $processor->next_tag(); + $processor->add_class( 'foo-class' ); + $processor->add_class( 'bar-class' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not reflect class names added to existing class attribute via subsequent add_class() calls' ); $this->assertSame( 'main with-border foo-class bar-class', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "get_attribute( 'class' ) does not reflect class names added to existing class attribute via subsequent add_class() calls" ); } @@ -1268,18 +1268,18 @@ public function test_add_class_appends_class_names_to_the_existing_class_attribu * @covers WP_HTML_Tag_Processor::remove_class */ 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->remove_class( 'main' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); + $processor->next_tag(); + $processor->remove_class( 'main' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not reflect class name removed from existing class attribute via remove_class()' ); $this->assertSame( ' with-border', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "get_attribute( 'class' ) does not reflect class name removed from existing class attribute via remove_class()" ); } @@ -1290,18 +1290,18 @@ public function test_remove_class_removes_a_single_class_from_the_class_attribut * @covers WP_HTML_Tag_Processor::remove_class */ public function test_calling_remove_class_with_all_listed_class_names_removes_the_existing_class_attribute_from_the_markup() { - $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); - $p->remove_class( 'main' ); - $p->remove_class( 'with-border' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); + $processor->next_tag(); + $processor->remove_class( 'main' ); + $processor->remove_class( 'with-border' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not reflect class attribute removed via subesequent remove_class() calls' ); $this->assertNull( - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "get_attribute( 'class' ) did not return null for class attribute removed via subesequent remove_class() calls" ); } @@ -1312,18 +1312,18 @@ public function test_calling_remove_class_with_all_listed_class_names_removes_th * @covers WP_HTML_Tag_Processor::add_class */ public function test_add_class_does_not_add_duplicate_class_names() { - $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); - $p->add_class( 'with-border' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); + $processor->next_tag(); + $processor->add_class( 'with-border' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not reflect deduplicated class name added via add_class()' ); $this->assertSame( 'main with-border', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "get_attribute( 'class' ) does not reflect deduplicated class name added via add_class()" ); } @@ -1334,18 +1334,18 @@ public function test_add_class_does_not_add_duplicate_class_names() { * @covers WP_HTML_Tag_Processor::add_class */ public function test_add_class_preserves_class_name_order_when_a_duplicate_class_name_is_added() { - $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); - $p->add_class( 'main' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); + $processor->next_tag(); + $processor->add_class( 'main' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not reflect class name order after adding duplicated class name via add_class()' ); $this->assertSame( 'main with-border', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "get_attribute( 'class' ) does not reflect class name order after adding duplicated class name added via add_class()" ); } @@ -1356,20 +1356,20 @@ public function test_add_class_preserves_class_name_order_when_a_duplicate_class * @covers WP_HTML_Tag_Processor::add_class */ public function test_add_class_when_there_is_a_class_attribute_with_excessive_whitespaces() { - $p = new WP_HTML_Tag_Processor( + $processor = new WP_HTML_Tag_Processor( '
Text
' ); - $p->next_tag(); - $p->add_class( 'foo-class' ); + $processor->next_tag(); + $processor->add_class( 'foo-class' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not reflect existing excessive whitespace after adding class name via add_class()' ); $this->assertSame( ' main with-border foo-class', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "get_attribute( 'class' ) does not reflect existing excessive whitespace after adding class name via add_class()" ); } @@ -1380,20 +1380,20 @@ public function test_add_class_when_there_is_a_class_attribute_with_excessive_wh * @covers WP_HTML_Tag_Processor::remove_class */ public function test_remove_class_preserves_whitespaces_when_there_is_a_class_attribute_with_excessive_whitespaces() { - $p = new WP_HTML_Tag_Processor( + $processor = new WP_HTML_Tag_Processor( '
Text
' ); - $p->next_tag(); - $p->remove_class( 'with-border' ); + $processor->next_tag(); + $processor->remove_class( 'with-border' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not reflect existing excessive whitespace after removing class name via remove_class()' ); $this->assertSame( ' main', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "get_attribute( 'class' ) does not reflect existing excessive whitespace after removing class name via removing_class()" ); } @@ -1404,19 +1404,19 @@ public function test_remove_class_preserves_whitespaces_when_there_is_a_class_at * @covers WP_HTML_Tag_Processor::remove_class */ public function test_removing_all_classes_removes_the_existing_class_attribute_from_the_markup_even_when_excessive_whitespaces_are_present() { - $p = new WP_HTML_Tag_Processor( + $processor = new WP_HTML_Tag_Processor( '
Text
' ); - $p->next_tag(); - $p->remove_class( 'main' ); - $p->remove_class( 'with-border' ); + $processor->next_tag(); + $processor->remove_class( 'main' ); + $processor->remove_class( 'with-border' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Updated HTML does not reflect removed class attribute after removing all class names via remove_class()' ); $this->assertNull( - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "get_attribute( 'class' ) did not return null after removing all class names via remove_class()" ); } @@ -1435,33 +1435,33 @@ public function test_removing_all_classes_removes_the_existing_class_attribute_f * @covers WP_HTML_Tag_Processor::set_attribute */ public function test_set_attribute_takes_priority_over_add_class() { - $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); - $p->add_class( 'add_class' ); - $p->set_attribute( 'class', 'set_attribute' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); + $processor->next_tag(); + $processor->add_class( 'add_class' ); + $processor->set_attribute( 'class', 'set_attribute' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), "Calling get_updated_html after updating first tag's attributes did not return the expected HTML" ); $this->assertSame( 'set_attribute', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "Calling get_attribute after updating first tag's attributes did not return the expected class name" ); - $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); - $p->set_attribute( 'class', 'set_attribute' ); - $p->add_class( 'add_class' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); + $processor->next_tag(); + $processor->set_attribute( 'class', 'set_attribute' ); + $processor->add_class( 'add_class' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), "Calling get_updated_html after updating first tag's attributes did not return the expected HTML" ); $this->assertSame( 'set_attribute add_class', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "Calling get_attribute after updating first tag's attributes did not return the expected class name" ); } @@ -1482,33 +1482,33 @@ public function test_set_attribute_takes_priority_over_add_class() { * @covers WP_HTML_Tag_Processor::set_attribute */ public function test_set_attribute_takes_priority_over_add_class_even_before_updating() { - $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); - $p->add_class( 'add_class' ); - $p->set_attribute( 'class', 'set_attribute' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); + $processor->next_tag(); + $processor->add_class( 'add_class' ); + $processor->set_attribute( 'class', 'set_attribute' ); $this->assertSame( 'set_attribute', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "Calling get_attribute after updating first tag's attributes did not return the expected class name" ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), "Calling get_updated_html after updating first tag's attributes did not return the expected HTML" ); - $p = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); - $p->next_tag(); - $p->set_attribute( 'class', 'set_attribute' ); - $p->add_class( 'add_class' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_WITH_CLASSES ); + $processor->next_tag(); + $processor->set_attribute( 'class', 'set_attribute' ); + $processor->add_class( 'add_class' ); $this->assertSame( 'set_attribute add_class', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "Calling get_attribute after updating first tag's attributes did not return the expected class name" ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), "Calling get_updated_html after updating first tag's attributes did not return the expected HTML" ); } @@ -1519,18 +1519,18 @@ public function test_set_attribute_takes_priority_over_add_class_even_before_upd * @covers WP_HTML_Tag_Processor::add_class */ public function test_add_class_overrides_boolean_class_attribute() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); - $p->set_attribute( 'class', true ); - $p->add_class( 'add_class' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->set_attribute( 'class', true ); + $processor->add_class( 'add_class' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), "Updated HTML doesn't reflect class added via add_class that was originally set as boolean attribute" ); $this->assertSame( 'add_class', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "get_attribute (called after get_updated_html()) doesn't reflect class added via add_class that was originally set as boolean attribute" ); } @@ -1541,18 +1541,18 @@ public function test_add_class_overrides_boolean_class_attribute() { * @covers WP_HTML_Tag_Processor::add_class */ public function test_add_class_overrides_boolean_class_attribute_even_before_updating() { - $p = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); - $p->next_tag(); - $p->set_attribute( 'class', true ); - $p->add_class( 'add_class' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_SIMPLE ); + $processor->next_tag(); + $processor->set_attribute( 'class', true ); + $processor->add_class( 'add_class' ); $this->assertSame( 'add_class', - $p->get_attribute( 'class' ), + $processor->get_attribute( 'class' ), "get_attribute (called before get_updated_html()) doesn't reflect class added via add_class that was originally set as boolean attribute" ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), "Updated HTML doesn't reflect class added via add_class that was originally set as boolean attribute" ); } @@ -1613,12 +1613,12 @@ public function test_advanced_use_case() {
HTML; - $p = new WP_HTML_Tag_Processor( $input ); - $this->assertTrue( $p->next_tag( 'div' ), 'Did not find first DIV tag in input.' ); - $p->set_attribute( 'data-details', '{ "key": "value" }' ); - $p->add_class( 'is-processed' ); + $processor = new WP_HTML_Tag_Processor( $input ); + $this->assertTrue( $processor->next_tag( 'div' ), 'Did not find first DIV tag in input.' ); + $processor->set_attribute( 'data-details', '{ "key": "value" }' ); + $processor->add_class( 'is-processed' ); $this->assertTrue( - $p->next_tag( + $processor->next_tag( array( 'tag_name' => 'div', 'class_name' => 'BtnGroup', @@ -1626,11 +1626,11 @@ public function test_advanced_use_case() { ), 'Did not find the first BtnGroup DIV tag' ); - $p->remove_class( 'BtnGroup' ); - $p->add_class( 'button-group' ); - $p->add_class( 'Another-Mixed-Case' ); + $processor->remove_class( 'BtnGroup' ); + $processor->add_class( 'button-group' ); + $processor->add_class( 'Another-Mixed-Case' ); $this->assertTrue( - $p->next_tag( + $processor->next_tag( array( 'tag_name' => 'div', 'class_name' => 'BtnGroup', @@ -1638,11 +1638,11 @@ public function test_advanced_use_case() { ), 'Did not find the second BtnGroup DIV tag' ); - $p->remove_class( 'BtnGroup' ); - $p->add_class( 'button-group' ); - $p->add_class( 'Another-Mixed-Case' ); + $processor->remove_class( 'BtnGroup' ); + $processor->add_class( 'button-group' ); + $processor->add_class( 'Another-Mixed-Case' ); $this->assertTrue( - $p->next_tag( + $processor->next_tag( array( 'tag_name' => 'button', 'class_name' => 'btn', @@ -1651,10 +1651,10 @@ public function test_advanced_use_case() { ), 'Did not find third BUTTON tag with "btn" CSS class' ); - $p->remove_attribute( 'class' ); - $this->assertFalse( $p->next_tag( 'non-existent' ), "Found a {$p->get_tag()} tag when none should have been found." ); - $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' ); + $processor->remove_attribute( 'class' ); + $this->assertFalse( $processor->next_tag( 'non-existent' ), "Found a {$processor->get_tag()} tag when none should have been found." ); + $processor->set_attribute( 'class', 'test' ); + $this->assertSame( $expected_output, $processor->get_updated_html(), 'Calling get_updated_html after updating the attributes did not return the expected HTML' ); } /** @@ -1663,26 +1663,26 @@ public function test_advanced_use_case() { * @covers WP_HTML_Tag_Processor::next_tag */ public function test_correctly_parses_html_attributes_wrapped_in_single_quotation_marks() { - $p = new WP_HTML_Tag_Processor( + $processor = new WP_HTML_Tag_Processor( '
Text
' ); - $p->next_tag( + $processor->next_tag( array( 'tag_name' => 'div', 'id' => 'first', ) ); - $p->remove_attribute( 'id' ); - $p->next_tag( + $processor->remove_attribute( 'id' ); + $processor->next_tag( array( 'tag_name' => 'span', 'id' => 'second', ) ); - $p->set_attribute( 'id', 'single-quote' ); + $processor->set_attribute( 'id', 'single-quote' ); $this->assertSame( '
Text
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Did not remove single-quoted attribute' ); } @@ -1693,14 +1693,14 @@ public function test_correctly_parses_html_attributes_wrapped_in_single_quotatio * @covers WP_HTML_Tag_Processor::set_attribute */ public function test_set_attribute_with_value_equal_to_true_adds_a_boolean_html_attribute_with_implicit_value() { - $p = new WP_HTML_Tag_Processor( + $processor = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag( 'input' ); - $p->set_attribute( 'checked', true ); + $processor->next_tag( 'input' ); + $processor->set_attribute( 'checked', true ); $this->assertSame( '
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Did not add "checked" as an expected boolean attribute' ); } @@ -1711,14 +1711,14 @@ public function test_set_attribute_with_value_equal_to_true_adds_a_boolean_html_ * @covers WP_HTML_Tag_Processor::set_attribute */ public function test_setting_a_boolean_attribute_to_false_removes_it_from_the_markup() { - $p = new WP_HTML_Tag_Processor( + $processor = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag( 'input' ); - $p->set_attribute( 'checked', false ); + $processor->next_tag( 'input' ); + $processor->set_attribute( 'checked', false ); $this->assertSame( '
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Did not remove boolean attribute when set to false' ); } @@ -1730,12 +1730,12 @@ 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->set_attribute( 'checked', false ); + $processor = new WP_HTML_Tag_Processor( $html_input ); + $processor->next_tag( 'input' ); + $processor->set_attribute( 'checked', false ); $this->assertSame( $html_input, - $p->get_updated_html(), + $processor->get_updated_html(), 'Changed the markup unexpectedly when setting a non-existing attribute to false' ); } @@ -1746,14 +1746,14 @@ public function test_setting_a_missing_attribute_to_false_does_not_change_the_ma * @covers WP_HTML_Tag_Processor::set_attribute */ public function test_setting_a_boolean_attribute_to_a_string_value_adds_explicit_value_to_the_markup() { - $p = new WP_HTML_Tag_Processor( + $processor = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag( 'input' ); - $p->set_attribute( 'checked', 'checked' ); + $processor->next_tag( 'input' ); + $processor->set_attribute( 'checked', 'checked' ); $this->assertSame( '
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Did not add string value to existing boolean attribute' ); } @@ -1765,18 +1765,18 @@ public function test_setting_a_boolean_attribute_to_a_string_value_adds_explicit * @covers WP_HTML_Tag_Processor::paused_at_incomplete_token */ public function test_unclosed_script_tag_should_not_cause_an_infinite_loop() { - $p = new WP_HTML_Tag_Processor( '