Skip to content

Commit 053dccf

Browse files
committed
Add carriage return tests
1 parent 6afd8fe commit 053dccf

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,56 @@ public function test_modifiable_text_special_textarea() {
2727
);
2828
}
2929

30+
/**
31+
* TEXTAREA elements ignore the first newline in their content.
32+
* Setting the modifiable text with a leading carriage return should be normalized
33+
* and ensure the leading newline is present in the resulting TEXTAREA.
34+
*
35+
* @ticket 64609
36+
*/
37+
public function test_modifiable_text_special_textarea_carriage_return() {
38+
$processor = WP_HTML_Processor::create_fragment( '<textarea></textarea>' );
39+
$processor->next_token();
40+
$processor->set_modifiable_text( "\rCR" );
41+
// Newline normalization transforms \r into \n, and special handling should preserve it.
42+
$this->assertSame(
43+
"\nCR",
44+
$processor->get_modifiable_text(),
45+
'Should have normalized carriage return and preserved the leading newline in the TEXTAREA content.'
46+
);
47+
$this->assertEqualHTML(
48+
"<textarea>\n\nCR</textarea>",
49+
$processor->get_updated_html(),
50+
'<body>',
51+
'Should have doubled the newline in the output HTML to preserve the leading newline.'
52+
);
53+
}
54+
55+
/**
56+
* TEXTAREA elements ignore the first newline in their content.
57+
* Setting the modifiable text with a leading carriage return + newline should be normalized
58+
* and ensure the leading newline is present in the resulting TEXTAREA.
59+
*
60+
* @ticket 64609
61+
*/
62+
public function test_modifiable_text_special_textarea_carriage_return_newline() {
63+
$processor = WP_HTML_Processor::create_fragment( '<textarea></textarea>' );
64+
$processor->next_token();
65+
$processor->set_modifiable_text( "\r\nCR-N" );
66+
// Newline normalization transforms \r\n into \n, and special handling should preserve it.
67+
$this->assertSame(
68+
"\nCR-N",
69+
$processor->get_modifiable_text(),
70+
'Should have normalized carriage return + newline and preserved the leading newline in the TEXTAREA content.'
71+
);
72+
$this->assertEqualHTML(
73+
"<textarea>\n\nCR-N</textarea>",
74+
$processor->get_updated_html(),
75+
'<body>',
76+
'Should have doubled the newline in the output HTML to preserve the leading newline.'
77+
);
78+
}
79+
3080
/**
3181
* PRE and LISTING elements ignore the first newline in their content.
3282
* Setting the modifiable text with a leading newline should ensure that the leading newline

0 commit comments

Comments
 (0)