Skip to content

Commit b61fc6d

Browse files
committed
Use data provider for repeat tests
1 parent 960638b commit b61fc6d

1 file changed

Lines changed: 34 additions & 45 deletions

File tree

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

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,69 +11,58 @@
1111
class Tests_HtmlApi_WpHtmlProcessorModifiableText extends WP_UnitTestCase {
1212
/**
1313
* TEXTAREA elements ignore the first newline in their content.
14-
* Setting the modifiable text with a leading newline should ensure that the leading newline
15-
* is present in the resulting TEXTAREA.
14+
* Setting the modifiable text with a leading newline (or carriage return variants)
15+
* should ensure that the leading newline is present in the resulting TEXTAREA.
1616
*
1717
* @ticket 64609
18-
*/
19-
public function test_modifiable_text_special_textarea() {
20-
$processor = WP_HTML_Processor::create_fragment( '<textarea></textarea>' );
21-
$processor->next_token();
22-
$processor->set_modifiable_text( "\nAFTER NEWLINE" );
23-
$this->assertSame(
24-
"\nAFTER NEWLINE",
25-
$processor->get_modifiable_text(),
26-
'Should have preserved the leading newline in the TEXTAREA content.'
27-
);
28-
}
29-
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.
3418
*
35-
* @ticket 64609
19+
* @dataProvider data_modifiable_text_special_textarea
20+
*
21+
* @param string $set_text Text to set.
22+
* @param string $expected_html Expected HTML output.
3623
*/
37-
public function test_modifiable_text_special_textarea_carriage_return() {
24+
public function test_modifiable_text_special_textarea( string $set_text, string $expected_html ) {
3825
$processor = WP_HTML_Processor::create_fragment( '<textarea></textarea>' );
3926
$processor->next_token();
40-
$processor->set_modifiable_text( "\rCR" );
41-
// Newline normalization transforms \r into \n, and special handling should preserve it.
27+
$processor->set_modifiable_text( $set_text );
4228
$this->assertSame(
43-
"\nCR",
29+
strtr(
30+
$set_text,
31+
array(
32+
"\r\n" => "\n",
33+
"\r" => "\n",
34+
)
35+
),
4436
$processor->get_modifiable_text(),
45-
'Should have normalized carriage return and preserved the leading newline in the TEXTAREA content.'
37+
'Should have preserved or normalized the leading newline in the TEXTAREA content.'
4638
);
4739
$this->assertEqualHTML(
48-
"<textarea>\n\nCR</textarea>",
40+
$expected_html,
4941
$processor->get_updated_html(),
5042
'<body>',
51-
'Should have doubled the newline in the output HTML to preserve the leading newline.'
43+
'Should have correctly output the TEXTAREA HTML.'
5244
);
5345
}
5446

5547
/**
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.
48+
* Data provider.
5949
*
60-
* @ticket 64609
50+
* @return array[]
6151
*/
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.'
52+
public static function data_modifiable_text_special_textarea() {
53+
return array(
54+
'Leading newline' => array(
55+
"\nAFTER NEWLINE",
56+
"<textarea>\n\nAFTER NEWLINE</textarea>",
57+
),
58+
'Leading carriage return' => array(
59+
"\rCR",
60+
"<textarea>\n\nCR</textarea>",
61+
),
62+
'Leading carriage return + newline' => array(
63+
"\r\nCR-N",
64+
"<textarea>\n\nCR-N</textarea>",
65+
),
7766
);
7867
}
7968

0 commit comments

Comments
 (0)