Skip to content

Commit 78db493

Browse files
committed
Revert TEXTAREA into its own test, keep PRE/LISTING data provider
TEXTAREA is a raw text element with different navigation semantics and should remain a separate test. Only PRE and LISTING share the same test structure. https://claude.ai/code/session_019ux8qzita5FCCk6v6A9cui
1 parent 69e5cd8 commit 78db493

1 file changed

Lines changed: 32 additions & 23 deletions

File tree

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

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -638,35 +638,47 @@ public function test_json_auto_escaping() {
638638
}
639639

640640
/**
641-
* TEXTAREA, PRE, and LISTING elements ignore the first newline in their content.
641+
* TEXTAREA elements ignore the first newline in their content.
642+
* Setting the modifiable text with a leading newline should ensure that the leading newline
643+
* is present in the resulting TEXTAREA.
644+
*
645+
* @ticket 64607
646+
*/
647+
public function test_modifiable_text_special_textarea() {
648+
$processor = new WP_HTML_Tag_Processor( '<textarea></textarea>' );
649+
$processor->next_token();
650+
$processor->set_modifiable_text( "\nAFTER NEWLINE" );
651+
$this->assertSame(
652+
"\nAFTER NEWLINE",
653+
$processor->get_modifiable_text(),
654+
'Should have preserved the leading newline in the TEXTAREA content.'
655+
);
656+
}
657+
658+
/**
659+
* PRE and LISTING elements ignore the first newline in their content.
642660
* Setting the modifiable text with a leading newline should ensure that the leading newline
643661
* is present in the resulting element.
644662
*
645663
* @ticket 64607
646664
*
647-
* @dataProvider data_modifiable_text_special_leading_newline_elements
665+
* @dataProvider data_modifiable_text_special_pre_tags
648666
*
649-
* @param string $html HTML containing the element to test.
650-
* @param int $advance_n_tokens Count of times to run `next_token()` before reaching target node.
651-
* @param string $expected_html Expected HTML output after setting modifiable text.
667+
* @param string $tag_name The tag name to test (e.g. 'pre', 'listing').
652668
*/
653-
public function test_modifiable_text_special_leading_newline_elements( string $html, int $advance_n_tokens, string $expected_html ) {
669+
public function test_modifiable_text_special_pre_tags( string $tag_name ) {
654670
$set_text = "\nAFTER NEWLINE";
655-
$processor = new WP_HTML_Tag_Processor( $html );
656-
while ( --$advance_n_tokens >= 0 ) {
657-
$processor->next_token();
658-
}
671+
$processor = new WP_HTML_Tag_Processor( "<{$tag_name}>REPLACEME<!--x--></{$tag_name}>" );
672+
$processor->next_tag();
673+
$processor->next_token();
674+
$this->assertSame( '#text', $processor->get_token_type() );
659675
$processor->set_modifiable_text( $set_text );
660-
$this->assertSame(
661-
$set_text,
662-
$processor->get_modifiable_text(),
663-
'Should have preserved the leading newline.'
664-
);
676+
$this->assertSame( $set_text, $processor->get_modifiable_text() );
665677
$this->assertEqualHTML(
666-
$expected_html,
678+
"<{$tag_name}>\n{$set_text}<!--x--></{$tag_name}>",
667679
$processor->get_updated_html(),
668680
'<body>',
669-
'Should have preserved the leading newline in the element content.'
681+
"Should have preserved the leading newline in the {$tag_name} content."
670682
);
671683
}
672684

@@ -675,13 +687,10 @@ public function test_modifiable_text_special_leading_newline_elements( string $h
675687
*
676688
* @return array[]
677689
*/
678-
public static function data_modifiable_text_special_leading_newline_elements() {
679-
$set_text = "\nAFTER NEWLINE";
680-
690+
public static function data_modifiable_text_special_pre_tags() {
681691
return array(
682-
'TEXTAREA' => array( '<textarea></textarea>', 1, "<textarea>\n{$set_text}</textarea>" ),
683-
'PRE' => array( '<pre>REPLACEME<!--x--></pre>', 2, "<pre>\n{$set_text}<!--x--></pre>" ),
684-
'LISTING' => array( '<listing>REPLACEME<!--x--></listing>', 2, "<listing>\n{$set_text}<!--x--></listing>" ),
692+
'PRE' => array( 'pre' ),
693+
'LISTING' => array( 'listing' ),
685694
);
686695
}
687696
}

0 commit comments

Comments
 (0)