mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTML API: Add tests confirming comment behavior in HTML Processor.
There was a bug-fix late in the 6.6 cycle in the HTML Processor which resolved an issue with the wrong name being reported when paused at processing-instruction look-alike invalid comments, but no tests were added to enforce the correct behaviors. This patch adds the missing tests. Developed in #6765 Discussed in https://core.trac.wordpress.org/ticket/61530 Follow-up to [58304], [58558]. Props dmsnell, jonsurrell. See #61530. git-svn-id: https://develop.svn.wordpress.org/trunk@58734 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/** | ||
* Unit tests covering WP_HTML_Processor functionality. | ||
* | ||
* @package WordPress | ||
* @subpackage HTML-API | ||
* | ||
* @since 6.7.0 | ||
* | ||
* @group html-api | ||
* | ||
* @coversDefaultClass WP_HTML_Processor | ||
*/ | ||
class Tests_HtmlApi_WpHtmlProcessorComments extends WP_UnitTestCase { | ||
/** | ||
* Ensures that different types of comments are processed correctly. | ||
* | ||
* @ticket 61530 | ||
* | ||
* @dataProvider data_comments | ||
*/ | ||
public function test_comment_processing( string $html, string $expected_comment_type, string $expected_modifiable_text, string $expected_tag = null ) { | ||
$processor = WP_HTML_Processor::create_fragment( $html ); | ||
$processor->next_token(); | ||
|
||
$this->assertSame( '#comment', $processor->get_token_name() ); | ||
$this->assertSame( $expected_comment_type, $processor->get_comment_type() ); | ||
$this->assertSame( $expected_modifiable_text, $processor->get_modifiable_text() ); | ||
$this->assertSame( $expected_tag, $processor->get_tag() ); | ||
} | ||
|
||
/** | ||
* Data provider. | ||
* | ||
* @return array[] | ||
*/ | ||
public static function data_comments() { | ||
return array( | ||
'Normative comment' => array( '<!-- A comment. -->', WP_HTML_Processor::COMMENT_AS_HTML_COMMENT, ' A comment. ' ), | ||
'Abruptly closed comment' => array( '<!-->', WP_HTML_Processor::COMMENT_AS_ABRUPTLY_CLOSED_COMMENT, '' ), | ||
'Invalid HTML comment !' => array( '<! Bang opener >', WP_HTML_Processor::COMMENT_AS_INVALID_HTML, ' Bang opener ' ), | ||
'Invalid HTML comment ?' => array( '<? Question opener >', WP_HTML_Processor::COMMENT_AS_INVALID_HTML, ' Question opener ' ), | ||
'CDATA comment' => array( '<![CDATA[ cdata body ]]>', WP_HTML_Processor::COMMENT_AS_CDATA_LOOKALIKE, ' cdata body ' ), | ||
'Processing instriction comment' => array( '<?pi-target Instruction body. ?>', WP_HTML_Processor::COMMENT_AS_PI_NODE_LOOKALIKE, ' Instruction body. ', 'pi-target' ), | ||
'Processing instriction php' => array( '<?php const HTML_COMMENT = true; ?>', WP_HTML_Processor::COMMENT_AS_PI_NODE_LOOKALIKE, ' const HTML_COMMENT = true; ', 'php' ), | ||
); | ||
} | ||
|
||
/** | ||
* Ensures that different types of comments are processed correctly. | ||
* | ||
* @ticket 61530 | ||
* | ||
* @dataProvider data_funky_comments | ||
*/ | ||
public function test_funky_comment( string $html, string $expected_modifiable_text ) { | ||
$processor = WP_HTML_Processor::create_fragment( $html ); | ||
$processor->next_token(); | ||
|
||
$this->assertSame( '#funky-comment', $processor->get_token_name() ); | ||
$this->assertSame( $expected_modifiable_text, $processor->get_modifiable_text() ); | ||
} | ||
|
||
/** | ||
* Data provider. | ||
* | ||
* @return array[] | ||
*/ | ||
public static function data_funky_comments() { | ||
return array( | ||
'Funky comment # (empty)' => array( '</#>', '#' ), | ||
'Funky comment #' => array( '</# foo>', '# foo' ), | ||
'Funky comment •' => array( '</• bar>', '• bar' ), | ||
); | ||
} | ||
} |