Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
15863a8
Introduce HTML Tag Processor
dmsnell Jan 26, 2023
40e1cb3
Move class_exists calls to wp-html
dmsnell Jan 30, 2023
8b507e5
Mark helper classes `final`
dmsnell Jan 30, 2023
561acff
Updates from review feedback, mostly docs
dmsnell Jan 30, 2023
57550e7
WP_HTML_Tag_Processor_Test: test improvements
hellofromtonya Jan 30, 2023
b708c6b
Load API files directly from wp-settings.php
hellofromtonya Jan 30, 2023
521a500
Tests: remove loading API files
hellofromtonya Jan 30, 2023
8bdfae4
Renames test classes to coding standard
hellofromtonya Jan 30, 2023
bc17086
Renames test filenames to coding standard
hellofromtonya Jan 30, 2023
334e415
Cleans HEADS from merge conflict from test file
hellofromtonya Jan 30, 2023
def4ed4
Reword explanation of lexical updates
dmsnell Jan 31, 2023
b924e03
docblock and consistency updates, addressing some PR feedback
dmsnell Jan 31, 2023
91dc772
Move HTML processing modules into new html directory
dmsnell Jan 31, 2023
1fd0d7d
Documentation wording updates.
dmsnell Jan 31, 2023
361710d
Rename library to "HTML-API" instead of "HTML"
dmsnell Jan 31, 2023
2d1411a
Un-finalize helper classes
dmsnell Jan 31, 2023
d8fdf41
Replace throwing with trigger_error( E_USER_WARNING )
dmsnell Jan 31, 2023
1465218
Add test to check for bug when encounting unexpected </SCRIPT> closer
dmsnell Feb 1, 2023
5c1a5d5
Update tests: fix data provider and remove Exception expectation
dmsnell Feb 1, 2023
c50ffee
Lint issue
dmsnell Feb 1, 2023
9a5ccf0
Fix broken tests
dmsnell Feb 1, 2023
13dd7d7
Remove some TODOs, most were done already
dmsnell Feb 1, 2023
b31cca4
Expand design and limitations discussion
dmsnell Feb 1, 2023
1a9bec0
Loosen assertion on warning
dmsnell Feb 1, 2023
28e9bf3
Rename some properties to clarify their purpose and expand comments.
dmsnell Feb 1, 2023
1e2ef09
Linter: yoda condition
dmsnell Feb 1, 2023
243dc7c
Typos in comments
dmsnell Feb 1, 2023
8152988
Rework @covers attributes
dmsnell Feb 1, 2023
a5f2d96
Was doing it wrong w.r.t. doing_it_wrong
dmsnell Feb 1, 2023
5b1d47e
Add additional type check to avoid throwing _doing_it_wrong error whe…
dmsnell Feb 1, 2023
3f9b274
Lada la di
dmsnell Feb 2, 2023
1b8c75c
Remove checks that _doing_it_wrong throws a notice
dmsnell Feb 2, 2023
aad5310
Set expected incorrect usage in tests.
dmsnell Feb 2, 2023
4a43850
Docblock updates
dmsnell Feb 2, 2023
fbbf382
Shorten function summary
dmsnell Feb 2, 2023
5b4ad8f
Ensure test assertions have a message parameter
dmsnell Feb 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Ensure test assertions have a message parameter
  • Loading branch information
dmsnell committed Feb 2, 2023
commit 5b4ad8fa5634177102ee5771a2b7edfd86927f8b
50 changes: 35 additions & 15 deletions tests/phpunit/tests/html/wpHtmlTagProcessor-bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class Tests_HTML_wpHtmlTagProcessor_Bookmark extends WP_UnitTestCase {
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.' );
$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.' );
$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' );
}

/**
Expand All @@ -35,9 +35,9 @@ public function test_set_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.' );
$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.' );
$this->assertTrue( $p->release_bookmark( 'first li' ), 'Could not release a bookmark' );
}

/**
Expand All @@ -58,7 +58,8 @@ public function test_seek() {

$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()
$p->get_updated_html(),
'Did not seek to the intended bookmark locations'
);
}

Expand Down Expand Up @@ -228,7 +229,8 @@ public function test_bookmarks_complex_use_case() {

$this->assertSame(
$expected_output,
$p->get_updated_html()
$p->get_updated_html(),
'Performing several attribute updates on different tags does not produce the expected HTML snippet'
);
}

Expand All @@ -249,7 +251,8 @@ public function test_updates_bookmark_for_additions_after_both_sides() {

$this->assertSame(
'<div class="first">First</div><div class="second">Second</div>',
$p->get_updated_html()
$p->get_updated_html(),
'The bookmark was updated incorrectly in response to HTML markup updates'
);
}

Expand All @@ -273,7 +276,8 @@ public function test_updates_bookmark_for_additions_before_both_sides() {

$this->assertSame(
'<div class="first">First</div><div class="second">Second</div>',
$p->get_updated_html()
$p->get_updated_html(),
'The bookmark was updated incorrectly in response to HTML markup updates'
);
}

Expand All @@ -293,9 +297,17 @@ public function test_updates_bookmark_for_deletions_after_both_sides() {
$p->set_attribute( 'untouched', true );

$this->assertSame(
/** @TODO: we shouldn't have to assert the extra space after removing the attribute. */
/*
* It shouldn't be necessary to assert the extra space after the tag
* following the attribute removal, but doing so makes the test easier
* to see than it would be if parsing the output HTML for proper
* validation. If the Tag Processor changes so that this space no longer
* appears then this test should be updated to reflect that. The space
* is not required.
*/
'<div untouched>First</div><div >Second</div>',
$p->get_updated_html()
$p->get_updated_html(),
'The bookmark was incorrectly in response to HTML markup updates'
);
}

Expand All @@ -318,9 +330,17 @@ public function test_updates_bookmark_for_deletions_before_both_sides() {
$p->set_attribute( 'safe', true );

$this->assertSame(
/** @TODO: we shouldn't have to assert the extra space after removing the attribute. */
/*
* It shouldn't be necessary to assert the extra space after the tag
* following the attribute removal, but doing so makes the test easier
* to see than it would be if parsing the output HTML for proper
* validation. If the Tag Processor changes so that this space no longer
* appears then this test should be updated to reflect that. The space
* is not required.
*/
'<div >First</div><div safe>Second</div>',
$p->get_updated_html()
$p->get_updated_html(),
'The bookmark was updated incorrectly in response to HTML markup updates'
);
}

Expand All @@ -338,7 +358,7 @@ public function test_limits_the_number_of_bookmarks() {
}

$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( $p->set_bookmark( 'final bookmark' ), "Allocated $i bookmarks, which is one above the limit" );
}

/**
Expand All @@ -356,6 +376,6 @@ public function test_limits_the_number_of_seek_calls() {
}

$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( $p->seek( 'bookmark' ), "$i-th seek() to the bookmark succeeded, even though it should exceed the allowed limit" );
}
}
Loading