Skip to content

Commit

Permalink
HTML API: Tests should use expectedIncorrectUsage phpunit annotation
Browse files Browse the repository at this point in the history
Some tests in the HTML API test suite use `setExpectedIncorrectUsage`.
The annotation `@expectedIncorrectUsage` can be used to simplify the tests.

Developed in WordPress#6449
Discussed in https://core.trac.wordpress.org/ticket/61080

Fixes #61080.
Props dmsnell, jonsurrell.


git-svn-id: https://develop.svn.wordpress.org/trunk@58048 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
dmsnell committed Apr 26, 2024
1 parent 81882dd commit 7de15eb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
8 changes: 1 addition & 7 deletions tests/phpunit/tests/html-api/wpHtmlProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,10 @@ class Tests_HtmlApi_WpHtmlProcessor extends WP_UnitTestCase {
* @ticket 58517
*
* @covers WP_HTML_Processor::__construct
* @expectedIncorrectUsage WP_HTML_Processor::__construct
*/
public function test_warns_that_the_static_creator_methods_should_be_called_instead_of_the_public_constructor() {
$this->setExpectedIncorrectUsage( 'WP_HTML_Processor::__construct' );

new WP_HTML_Processor( '<p>Light roast.</p>' );

$this->assertNotNull(
$this->caught_doing_it_wrong['WP_HTML_Processor::__construct'],
"Calling the public constructor should warn to call the static creator methods instead, but didn't."
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ public function test_updates_bookmark_for_deletions_before_both_sides() {
* @ticket 56299
*
* @covers WP_HTML_Tag_Processor::set_bookmark
* @expectedIncorrectUsage WP_HTML_Tag_Processor::set_bookmark
*/
public function test_limits_the_number_of_bookmarks() {
$processor = new WP_HTML_Tag_Processor( '<ul><li>One</li><li>Two</li><li>Three</li></ul>' );
Expand All @@ -423,7 +424,6 @@ public function test_limits_the_number_of_bookmarks() {
$this->assertTrue( $processor->set_bookmark( "bookmark $i" ), "Could not allocate the bookmark #$i" );
}

$this->setExpectedIncorrectUsage( 'WP_HTML_Tag_Processor::set_bookmark' );
$this->assertFalse( $processor->set_bookmark( 'final bookmark' ), "Allocated $i bookmarks, which is one above the limit" );
}

Expand Down

0 comments on commit 7de15eb

Please sign in to comment.