From b9cb260eace859d3f356c6343be9531f731e5638 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Feb 2026 22:02:06 +0000 Subject: [PATCH 1/8] Refactor PRE and LISTING modifiable text tests to use a data provider The test_modifiable_text_special_pre and test_modifiable_text_special_listing tests had identical structure, differing only in tag name. Consolidate them into a single data-provider-driven test. https://claude.ai/code/session_019ux8qzita5FCCk6v6A9cui --- .../wpHtmlTagProcessorModifiableText.php | 45 +++++++------------ 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php index 16f55f6281e4e..e5c1fb8a49e8e 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php @@ -656,54 +656,41 @@ public function test_modifiable_text_special_textarea() { } /** - * PRE elements ignore the first newline in their content. + * PRE and LISTING 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. + * is present in the resulting element. * * @ticket 64607 + * + * @dataProvider data_modifiable_text_special_pre_tags + * + * @param string $tag_name The tag name to test (e.g. 'pre', 'listing'). */ - public function test_modifiable_text_special_pre() { + public function test_modifiable_text_special_pre_tags( string $tag_name ) { $set_text = "\nAFTER NEWLINE"; - $processor = new WP_HTML_Tag_Processor( '
REPLACEME
' ); + $processor = new WP_HTML_Tag_Processor( "<{$tag_name}>REPLACEME" ); $processor->next_tag(); $processor->next_token(); $this->assertSame( '#text', $processor->get_token_type() ); $processor->set_modifiable_text( $set_text ); $this->assertSame( $set_text, $processor->get_modifiable_text() ); $this->assertEqualHTML( - << - {$set_text} - HTML, + "<{$tag_name}>\n{$set_text}", $processor->get_updated_html(), '', - 'Should have preserved the leading newline in the TEXTAREA content.' + "Should have preserved the leading newline in the {$tag_name} content." ); } /** - * LISTING 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. + * Data provider. * - * @ticket 64607 + * @return array[] */ - public function test_modifiable_text_special_listing() { - $set_text = "\nAFTER NEWLINE"; - $processor = new WP_HTML_Tag_Processor( 'REPLACEME' ); - $processor->next_tag(); - $processor->next_token(); - $this->assertSame( '#text', $processor->get_token_type() ); - $processor->set_modifiable_text( $set_text ); - $this->assertSame( $set_text, $processor->get_modifiable_text() ); - $this->assertEqualHTML( - << - {$set_text} - HTML, - $processor->get_updated_html(), - '', - 'Should have preserved the leading newline in the TEXTAREA content.' + public static function data_modifiable_text_special_pre_tags() { + return array( + 'PRE' => array( 'pre' ), + 'LISTING' => array( 'listing' ), ); } } From 69e5cd8ee7387d92447850b5ddcfca6ffecfb5ec Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Feb 2026 22:06:33 +0000 Subject: [PATCH 2/8] Include TEXTAREA in the leading-newline data provider TEXTAREA, like PRE and LISTING, ignores the first newline in its content. Fold the separate TEXTAREA test into the shared data provider, also adding an assertEqualHTML check it previously lacked. Use advance_n_tokens to handle the navigation difference (TEXTAREA is a raw text element reached in one next_token() call vs two for PRE/LISTING). https://claude.ai/code/session_019ux8qzita5FCCk6v6A9cui --- .../wpHtmlTagProcessorModifiableText.php | 55 ++++++++----------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php index e5c1fb8a49e8e..a8cf27d10089f 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php @@ -638,47 +638,35 @@ public function test_json_auto_escaping() { } /** - * 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. - * - * @ticket 64607 - */ - public function test_modifiable_text_special_textarea() { - $processor = new WP_HTML_Tag_Processor( '' ); - $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.' - ); - } - - /** - * PRE and LISTING elements ignore the first newline in their content. + * TEXTAREA, PRE, and LISTING 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 element. * * @ticket 64607 * - * @dataProvider data_modifiable_text_special_pre_tags + * @dataProvider data_modifiable_text_special_leading_newline_elements * - * @param string $tag_name The tag name to test (e.g. 'pre', 'listing'). + * @param string $html HTML containing the element to test. + * @param int $advance_n_tokens Count of times to run `next_token()` before reaching target node. + * @param string $expected_html Expected HTML output after setting modifiable text. */ - public function test_modifiable_text_special_pre_tags( string $tag_name ) { + public function test_modifiable_text_special_leading_newline_elements( string $html, int $advance_n_tokens, string $expected_html ) { $set_text = "\nAFTER NEWLINE"; - $processor = new WP_HTML_Tag_Processor( "<{$tag_name}>REPLACEME" ); - $processor->next_tag(); - $processor->next_token(); - $this->assertSame( '#text', $processor->get_token_type() ); + $processor = new WP_HTML_Tag_Processor( $html ); + while ( --$advance_n_tokens >= 0 ) { + $processor->next_token(); + } $processor->set_modifiable_text( $set_text ); - $this->assertSame( $set_text, $processor->get_modifiable_text() ); + $this->assertSame( + $set_text, + $processor->get_modifiable_text(), + 'Should have preserved the leading newline.' + ); $this->assertEqualHTML( - "<{$tag_name}>\n{$set_text}", + $expected_html, $processor->get_updated_html(), '', - "Should have preserved the leading newline in the {$tag_name} content." + 'Should have preserved the leading newline in the element content.' ); } @@ -687,10 +675,13 @@ public function test_modifiable_text_special_pre_tags( string $tag_name ) { * * @return array[] */ - public static function data_modifiable_text_special_pre_tags() { + public static function data_modifiable_text_special_leading_newline_elements() { + $set_text = "\nAFTER NEWLINE"; + return array( - 'PRE' => array( 'pre' ), - 'LISTING' => array( 'listing' ), + 'TEXTAREA' => array( '', 1, "" ), + 'PRE' => array( '
REPLACEME
', 2, "
\n{$set_text}
" ), + 'LISTING' => array( 'REPLACEME', 2, "\n{$set_text}" ), ); } } From 78db4934c0bbf9e70fb9a6bf0ef0b2acdc29b8ff Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Feb 2026 22:15:23 +0000 Subject: [PATCH 3/8] 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 --- .../wpHtmlTagProcessorModifiableText.php | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php index a8cf27d10089f..e5c1fb8a49e8e 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php @@ -638,35 +638,47 @@ public function test_json_auto_escaping() { } /** - * TEXTAREA, PRE, and LISTING elements ignore the first newline in their content. + * 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. + * + * @ticket 64607 + */ + public function test_modifiable_text_special_textarea() { + $processor = new WP_HTML_Tag_Processor( '' ); + $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.' + ); + } + + /** + * PRE and LISTING 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 element. * * @ticket 64607 * - * @dataProvider data_modifiable_text_special_leading_newline_elements + * @dataProvider data_modifiable_text_special_pre_tags * - * @param string $html HTML containing the element to test. - * @param int $advance_n_tokens Count of times to run `next_token()` before reaching target node. - * @param string $expected_html Expected HTML output after setting modifiable text. + * @param string $tag_name The tag name to test (e.g. 'pre', 'listing'). */ - public function test_modifiable_text_special_leading_newline_elements( string $html, int $advance_n_tokens, string $expected_html ) { + public function test_modifiable_text_special_pre_tags( string $tag_name ) { $set_text = "\nAFTER NEWLINE"; - $processor = new WP_HTML_Tag_Processor( $html ); - while ( --$advance_n_tokens >= 0 ) { - $processor->next_token(); - } + $processor = new WP_HTML_Tag_Processor( "<{$tag_name}>REPLACEME" ); + $processor->next_tag(); + $processor->next_token(); + $this->assertSame( '#text', $processor->get_token_type() ); $processor->set_modifiable_text( $set_text ); - $this->assertSame( - $set_text, - $processor->get_modifiable_text(), - 'Should have preserved the leading newline.' - ); + $this->assertSame( $set_text, $processor->get_modifiable_text() ); $this->assertEqualHTML( - $expected_html, + "<{$tag_name}>\n{$set_text}", $processor->get_updated_html(), '', - 'Should have preserved the leading newline in the element content.' + "Should have preserved the leading newline in the {$tag_name} content." ); } @@ -675,13 +687,10 @@ public function test_modifiable_text_special_leading_newline_elements( string $h * * @return array[] */ - public static function data_modifiable_text_special_leading_newline_elements() { - $set_text = "\nAFTER NEWLINE"; - + public static function data_modifiable_text_special_pre_tags() { return array( - 'TEXTAREA' => array( '', 1, "" ), - 'PRE' => array( '
REPLACEME
', 2, "
\n{$set_text}
" ), - 'LISTING' => array( 'REPLACEME', 2, "\n{$set_text}" ), + 'PRE' => array( 'pre' ), + 'LISTING' => array( 'listing' ), ); } } From e6ba8651e4b2de6ab55ca893a9f8c0fce9ba4ea1 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Feb 2026 22:21:25 +0000 Subject: [PATCH 4/8] Refactor PRE and LISTING HTML Processor modifiable text tests to use a data provider The test_modifiable_text_special_pre and test_modifiable_text_special_listing tests had identical structure, differing only in tag name. Consolidate them into a single data-provider-driven test. https://claude.ai/code/session_019ux8qzita5FCCk6v6A9cui --- .../wpHtmlProcessorModifiableText.php | 57 ++++++++----------- .../wpHtmlTagProcessorModifiableText.php | 45 +++++++++------ 2 files changed, 52 insertions(+), 50 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index 01af358fa1b23..82a34fdd1fc12 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -28,15 +28,19 @@ public function test_modifiable_text_special_textarea() { } /** - * PRE elements ignore the first newline in their content. + * PRE and LISTING 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. + * is present in the resulting element. * * @ticket 64607 + * + * @dataProvider data_modifiable_text_special_pre_tags + * + * @param string $tag_name The tag name to test (e.g. 'pre', 'listing'). */ - public function test_modifiable_text_special_pre() { + public function test_modifiable_text_special_pre_tags( string $tag_name ) { $set_text = "\nAFTER NEWLINE"; - $processor = WP_HTML_Processor::create_fragment( '
REPLACEME
' ); + $processor = WP_HTML_Processor::create_fragment( "<{$tag_name}>REPLACEME" ); $processor->next_tag(); $processor->next_token(); $this->assertSame( '#text', $processor->get_token_type() ); @@ -44,12 +48,24 @@ public function test_modifiable_text_special_pre() { $this->assertSame( $set_text, $processor->get_modifiable_text() ); $this->assertEqualHTML( << - {$set_text} + <{$tag_name}> + {$set_text} HTML, $processor->get_updated_html(), '', - 'Should have preserved the leading newline in the TEXTAREA content.' + "Should have preserved the leading newline in the {$tag_name} content." + ); + } + + /** + * Data provider. + * + * @return array[] + */ + public static function data_modifiable_text_special_pre_tags() { + return array( + 'PRE' => array( 'pre' ), + 'LISTING' => array( 'listing' ), ); } @@ -134,31 +150,4 @@ public function test_modifiable_text_special_pre_leading_whitespace() { ); } - /** - * LISTING 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. - * - * @todo Leading whitespace mage split into multiple text nodes. Add appropriate tests. - * - * @ticket 64607 - */ - public function test_modifiable_text_special_listing() { - $set_text = "\nAFTER NEWLINE"; - $processor = WP_HTML_Processor::create_fragment( 'REPLACEME' ); - $processor->next_tag(); - $processor->next_token(); - $this->assertSame( '#text', $processor->get_token_type() ); - $processor->set_modifiable_text( $set_text ); - $this->assertSame( $set_text, $processor->get_modifiable_text() ); - $this->assertEqualHTML( - << - {$set_text} - HTML, - $processor->get_updated_html(), - '', - 'Should have preserved the leading newline in the TEXTAREA content.' - ); - } } diff --git a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php index e5c1fb8a49e8e..16f55f6281e4e 100644 --- a/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlTagProcessorModifiableText.php @@ -656,41 +656,54 @@ public function test_modifiable_text_special_textarea() { } /** - * PRE and LISTING elements ignore the first newline in their content. + * PRE 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 element. + * is present in the resulting TEXTAREA. * * @ticket 64607 - * - * @dataProvider data_modifiable_text_special_pre_tags - * - * @param string $tag_name The tag name to test (e.g. 'pre', 'listing'). */ - public function test_modifiable_text_special_pre_tags( string $tag_name ) { + public function test_modifiable_text_special_pre() { $set_text = "\nAFTER NEWLINE"; - $processor = new WP_HTML_Tag_Processor( "<{$tag_name}>REPLACEME" ); + $processor = new WP_HTML_Tag_Processor( '
REPLACEME
' ); $processor->next_tag(); $processor->next_token(); $this->assertSame( '#text', $processor->get_token_type() ); $processor->set_modifiable_text( $set_text ); $this->assertSame( $set_text, $processor->get_modifiable_text() ); $this->assertEqualHTML( - "<{$tag_name}>\n{$set_text}", + << + {$set_text} + HTML, $processor->get_updated_html(), '', - "Should have preserved the leading newline in the {$tag_name} content." + 'Should have preserved the leading newline in the TEXTAREA content.' ); } /** - * Data provider. + * LISTING 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. * - * @return array[] + * @ticket 64607 */ - public static function data_modifiable_text_special_pre_tags() { - return array( - 'PRE' => array( 'pre' ), - 'LISTING' => array( 'listing' ), + public function test_modifiable_text_special_listing() { + $set_text = "\nAFTER NEWLINE"; + $processor = new WP_HTML_Tag_Processor( 'REPLACEME' ); + $processor->next_tag(); + $processor->next_token(); + $this->assertSame( '#text', $processor->get_token_type() ); + $processor->set_modifiable_text( $set_text ); + $this->assertSame( $set_text, $processor->get_modifiable_text() ); + $this->assertEqualHTML( + << + {$set_text} + HTML, + $processor->get_updated_html(), + '', + 'Should have preserved the leading newline in the TEXTAREA content.' ); } } From c4d4fadf98b0e272cc23efec8fbfead564c49c53 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Feb 2026 22:28:42 +0000 Subject: [PATCH 5/8] Refactor leading whitespace tests to use a data provider for PRE and LISTING Replace the monolithic test_modifiable_text_special_pre_leading_whitespace with a data-provider-driven test that runs the same 4 cases for both PRE and LISTING elements. This also addresses the @todo on the former LISTING test about adding leading whitespace tests. https://claude.ai/code/session_019ux8qzita5FCCk6v6A9cui --- .../wpHtmlProcessorModifiableText.php | 124 +++++++++--------- 1 file changed, 60 insertions(+), 64 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index 82a34fdd1fc12..015e8d1c676b7 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -70,84 +70,80 @@ public static function data_modifiable_text_special_pre_tags() { } /** + * PRE and LISTING elements ignore the first newline in their content. + * Leading whitespace may split into multiple text nodes in the HTML Processor. + * Setting the modifiable text with a leading newline should ensure that the + * leading newline is present in the resulting element. * * @ticket 64607 + * + * @dataProvider data_modifiable_text_special_leading_whitespace + * + * @param string $html HTML containing the element to test. + * @param int $advance_n_tokens Count of times to run `next_token()` after `next_tag()`. + * @param string $initial_text Expected modifiable text before the update. + * @param string $expected_html Expected HTML output after setting modifiable text. */ - public function test_modifiable_text_special_pre_leading_whitespace() { + public function test_modifiable_text_special_leading_whitespace( string $html, int $advance_n_tokens, string $initial_text, string $expected_html ) { $set_text = "\nAFTER NEWLINE."; - $processor = WP_HTML_Processor::create_fragment( "
\nREPLACEME
" ); + $processor = WP_HTML_Processor::create_fragment( $html ); $processor->next_tag(); - $processor->next_token(); + while ( --$advance_n_tokens >= 0 ) { + $processor->next_token(); + } $this->assertSame( '#text', $processor->get_token_type() ); - // This is an empty text node because of how the HTML Processor works. - $this->assertSame( '', $processor->get_modifiable_text() ); + $this->assertSame( $initial_text, $processor->get_modifiable_text() ); $processor->set_modifiable_text( $set_text ); $this->assertSame( $set_text, $processor->get_modifiable_text() ); $this->assertEqualHTML( - << - {$set_text}REPLACEME - HTML, + $expected_html, $processor->get_updated_html(), '', - 'Should have preserved the leading newline in the TEXTAREA content.' + 'Should have preserved the leading newline in the element content.' ); + } - $processor = WP_HTML_Processor::create_fragment( "
\nREPLACEME
" ); - $processor->next_tag(); - $processor->next_token(); - $processor->next_token(); - $this->assertSame( '#text', $processor->get_token_type() ); - // This is an empty text node because of how the HTML Processor works. - $this->assertSame( 'REPLACEME', $processor->get_modifiable_text() ); - $processor->set_modifiable_text( $set_text ); - $this->assertSame( $set_text, $processor->get_modifiable_text() ); - $this->assertEqualHTML( - << - {$set_text} - HTML, - $processor->get_updated_html(), - '', - 'Should have preserved the leading newline in the TEXTAREA content.' - ); + /** + * Data provider. + * + * @return array[] + */ + public static function data_modifiable_text_special_leading_whitespace() { + $set_text = "\nAFTER NEWLINE."; + $cases = array(); - $processor = WP_HTML_Processor::create_fragment( '
 REPLACEME
' ); - $processor->next_tag(); - $processor->next_token(); - $this->assertSame( '#text', $processor->get_token_type() ); - // This is an empty text node because of how the HTML Processor works. - $this->assertSame( ' ', $processor->get_modifiable_text() ); - $processor->set_modifiable_text( $set_text ); - $this->assertSame( $set_text, $processor->get_modifiable_text() ); - $this->assertEqualHTML( - << - {$set_text}REPLACEME - HTML, - $processor->get_updated_html(), - '', - 'Should have preserved the leading newline in the TEXTAREA content.' - ); + foreach ( array( 'pre', 'listing' ) as $tag_name ) { + $TAG = strtoupper( $tag_name ); - $processor = WP_HTML_Processor::create_fragment( '
 REPLACEME
' ); - $processor->next_tag(); - $processor->next_token(); - $processor->next_token(); - $this->assertSame( '#text', $processor->get_token_type() ); - // This is an empty text node because of how the HTML Processor works. - $this->assertSame( 'REPLACEME', $processor->get_modifiable_text() ); - $processor->set_modifiable_text( $set_text ); - $this->assertSame( $set_text, $processor->get_modifiable_text() ); - $this->assertEqualHTML( - << - {$set_text} - HTML, - $processor->get_updated_html(), - '', - 'Should have preserved the leading newline in the TEXTAREA content.' - ); - } + $cases[ "{$TAG} with leading newline, first text node" ] = array( + "<{$tag_name}>\nREPLACEME", + 1, + '', + "<{$tag_name}>\n{$set_text}REPLACEME", + ); + + $cases[ "{$TAG} with leading newline, second text node" ] = array( + "<{$tag_name}>\nREPLACEME", + 2, + 'REPLACEME', + "<{$tag_name}>\n{$set_text}", + ); + $cases[ "{$TAG} with leading space, first text node" ] = array( + "<{$tag_name}> REPLACEME", + 1, + ' ', + "<{$tag_name}>\n{$set_text}REPLACEME", + ); + + $cases[ "{$TAG} with leading space, second text node" ] = array( + "<{$tag_name}> REPLACEME", + 2, + 'REPLACEME', + "<{$tag_name}>\n {$set_text}", + ); + } + + return $cases; + } } From 95a19bc811d4ae9c9614bdb7fb2d7642d8a80363 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Feb 2026 22:39:18 +0000 Subject: [PATCH 6/8] Use a direct array return in the leading whitespace data provider https://claude.ai/code/session_019ux8qzita5FCCk6v6A9cui --- .../wpHtmlProcessorModifiableText.php | 44 +++++-------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index 015e8d1c676b7..877fe108f0128 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -110,40 +110,16 @@ public function test_modifiable_text_special_leading_whitespace( string $html, i */ public static function data_modifiable_text_special_leading_whitespace() { $set_text = "\nAFTER NEWLINE."; - $cases = array(); - foreach ( array( 'pre', 'listing' ) as $tag_name ) { - $TAG = strtoupper( $tag_name ); - - $cases[ "{$TAG} with leading newline, first text node" ] = array( - "<{$tag_name}>\nREPLACEME", - 1, - '', - "<{$tag_name}>\n{$set_text}REPLACEME", - ); - - $cases[ "{$TAG} with leading newline, second text node" ] = array( - "<{$tag_name}>\nREPLACEME", - 2, - 'REPLACEME', - "<{$tag_name}>\n{$set_text}", - ); - - $cases[ "{$TAG} with leading space, first text node" ] = array( - "<{$tag_name}> REPLACEME", - 1, - ' ', - "<{$tag_name}>\n{$set_text}REPLACEME", - ); - - $cases[ "{$TAG} with leading space, second text node" ] = array( - "<{$tag_name}> REPLACEME", - 2, - 'REPLACEME', - "<{$tag_name}>\n {$set_text}", - ); - } - - return $cases; + return array( + 'PRE with leading newline, first text node' => array( "
\nREPLACEME
", 1, '', "
\n{$set_text}REPLACEME
" ), + 'PRE with leading newline, second text node' => array( "
\nREPLACEME
", 2, 'REPLACEME', "
\n{$set_text}
" ), + 'PRE with leading space, first text node' => array( '
 REPLACEME
', 1, ' ', "
\n{$set_text}REPLACEME
" ), + 'PRE with leading space, second text node' => array( '
 REPLACEME
', 2, 'REPLACEME', "
\n {$set_text}
" ), + 'LISTING with leading newline, first text node' => array( "\nREPLACEME", 1, '', "\n{$set_text}REPLACEME" ), + 'LISTING with leading newline, second text node' => array( "\nREPLACEME", 2, 'REPLACEME', "\n{$set_text}" ), + 'LISTING with leading space, first text node' => array( ' REPLACEME', 1, ' ', "\n{$set_text}REPLACEME" ), + 'LISTING with leading space, second text node' => array( ' REPLACEME', 2, 'REPLACEME', "\n {$set_text}" ), + ); } } From db592ed0054cc56c2737eebed4c3fdcae15d089f Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Feb 2026 07:53:18 +0000 Subject: [PATCH 7/8] Derive leading whitespace test cases from data_modifiable_text_special_pre_tags Loop over data_modifiable_text_special_pre_tags() to produce tag names, so adding a new tag to that data provider automatically covers the leading whitespace cases too. https://claude.ai/code/session_019ux8qzita5FCCk6v6A9cui --- .../wpHtmlProcessorModifiableText.php | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index 877fe108f0128..a277606ba83e4 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -110,16 +110,18 @@ public function test_modifiable_text_special_leading_whitespace( string $html, i */ public static function data_modifiable_text_special_leading_whitespace() { $set_text = "\nAFTER NEWLINE."; + $cases = array(); - return array( - 'PRE with leading newline, first text node' => array( "
\nREPLACEME
", 1, '', "
\n{$set_text}REPLACEME
" ), - 'PRE with leading newline, second text node' => array( "
\nREPLACEME
", 2, 'REPLACEME', "
\n{$set_text}
" ), - 'PRE with leading space, first text node' => array( '
 REPLACEME
', 1, ' ', "
\n{$set_text}REPLACEME
" ), - 'PRE with leading space, second text node' => array( '
 REPLACEME
', 2, 'REPLACEME', "
\n {$set_text}
" ), - 'LISTING with leading newline, first text node' => array( "\nREPLACEME", 1, '', "\n{$set_text}REPLACEME" ), - 'LISTING with leading newline, second text node' => array( "\nREPLACEME", 2, 'REPLACEME', "\n{$set_text}" ), - 'LISTING with leading space, first text node' => array( ' REPLACEME', 1, ' ', "\n{$set_text}REPLACEME" ), - 'LISTING with leading space, second text node' => array( ' REPLACEME', 2, 'REPLACEME', "\n {$set_text}" ), - ); + foreach ( self::data_modifiable_text_special_pre_tags() as $label => $tag_data ) { + $tag_name = $tag_data[0]; + $TAG = strtoupper( $tag_name ); + + $cases[ "{$TAG} with leading newline, first text node" ] = array( "<{$tag_name}>\nREPLACEME", 1, '', "<{$tag_name}>\n{$set_text}REPLACEME" ); + $cases[ "{$TAG} with leading newline, second text node" ] = array( "<{$tag_name}>\nREPLACEME", 2, 'REPLACEME', "<{$tag_name}>\n{$set_text}" ); + $cases[ "{$TAG} with leading space, first text node" ] = array( "<{$tag_name}> REPLACEME", 1, ' ', "<{$tag_name}>\n{$set_text}REPLACEME" ); + $cases[ "{$TAG} with leading space, second text node" ] = array( "<{$tag_name}> REPLACEME", 2, 'REPLACEME', "<{$tag_name}>\n {$set_text}" ); + } + + return $cases; } } From 1d15f7ef1dec26e98fbd94fde48bb07c1c71c5ff Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 6 Feb 2026 09:49:28 +0000 Subject: [PATCH 8/8] Use yield in leading whitespace data provider https://claude.ai/code/session_019ux8qzita5FCCk6v6A9cui --- .../html-api/wpHtmlProcessorModifiableText.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php index a277606ba83e4..941c4f43b5a33 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorModifiableText.php @@ -106,22 +106,19 @@ public function test_modifiable_text_special_leading_whitespace( string $html, i /** * Data provider. * - * @return array[] + * @return Generator */ public static function data_modifiable_text_special_leading_whitespace() { $set_text = "\nAFTER NEWLINE."; - $cases = array(); - foreach ( self::data_modifiable_text_special_pre_tags() as $label => $tag_data ) { + foreach ( self::data_modifiable_text_special_pre_tags() as $tag_data ) { $tag_name = $tag_data[0]; $TAG = strtoupper( $tag_name ); - $cases[ "{$TAG} with leading newline, first text node" ] = array( "<{$tag_name}>\nREPLACEME", 1, '', "<{$tag_name}>\n{$set_text}REPLACEME" ); - $cases[ "{$TAG} with leading newline, second text node" ] = array( "<{$tag_name}>\nREPLACEME", 2, 'REPLACEME', "<{$tag_name}>\n{$set_text}" ); - $cases[ "{$TAG} with leading space, first text node" ] = array( "<{$tag_name}> REPLACEME", 1, ' ', "<{$tag_name}>\n{$set_text}REPLACEME" ); - $cases[ "{$TAG} with leading space, second text node" ] = array( "<{$tag_name}> REPLACEME", 2, 'REPLACEME', "<{$tag_name}>\n {$set_text}" ); + yield "{$TAG} with leading newline, first text node" => array( "<{$tag_name}>\nREPLACEME", 1, '', "<{$tag_name}>\n{$set_text}REPLACEME" ); + yield "{$TAG} with leading newline, second text node" => array( "<{$tag_name}>\nREPLACEME", 2, 'REPLACEME', "<{$tag_name}>\n{$set_text}" ); + yield "{$TAG} with leading space, first text node" => array( "<{$tag_name}> REPLACEME", 1, ' ', "<{$tag_name}>\n{$set_text}REPLACEME" ); + yield "{$TAG} with leading space, second text node" => array( "<{$tag_name}> REPLACEME", 2, 'REPLACEME', "<{$tag_name}>\n {$set_text}" ); } - - return $cases; } }