mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML API: Add tests for virtual node breadcrumbs and depth #6929
Closed
sirreal
wants to merge
3
commits into
WordPress:trunk
from
sirreal:html-api/add-virtual-node-breadcrumb-depth-tests
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -573,4 +573,66 @@ public function test_retains_proper_bookmarks_after_seeking_back_to_closed_eleme | |
'Should have retained breadcrumbs from bookmarked location after seeking backwards to it.' | ||
); | ||
} | ||
|
||
/** | ||
* Ensures that breadcrumbs are properly reported on virtual nodes. | ||
* | ||
* @dataProvider data_virtual_nodes_breadcrumbs | ||
* | ||
* @ticket 61348 | ||
*/ | ||
public function test_breadcrumbs_on_virtual_nodes( string $html, int $token_position, string $expected_tag_name, string $expect_open_close, array $expected_breadcrumbs ) { | ||
$processor = WP_HTML_Processor::create_fragment( $html ); | ||
|
||
for ( $i = 0; $i < $token_position; $i++ ) { | ||
$processor->next_token(); | ||
} | ||
|
||
$this->assertSame( $expected_tag_name, $processor->get_tag(), "Found incorrect tag name {$processor->get_tag()}." ); | ||
if ( 'open' === $expect_open_close ) { | ||
$this->assertFalse( $processor->is_tag_closer(), "Found closer when opener expected at {$processor->get_tag()}." ); | ||
} else { | ||
$this->assertTrue( $processor->is_tag_closer(), "Found opener when closer expected at {$processor->get_tag()}." ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for tests it's probably helpful to use |
||
} | ||
|
||
$this->assertEquals( $expected_breadcrumbs, $processor->get_breadcrumbs(), "Found incorrect breadcrumbs in {$html}." ); | ||
} | ||
|
||
/** | ||
* Ensures that get_current_depth reports the correct depth on virtual nodes. | ||
* | ||
* @dataProvider data_virtual_nodes_breadcrumbs | ||
* | ||
* @ticket 61348 | ||
*/ | ||
public function test_depth_on_virtual_nodes( string $html, int $token_position, string $expected_tag_name, string $expect_open_close, array $expected_breadcrumbs ) { | ||
$processor = WP_HTML_Processor::create_fragment( $html ); | ||
|
||
for ( $i = 0; $i < $token_position; $i++ ) { | ||
$processor->next_token(); | ||
} | ||
|
||
$this->assertSame( count( $expected_breadcrumbs ), $processor->get_current_depth(), "Found incorrect depth in {$html}." ); | ||
} | ||
|
||
/** | ||
* Data provider. | ||
* | ||
* Data arrays will have the following shape: | ||
* 0: string Input html. | ||
* 1: int Token index to seek. | ||
* 2: string Expected tag name. | ||
* 3: string 'open' or 'close' indicating an opener or closer is expected. | ||
* 4: array<string> Expected breadcrumbs. | ||
* | ||
* @return array[] | ||
*/ | ||
public static function data_virtual_nodes_breadcrumbs() { | ||
return array( | ||
'Implied P tag opener on unmatched closer' => array( '</p>', 1, 'P', 'open', array( 'HTML', 'BODY', 'P' ) ), | ||
'Implied heading tag closer on heading child' => array( '<h1><h2>', 2, 'H1', 'close', array( 'HTML', 'BODY' ) ), | ||
'Implied A tag closer on A tag child' => array( '<a><a>', 2, 'A', 'close', array( 'HTML', 'BODY' ) ), | ||
'Implied A tag closer on A tag descendent' => array( '<a><span><a>', 4, 'A', 'close', array( 'HTML', 'BODY' ) ), | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted in #6765 I generally try to avoid duplicating content in the test failure when it's already reported. Either it's simple enough to let the error say "Failed to find expected tag name" or we add some new and useful information in the interpolation. It's never worth repeating the invalid information in my opinion, because that only repeats that the test failed instead of clueing someone in to what it should be or how they can make it right.