mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for __experimentalSkiSerialization to the shadow attribute #6279
Closed
colinduwe
wants to merge
4
commits into
WordPress:trunk
from
colinduwe:enhancement/shadow-enable-skip-serialization
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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_wp_apply_shadow_support( $support, $value, $expected ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tellthemachines why the ticket number is not mention for test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for spotting that! Fixed in https://core.trac.wordpress.org/changeset/58315. |
||
$block_type = self::register_shadow_block_with_support( | ||
'test/shadow-block', | ||
array( 'shadow' => $support ) | ||
); | ||
$block_attrs = array( 'style' => array( 'shadow' => $value ) ); | ||
$actual = wp_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 ); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to add a
since
note to the docblock above; something like@since 6.6.0 Return early if __experimentalSkipSerialization is true.
(it should be added just below
@since 6.3.0
)