Skip to content

Commit 388bf19

Browse files
committed
Add and improve HTML processor bookmark tests
1 parent d5bf14c commit 388bf19

1 file changed

Lines changed: 48 additions & 3 deletions

File tree

tests/phpunit/tests/html-api/wpHtmlProcessor-bookmark.php

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,27 @@
1313
*/
1414
class Tests_HtmlApi_WpHtmlProcessor_Bookmark extends WP_UnitTestCase {
1515
/**
16-
* Ensures that bookmarks can be set and seeked to for the full processor.
17-
*
1816
* @ticket 62290
1917
*/
20-
public function test_full_processor_seek() {
18+
public function test_full_processor_seek_same_location() {
19+
$bookmark_name = 'the-bookmark';
20+
$processor = WP_HTML_Processor::create_full_parser( '<html><body><div>' );
21+
$this->assertTrue( $processor->next_tag( 'BODY' ) );
22+
$this->assertTrue( $processor->set_bookmark( $bookmark_name ), 'Failed to set bookmark.' );
23+
$this->assertTrue( $processor->has_bookmark( $bookmark_name ), 'Failed has_bookmark check.' );
24+
25+
// Confirm the bookmark works.
26+
$this->assertTrue( $processor->seek( $bookmark_name ), 'Failed to seek to bookmark.' );
27+
$this->assertSame( 'BODY', $processor->get_tag() );
28+
$this->assertTrue( $processor->next_tag() );
29+
$this->assertSame( 'DIV', $processor->get_tag() );
30+
$this->assertSame( array( 'HTML', 'BODY', 'DIV' ), $processor->get_breadcrumbs() );
31+
}
32+
33+
/**
34+
* @ticket 62290
35+
*/
36+
public function test_full_processor_seek_backward() {
2137
$bookmark_name = 'the-bookmark';
2238
$processor = WP_HTML_Processor::create_full_parser( '<html><body><div>' );
2339
$this->assertTrue( $processor->next_tag( 'BODY' ) );
@@ -31,4 +47,33 @@ public function test_full_processor_seek() {
3147
$this->assertTrue( $processor->seek( $bookmark_name ), 'Failed to seek to bookmark.' );
3248
$this->assertSame( 'BODY', $processor->get_tag() );
3349
}
50+
51+
/**
52+
* @ticket 62290
53+
*/
54+
public function test_full_processor_seek_forward() {
55+
$processor = WP_HTML_Processor::create_full_parser( '<html><body><div one></div><div two>' );
56+
$this->assertTrue( $processor->next_tag( 'BODY' ) );
57+
$this->assertTrue( $processor->set_bookmark( 'body' ), 'Failed to set bookmark "body".' );
58+
$this->assertTrue( $processor->has_bookmark( 'body' ), 'Failed "body" has_bookmark check.' );
59+
60+
// Move past the bookmark so it must scan backwards.
61+
$this->assertTrue( $processor->next_tag( 'DIV' ) );
62+
$this->assertTrue( $processor->get_attribute( 'one' ) );
63+
$this->assertTrue( $processor->set_bookmark( 'one' ), 'Failed to set bookmark "one".' );
64+
$this->assertTrue( $processor->has_bookmark( 'one' ), 'Failed "one" has_bookmark check.' );
65+
66+
// Seek back.
67+
$this->assertTrue( $processor->seek( 'body' ), 'Failed to seek to bookmark "body".' );
68+
$this->assertSame( 'BODY', $processor->get_tag() );
69+
70+
// Seek forward and continue processing.
71+
$this->assertTrue( $processor->seek( 'one' ), 'Failed to seek to bookmark "one".' );
72+
$this->assertSame( 'DIV', $processor->get_tag() );
73+
$this->assertTrue( $processor->get_attribute( 'one' ) );
74+
$this->assertTrue( $processor->next_tag() );
75+
76+
$this->assertSame( 'DIV', $processor->get_tag() );
77+
$this->assertTrue( $processor->get_attribute( 'two' ) );
78+
}
3479
}

0 commit comments

Comments
 (0)