Repository navigation
Block Supports: Add a helper that returns every support's classes and styles #15485
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
Open
aaronrobertshaw
wants to merge
3
commits into
WordPress:trunk
Choose a base branch
from
aaronrobertshaw:backport/block-supports-classes-and-styles-helper
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
021f363
Block Supports: Add a helper that returns every support's classes and…
aaronrobertshaw 42336cb
Tests: Add the Trac ticket number to the block supports helper test.
aaronrobertshaw aa2f1d5
Block Supports: Narrow the docblock types of the block supports helper.
aaronrobertshaw 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 hidden or 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
79 changes: 79 additions & 0 deletions
79
tests/phpunit/tests/block-supports/wpGetBlockSupportsClassesAndStyles.php
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
| /** | ||
| * @group block-supports | ||
| * | ||
| * @covers ::wp_get_block_supports_classes_and_styles | ||
| */ | ||
| class Tests_Block_Supports_WpGetBlockSupportsClassesAndStyles extends WP_UnitTestCase { | ||
| /** | ||
| * Tests that block support classes and styles are combined from block attributes. | ||
| * | ||
| * @ticket 66485 | ||
| * | ||
| * @dataProvider data_get_block_supports_classes_and_styles | ||
| * | ||
| * @param array<string, mixed>|null $block_attributes Block attributes, or null to check the guard. | ||
| * @param string[]|null $supports Supports to include. | ||
| * @param array<string, string> $expected Expected classes and styles. | ||
| */ | ||
| public function test_get_block_supports_classes_and_styles( $block_attributes, $supports, $expected ) { | ||
| $this->assertSame( $expected, wp_get_block_supports_classes_and_styles( $block_attributes, $supports ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider for {@see self::test_get_block_supports_classes_and_styles()}. | ||
| * | ||
| * @return array<string, array{ block_attributes: array<string, mixed>|null, supports: string[]|null, expected: array{ class?: non-empty-string, style?: non-empty-string } }> | ||
| */ | ||
| public static function data_get_block_supports_classes_and_styles() { | ||
| $block_attributes = array( | ||
| 'backgroundColor' => 'contrast', | ||
| 'borderColor' => 'accent-2', | ||
| 'style' => array( | ||
| 'background' => array( 'gradient' => 'linear-gradient(#000,#fff)' ), | ||
| 'border' => array( 'width' => '2px' ), | ||
| 'shadow' => '1px 1px 1px #000', | ||
| 'spacing' => array( 'padding' => array( 'top' => '10px' ) ), | ||
| ), | ||
| ); | ||
|
|
||
| return array( | ||
| 'all supports' => array( | ||
| 'block_attributes' => $block_attributes, | ||
| 'supports' => null, | ||
| 'expected' => array( | ||
| 'class' => 'has-background has-contrast-background-color has-border-color has-accent-2-border-color', | ||
| 'style' => 'background-image:linear-gradient(#000,#fff);border-width:2px;box-shadow:1px 1px 1px #000;padding-top:10px;', | ||
| ), | ||
| ), | ||
| 'selected supports' => array( | ||
| 'block_attributes' => $block_attributes, | ||
| 'supports' => array( 'shadow', 'border' ), | ||
| 'expected' => array( | ||
| 'class' => 'has-border-color has-accent-2-border-color', | ||
| 'style' => 'border-width:2px;box-shadow:1px 1px 1px #000;', | ||
| ), | ||
| ), | ||
| 'unknown support' => array( | ||
| 'block_attributes' => $block_attributes, | ||
| 'supports' => array( 'typography' ), | ||
| 'expected' => array(), | ||
| ), | ||
| 'no supports' => array( | ||
| 'block_attributes' => $block_attributes, | ||
| 'supports' => array(), | ||
| 'expected' => array(), | ||
| ), | ||
| 'empty attributes' => array( | ||
| 'block_attributes' => array(), | ||
| 'supports' => null, | ||
| 'expected' => array(), | ||
| ), | ||
| 'non-array attributes' => array( | ||
| 'block_attributes' => null, | ||
| 'supports' => null, | ||
| 'expected' => array(), | ||
| ), | ||
| ); | ||
| } | ||
| } |
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.
Bonus: