From e4bbc98c74da31aeb1f0c8f749d0b741c283a091 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Tue, 25 Oct 2022 11:55:52 +0200 Subject: [PATCH 1/6] Add backport for the bugfix --- src/wp-includes/class-wp-theme-json.php | 52 ++++++++++ tests/phpunit/tests/theme/wpThemeJson.php | 114 ++++++++++++++++++++++ 2 files changed, 166 insertions(+) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 555898370f863..5900342a41964 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -1925,6 +1925,53 @@ public function get_styles_block_nodes() { return static::get_block_nodes( $this->theme_json ); } + /** + * Returns a filtered declarations array if there is a separator block with only a background + * style defined in theme.json by adding a color attribute to reflect the changes in the front. + * + * @since 6.1.0 + * + * @param array $declarations List of declarations. + * + * @return array $declarations List of declarations filtered. + */ + private static function update_separator_declarations( $declarations ) { + $background_matches = array_values( + array_filter( + $declarations, + function( $declaration ) { + return 'background-color' === $declaration['name']; + } + ) + ); + if ( ! empty( $background_matches && isset( $background_matches[0]['value'] ) ) ) { + $border_color_matches = array_values( + array_filter( + $declarations, + function( $declaration ) { + return 'border-color' === $declaration['name']; + } + ) + ); + $text_color_matches = array_values( + array_filter( + $declarations, + function( $declaration ) { + return 'color' === $declaration['name']; + } + ) + ); + if ( empty( $border_color_matches ) && empty( $text_color_matches ) ) { + $declarations[] = array( + 'name' => 'color', + 'value' => $background_matches[0]['value'], + ); + } + } + + return $declarations; + } + /** * An internal method to get the block nodes from a theme.json file. * @@ -2101,6 +2148,11 @@ function( $pseudo_selector ) use ( $selector ) { } } + // Update declarations if there are separators with only background color defined. + if ( '.wp-block-separator' === $selector ) { + $declarations = static::update_separator_declarations( $declarations ); + } + // 2. Generate and append the rules that use the general selector. $block_rules .= static::to_ruleset( $selector, $declarations ); diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index 56b1bec0e138c..a931f7beda838 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -3997,4 +3997,118 @@ function data_set_spacing_sizes_when_invalid() { ), ); } + + /** + * @ticket 56903 + */ + function test_update_separator_declarations() { + // If only background is defined, test that includes border-color to the style so it is applied on the front end. + $theme_json = new WP_Theme_JSON_Gutenberg( + array( + 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, + 'styles' => array( + 'blocks' => array( + 'core/separator' => array( + 'color' => array( + 'background' => 'blue', + ), + ), + ), + ), + ), + 'default' + ); + $expected = 'body { margin: 0;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;color: blue;}'; + $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); + $this->assertEquals( $expected, $stylesheet ); + + // If background and text are defined, do not include border-color, as text color is enough. + $theme_json = new WP_Theme_JSON_Gutenberg( + array( + 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, + 'styles' => array( + 'blocks' => array( + 'core/separator' => array( + 'color' => array( + 'background' => 'blue', + 'text' => 'red', + ), + ), + ), + ), + ), + 'default' + ); + $expected = 'body { margin: 0;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;color: red;}'; + $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); + $this->assertEquals( $expected, $stylesheet ); + + // If only text is defined, do not include border-color, as by itself is enough. + $theme_json = new WP_Theme_JSON_Gutenberg( + array( + 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, + 'styles' => array( + 'blocks' => array( + 'core/separator' => array( + 'color' => array( + 'text' => 'red', + ), + ), + ), + ), + ), + 'default' + ); + $expected = 'body { margin: 0;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{color: red;}'; + $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); + $this->assertEquals( $expected, $stylesheet ); + + // If background, text, and border-color are defined, include everything, CSS specifity will decide which to apply. + $theme_json = new WP_Theme_JSON_Gutenberg( + array( + 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, + 'styles' => array( + 'blocks' => array( + 'core/separator' => array( + 'color' => array( + 'background' => 'blue', + 'text' => 'red', + ), + 'border' => array( + 'color' => 'pink', + ), + ), + ), + ), + ), + 'default' + ); + $expected = 'body { margin: 0;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;border-color: pink;color: red;}'; + $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); + $this->assertEquals( $expected, $stylesheet ); + + // If background and border color are defined, include everything, CSS specifity will decide which to apply. + $theme_json = new WP_Theme_JSON_Gutenberg( + array( + 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, + 'styles' => array( + 'blocks' => array( + 'core/separator' => array( + 'color' => array( + 'background' => 'blue', + ), + 'border' => array( + 'color' => 'pink', + ), + ), + ), + ), + ), + 'default' + ); + $expected = 'body { margin: 0;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;border-color: pink;}'; + $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); + $this->assertEquals( $expected, $stylesheet ); + + } } From cb6282329153ae6284c7f4d0f0388f54105d4c04 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Thu, 3 Nov 2022 14:28:31 +0100 Subject: [PATCH 2/6] Update version on comment --- src/wp-includes/class-wp-theme-json.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 5900342a41964..d67a21033bf8a 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -1929,7 +1929,7 @@ public function get_styles_block_nodes() { * Returns a filtered declarations array if there is a separator block with only a background * style defined in theme.json by adding a color attribute to reflect the changes in the front. * - * @since 6.1.0 + * @since 6.1.1 * * @param array $declarations List of declarations. * From 620a79a8d318cdb4cf446465487a1f56217d7124 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Fri, 4 Nov 2022 14:10:24 +0100 Subject: [PATCH 3/6] Update class name without Gutenberg on tests --- tests/phpunit/tests/theme/wpThemeJson.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index a931f7beda838..0419351c7f3f2 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -4003,9 +4003,9 @@ function data_set_spacing_sizes_when_invalid() { */ function test_update_separator_declarations() { // If only background is defined, test that includes border-color to the style so it is applied on the front end. - $theme_json = new WP_Theme_JSON_Gutenberg( + $theme_json = new WP_Theme_JSON( array( - 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, + 'version' => WP_Theme_JSON::LATEST_SCHEMA, 'styles' => array( 'blocks' => array( 'core/separator' => array( @@ -4023,9 +4023,9 @@ function test_update_separator_declarations() { $this->assertEquals( $expected, $stylesheet ); // If background and text are defined, do not include border-color, as text color is enough. - $theme_json = new WP_Theme_JSON_Gutenberg( + $theme_json = new WP_Theme_JSON( array( - 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, + 'version' => WP_Theme_JSON::LATEST_SCHEMA, 'styles' => array( 'blocks' => array( 'core/separator' => array( @@ -4044,9 +4044,9 @@ function test_update_separator_declarations() { $this->assertEquals( $expected, $stylesheet ); // If only text is defined, do not include border-color, as by itself is enough. - $theme_json = new WP_Theme_JSON_Gutenberg( + $theme_json = new WP_Theme_JSON( array( - 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, + 'version' => WP_Theme_JSON::LATEST_SCHEMA, 'styles' => array( 'blocks' => array( 'core/separator' => array( @@ -4064,9 +4064,9 @@ function test_update_separator_declarations() { $this->assertEquals( $expected, $stylesheet ); // If background, text, and border-color are defined, include everything, CSS specifity will decide which to apply. - $theme_json = new WP_Theme_JSON_Gutenberg( + $theme_json = new WP_Theme_JSON( array( - 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, + 'version' => WP_Theme_JSON::LATEST_SCHEMA, 'styles' => array( 'blocks' => array( 'core/separator' => array( @@ -4088,9 +4088,9 @@ function test_update_separator_declarations() { $this->assertEquals( $expected, $stylesheet ); // If background and border color are defined, include everything, CSS specifity will decide which to apply. - $theme_json = new WP_Theme_JSON_Gutenberg( + $theme_json = new WP_Theme_JSON( array( - 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, + 'version' => WP_Theme_JSON::LATEST_SCHEMA, 'styles' => array( 'blocks' => array( 'core/separator' => array( From 11021ea28f03cec31c9970fbae3931d7a56afa22 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Tue, 8 Nov 2022 12:13:39 -0700 Subject: [PATCH 4/6] Try fix blank space --- tests/phpunit/tests/theme/wpThemeJson.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index 0419351c7f3f2..edfe95aedc538 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -4018,7 +4018,7 @@ function test_update_separator_declarations() { ), 'default' ); - $expected = 'body { margin: 0;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;color: blue;}'; + $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;color: blue;}'; $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); $this->assertEquals( $expected, $stylesheet ); @@ -4039,7 +4039,7 @@ function test_update_separator_declarations() { ), 'default' ); - $expected = 'body { margin: 0;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;color: red;}'; + $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;color: red;}'; $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); $this->assertEquals( $expected, $stylesheet ); @@ -4059,7 +4059,7 @@ function test_update_separator_declarations() { ), 'default' ); - $expected = 'body { margin: 0;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{color: red;}'; + $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{color: red;}'; $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); $this->assertEquals( $expected, $stylesheet ); @@ -4083,7 +4083,7 @@ function test_update_separator_declarations() { ), 'default' ); - $expected = 'body { margin: 0;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;border-color: pink;color: red;}'; + $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;border-color: pink;color: red;}'; $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); $this->assertEquals( $expected, $stylesheet ); @@ -4106,7 +4106,7 @@ function test_update_separator_declarations() { ), 'default' ); - $expected = 'body { margin: 0;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;border-color: pink;}'; + $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;border-color: pink;}'; $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); $this->assertEquals( $expected, $stylesheet ); From 8a0be43f3c4c576b6ac96655fbabc67131983785 Mon Sep 17 00:00:00 2001 From: David Baumwald Date: Thu, 10 Nov 2022 12:14:06 -0500 Subject: [PATCH 5/6] Tweaks from reviews --- src/wp-includes/class-wp-theme-json.php | 35 +++--- tests/phpunit/tests/theme/wpThemeJson.php | 144 +++++++++------------- 2 files changed, 76 insertions(+), 103 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index d67a21033bf8a..d59206f3fecf5 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -1932,36 +1932,31 @@ public function get_styles_block_nodes() { * @since 6.1.1 * * @param array $declarations List of declarations. - * * @return array $declarations List of declarations filtered. */ private static function update_separator_declarations( $declarations ) { $background_matches = array_values( array_filter( $declarations, - function( $declaration ) { + static function( $declaration ) { return 'background-color' === $declaration['name']; } ) ); - if ( ! empty( $background_matches && isset( $background_matches[0]['value'] ) ) ) { - $border_color_matches = array_values( - array_filter( - $declarations, - function( $declaration ) { - return 'border-color' === $declaration['name']; - } - ) - ); - $text_color_matches = array_values( - array_filter( - $declarations, - function( $declaration ) { - return 'color' === $declaration['name']; - } - ) - ); - if ( empty( $border_color_matches ) && empty( $text_color_matches ) ) { + + if ( isset( $background_matches[0]['value'] ) ) { + $border_color_matches = false; + $text_color_matches = false; + + foreach ( $declarations as $declaration ) { + if ( 'border-color' === $declaration['name'] ) { + $border_color_matches = true; + } elseif ( 'color' === $declaration['name'] ) { + $text_color_matches = true; + } + } + + if ( ! $border_color_matches && ! $text_color_matches ) { $declarations[] = array( 'name' => 'color', 'value' => $background_matches[0]['value'], diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index edfe95aedc538..969ce41dc0cc3 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -3999,116 +3999,94 @@ function data_set_spacing_sizes_when_invalid() { } /** + * Tests the core separator block outbut based on various provided settings. + * * @ticket 56903 + * + * @dataProvider data_update_separator_declarations + * + * @param array $separator_block_settings Example separator block settings from the data provider. + * @param array $expected_output Expected output from data provider. */ - function test_update_separator_declarations() { + public function test_update_separator_declarations( $separator_block_settings, $expected_output ) { // If only background is defined, test that includes border-color to the style so it is applied on the front end. $theme_json = new WP_Theme_JSON( array( 'version' => WP_Theme_JSON::LATEST_SCHEMA, 'styles' => array( 'blocks' => array( - 'core/separator' => array( - 'color' => array( - 'background' => 'blue', - ), - ), + 'core/separator' => $separator_block_settings, ), ), ), 'default' ); - $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;color: blue;}'; + $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); - $this->assertEquals( $expected, $stylesheet ); - // If background and text are defined, do not include border-color, as text color is enough. - $theme_json = new WP_Theme_JSON( - array( - 'version' => WP_Theme_JSON::LATEST_SCHEMA, - 'styles' => array( - 'blocks' => array( - 'core/separator' => array( - 'color' => array( - 'background' => 'blue', - 'text' => 'red', - ), - ), + $this->assertSame( $expected_output, $stylesheet ); + } + + /** + * Data provider for separator declaration tests. + * + * @return array + */ + function data_update_separator_declarations() { + return array( + // If only background is defined, test that includes border-color to the style so it is applied on the front end. + 'only background' => array( + array( + 'color' => array( + 'background' => 'blue', ), ), + 'expected_output' => 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;color: blue;}', ), - 'default' - ); - $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;color: red;}'; - $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); - $this->assertEquals( $expected, $stylesheet ); - - // If only text is defined, do not include border-color, as by itself is enough. - $theme_json = new WP_Theme_JSON( - array( - 'version' => WP_Theme_JSON::LATEST_SCHEMA, - 'styles' => array( - 'blocks' => array( - 'core/separator' => array( - 'color' => array( - 'text' => 'red', - ), - ), + // If background and text are defined, do not include border-color, as text color is enough. + 'background and text, no border-color' => array( + array( + 'color' => array( + 'background' => 'blue', + 'text' => 'red', ), ), + 'expected_output' => 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;color: red;}', ), - 'default' - ); - $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{color: red;}'; - $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); - $this->assertEquals( $expected, $stylesheet ); - - // If background, text, and border-color are defined, include everything, CSS specifity will decide which to apply. - $theme_json = new WP_Theme_JSON( - array( - 'version' => WP_Theme_JSON::LATEST_SCHEMA, - 'styles' => array( - 'blocks' => array( - 'core/separator' => array( - 'color' => array( - 'background' => 'blue', - 'text' => 'red', - ), - 'border' => array( - 'color' => 'pink', - ), - ), + // If only text is defined, do not include border-color, as by itself is enough. + 'only text' => array( + array( + 'color' => array( + 'text' => 'red', ), ), + 'expected_output' => 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{color: red;}', ), - 'default' - ); - $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;border-color: pink;color: red;}'; - $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); - $this->assertEquals( $expected, $stylesheet ); - - // If background and border color are defined, include everything, CSS specifity will decide which to apply. - $theme_json = new WP_Theme_JSON( - array( - 'version' => WP_Theme_JSON::LATEST_SCHEMA, - 'styles' => array( - 'blocks' => array( - 'core/separator' => array( - 'color' => array( - 'background' => 'blue', - ), - 'border' => array( - 'color' => 'pink', - ), - ), + // If background, text, and border-color are defined, include everything, CSS specifity will decide which to apply. + 'background, text, and border-color' => array( + array( + 'color' => array( + 'background' => 'blue', + 'text' => 'red', + ), + 'border' => array( + 'color' => 'pink', ), ), + 'expected_output' => 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;border-color: pink;color: red;}', + ), + // If background and border color are defined, include everything, CSS specifity will decide which to apply. + 'background, text, and border-color' => array( + array( + 'color' => array( + 'background' => 'blue', + ), + 'border' => array( + 'color' => 'pink', + ), + ), + 'expected_output' => 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;border-color: pink;}', ), - 'default' ); - $expected = 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;border-color: pink;}'; - $stylesheet = $theme_json->get_stylesheet( array( 'styles' ) ); - $this->assertEquals( $expected, $stylesheet ); - } } From b4905cbf4c62daa1ccb272e900e78f94f0d5da74 Mon Sep 17 00:00:00 2001 From: David Baumwald Date: Thu, 10 Nov 2022 12:57:45 -0500 Subject: [PATCH 6/6] WPCS --- tests/phpunit/tests/theme/wpThemeJson.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index 969ce41dc0cc3..5f373b52e2053 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -4035,7 +4035,7 @@ public function test_update_separator_declarations( $separator_block_settings, $ function data_update_separator_declarations() { return array( // If only background is defined, test that includes border-color to the style so it is applied on the front end. - 'only background' => array( + 'only background' => array( array( 'color' => array( 'background' => 'blue', @@ -4044,7 +4044,7 @@ function data_update_separator_declarations() { 'expected_output' => 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;color: blue;}', ), // If background and text are defined, do not include border-color, as text color is enough. - 'background and text, no border-color' => array( + 'background and text, no border-color' => array( array( 'color' => array( 'background' => 'blue', @@ -4054,7 +4054,7 @@ function data_update_separator_declarations() { 'expected_output' => 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;color: red;}', ), // If only text is defined, do not include border-color, as by itself is enough. - 'only text' => array( + 'only text' => array( array( 'color' => array( 'text' => 'red', @@ -4063,7 +4063,7 @@ function data_update_separator_declarations() { 'expected_output' => 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{color: red;}', ), // If background, text, and border-color are defined, include everything, CSS specifity will decide which to apply. - 'background, text, and border-color' => array( + 'background, text, and border-color' => array( array( 'color' => array( 'background' => 'blue', @@ -4076,7 +4076,7 @@ function data_update_separator_declarations() { 'expected_output' => 'body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.wp-block-separator{background-color: blue;border-color: pink;color: red;}', ), // If background and border color are defined, include everything, CSS specifity will decide which to apply. - 'background, text, and border-color' => array( + 'background, text, and border-color' => array( array( 'color' => array( 'background' => 'blue',