mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
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
This commit is contained in:
parent
cdb218b200
commit
f16c79281c
@ -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( '<div class="test">Test</div>' );
|
||||
$p->next_tag();
|
||||
$this->assertSame( 'DIV', $p->get_tag() );
|
||||
$processor = WP_HTML_Processor::create_fragment( '<div class="test">Test</div>' );
|
||||
$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( '<div one><strong></strong></div><p><strong two></strong></p>' );
|
||||
$processor = WP_HTML_Processor::create_fragment( '<div one><strong></strong></div><p><strong two></strong></p>' );
|
||||
|
||||
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( '<p><em>One<p><em>Two<p><em>Three<p><em>Four' );
|
||||
$processor = WP_HTML_Processor::create_fragment( '<p><em>One<p><em>Two<p><em>Three<p><em>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' ),
|
||||
|
||||
@ -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(
|
||||
'<a><strong>Click <a supported><big unsupported>Here</big></a></strong></a>',
|
||||
@ -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( '<img target>', array( 'HTML', 'BODY', 'IMG' ), 1 ),
|
||||
'Two sibling IMG tags' => array( '<img><img target>', 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( '<div><span><figure><img target></figure></span></div>', 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( '<div><button>First<button><b here>Second' );
|
||||
$p->next_tag( array( 'breadcrumbs' => array( 'BUTTON', 'B' ) ) );
|
||||
$processor = WP_HTML_Processor::create_fragment( '<div><button>First<button><b here>Second' );
|
||||
$processor->next_tag( array( 'breadcrumbs' => array( 'BUTTON', 'B' ) ) );
|
||||
|
||||
$this->assertSame(
|
||||
array( 'HTML', 'BODY', 'DIV', 'BUTTON', 'B' ),
|
||||
$p->get_breadcrumbs(),
|
||||
$processor->get_breadcrumbs(),
|
||||
'Found the wrong nested structure at the matched tag.'
|
||||
);
|
||||
|
||||
$p->set_attribute( 'a-name', 'a-value' );
|
||||
$processor->set_attribute( 'a-name', 'a-value' );
|
||||
|
||||
$this->assertTrue(
|
||||
$p->get_attribute( 'here' ),
|
||||
$processor->get_attribute( 'here' ),
|
||||
'Should have found the B tag but could not find expected "here" attribute.'
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
array( 'HTML', 'BODY', 'DIV', 'BUTTON', 'B' ),
|
||||
$p->get_breadcrumbs(),
|
||||
$processor->get_breadcrumbs(),
|
||||
'Found the wrong nested structure at the matched tag.'
|
||||
);
|
||||
|
||||
$p->get_updated_html();
|
||||
$processor->get_updated_html();
|
||||
|
||||
$this->assertTrue(
|
||||
$p->get_attribute( 'here' ),
|
||||
$processor->get_attribute( 'here' ),
|
||||
'Should have stayed at the B tag but could not find expected "here" attribute.'
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
array( 'HTML', 'BODY', 'DIV', 'BUTTON', 'B' ),
|
||||
$p->get_breadcrumbs(),
|
||||
$processor->get_breadcrumbs(),
|
||||
'Found the wrong nested structure at the matched tag after updating attributes.'
|
||||
);
|
||||
}
|
||||
@ -479,12 +479,12 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase {
|
||||
* @covers WP_HTML_Tag_Processor::set_attribute
|
||||
*/
|
||||
public function test_can_modify_attributes_after_finding_tag() {
|
||||
$p = WP_HTML_Processor::create_fragment( '<div><figure><img><figcaption>test</figcaption></figure>' );
|
||||
$processor = WP_HTML_Processor::create_fragment( '<div><figure><img><figcaption>test</figcaption></figure>' );
|
||||
|
||||
$this->assertTrue( $p->next_tag( array( 'breadcrumbs' => array( 'figcaption' ) ) ), 'Unable to find given tag.' );
|
||||
$this->assertTrue( $processor->next_tag( array( 'breadcrumbs' => array( 'figcaption' ) ) ), 'Unable to find given tag.' );
|
||||
|
||||
$p->set_attribute( 'found-it', true );
|
||||
$this->assertSame( '<div><figure><img><figcaption found-it>test</figcaption></figure>', $p->get_updated_html() );
|
||||
$processor->set_attribute( 'found-it', true );
|
||||
$this->assertSame( '<div><figure><img><figcaption found-it>test</figcaption></figure>', $processor->get_updated_html() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -497,11 +497,11 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase {
|
||||
* @covers WP_HTML_Processor::next_tag
|
||||
*/
|
||||
public function test_can_query_an_element_by_tag_name() {
|
||||
$p = WP_HTML_Processor::create_fragment( '<div><DIV><strong><img></strong></DIV>' );
|
||||
$p->next_tag( 'IMG' );
|
||||
$p->set_attribute( 'loading', 'lazy' );
|
||||
$processor = WP_HTML_Processor::create_fragment( '<div><DIV><strong><img></strong></DIV>' );
|
||||
$processor->next_tag( 'IMG' );
|
||||
$processor->set_attribute( 'loading', 'lazy' );
|
||||
|
||||
$this->assertSame( '<div><DIV><strong><img loading="lazy"></strong></DIV>', $p->get_updated_html() );
|
||||
$this->assertSame( '<div><DIV><strong><img loading="lazy"></strong></DIV>', $processor->get_updated_html() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -514,35 +514,35 @@ class Tests_HtmlApi_WpHtmlProcessorBreadcrumbs extends WP_UnitTestCase {
|
||||
* @covers WP_HTML_Processor::seek
|
||||
*/
|
||||
public function test_can_seek_back_and_forth() {
|
||||
$p = WP_HTML_Processor::create_fragment(
|
||||
$processor = WP_HTML_Processor::create_fragment(
|
||||
<<<'HTML'
|
||||
<div>text<p one>more stuff<div><![CDATA[this is not real CDATA]]><p><!-- hi --><div two><p><div><p>three comes soon<div><p three>' );
|
||||
HTML
|
||||
);
|
||||
|
||||
// Find first tag of interest.
|
||||
while ( $p->next_tag() && null === $p->get_attribute( 'one' ) ) {
|
||||
while ( $processor->next_tag() && null === $processor->get_attribute( 'one' ) ) {
|
||||
continue;
|
||||
}
|
||||
$p->set_bookmark( 'first' );
|
||||
$processor->set_bookmark( 'first' );
|
||||
|
||||
// Find second tag of interest.
|
||||
while ( $p->next_tag() && null === $p->get_attribute( 'two' ) ) {
|
||||
while ( $processor->next_tag() && null === $processor->get_attribute( 'two' ) ) {
|
||||
continue;
|
||||
}
|
||||
$p->set_bookmark( 'second' );
|
||||
$processor->set_bookmark( 'second' );
|
||||
|
||||
// Find third tag of interest.
|
||||
while ( $p->next_tag() && null === $p->get_attribute( 'three' ) ) {
|
||||
while ( $processor->next_tag() && null === $processor->get_attribute( 'three' ) ) {
|
||||
continue;
|
||||
}
|
||||
$p->set_bookmark( 'third' );
|
||||
$processor->set_bookmark( 'third' );
|
||||
|
||||
// Seek backwards.
|
||||
$p->seek( 'first' );
|
||||
$processor->seek( 'first' );
|
||||
|
||||
// Seek forwards. If the current token isn't also updated this could appear like a backwards seek.
|
||||
$p->seek( 'second' );
|
||||
$this->assertTrue( $p->get_attribute( 'two' ) );
|
||||
$processor->seek( 'second' );
|
||||
$this->assertTrue( $processor->get_attribute( 'two' ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase {
|
||||
*
|
||||
* @return array[].
|
||||
*/
|
||||
public function data_article_container_group() {
|
||||
public static function data_article_container_group() {
|
||||
$group = array();
|
||||
|
||||
foreach (
|
||||
@ -122,19 +122,19 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase {
|
||||
* @ticket 58961
|
||||
*/
|
||||
public function test_in_body_skips_unexpected_button_closer() {
|
||||
$p = WP_HTML_Processor::create_fragment( '<div>Test</button></div>' );
|
||||
$processor = WP_HTML_Processor::create_fragment( '<div>Test</button></div>' );
|
||||
|
||||
$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( '<div><p>Click the button <button one>here</button>!</p></div><button two>not here</button>' );
|
||||
$processor = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>here</button>!</p></div><button two>not here</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( '<div><p>Click the button <button one>almost<button two>here</button>!</p></div><button three>not here</button>' );
|
||||
$processor = WP_HTML_Processor::create_fragment( '<div><p>Click the button <button one>almost<button two>here</button>!</p></div><button three>not here</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( '<div><button one><p>Click the button <span><button two>here</button>!</span></p></div><button three>not here</button>' );
|
||||
$processor = WP_HTML_Processor::create_fragment( '<div><button one><p>Click the button <span><button two>here</button>!</span></p></div><button three>not here</button>' );
|
||||
|
||||
// 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( '<div><span><p></span><div>' );
|
||||
$processor = WP_HTML_Processor::create_fragment( '<div><span><p></span><div>' );
|
||||
|
||||
$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( '<div><span><code></span><div>' );
|
||||
$processor = WP_HTML_Processor::create_fragment( '<div><span><code></span><div>' );
|
||||
|
||||
$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( '</br>' );
|
||||
$processor = WP_HTML_Processor::create_fragment( '</br>' );
|
||||
|
||||
$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() );
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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." );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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." );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
|
||||
$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( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
|
||||
$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( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
|
||||
$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( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
|
||||
$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( '<div>Test</div>' );
|
||||
$this->assertFalse( $p->has_bookmark( 'my-bookmark' ) );
|
||||
$processor = new WP_HTML_Tag_Processor( '<div>Test</div>' );
|
||||
$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( '<div>Test</div>' );
|
||||
$p->next_tag();
|
||||
$p->set_bookmark( 'my-bookmark' );
|
||||
$this->assertTrue( $p->has_bookmark( 'my-bookmark' ) );
|
||||
$processor = new WP_HTML_Tag_Processor( '<div>Test</div>' );
|
||||
$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( '<div>Test</div>' );
|
||||
$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( '<div>Test</div>' );
|
||||
$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( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
|
||||
$p->next_tag( 'li' );
|
||||
$p->set_bookmark( 'first li' );
|
||||
$processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
|
||||
$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(
|
||||
'<ul><li foo-1="bar-1">One</li><li foo-2="bar-2">Two</li><li>Three</li></ul>',
|
||||
$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( '<div>First</div><span>Second</span>' );
|
||||
$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( '<div>First</div><span>Second</span>' );
|
||||
$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
|
||||
$input = <<<HTML
|
||||
<button twenty_one_characters 7_chars></button><button></button>
|
||||
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;
|
||||
</div>
|
||||
</div>
|
||||
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( '<div>First</div><div>Second</div>' );
|
||||
$p->next_tag();
|
||||
$p->set_bookmark( 'first' );
|
||||
$p->next_tag();
|
||||
$p->add_class( 'second' );
|
||||
$processor = new WP_HTML_Tag_Processor( '<div>First</div><div>Second</div>' );
|
||||
$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(
|
||||
'<div class="first">First</div><div class="second">Second</div>',
|
||||
$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( '<div>First</div><div>Second</div>' );
|
||||
$p->next_tag();
|
||||
$p->set_bookmark( 'first' );
|
||||
$p->next_tag();
|
||||
$p->set_bookmark( 'second' );
|
||||
$processor = new WP_HTML_Tag_Processor( '<div>First</div><div>Second</div>' );
|
||||
$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(
|
||||
'<div class="first">First</div><div class="second">Second</div>',
|
||||
$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( '<div>First</div><div disabled>Second</div>' );
|
||||
$p->next_tag();
|
||||
$p->set_bookmark( 'first' );
|
||||
$p->next_tag();
|
||||
$p->remove_attribute( 'disabled' );
|
||||
$processor = new WP_HTML_Tag_Processor( '<div>First</div><div disabled>Second</div>' );
|
||||
$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.
|
||||
*/
|
||||
'<div untouched>First</div><div >Second</div>',
|
||||
$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( '<div disabled>First</div><div>Second</div>' );
|
||||
$p->next_tag();
|
||||
$p->set_bookmark( 'first' );
|
||||
$p->next_tag();
|
||||
$p->set_bookmark( 'second' );
|
||||
$processor = new WP_HTML_Tag_Processor( '<div disabled>First</div><div>Second</div>' );
|
||||
$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.
|
||||
*/
|
||||
'<div >First</div><div safe>Second</div>',
|
||||
$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( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
|
||||
$p->next_tag( 'li' );
|
||||
$processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
|
||||
$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( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
|
||||
$p->next_tag( 'li' );
|
||||
$p->set_bookmark( 'bookmark' );
|
||||
$processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
|
||||
$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" );
|
||||
}
|
||||
}
|
||||
|
||||
@ -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( '<!--->', '' ),
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user