diff --git a/lib/experimental/html/class-wp-html-tag-processor.php b/lib/experimental/html/class-wp-html-tag-processor.php
index 433c16a150806..9db2a9b09ca17 100644
--- a/lib/experimental/html/class-wp-html-tag-processor.php
+++ b/lib/experimental/html/class-wp-html-tag-processor.php
@@ -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;
}
diff --git a/phpunit/html/wp-html-tag-processor-bookmark-test.php b/phpunit/html/wp-html-tag-processor-bookmark-test.php
index 759d9d0449088..8e7e5cbe4887b 100644
--- a/phpunit/html/wp-html-tag-processor-bookmark-test.php
+++ b/phpunit/html/wp-html-tag-processor-bookmark-test.php
@@ -341,13 +341,12 @@ public function test_limits_the_number_of_bookmarks() {
$p = new WP_HTML_Tag_Processor( '
' );
$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" );
}
/**
@@ -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" );
}
}