From e42e65def6ddad2c9a100e303c06b39aaff733d0 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 23 Jan 2024 09:04:51 +0000 Subject: [PATCH] Editor: Update the ThemeJson unit test to cover custom CSS feature. In #59499 a fix have been shipped to theme.json custom CSS when applied to blocks with multiple CSS selectors. This commit covers that fix with a unit test. Props wildworks. Fixes #60294. git-svn-id: https://develop.svn.wordpress.org/trunk@57333 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/theme/wpThemeJson.php | 28 +++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index 2f561ed8c07ca..2a452ca2e1ad3 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -4688,29 +4688,37 @@ public function test_process_blocks_custom_css( $input, $expected ) { */ public function data_process_blocks_custom_css() { return array( - // Simple CSS without any child selectors. - 'no child selectors' => array( + // Simple CSS without any nested selectors. + 'no nested selectors' => array( 'input' => array( 'selector' => '.foo', 'css' => 'color: red; margin: auto;', ), 'expected' => '.foo{color: red; margin: auto;}', ), - // CSS with child selectors. - 'with children' => array( + // CSS with nested selectors. + 'with nested selector' => array( 'input' => array( 'selector' => '.foo', - 'css' => 'color: red; margin: auto; & .bar{color: blue;}', + 'css' => 'color: red; margin: auto; &.one{color: blue;} & .two{color: green;}', ), - 'expected' => '.foo{color: red; margin: auto;}.foo .bar{color: blue;}', + 'expected' => '.foo{color: red; margin: auto;}.foo.one{color: blue;}.foo .two{color: green;}', ), - // CSS with child selectors and pseudo elements. - 'with children and pseudo elements' => array( + // CSS with pseudo elements. + 'with pseudo elements' => array( 'input' => array( 'selector' => '.foo', - 'css' => 'color: red; margin: auto; & .bar{color: blue;} &::before{color: green;}', + 'css' => 'color: red; margin: auto; &::before{color: blue;} & ::before{color: green;} &.one::before{color: yellow;} & .two::before{color: purple;}', ), - 'expected' => '.foo{color: red; margin: auto;}.foo .bar{color: blue;}.foo::before{color: green;}', + 'expected' => '.foo{color: red; margin: auto;}.foo::before{color: blue;}.foo ::before{color: green;}.foo.one::before{color: yellow;}.foo .two::before{color: purple;}', + ), + // CSS with multiple root selectors. + 'with multiple root selectors' => array( + 'input' => array( + 'selector' => '.foo, .bar', + 'css' => 'color: red; margin: auto; &.one{color: blue;} & .two{color: green;} &::before{color: yellow;} & ::before{color: purple;} &.three::before{color: orange;} & .four::before{color: skyblue;}', + ), + 'expected' => '.foo, .bar{color: red; margin: auto;}.foo.one, .bar.one{color: blue;}.foo .two, .bar .two{color: green;}.foo::before, .bar::before{color: yellow;}.foo ::before, .bar ::before{color: purple;}.foo.three::before, .bar.three::before{color: orange;}.foo .four::before, .bar .four::before{color: skyblue;}', ), ); }