-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Shadow: add unit tests for shadow support #60063
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
3b9e3d3
to
da7c03b
Compare
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.
Thanks for the quick turnaround and adding these tests @madhusudhand 🚀
They test well for me.
I appreciate these follow the existing approaches in some of our other block support tests. What do you think about using a data provider here instead?
It will make the tests a little more concise and readable as well as more aligned with how they end up being backported to core.
Diff to switch to a data provider
diff --git a/phpunit/block-supports/shadow-test.php b/phpunit/block-supports/shadow-test.php
index 89ede32621..bc0c1964e2 100644
--- a/phpunit/block-supports/shadow-test.php
+++ b/phpunit/block-supports/shadow-test.php
@@ -50,119 +50,58 @@ class WP_Block_Supports_Shadow_Test extends WP_UnitTestCase {
return $registry->get_registered( $this->test_block_name );
}
- public function test_shadow_object_with_no_styles() {
+ /**
+ * 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-object-with-no-styles',
- array(
- 'shadow' => true,
- )
+ 'test/shadow-block',
+ array( 'shadow' => $support )
);
- $block_attrs = array( 'style' => array( 'shadow' => '' ) );
+ $block_attrs = array( 'style' => array( 'shadow' => $value ) );
$actual = gutenberg_apply_shadow_support( $block_type, $block_attrs );
- $expected = array();
$this->assertSame( $expected, $actual );
}
- public function test_shadow_without_support() {
- $block_type = self::register_shadow_block_with_support(
- 'test/shadow-without-support',
- array(
- 'shadow' => false,
- )
- );
- $block_atts = array(
- 'style' => array(
- 'shadow' => '1px 1px 1px #000',
+ public function data_generate_shadow_fixtures() {
+ return array(
+ 'with no styles' => array(
+ 'support' => true,
+ 'value' => '',
+ 'expected' => array(),
),
- );
-
- $actual = gutenberg_apply_shadow_support( $block_type, $block_atts );
- $expected = array();
-
- $this->assertSame( $expected, $actual );
- }
-
- public function test_shadow_with_single_shadow() {
- $block_type = self::register_shadow_block_with_support(
- 'test/shadow-with-single-shadow',
- array(
- 'shadow' => true,
- )
- );
- $block_atts = array(
- 'style' => array(
- 'shadow' => '1px 1px 1px #000',
+ 'without support' => array(
+ 'support' => false,
+ 'value' => '1px 1px 1px #000',
+ 'expected' => array(),
),
- );
-
- $actual = gutenberg_apply_shadow_support( $block_type, $block_atts );
- $expected = array(
- 'style' => 'box-shadow:1px 1px 1px #000;',
- );
-
- $this->assertSame( $expected, $actual );
- }
-
- public function test_shadow_with_comma_separated_shadows() {
- $block_type = self::register_shadow_block_with_support(
- 'test/shadow-with-comma-separated-shadows',
- array(
- 'shadow' => true,
- )
- );
- $block_atts = array(
- 'style' => array(
- 'shadow' => '1px 1px 1px #000, 2px 2px 2px #fff',
+ 'with single shadow' => array(
+ 'support' => true,
+ 'value' => '1px 1px 1px #000',
+ 'expected' => array( 'style' => 'box-shadow:1px 1px 1px #000;' ),
),
- );
-
- $actual = gutenberg_apply_shadow_support( $block_type, $block_atts );
- $expected = array(
- 'style' => 'box-shadow:1px 1px 1px #000, 2px 2px 2px #fff;',
- );
-
- $this->assertSame( $expected, $actual );
- }
-
- public function test_shadow_with_named_shadow() {
- $block_type = self::register_shadow_block_with_support(
- 'test/shadow-with-named-shadow',
- array(
- 'shadow' => true,
- )
- );
- $block_attrs = array(
- 'style' => array(
- 'shadow' => 'var:preset|shadow|natural',
+ '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;' ),
),
- );
- $actual = gutenberg_apply_shadow_support( $block_type, $block_attrs );
- $expected = array(
- 'style' => 'box-shadow:var(--wp--preset--shadow--natural);',
- );
-
- $this->assertSame( $expected, $actual );
- }
-
- public function test_shadow_with_skipped_serialization() {
- $block_type = self::register_shadow_block_with_support(
- 'test/shadow-with-skipped-serialization',
- array(
- 'shadow' => array(
- '__experimentalSkipSerialization' => true,
- ),
- )
- );
- $block_atts = array(
- 'style' => array(
- 'shadow' => '1px 1px 1px #000',
+ '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 = gutenberg_apply_shadow_support( $block_type, $block_atts );
- $expected = array();
-
- $this->assertSame( $expected, $actual );
}
}
Thanks @aaronrobertshaw. Applied the suggested patch. It now looks neat. |
Flaky tests detected in a6ae8d7. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9190853846
|
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.
Code looks good to me; I believe it's covering the logic added in #59887 and it tests well 👍
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.
@madhusudhand Is this good to merge? |
6f139c3
to
17dc20d
Compare
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ phpunit/block-supports/shadow-test.php |
These changes to be included in WordPress/wordpress-develop#6279 which fixes https://core.trac.wordpress.org/ticket/60784 |
Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
17dc20d
to
a6ae8d7
Compare
* add unit tests for shadow support * refactor tests * Update method doc block Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> * add core pr reference --------- Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Co-authored-by: madhusudhand <madhudollu@git.wordpress.org> Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org> Co-authored-by: mikachan <mikachan@git.wordpress.org> Co-authored-by: vcanales <vcanales@git.wordpress.org>
* add unit tests for shadow support * refactor tests * Update method doc block Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> * add core pr reference --------- Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Co-authored-by: madhusudhand <madhudollu@git.wordpress.org> Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org> Co-authored-by: mikachan <mikachan@git.wordpress.org> Co-authored-by: vcanales <vcanales@git.wordpress.org>
What?
This PR adds missing PHP unit tests for Shadow support.
It tests
Testing Instructions
Not applicable.
Related fix: #59887