11<?php
2+
3+ use function PHPUnit \Framework \assertNotEmpty ;
24/**
35 * Unit tests covering WP_HTML_Processor serialization functionality.
46 *
@@ -325,18 +327,16 @@ public static function data_provider_serialize_doctype() {
325327 /**
326328 * @ticket TBD
327329 *
328- * @dataProvider data_provider_special_leading_newline_cases
330+ * @dataProvider data_provider_normalize_special_leading_newline_cases
329331 */
330- public function test_special_leading_newline_handling ( string $ input , string $ expected ) {
332+ public function test_normalize_special_leading_newline_handling ( string $ input , string $ expected ) {
331333 $ normalized = WP_HTML_Processor::normalize ( $ input );
332334 $ this ->assertEqualHTML ( $ expected , $ normalized );
333335 $ normalized_twice = WP_HTML_Processor::normalize ( $ normalized );
334336 $ this ->assertEqualHTML ( $ expected , $ normalized_twice );
335337 }
336338
337- /**
338- */
339- public static function data_provider_special_leading_newline_cases () {
339+ public static function data_provider_normalize_special_leading_newline_cases () {
340340 return array (
341341 'Leading newline in PRE ' => array (
342342 "<pre> \nline 1 \nline 2</pre> " ,
@@ -356,4 +356,29 @@ public static function data_provider_special_leading_newline_cases() {
356356 ),
357357 );
358358 }
359+
360+ /**
361+ * @ticket TBD
362+ */
363+ public function test_serialize_special_pre_leading_newline_handling () {
364+ $ processor = WP_HTML_Processor::create_fragment ( "<pre> \n\nx</pre> " );
365+ $ text_content = '' ;
366+ while ( $ processor ->next_token () ) {
367+ if ( '#text ' === $ processor ->get_token_type () ) {
368+ $ text_content .= $ processor ->serialize_token ();
369+ }
370+ }
371+ $ this ->assertSame ( "\n\nx " , $ text_content );
372+ }
373+
374+ /**
375+ * @ticket TBD
376+ */
377+ public function test_serialize_special_textarea_leading_newline_handling () {
378+ $ normalized = WP_HTML_Processor::normalize ( "<textarea> \n\nx</textarea> " );
379+ $ processor = WP_HTML_Processor::create_fragment ( $ normalized );
380+ $ processor ->next_token ();
381+ $ text_content = $ processor ->get_modifiable_text ();
382+ $ this ->assertSame ( "\nx " , $ text_content );
383+ }
359384}
0 commit comments