From 9ddf515910478b1e805d1f7e3c3446d4c63e2aa0 Mon Sep 17 00:00:00 2001 From: colinduwe Date: Fri, 15 Mar 2024 09:08:55 -0700 Subject: [PATCH 1/4] add support for __experimentalSkiSerialization to the shadow attribute --- src/wp-includes/block-supports/shadow.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/block-supports/shadow.php b/src/wp-includes/block-supports/shadow.php index 0ccaf3fd44b76..776758f07f86f 100644 --- a/src/wp-includes/block-supports/shadow.php +++ b/src/wp-includes/block-supports/shadow.php @@ -52,7 +52,10 @@ function wp_register_shadow_support( $block_type ) { function wp_apply_shadow_support( $block_type, $block_attributes ) { $has_shadow_support = block_has_support( $block_type, 'shadow', false ); - if ( ! $has_shadow_support ) { + if ( + ! $has_shadow_support || + wp_should_skip_block_supports_serialization( $block_type, 'shadow' ) + ) { return array(); } From 2d66dc92cb5b9ec4dc89dfdfda8d8170bae4801e Mon Sep 17 00:00:00 2001 From: madhusudhand Date: Thu, 23 May 2024 15:58:54 +0200 Subject: [PATCH 2/4] add unit tests for shadow support --- tests/phpunit/tests/block-supports/shadow.php | 103 +++++++++++------- 1 file changed, 62 insertions(+), 41 deletions(-) diff --git a/tests/phpunit/tests/block-supports/shadow.php b/tests/phpunit/tests/block-supports/shadow.php index 0ccc5f08e45b2..7017df0ca5498 100644 --- a/tests/phpunit/tests/block-supports/shadow.php +++ b/tests/phpunit/tests/block-supports/shadow.php @@ -22,10 +22,15 @@ public function tear_down() { } /** - * @ticket 58590 + * Registers a new block for testing shadow support. + * + * @param string $block_name Name for the test block. + * @param array $supports Array defining block support configuration. + * + * @return WP_Block_Type The block type for the newly registered test block. */ - public function test_shadow_style_is_applied() { - $this->test_block_name = 'test/shadow-style-is-applied'; + private function register_shadow_block_with_support( $block_name, $supports = array() ) { + $this->test_block_name = $block_name; register_block_type( $this->test_block_name, array( @@ -35,55 +40,71 @@ public function test_shadow_style_is_applied() { 'type' => 'object', ), ), - 'supports' => array( - 'shadow' => true, - ), + 'supports' => $supports, ) ); - $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $this->test_block_name ); - $block_atts = array( - 'style' => array( - 'shadow' => '60px -16px teal', - ), - ); + $registry = WP_Block_Type_Registry::get_instance(); - $actual = wp_apply_shadow_support( $block_type, $block_atts ); - $expected = array( - 'style' => 'box-shadow:60px -16px teal;', + return $registry->get_registered( $this->test_block_name ); + } + + /** + * Tests the generation of shadow block support styles. + * + * @dataProvider data_generate_shadow_fixtures + * + * @param boolean|array $support Shadow block support configuration. + * @param string $value Shadow style value for style attribute object. + * @param array $expected Expected shadow block support styles. + */ + public function test_gutenberg_apply_shadow_support( $support, $value, $expected ) { + $block_type = self::register_shadow_block_with_support( + 'test/shadow-block', + array( 'shadow' => $support ) ); + $block_attrs = array( 'style' => array( 'shadow' => $value ) ); + $actual = gutenberg_apply_shadow_support( $block_type, $block_attrs ); $this->assertSame( $expected, $actual ); } /** - * @ticket 58590 + * Data provider. + * + * @return array */ - public function test_shadow_without_block_supports() { - $this->test_block_name = 'test/shadow-with-skipped-serialization-block-supports'; - register_block_type( - $this->test_block_name, - array( - 'api_version' => 2, - 'attributes' => array( - 'style' => array( - 'type' => 'object', - ), - ), - 'supports' => array(), - ) - ); - $registry = WP_Block_Type_Registry::get_instance(); - $block_type = $registry->get_registered( $this->test_block_name ); - $block_atts = array( - 'style' => array( - 'shadow' => '60px -16px teal', + public function data_generate_shadow_fixtures() { + return array( + 'with no styles' => array( + 'support' => true, + 'value' => '', + 'expected' => array(), + ), + 'without support' => array( + 'support' => false, + 'value' => '1px 1px 1px #000', + 'expected' => array(), + ), + 'with single shadow' => array( + 'support' => true, + 'value' => '1px 1px 1px #000', + 'expected' => array( 'style' => 'box-shadow:1px 1px 1px #000;' ), + ), + 'with comma separated shadows' => array( + 'support' => true, + 'value' => '1px 1px 1px #000, 2px 2px 2px #fff', + 'expected' => array( 'style' => 'box-shadow:1px 1px 1px #000, 2px 2px 2px #fff;' ), + ), + 'with preset shadow' => array( + 'support' => true, + 'value' => 'var:preset|shadow|natural', + 'expected' => array( 'style' => 'box-shadow:var(--wp--preset--shadow--natural);' ), + ), + 'with serialization skipped' => array( + 'support' => array( '__experimentalSkipSerialization' => true ), + 'value' => '1px 1px 1px #000', + 'expected' => array(), ), ); - - $actual = wp_apply_spacing_support( $block_type, $block_atts ); - $expected = array(); - - $this->assertSame( $expected, $actual ); } } From c7355fac0b82ab547d8dfa1ada8e68a525e34ed3 Mon Sep 17 00:00:00 2001 From: madhusudhand Date: Sat, 25 May 2024 18:14:05 +0200 Subject: [PATCH 3/4] fix unit tests --- tests/phpunit/tests/block-supports/shadow.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/block-supports/shadow.php b/tests/phpunit/tests/block-supports/shadow.php index 7017df0ca5498..06f1f7ef19269 100644 --- a/tests/phpunit/tests/block-supports/shadow.php +++ b/tests/phpunit/tests/block-supports/shadow.php @@ -57,13 +57,13 @@ private function register_shadow_block_with_support( $block_name, $supports = ar * @param string $value Shadow style value for style attribute object. * @param array $expected Expected shadow block support styles. */ - public function test_gutenberg_apply_shadow_support( $support, $value, $expected ) { + public function test_wp_apply_shadow_support( $support, $value, $expected ) { $block_type = self::register_shadow_block_with_support( 'test/shadow-block', array( 'shadow' => $support ) ); $block_attrs = array( 'style' => array( 'shadow' => $value ) ); - $actual = gutenberg_apply_shadow_support( $block_type, $block_attrs ); + $actual = wp_apply_shadow_support( $block_type, $block_attrs ); $this->assertSame( $expected, $actual ); } From a72ac7297fb53b05fa997c3361c02296bc00844d Mon Sep 17 00:00:00 2001 From: colinduwe Date: Mon, 3 Jun 2024 10:09:27 -0700 Subject: [PATCH 4/4] Add @since to docblock --- src/wp-includes/block-supports/shadow.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wp-includes/block-supports/shadow.php b/src/wp-includes/block-supports/shadow.php index 776758f07f86f..fffc72e6b88ff 100644 --- a/src/wp-includes/block-supports/shadow.php +++ b/src/wp-includes/block-supports/shadow.php @@ -43,6 +43,7 @@ function wp_register_shadow_support( $block_type ) { * This will be applied to the block markup in the front-end. * * @since 6.3.0 + * @since 6.6.0 Return early if __experimentalSkipSerialization is true. * @access private * * @param WP_Block_Type $block_type Block type.