-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Block support: Add server-side processing for ariaLabel #69096
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 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
Prev
Previous commit
Add unit test
- Loading branch information
commit 0800493fca9cc7fe4df44f220b85f28698302b15
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| <?php | ||
| /** | ||
| * Test the aria-label block support. | ||
| * | ||
| * @package Gutenberg | ||
| */ | ||
| class WP_Block_Supports_Aria_Label_Test extends WP_UnitTestCase { | ||
| /** | ||
| * @var string|null | ||
| */ | ||
| private $test_block_name; | ||
|
|
||
| public function set_up() { | ||
| parent::set_up(); | ||
| $this->test_block_name = null; | ||
| } | ||
|
|
||
| public function tear_down() { | ||
| unregister_block_type( $this->test_block_name ); | ||
| $this->test_block_name = null; | ||
| parent::tear_down(); | ||
| } | ||
|
|
||
| /** | ||
| * Registers a new block for testing aria-label 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. | ||
| */ | ||
| private function register_aria_label_block_with_support( $block_name, $supports = array() ) { | ||
| $this->test_block_name = $block_name; | ||
| register_block_type( | ||
| $this->test_block_name, | ||
| array( | ||
| 'api_version' => 3, | ||
| 'supports' => $supports, | ||
| ) | ||
| ); | ||
| $registry = WP_Block_Type_Registry::get_instance(); | ||
|
|
||
| return $registry->get_registered( $this->test_block_name ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that position block support works as expected. | ||
| * | ||
| * @dataProvider data_aria_label_block_support | ||
| * | ||
| * @param boolean|array $support Aria label block support configuration. | ||
| * @param string $value Aria label value for attribute object. | ||
| * @param array $expected Expected aria label block support styles. | ||
| */ | ||
| public function test_gutenberg_apply_aria_label_support( $support, $value, $expected ) { | ||
| $block_type = self::register_aria_label_block_with_support( | ||
| 'test/aria-label-block', | ||
| array( 'ariaLabel' => $support ) | ||
| ); | ||
| $block_attrs = array( 'ariaLabel' => $value ); | ||
| $actual = gutenberg_apply_aria_label_support( $block_type, $block_attrs ); | ||
|
|
||
| $this->assertSame( $expected, $actual ); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider. | ||
| * | ||
| * @return array | ||
| */ | ||
| public function data_aria_label_block_support() { | ||
| return array( | ||
| 'aria-label attribute is applied' => array( | ||
| 'support' => true, | ||
| 'value' => 'Label', | ||
| 'expected' => array( 'aria-label' => 'Label' ), | ||
| ), | ||
| 'aria-label attribute is not applied if block does not support it' => array( | ||
| 'support' => false, | ||
| 'value' => 'Label', | ||
| '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.
This unit test is identical to the test in the core backport PR:
https://github.com/WordPress/wordpress-develop/pull/8274/files#diff-0f32f800b7e03fe08c378308dfb322156ea606714e2f39d095971d02add72a93
On the other hand, the following unit test cannot be included in this PR because it will not pass unless the
aria-labelattribute is allowed by default in theget_block_wrapper_attributesfunction:https://github.com/WordPress/wordpress-develop/pull/8274/files#diff-699d565e390f7fb85d4d1c7ade8706b63fe2cec31043e8e18117961ca3f7083d