@@ -32,8 +32,6 @@ public function test_modifiable_text_special_textarea() {
3232 * Setting the modifiable text with a leading newline should ensure that the leading newline
3333 * is present in the resulting TEXTAREA.
3434 *
35- * @todo Leading whitespace mage split into multiple text nodes. Add appropriate tests.
36- *
3735 * @ticket 64607
3836 */
3937 public function test_modifiable_text_special_pre () {
@@ -55,6 +53,87 @@ public function test_modifiable_text_special_pre() {
5553 );
5654 }
5755
56+ /**
57+ *
58+ * @ticket 64607
59+ */
60+ public function test_modifiable_text_special_pre_leading_whitespace () {
61+ $ set_text = "\nAFTER NEWLINE. " ;
62+ $ processor = WP_HTML_Processor::create_fragment ( "<pre> \nREPLACEME<!--x--></pre> " );
63+ $ processor ->next_tag ();
64+ $ processor ->next_token ();
65+ $ this ->assertSame ( '#text ' , $ processor ->get_token_type () );
66+ // This is an empty text node because of how the HTML Processor works.
67+ $ this ->assertSame ( '' , $ processor ->get_modifiable_text () );
68+ $ processor ->set_modifiable_text ( $ set_text );
69+ $ this ->assertSame ( $ set_text , $ processor ->get_modifiable_text () );
70+ $ this ->assertEqualHTML (
71+ <<<HTML
72+ <pre>
73+ {$ set_text }REPLACEME<!--x--></pre>
74+ HTML ,
75+ $ processor ->get_updated_html (),
76+ '<body> ' ,
77+ 'Should have preserved the leading newline in the TEXTAREA content. '
78+ );
79+
80+ $ processor = WP_HTML_Processor::create_fragment ( "<pre> \nREPLACEME<!--x--></pre> " );
81+ $ processor ->next_tag ();
82+ $ processor ->next_token ();
83+ $ processor ->next_token ();
84+ $ this ->assertSame ( '#text ' , $ processor ->get_token_type () );
85+ // This is an empty text node because of how the HTML Processor works.
86+ $ this ->assertSame ( 'REPLACEME ' , $ processor ->get_modifiable_text () );
87+ $ processor ->set_modifiable_text ( $ set_text );
88+ $ this ->assertSame ( $ set_text , $ processor ->get_modifiable_text () );
89+ $ this ->assertEqualHTML (
90+ <<<HTML
91+ <pre>
92+ {$ set_text }<!--x--></pre>
93+ HTML ,
94+ $ processor ->get_updated_html (),
95+ '<body> ' ,
96+ 'Should have preserved the leading newline in the TEXTAREA content. '
97+ );
98+
99+ $ processor = WP_HTML_Processor::create_fragment ( '<pre> REPLACEME<!--x--></pre> ' );
100+ $ processor ->next_tag ();
101+ $ processor ->next_token ();
102+ $ this ->assertSame ( '#text ' , $ processor ->get_token_type () );
103+ // This is an empty text node because of how the HTML Processor works.
104+ $ this ->assertSame ( ' ' , $ processor ->get_modifiable_text () );
105+ $ processor ->set_modifiable_text ( $ set_text );
106+ $ this ->assertSame ( $ set_text , $ processor ->get_modifiable_text () );
107+ $ this ->assertEqualHTML (
108+ <<<HTML
109+ <pre>
110+ {$ set_text }REPLACEME<!--x--></pre>
111+ HTML ,
112+ $ processor ->get_updated_html (),
113+ '<body> ' ,
114+ 'Should have preserved the leading newline in the TEXTAREA content. '
115+ );
116+
117+ $ processor = WP_HTML_Processor::create_fragment ( '<pre> REPLACEME<!--x--></pre> ' );
118+ $ processor ->next_tag ();
119+ $ processor ->next_token ();
120+ $ processor ->next_token ();
121+ $ this ->assertSame ( '#text ' , $ processor ->get_token_type () );
122+ // This is an empty text node because of how the HTML Processor works.
123+ $ this ->assertSame ( 'REPLACEME ' , $ processor ->get_modifiable_text () );
124+ $ processor ->set_modifiable_text ( $ set_text );
125+ $ this ->assertSame ( $ set_text , $ processor ->get_modifiable_text () );
126+ $ this ->assertEqualHTML (
127+ <<<HTML
128+ <pre>
129+ {$ set_text }<!--x--></pre>
130+ HTML ,
131+ $ processor ->get_updated_html (),
132+ '<body> ' ,
133+ 'Should have preserved the leading newline in the TEXTAREA content. '
134+ );
135+ }
136+
58137 /**
59138 * LISTING elements ignore the first newline in their content.
60139 * Setting the modifiable text with a leading newline should ensure that the leading newline
0 commit comments