|
11 | 11 | class Tests_HtmlApi_WpHtmlProcessorModifiableText extends WP_UnitTestCase { |
12 | 12 | /** |
13 | 13 | * 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. |
16 | 16 | * |
17 | 17 | * @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. |
34 | 18 | * |
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. |
36 | 23 | */ |
37 | | - public function test_modifiable_text_special_textarea_carriage_return() { |
| 24 | + public function test_modifiable_text_special_textarea( string $set_text, string $expected_html ) { |
38 | 25 | $processor = WP_HTML_Processor::create_fragment( '<textarea></textarea>' ); |
39 | 26 | $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 ); |
42 | 28 | $this->assertSame( |
43 | | - "\nCR", |
| 29 | + strtr( |
| 30 | + $set_text, |
| 31 | + array( |
| 32 | + "\r\n" => "\n", |
| 33 | + "\r" => "\n", |
| 34 | + ) |
| 35 | + ), |
44 | 36 | $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.' |
46 | 38 | ); |
47 | 39 | $this->assertEqualHTML( |
48 | | - "<textarea>\n\nCR</textarea>", |
| 40 | + $expected_html, |
49 | 41 | $processor->get_updated_html(), |
50 | 42 | '<body>', |
51 | | - 'Should have doubled the newline in the output HTML to preserve the leading newline.' |
| 43 | + 'Should have correctly output the TEXTAREA HTML.' |
52 | 44 | ); |
53 | 45 | } |
54 | 46 |
|
55 | 47 | /** |
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. |
59 | 49 | * |
60 | | - * @ticket 64609 |
| 50 | + * @return array[] |
61 | 51 | */ |
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 | + ), |
77 | 66 | ); |
78 | 67 | } |
79 | 68 |
|
|
0 commit comments