Skip to content
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

Global Styles: Fix handling of booleans when stabilizing block supports #67552

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backport-changelog/6.8/7069.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ https://github.com/WordPress/wordpress-develop/pull/7069
* https://github.com/WordPress/gutenberg/pull/63401
* https://github.com/WordPress/gutenberg/pull/66918
* https://github.com/WordPress/gutenberg/pull/67018
* https://github.com/WordPress/gutenberg/pull/67552
25 changes: 15 additions & 10 deletions lib/compat/wordpress-6.8/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ function gutenberg_stabilize_experimental_block_supports( $args ) {
}

$stabilize_config = function ( $unstable_config, $stable_support_key ) use ( $experimental_support_properties, $common_experimental_properties ) {
if ( ! is_array( $unstable_config ) ) {
return $unstable_config;
}

$stable_config = array();
foreach ( $unstable_config as $key => $value ) {
// Get stable key from support-specific map, common properties map, or keep original.
Expand Down Expand Up @@ -116,18 +120,19 @@ function gutenberg_stabilize_experimental_block_supports( $args ) {
( $key_positions[ $support ] ?? PHP_INT_MAX ) <
( $key_positions[ $stable_support_key ] ?? PHP_INT_MAX );

if ( is_array( $args['supports'][ $stable_support_key ] ) ) {
/*
* To merge the alternative support config effectively, it also needs to be
* stabilized before merging to keep stabilized and experimental flags in
* sync.
*/
$args['supports'][ $stable_support_key ] = $stabilize_config( $args['supports'][ $stable_support_key ], $stable_support_key );
$stable_config = $experimental_first
/*
* To merge the alternative support config effectively, it also needs to be
* stabilized before merging to keep stabilized and experimental flags in
* sync.
*/
$args['supports'][ $stable_support_key ] = $stabilize_config( $args['supports'][ $stable_support_key ], $stable_support_key );
// Prevents reprocessing this support as it was stabilized above.
$done[ $stable_support_key ] = true;

if ( is_array( $stable_config ) && is_array( $args['supports'][ $stable_support_key ] ) ) {
$stable_config = $experimental_first
? array_merge( $stable_config, $args['supports'][ $stable_support_key ] )
: array_merge( $args['supports'][ $stable_support_key ], $stable_config );
// Prevents reprocessing this support as it was merged above.
$done[ $stable_support_key ] = true;
} else {
$stable_config = $experimental_first
? $args['supports'][ $stable_support_key ]
Expand Down
100 changes: 100 additions & 0 deletions phpunit/block-supports/border-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,4 +730,104 @@ public function test_should_stabilize_border_supports_using_order_based_merge()
);
$this->assertSame( $expected, $actual, 'Merged stabilized border block support config does not match when stable keys are first.' );
}

/**
* Tests that boolean border support configurations are handled correctly.
*
* @dataProvider data_boolean_border_supports
*
* @param array $supports The supports configuration to test.
* @param boolean|array $expected_value The expected final border support value.
*/
public function test_should_handle_boolean_border_supports( $supports, $expected_value ) {
$args = array(
'supports' => $supports,
);

$actual = gutenberg_stabilize_experimental_block_supports( $args );

$this->assertSame( $expected_value, $actual['supports']['border'] );
}

/**
* Data provider for boolean border support tests.
*
* @return array Test parameters.
*/
public function data_boolean_border_supports() {
return array(
'experimental true only' => array(
array(
'__experimentalBorder' => true,
),
true,
),
'experimental false only' => array(
array(
'__experimentalBorder' => false,
),
false,
),
'experimental true before stable false' => array(
array(
'__experimentalBorder' => true,
'border' => false,
),
false,
),
'stable true before experimental false' => array(
array(
'border' => true,
'__experimentalBorder' => false,
),
false,
),
'experimental array before stable boolean' => array(
array(
'__experimentalBorder' => array(
'color' => true,
'width' => true,
),
'border' => false,
),
false,
),
'stable array before experimental boolean' => array(
array(
'border' => array(
'color' => true,
'width' => true,
),
'__experimentalBorder' => true,
),
true,
),
'experimental boolean before stable array' => array(
array(
'__experimentalBorder' => true,
'border' => array(
'color' => true,
'width' => true,
),
),
array(
'color' => true,
'width' => true,
),
),
'stable boolean before experimental array' => array(
array(
'border' => false,
'__experimentalBorder' => array(
'color' => true,
'width' => true,
),
),
array(
'color' => true,
'width' => true,
),
),
);
}
}
Loading