Skip to content

Commit da70697

Browse files
committed
Add CSS string token round-trip tests
1 parent 65f91e1 commit da70697

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tests/phpunit/tests/css-api/wpCssBuilder.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ class Tests_CssApi_WpCssBuilder extends WP_UnitTestCase {
1515
*/
1616
public function test_string_escaping( string $input, string $expected ): void {
1717
$this->assertSame( $expected, WP_CSS_Builder::string( $input ) );
18+
19+
/**
20+
* Ensure that a single, equivalent CSS string is produced.
21+
*
22+
* CSS pre-processing normalization is applied to the input to ensure
23+
* a match can be found.
24+
*
25+
* @see https://www.w3.org/TR/css-syntax-3/#input-preprocessing
26+
*/
27+
$processor = WP_CSS_Token_Processor::create( WP_CSS_Builder::string( $input ) );
28+
$processor->next_token();
29+
$this->assertSame( WP_CSS_Token_Processor::TOKEN_STRING, $processor->get_token_type() );
30+
$expected_decoded_value = strtr(
31+
$input,
32+
array(
33+
"\r\n" => "\n",
34+
"\r" => "\n",
35+
"\f" => "\n",
36+
"\0" => '',
37+
)
38+
);
39+
$this->assertSame( $expected_decoded_value, $processor->get_token_value() );
40+
$this->assertFalse( $processor->next_token() );
1841
}
1942

2043
/**

0 commit comments

Comments
 (0)