From f16c79281c4f0a1f3bf016d935801f59d059dfa7 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Thu, 1 Feb 2024 01:00:56 +0000 Subject: [PATCH] HTML API: Test cleanup Rename `$p` variable to `$processor` in tests for clarity. Use static data providers. A mix of static and non-static data providers were used in HTML API tests. Data providers are required to be static in the next PHPUnit version and there's no harm in using them consistently now. Follow-up to [57507] Props jonsurrell See #59647 git-svn-id: https://develop.svn.wordpress.org/trunk@57508 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/html-api/wpHtmlProcessor.php | 50 +- .../html-api/wpHtmlProcessorBreadcrumbs.php | 98 +- .../html-api/wpHtmlProcessorSemanticRules.php | 114 +- ...lProcessorSemanticRulesHeadingElements.php | 4 +- .../wpHtmlSupportRequiredHtmlProcessor.php | 4 +- .../wpHtmlSupportRequiredOpenElements.php | 4 +- .../html-api/wpHtmlTagProcessor-bookmark.php | 256 ++-- .../wpHtmlTagProcessor-token-scanning.php | 4 +- .../tests/html-api/wpHtmlTagProcessor.php | 1040 ++++++++--------- 9 files changed, 787 insertions(+), 787 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessor.php b/tests/phpunit/tests/html-api/wpHtmlProcessor.php index 60d368efae..26dc7b0bdb 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessor.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessor.php @@ -52,12 +52,12 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase { * @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.' ); } /** @@ -246,7 +246,7 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase { * * @return array[] */ - public function data_void_tags() { + public static function data_void_tags() { return array( 'AREA' => array( 'AREA' ), 'BASE' => array( 'BASE' ), @@ -290,7 +290,7 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase { * * @return array[] */ - public function data_unsupported_special_in_body_tags() { + public static function data_unsupported_special_in_body_tags() { return array( 'APPLET' => array( 'APPLET' ), 'BASE' => array( 'BASE' ), diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php b/tests/phpunit/tests/html-api/wpHtmlProcessorBreadcrumbs.php index 8576840415..1488be9165 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." ); } /** @@ -34,7 +34,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase { * * @return array[] */ - public function data_single_tag_of_supported_elements() { + public static function data_single_tag_of_supported_elements() { $supported_elements = array( 'A', 'ABBR', @@ -155,9 +155,9 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase { * @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." ); } /** @@ -165,7 +165,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase { * * @return array[] */ - public function data_unsupported_elements() { + public static function data_unsupported_elements() { $unsupported_elements = array( 'APPLET', // Deprecated. 'BASE', @@ -229,14 +229,14 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase { * @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}" ); } /** @@ -244,7 +244,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase { * * @return array[] */ - public function data_unsupported_markup() { + public static function data_unsupported_markup() { return array( 'A with formatting following unclosed A' => array( 'Click Here', @@ -270,17 +270,17 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase { * @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.' ); } /** @@ -310,7 +310,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase { * * @return array[] */ - public function data_html_target_with_breadcrumbs() { + public static function data_html_target_with_breadcrumbs() { return array( 'Simple IMG tag' => array( '', array( 'HTML', 'BODY', 'IMG' ), 1 ), 'Two sibling IMG tags' => array( '', array( 'HTML', 'BODY', 'IMG' ), 2 ), @@ -393,7 +393,7 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase { * * @return array[]. */ - public function data_html_with_breadcrumbs_of_various_specificity() { + public static function data_html_with_breadcrumbs_of_various_specificity() { return array( // Test with void elements. 'Inner IMG' => array( '

', array( 'span', 'figure', 'img' ), true ), @@ -433,38 +433,38 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase { * 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.' ); } /** @@ -274,7 +274,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase { * * @return array[]. */ - public function data_heading_elements() { + public static function data_heading_elements() { return array( 'H1' => array( 'H1' ), 'H2' => array( 'H2' ), @@ -328,7 +328,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase { * * @return array[] */ - public function data_heading_combinations() { + public static function data_heading_combinations() { $headings = array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ); $combinations = array(); @@ -355,15 +355,15 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase { * @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/wpHtmlProcessorSemanticRulesHeadingElements.php b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRulesHeadingElements.php index d8d70acb61..b33c6e072d 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRulesHeadingElements.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRulesHeadingElements.php @@ -53,7 +53,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRulesHeadingElements extends WP_UnitT * * @return array[]. */ - public function data_heading_elements() { + public static function data_heading_elements() { return array( 'H1' => array( 'H1' ), 'H2' => array( 'H2' ), @@ -109,7 +109,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRulesHeadingElements extends WP_UnitT * * @return array[] */ - public function data_heading_combinations() { + public static function data_heading_combinations() { $headings = array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ); $combinations = array(); diff --git a/tests/phpunit/tests/html-api/wpHtmlSupportRequiredHtmlProcessor.php b/tests/phpunit/tests/html-api/wpHtmlSupportRequiredHtmlProcessor.php index 2770acb736..2d3cd21ce4 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 0a05629e02..c2e8c697e8 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 90adfb20be..1041dabd43 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 @@ class Tests_HtmlApi_WpHtmlTagProcessor_Bookmark extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor_Bookmark extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor_Bookmark extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor_Bookmark extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor_Bookmark extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor_Bookmark extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor_Bookmark extends WP_UnitTestCase { * @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 @@ HTML;
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' ); + $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' ); - $p->seek( 'first button' ); - $p->set_attribute( 'type', 'submit' ); + $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 @@ HTML; * @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 @@ HTML; * @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 @@ HTML; * @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 @@ HTML; * 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 @@ HTML; * @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 @@ HTML; * 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 @@ HTML; * @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 @@ HTML; * @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-token-scanning.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessor-token-scanning.php index 295063a04c..4f1e1dab24 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessor-token-scanning.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessor-token-scanning.php @@ -295,7 +295,7 @@ HTML * * @return array[]. */ - public function data_rawtext_elements() { + public static function data_rawtext_elements() { return array( 'IFRAME' => array( 'IFRAME' ), 'NOEMBED' => array( 'NOEMBED' ), @@ -580,7 +580,7 @@ HTML * * @return array[]. */ - public function data_common_comments() { + public static function data_common_comments() { return array( 'Shortest comment' => array( '', '' ), 'Short comment' => array( '', '' ), diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessor.php index dda0872408..5375a2fca0 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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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.' ); } } @@ -77,7 +77,7 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * * @return array[] */ - public function data_has_self_closing_flag() { + public static function data_has_self_closing_flag() { return array( // These should not have a self-closer, and will leave an element un-closed if it's assumed they are self-closing. 'Self-closing flag on non-void HTML element' => array( '
', true ), @@ -107,9 +107,9 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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' ); } @@ -259,7 +259,7 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * * @return array[]. */ - public function data_attribute_name_case_variants() { + public static function data_attribute_name_case_variants() { return array( array( 'DATA-enabled' ), array( 'data-enabled' ), @@ -274,11 +274,11 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { ), '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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * 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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * 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' ); @@ -724,7 +724,7 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * * @return string[][]. */ - public function data_set_attribute_prevents_xss() { + public static function data_set_attribute_prevents_xss() { return array( array( '"' ), array( '"' ), @@ -744,18 +744,18 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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() ); } /** @@ -1146,7 +1146,7 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * * @return array[]. */ - public function data_html_with_duplicated_attributes() { + public static function data_html_with_duplicated_attributes() { return array( 'Double attributes' => array( '
', 'id' ), 'Triple attributes' => array( '
', 'id' ), @@ -1162,13 +1162,13 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ class Tests_HtmlApi_WpHtmlTagProcessor extends WP_UnitTestCase { * @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 @@ HTML;
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 @@ HTML; ), '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 @@ HTML; ), '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 @@ HTML; ), '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 @@ HTML; * @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 @@ HTML; * @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 @@ 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 @@ HTML; */ 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 @@ HTML; * @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 @@ HTML; * @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( '
', @@ -1866,11 +1866,11 @@ HTML; * element after contain the "start" and "end" CSS classes. */ public function test_next_tag_ignores_invalid_first_character_of_tag_name_comments( $html_with_markers ) { - $p = new WP_HTML_Tag_Processor( $html_with_markers ); - $p->next_tag( array( 'class_name' => 'start' ) ); - $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( $html_with_markers ); + $processor->next_tag( array( 'class_name' => 'start' ) ); + $processor->next_tag(); - $this->assertSame( 'end', $p->get_attribute( 'class' ) ); + $this->assertSame( 'end', $processor->get_attribute( 'class' ) ); } /** @@ -1878,7 +1878,7 @@ HTML; * * @return array[] */ - public function data_next_tag_ignores_invalid_first_character_of_tag_name_comments() { + public static function data_next_tag_ignores_invalid_first_character_of_tag_name_comments() { return array( 'Invalid tag openers as normal text' => array( '
  • I <3 when outflow > inflow
', @@ -1905,11 +1905,11 @@ HTML; * @param string $rcdata_tag RCDATA tag. */ public function test_next_tag_ignores_contents_of_rcdata_tag( $rcdata_then_div, $rcdata_tag ) { - $p = new WP_HTML_Tag_Processor( $rcdata_then_div ); - $p->next_tag(); - $this->assertSame( $rcdata_tag, $p->get_tag(), "The first found tag was not '$rcdata_tag'" ); - $p->next_tag(); - $this->assertSame( 'DIV', $p->get_tag(), "The second found tag was not 'div'" ); + $processor = new WP_HTML_Tag_Processor( $rcdata_then_div ); + $processor->next_tag(); + $this->assertSame( $rcdata_tag, $processor->get_tag(), "The first found tag was not '$rcdata_tag'" ); + $processor->next_tag(); + $this->assertSame( 'DIV', $processor->get_tag(), "The second found tag was not 'div'" ); } /** @@ -1917,7 +1917,7 @@ HTML; * * @return array[] */ - public function data_next_tag_ignores_contents_of_rcdata_tag() { + public static function data_next_tag_ignores_contents_of_rcdata_tag() { return array( 'simple textarea' => array( 'rcdata_then_div' => '
', @@ -1964,10 +1964,10 @@ HTML; * @covers WP_HTML_Tag_Processor::next_tag */ public function test_processes_inside_of_noscript_elements() { - $p = new WP_HTML_Tag_Processor( '
' ); + $processor = new WP_HTML_Tag_Processor( '
' ); - $this->assertTrue( $p->next_tag( 'INPUT' ), 'Failed to find INPUT element inside NOSCRIPT element.' ); - $this->assertTrue( $p->next_tag( 'DIV' ), 'Failed to find DIV element after NOSCRIPT element.' ); + $this->assertTrue( $processor->next_tag( 'INPUT' ), 'Failed to find INPUT element inside NOSCRIPT element.' ); + $this->assertTrue( $processor->next_tag( 'DIV' ), 'Failed to find DIV element after NOSCRIPT element.' ); } /** @@ -1996,7 +1996,7 @@ HTML; * * @return array[]. */ - public function data_next_tag_ignores_contents_of_rawtext_tags() { + public static function data_next_tag_ignores_contents_of_rawtext_tags() { return array( 'IFRAME' => array( '
' ), 'NOEMBED' => array( '<p></p>
' ), @@ -2012,11 +2012,11 @@ HTML; * @covers WP_HTML_Tag_Processor::class_list */ public function test_class_list_empty_when_missing_class() { - $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( '
' ); + $processor->next_tag(); $found_classes = false; - foreach ( $p->class_list() as $class ) { + foreach ( $processor->class_list() as $class ) { $found_classes = true; } @@ -2029,11 +2029,11 @@ HTML; * @covers WP_HTML_Tag_Processor::class_list */ public function test_class_list_empty_when_class_is_boolean() { - $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( '
' ); + $processor->next_tag(); $found_classes = false; - foreach ( $p->class_list() as $class ) { + foreach ( $processor->class_list() as $class ) { $found_classes = true; } @@ -2046,11 +2046,11 @@ HTML; * @covers WP_HTML_Tag_Processor::class_list */ public function test_class_list_empty_when_class_is_empty() { - $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( '
' ); + $processor->next_tag(); $found_classes = false; - foreach ( $p->class_list() as $class ) { + foreach ( $processor->class_list() as $class ) { $found_classes = true; } @@ -2063,11 +2063,11 @@ HTML; * @covers WP_HTML_Tag_Processor::class_list */ public function test_class_list_visits_each_class_in_order() { - $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( '
' ); + $processor->next_tag(); $found_classes = array(); - foreach ( $p->class_list() as $class ) { + foreach ( $processor->class_list() as $class ) { $found_classes[] = $class; } @@ -2080,11 +2080,11 @@ HTML; * @covers WP_HTML_Tag_Processor::class_list */ public function test_class_list_decodes_class_names() { - $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( '
' ); + $processor->next_tag(); $found_classes = array(); - foreach ( $p->class_list() as $class ) { + foreach ( $processor->class_list() as $class ) { $found_classes[] = $class; } @@ -2097,11 +2097,11 @@ HTML; * @covers WP_HTML_Tag_Processor::class_list */ public function test_class_list_visits_unique_class_names_only_once() { - $p = new WP_HTML_Tag_Processor( '
' ); - $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( '
' ); + $processor->next_tag(); $found_classes = array(); - foreach ( $p->class_list() as $class ) { + foreach ( $processor->class_list() as $class ) { $found_classes[] = $class; } @@ -2120,13 +2120,13 @@ HTML; * @param bool $has_class Whether the sought class exists in the given HTML. */ public function test_has_class_handles_expected_class_name_variations( $html, $sought_class, $has_class ) { - $p = new WP_HTML_Tag_Processor( $html ); - $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( $html ); + $processor->next_tag(); if ( $has_class ) { - $this->assertTrue( $p->has_class( $sought_class ), "Failed to find expected class {$sought_class}." ); + $this->assertTrue( $processor->has_class( $sought_class ), "Failed to find expected class {$sought_class}." ); } else { - $this->assertFalse( $p->has_class( $sought_class ), "Found class {$sought_class} when it doesn't exist." ); + $this->assertFalse( $processor->has_class( $sought_class ), "Found class {$sought_class} when it doesn't exist." ); } } @@ -2135,7 +2135,7 @@ HTML; * * @return array[] */ - public function data_html_with_variations_of_class_values_and_sought_class_names() { + public static function data_html_with_variations_of_class_values_and_sought_class_names() { return array( 'Tag without any classes' => array( '
', 'foo', false ), 'Tag with boolean class' => array( '', 'foo', false ), @@ -2159,16 +2159,16 @@ HTML; * */ public function test_allows_incorrectly_closed_comments() { - $p = new WP_HTML_Tag_Processor( '-->' ); + $processor = new WP_HTML_Tag_Processor( '-->' ); - $p->next_tag(); - $this->assertSame( 'before', $p->get_attribute( 'id' ), 'Did not find starting tag.' ); + $processor->next_tag(); + $this->assertSame( 'before', $processor->get_attribute( 'id' ), 'Did not find starting tag.' ); - $p->next_tag(); - $this->assertSame( 'after', $p->get_attribute( 'id' ), 'Did not properly close improperly-closed comment.' ); + $processor->next_tag(); + $this->assertSame( 'after', $processor->get_attribute( 'id' ), 'Did not properly close improperly-closed comment.' ); - $p->next_tag(); - $this->assertSame( 'final', $p->get_attribute( 'id' ), 'Did not skip over unopened comment-closer.' ); + $processor->next_tag(); + $this->assertSame( 'final', $processor->get_attribute( 'id' ), 'Did not skip over unopened comment-closer.' ); } /** @@ -2184,15 +2184,15 @@ HTML; * @param string $html_ending_before_comment_close HTML with opened comments that aren't closed. */ public function test_documents_may_end_with_unclosed_comment( $html_ending_before_comment_close ) { - $p = new WP_HTML_Tag_Processor( $html_ending_before_comment_close ); + $processor = new WP_HTML_Tag_Processor( $html_ending_before_comment_close ); $this->assertFalse( - $p->next_tag(), - "Should not have found any tag, but found {$p->get_tag()}." + $processor->next_tag(), + "Should not have found any tag, but found {$processor->get_tag()}." ); $this->assertTrue( - $p->paused_at_incomplete_token(), + $processor->paused_at_incomplete_token(), "Should have indicated that the parser found an incomplete token but didn't." ); } @@ -2202,7 +2202,7 @@ HTML; * * @return array[] */ - public function data_html_with_unclosed_comments() { + public static function data_html_with_unclosed_comments() { return array( 'Shortest open valid comment' => array( '
' ), 'Empty comment with two dashes only, improperly closed' => array( '

' ), @@ -2262,11 +2262,11 @@ HTML; * @param $input_html HTML with multiple divs, one of which carries the "target" attribute. */ public function test_skips_contents_of_script_and_rcdata_regions( $input_html ) { - $p = new WP_HTML_Tag_Processor( $input_html ); - $p->next_tag( 'div' ); + $processor = new WP_HTML_Tag_Processor( $input_html ); + $processor->next_tag( 'div' ); $this->assertTrue( - $p->get_attribute( 'target' ), + $processor->get_attribute( 'target' ), 'Did not properly skip over script and rcdata regions; incorrectly found tags inside' ); } @@ -2276,7 +2276,7 @@ HTML; * * @return array[] */ - public function data_skips_contents_of_script_and_rcdata_regions() { + public static function data_skips_contents_of_script_and_rcdata_regions() { return array( 'Balanced SCRIPT tags' => array( '
' ), 'Unexpected SCRIPT closer after DIV' => array( 'console.log("
")
' ), @@ -2295,16 +2295,16 @@ HTML; * @covers WP_HTML_Tag_Processor::set_attribute */ public function test_can_query_and_update_wrongly_nested_tags() { - $p = new WP_HTML_Tag_Processor( + $processor = new WP_HTML_Tag_Processor( '123

456789

' ); - $p->next_tag( 'span' ); - $p->set_attribute( 'class', 'span-class' ); - $p->next_tag( 'p' ); - $p->set_attribute( 'class', 'p-class' ); + $processor->next_tag( 'span' ); + $processor->set_attribute( 'class', 'span-class' ); + $processor->next_tag( 'p' ); + $processor->set_attribute( 'class', 'p-class' ); $this->assertSame( '123

456789

', - $p->get_updated_html(), + $processor->get_updated_html(), 'Did not find overlapping p tag' ); } @@ -2316,12 +2316,12 @@ HTML; * @covers WP_HTML_Tag_Processor::remove_attribute */ public function test_removing_specific_attributes_in_malformed_html() { - $p = new WP_HTML_Tag_Processor( self::HTML_MALFORMED ); - $p->next_tag( 'span' ); - $p->remove_attribute( 'Notifications<' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_MALFORMED ); + $processor->next_tag( 'span' ); + $processor->remove_attribute( 'Notifications<' ); $this->assertSame( '
Back to notifications
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Did not remove "Notifications<" attribute in malformed input' ); } @@ -2357,7 +2357,7 @@ HTML; * * @return array[] */ - public function data_html_without_tags() { + public static function data_html_without_tags() { return array( 'DOCTYPE declaration' => array( 'Just some HTML' ), 'No tags' => array( 'this is nothing more than a text node' ), @@ -2382,15 +2382,15 @@ HTML; * @param string $incomplete_html HTML text containing some kind of incomplete syntax. */ public function test_next_tag_returns_false_for_incomplete_syntax_elements( $incomplete_html ) { - $p = new WP_HTML_Tag_Processor( $incomplete_html ); + $processor = new WP_HTML_Tag_Processor( $incomplete_html ); $this->assertFalse( - $p->next_tag(), - "Shouldn't have found any tags but found {$p->get_tag()}." + $processor->next_tag(), + "Shouldn't have found any tags but found {$processor->get_tag()}." ); $this->assertTrue( - $p->paused_at_incomplete_token(), + $processor->paused_at_incomplete_token(), "Should have indicated that the parser found an incomplete token but didn't." ); } @@ -2400,7 +2400,7 @@ HTML; * * @return array[] */ - public function data_incomplete_syntax_elements() { + public static function data_incomplete_syntax_elements() { return array( 'Incomplete tag name' => array( ' array( 'next_tag( 'span' ); - $p->set_attribute( 'id', 'first' ); - $p->next_tag( 'span' ); - $p->set_attribute( 'id', 'second' ); + $processor = new WP_HTML_Tag_Processor( self::HTML_MALFORMED ); + $processor->next_tag( 'span' ); + $processor->set_attribute( 'id', 'first' ); + $processor->next_tag( 'span' ); + $processor->set_attribute( 'id', 'second' ); $this->assertSame( '
Back to notifications
', - $p->get_updated_html(), + $processor->get_updated_html(), 'Did not add id attributes properly to malformed input' ); } @@ -2466,16 +2466,16 @@ HTML; * @param string $expected Expected updated HTML. */ public function test_updating_attributes( $html, $expected ) { - $p = new WP_HTML_Tag_Processor( $html ); - $p->next_tag(); - $p->set_attribute( 'foo', 'bar' ); - $p->add_class( 'firstTag' ); - $p->next_tag(); - $p->add_class( 'secondTag' ); + $processor = new WP_HTML_Tag_Processor( $html ); + $processor->next_tag(); + $processor->set_attribute( 'foo', 'bar' ); + $processor->add_class( 'firstTag' ); + $processor->next_tag(); + $processor->add_class( 'secondTag' ); $this->assertSame( $expected, - $p->get_updated_html(), + $processor->get_updated_html(), 'Did not properly add attributes and class names' ); } @@ -2485,7 +2485,7 @@ HTML; * * @return array[] */ - public function data_updating_attributes() { + public static function data_updating_attributes() { return array( 'tags inside of a comment' => array( 'input' => 'test', @@ -2530,16 +2530,16 @@ HTML; * @param string $expected Expected updated HTML. */ public function test_updating_attributes_in_malformed_html( $html, $expected ) { - $p = new WP_HTML_Tag_Processor( $html ); - $this->assertTrue( $p->next_tag(), 'Could not find first tag.' ); - $p->set_attribute( 'foo', 'bar' ); - $p->add_class( 'firstTag' ); - $p->next_tag(); - $p->add_class( 'secondTag' ); + $processor = new WP_HTML_Tag_Processor( $html ); + $this->assertTrue( $processor->next_tag(), 'Could not find first tag.' ); + $processor->set_attribute( 'foo', 'bar' ); + $processor->add_class( 'firstTag' ); + $processor->next_tag(); + $processor->add_class( 'secondTag' ); $this->assertSame( $expected, - $p->get_updated_html(), + $processor->get_updated_html(), 'Did not properly update attributes and classnames given malformed input' ); } @@ -2549,7 +2549,7 @@ HTML; * * @return array[] */ - public function data_updating_attributes_in_malformed_html() { + public static function data_updating_attributes_in_malformed_html() { return array( 'Invalid entity inside attribute value' => array( 'input' => 'test', @@ -2702,8 +2702,8 @@ HTML * @covers WP_HTML_Tag_Processor::next_tag */ public function test_handles_malformed_taglike_open_short_html() { - $p = new WP_HTML_Tag_Processor( '<' ); - $result = $p->next_tag(); + $processor = new WP_HTML_Tag_Processor( '<' ); + $result = $processor->next_tag(); $this->assertFalse( $result, 'Did not handle "<" html properly.' ); } @@ -2711,8 +2711,8 @@ HTML * @covers WP_HTML_Tag_Processor::next_tag */ public function test_handles_malformed_taglike_close_short_html() { - $p = new WP_HTML_Tag_Processor( 'next_tag(); + $processor = new WP_HTML_Tag_Processor( 'next_tag(); $this->assertFalse( $result, 'Did not handle "' ); - $p->next_token(); - $this->assertSame( '#text', $p->get_token_type(), 'Did not find text node.' ); - $this->assertSame( 'test< /A>', $p->get_modifiable_text(), 'Did not find complete text node.' ); + $processor = new WP_HTML_Tag_Processor( 'test< /A>' ); + $processor->next_token(); + $this->assertSame( '#text', $processor->get_token_type(), 'Did not find text node.' ); + $this->assertSame( 'test< /A>', $processor->get_modifiable_text(), 'Did not find complete text node.' ); } }