From ee45b795185dc8d75d1ef8e66949723ee8b2dd75 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Fri, 3 Feb 2023 14:48:38 +1100 Subject: [PATCH 1/2] Copy failing WP_HTML_Tag_Processor_Bookmark_Test tests from Core --- .../html/wp-html-tag-processor-bookmark-test.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/phpunit/html/wp-html-tag-processor-bookmark-test.php b/phpunit/html/wp-html-tag-processor-bookmark-test.php index 759d9d04490880..8e7e5cbe4887b2 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" ); } } From 975dba61a9e7b898e09b6cffc068dfc48a00bf05 Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Fri, 3 Feb 2023 15:12:28 +1100 Subject: [PATCH 2/2] Update set_bookmark() to match Core as well --- lib/experimental/html/class-wp-html-tag-processor.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/experimental/html/class-wp-html-tag-processor.php b/lib/experimental/html/class-wp-html-tag-processor.php index 433c16a150806c..9db2a9b09ca174 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; }