diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorComments.php b/tests/phpunit/tests/html-api/wpHtmlProcessorComments.php new file mode 100644 index 0000000000000..f02631bc56222 --- /dev/null +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorComments.php @@ -0,0 +1,76 @@ +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( '', 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( '', WP_HTML_Processor::COMMENT_AS_INVALID_HTML, ' Bang opener ' ), + 'Invalid HTML comment ?' => array( '', WP_HTML_Processor::COMMENT_AS_INVALID_HTML, ' Question opener ' ), + 'CDATA comment' => array( '', WP_HTML_Processor::COMMENT_AS_CDATA_LOOKALIKE, ' cdata body ' ), + 'Processing instriction comment' => array( '', WP_HTML_Processor::COMMENT_AS_PI_NODE_LOOKALIKE, ' Instruction body. ', 'pi-target' ), + 'Processing instriction php' => array( '', 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' ), + 'Funky comment •' => array( '', '• bar' ), + ); + } +}