From bf5bed8bb4595c2fae9e714ce64c32d30197351d Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Mon, 8 Jan 2024 10:37:23 +1100 Subject: [PATCH] Add has-background classname output --- src/wp-includes/block-supports/background.php | 1 + .../block-supports/wpRenderBackgroundSupport.php | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/block-supports/background.php b/src/wp-includes/block-supports/background.php index 62c6d83c0d730..0eac8eb810aa8 100644 --- a/src/wp-includes/block-supports/background.php +++ b/src/wp-includes/block-supports/background.php @@ -113,6 +113,7 @@ function wp_render_background_support( $block_content, $block ) { $updated_style .= $styles['css']; $tags->set_attribute( 'style', $updated_style ); + $tags->add_class( 'has-background' ); } return $tags->get_updated_html(); diff --git a/tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php b/tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php index f5867a9f3ce3d..83ea7cd47c972 100644 --- a/tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php +++ b/tests/phpunit/tests/block-supports/wpRenderBackgroundSupport.php @@ -136,7 +136,7 @@ public function data_background_block_support() { 'source' => 'file', ), ), - 'expected_wrapper' => '
Content
', + 'expected_wrapper' => '
Content
', 'wrapper' => '
Content
', ), 'background image style with contain, position, and repeat is applied' => array( @@ -153,7 +153,7 @@ public function data_background_block_support() { 'backgroundRepeat' => 'no-repeat', 'backgroundSize' => 'contain', ), - 'expected_wrapper' => '
Content
', + 'expected_wrapper' => '
Content
', 'wrapper' => '
Content
', ), 'background image style is appended if a style attribute already exists' => array( @@ -168,8 +168,8 @@ public function data_background_block_support() { 'source' => 'file', ), ), - 'expected_wrapper' => '
Content
', - 'wrapper' => '
Content
', + 'expected_wrapper' => '
Content
', + 'wrapper' => '
Content
', ), 'background image style is appended if a style attribute containing multiple styles already exists' => array( 'theme_name' => 'block-theme-child-with-fluid-typography', @@ -183,8 +183,8 @@ public function data_background_block_support() { 'source' => 'file', ), ), - 'expected_wrapper' => '
Content
', - 'wrapper' => '
Content
', + 'expected_wrapper' => '
Content
', + 'wrapper' => '
Content
', ), 'background image style is not applied if the block does not support background image' => array( 'theme_name' => 'block-theme-child-with-fluid-typography',