From 577309f619dbbe813d36f152d71f723898c46ef8 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 19 Dec 2024 15:29:48 +0530 Subject: [PATCH 1/4] Block theme: Test custom CSS behaviour --- tests/phpunit/tests/theme/wpThemeJson.php | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index 8fe8c7d5d0d65..fa98283bbb666 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -6119,4 +6119,30 @@ public function test_opt_in_to_block_style_variations() { $this->assertSame( $expected, $button_variations ); } + + public function test_custom_css_behaviour() { + //add_filter( 'should_load_separate_core_block_assets', '__return_false', 11 ); + $theme_json = new WP_Theme_JSON( + array( + 'version' => WP_Theme_JSON::LATEST_SCHEMA, + 'styles' => array( + 'css' => 'body {color:purple;}', + 'blocks' => array( + 'core/paragraph' => array( + 'css' => 'color:red;', + ), + ), + ), + ) + ); + + $custom_css = 'body {color:purple;}'; + $block_custom_css = ':root :where(p){color:red;}'; + + if ( version_compare( get_bloginfo( 'version' ), '6.7', '>=' ) ) { + $this->assertSame( $custom_css . $block_custom_css, $theme_json->get_stylesheet( array( 'custom-css' ) ) ); + } else { + $this->assertSame( $custom_css . $block_custom_css, $theme_json->get_custom_css() ); + } + } } From cafedb01a96537553a8e290264a3f8cf82559231 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 19 Dec 2024 16:48:00 +0530 Subject: [PATCH 2/4] Temp revert deprecated function changes --- src/wp-includes/class-wp-theme-json.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 7d1216a4515d3..0fcd29874a6bd 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -1497,12 +1497,10 @@ protected function process_blocks_custom_css( $css, $selector ) { * Returns the global styles custom CSS. * * @since 6.2.0 - * @deprecated 6.7.0 Use {@see 'get_stylesheet'} instead. * * @return string The global styles custom CSS. */ public function get_custom_css() { - _deprecated_function( __METHOD__, '6.7.0', 'get_stylesheet' ); // Add the global styles root CSS. $stylesheet = isset( $this->theme_json['styles']['css'] ) ? $this->theme_json['styles']['css'] : ''; From 70a4a9f30a25ee98a216f88b7b4a477c187ab081 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 19 Dec 2024 16:51:21 +0530 Subject: [PATCH 3/4] Remove version condition --- tests/phpunit/tests/theme/wpThemeJson.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index fa98283bbb666..f1ccbb722cfe3 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -6121,7 +6121,6 @@ public function test_opt_in_to_block_style_variations() { } public function test_custom_css_behaviour() { - //add_filter( 'should_load_separate_core_block_assets', '__return_false', 11 ); $theme_json = new WP_Theme_JSON( array( 'version' => WP_Theme_JSON::LATEST_SCHEMA, @@ -6139,10 +6138,9 @@ public function test_custom_css_behaviour() { $custom_css = 'body {color:purple;}'; $block_custom_css = ':root :where(p){color:red;}'; - if ( version_compare( get_bloginfo( 'version' ), '6.7', '>=' ) ) { - $this->assertSame( $custom_css . $block_custom_css, $theme_json->get_stylesheet( array( 'custom-css' ) ) ); - } else { - $this->assertSame( $custom_css . $block_custom_css, $theme_json->get_custom_css() ); - } + // get_custom_css() should return both CSS. + $this->assertSame( $custom_css . $block_custom_css, $theme_json->get_custom_css() ); + // Per #6750, The get_stylesheet() returns only $custom_css. + $this->assertSame( $custom_css . $block_custom_css, $theme_json->get_stylesheet( array( 'custom-css' ) ) ); } } From e2ec9063cdf6039f0b2d108d0e53410214e64ad4 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 19 Dec 2024 16:53:26 +0530 Subject: [PATCH 4/4] Fix PHPCS --- tests/phpunit/tests/theme/wpThemeJson.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index f1ccbb722cfe3..771fa2ae775c4 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -6140,7 +6140,7 @@ public function test_custom_css_behaviour() { // get_custom_css() should return both CSS. $this->assertSame( $custom_css . $block_custom_css, $theme_json->get_custom_css() ); - // Per #6750, The get_stylesheet() returns only $custom_css. + // Per #6750, The get_stylesheet() returns only $custom_css. $this->assertSame( $custom_css . $block_custom_css, $theme_json->get_stylesheet( array( 'custom-css' ) ) ); } }