diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index 4d7eab0f90867..bc256ed72c7e5 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -11,69 +11,56 @@ class Tests_HtmlApi_WpHtmlProcessorModifiableText extends WP_UnitTestCase { /** * TEXTAREA elements ignore the first newline in their content. - * Setting the modifiable text with a leading newline should ensure that the leading newline - * is present in the resulting TEXTAREA. + * Setting the modifiable text with a leading newline (or carriage return variants) + * should ensure that the leading newline is present in the resulting TEXTAREA. * * @ticket 64609 - */ - public function test_modifiable_text_special_textarea() { - $processor = WP_HTML_Processor::create_fragment( '' ); - $processor->next_token(); - $processor->set_modifiable_text( "\nAFTER NEWLINE" ); - $this->assertSame( - "\nAFTER NEWLINE", - $processor->get_modifiable_text(), - 'Should have preserved the leading newline in the TEXTAREA content.' - ); - } - - /** - * TEXTAREA elements ignore the first newline in their content. - * Setting the modifiable text with a leading carriage return should be normalized - * and ensure the leading newline is present in the resulting TEXTAREA. * - * @ticket 64609 + * @dataProvider data_modifiable_text_special_textarea + * + * @param string $set_text Text to set. + * @param string $expected_text Expected text after normalization. + * @param string $expected_html Expected HTML output. */ - public function test_modifiable_text_special_textarea_carriage_return() { + public function test_modifiable_text_special_textarea( string $set_text, string $expected_text, string $expected_html ) { $processor = WP_HTML_Processor::create_fragment( '' ); $processor->next_token(); - $processor->set_modifiable_text( "\rCR" ); - // Newline normalization transforms \r into \n, and special handling should preserve it. + $processor->set_modifiable_text( $set_text ); $this->assertSame( - "\nCR", + $expected_text, $processor->get_modifiable_text(), - 'Should have normalized carriage return and preserved the leading newline in the TEXTAREA content.' + 'Should have preserved or normalized the leading newline in the TEXTAREA content.' ); $this->assertEqualHTML( - "", + $expected_html, $processor->get_updated_html(), '
', - 'Should have doubled the newline in the output HTML to preserve the leading newline.' + 'Should have correctly output the TEXTAREA HTML.' ); } /** - * TEXTAREA elements ignore the first newline in their content. - * Setting the modifiable text with a leading carriage return + newline should be normalized - * and ensure the leading newline is present in the resulting TEXTAREA. + * Data provider for test_modifiable_text_special_textarea(). * - * @ticket 64609 + * @return array[] */ - public function test_modifiable_text_special_textarea_carriage_return_newline() { - $processor = WP_HTML_Processor::create_fragment( '' ); - $processor->next_token(); - $processor->set_modifiable_text( "\r\nCR-N" ); - // Newline normalization transforms \r\n into \n, and special handling should preserve it. - $this->assertSame( - "\nCR-N", - $processor->get_modifiable_text(), - 'Should have normalized carriage return + newline and preserved the leading newline in the TEXTAREA content.' - ); - $this->assertEqualHTML( - "", - $processor->get_updated_html(), - '', - 'Should have doubled the newline in the output HTML to preserve the leading newline.' + public static function data_modifiable_text_special_textarea() { + return array( + 'Leading newline' => array( + "\nAFTER NEWLINE", + "\nAFTER NEWLINE", + "", + ), + 'Leading carriage return' => array( + "\rCR", + "\nCR", + "", + ), + 'Leading carriage return + newline' => array( + "\r\nCR-N", + "\nCR-N", + "", + ), ); }