mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Editor: Simplify usage of block_has_support() function by supporting a string.
Most block feature checks are for a single feature string, and for such cases it is not intuitive to require an array for the `$feature` parameter of the `block_has_support()` function. This changeset brings it in line with other functions like `post_type_supports()`, allowing to pass a string for the `$feature`. An array is still supported for more complex cases where support for sub-features needs to be determined. This change furthermore includes a very minor performance tweak by avoiding calls to the `_wp_array_get()` function if a single feature string is being checked for. Props thekt12, nihar007, mukesh27, swissspidy. Fixes #58532. git-svn-id: https://develop.svn.wordpress.org/trunk@56382 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -682,6 +682,81 @@ class Tests_Blocks_wpBlock extends WP_UnitTestCase {
|
||||
$this->assertFalse( $gradient_support );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 58532
|
||||
*
|
||||
* @dataProvider data_block_has_support_string
|
||||
*
|
||||
* @param array $block_data Block data.
|
||||
* @param string $support Support string to check.
|
||||
* @param bool $expected Expected result.
|
||||
*/
|
||||
public function test_block_has_support_string( $block_data, $support, $expected, $message ) {
|
||||
$this->registry->register( 'core/example', $block_data );
|
||||
$block_type = $this->registry->get_registered( 'core/example' );
|
||||
$has_support = block_has_support( $block_type, $support );
|
||||
$this->assertEquals( $expected, $has_support, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_block_has_support_string
|
||||
*/
|
||||
public function data_block_has_support_string() {
|
||||
return array(
|
||||
array(
|
||||
array(),
|
||||
'color',
|
||||
false,
|
||||
'Block with empty support array.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'supports' => array(
|
||||
'align' => array( 'wide', 'full' ),
|
||||
'fontSize' => true,
|
||||
'color' => array(
|
||||
'link' => true,
|
||||
'gradient' => false,
|
||||
),
|
||||
),
|
||||
),
|
||||
'align',
|
||||
true,
|
||||
'Feature present in support array.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'supports' => array(
|
||||
'align' => array( 'wide', 'full' ),
|
||||
'fontSize' => true,
|
||||
'color' => array(
|
||||
'link' => true,
|
||||
'gradient' => false,
|
||||
),
|
||||
),
|
||||
),
|
||||
'anchor',
|
||||
false,
|
||||
'Feature not present in support array.',
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'supports' => array(
|
||||
'align' => array( 'wide', 'full' ),
|
||||
'fontSize' => true,
|
||||
'color' => array(
|
||||
'link' => true,
|
||||
'gradient' => false,
|
||||
),
|
||||
),
|
||||
),
|
||||
array( 'align' ),
|
||||
true,
|
||||
'Feature present in support array, single element array.',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 51612
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user