Skip to content

Commit

Permalink
Copy failing WP_HTML_Tag_Processor_Bookmark_Test tests from Core (#47720
Browse files Browse the repository at this point in the history
)

* Copy failing WP_HTML_Tag_Processor_Bookmark_Test tests from Core

* Update set_bookmark() to match Core as well
  • Loading branch information
noisysocks authored and ntsekouras committed Feb 3, 2023
1 parent e9ff92d commit ea0010b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
7 changes: 4 additions & 3 deletions lib/experimental/html/class-wp-html-tag-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,10 @@ public function set_bookmark( $name ) {
}

if ( ! array_key_exists( $name, $this->bookmarks ) && count( $this->bookmarks ) >= self::MAX_BOOKMARKS ) {
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
throw new Exception( "Tried to jump to a non-existent HTML bookmark {$name}." );
}
_doing_it_wrong(
__METHOD__,
__( 'Too many bookmarks: cannot create any more.', 'gutenberg' )
);
return false;
}

Expand Down
13 changes: 6 additions & 7 deletions phpunit/html/wp-html-tag-processor-bookmark-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,12 @@ 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' );

$this->expectException( Exception::class );

for ( $i = 0;$i < WP_HTML_Tag_Processor::MAX_BOOKMARKS;$i++ ) {
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->assertFalse( $p->set_bookmark( 'final bookmark' ), "Allocated $i bookmarks, which is one above the limit." );
$this->setExpectedIncorrectUsage( 'WP_HTML_Tag_Processor::set_bookmark' );
$this->assertFalse( $p->set_bookmark( 'final bookmark' ), "Allocated $i bookmarks, which is one above the limit" );
}

/**
Expand All @@ -360,11 +359,11 @@ public function test_limits_the_number_of_seek_calls() {
$p->next_tag( 'li' );
$p->set_bookmark( 'bookmark' );

$this->expectException( Exception::class );

for ( $i = 0; $i < WP_HTML_Tag_Processor::MAX_SEEK_OPS; $i++ ) {
$this->assertTrue( $p->seek( 'bookmark' ), 'Could not seek to the "bookmark"' );
}
$this->assertFalse( $p->seek( 'bookmark' ), "$i-th seek() to the bookmark succeeded, even though it should exceed the allowed limit." );

$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" );
}
}

1 comment on commit ea0010b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in ea0010b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4083825535
📝 Reported issues:

Please sign in to comment.