From 35498b3f72410522642b263dba6b8c661f179171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Thu, 9 Dec 2021 14:10:36 +0100 Subject: [PATCH] Only opt-in into tools if it is actually true --- .../class-wp-theme-json-gutenberg.php | 7 ++- phpunit/class-wp-theme-json-test.php | 55 ++++++++++++++++++- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-gutenberg.php b/lib/compat/wordpress-5.9/class-wp-theme-json-gutenberg.php index 0ae828ac5c9f5..1f2a6c00bb5da 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-gutenberg.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-gutenberg.php @@ -359,13 +359,16 @@ public function __construct( $theme_json = array(), $origin = 'theme' ) { private static function maybe_opt_in_into_settings( $theme_json ) { $new_theme_json = $theme_json; - if ( isset( $new_theme_json['settings']['appearanceTools'] ) ) { + if ( + isset( $new_theme_json['settings']['appearanceTools'] ) && + true === $new_theme_json['settings']['appearanceTools'] + ) { self::do_opt_in_into_settings( $new_theme_json['settings'] ); } if ( isset( $new_theme_json['settings']['blocks'] ) && is_array( $new_theme_json['settings']['blocks'] ) ) { foreach ( $new_theme_json['settings']['blocks'] as &$block ) { - if ( isset( $block['appearanceTools'] ) ) { + if ( isset( $block['appearanceTools'] ) && ( true === $block['appearanceTools'] ) ) { self::do_opt_in_into_settings( $block ); } } diff --git a/phpunit/class-wp-theme-json-test.php b/phpunit/class-wp-theme-json-test.php index add58e8e0d2f9..4637ec7504fc8 100644 --- a/phpunit/class-wp-theme-json-test.php +++ b/phpunit/class-wp-theme-json-test.php @@ -188,12 +188,15 @@ function test_get_settings_presets_are_keyed_by_origin() { $this->assertEqualSetsWithIndex( $expected_no_origin, $actual_no_origin ); } - function test_get_settings_using_opt_in_key() { + function test_get_settings_appearance_true_opts_in() { $theme_json = new WP_Theme_JSON_Gutenberg( array( 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, 'settings' => array( 'appearanceTools' => true, + 'spacing' => array( + 'blockGap' => false, // This should override appearanceTools. + ), 'blocks' => array( 'core/paragraph' => array( 'typography' => array( @@ -223,7 +226,7 @@ function test_get_settings_using_opt_in_key() { 'link' => true, ), 'spacing' => array( - 'blockGap' => true, + 'blockGap' => false, 'margin' => true, 'padding' => true, ), @@ -261,6 +264,54 @@ function test_get_settings_using_opt_in_key() { $this->assertEqualSetsWithIndex( $expected, $actual ); } + function test_get_settings_appearance_false_does_not_opt_in() { + $theme_json = new WP_Theme_JSON_Gutenberg( + array( + 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA, + 'settings' => array( + 'appearanceTools' => false, + 'border' => array( + 'width' => true, + ), + 'blocks' => array( + 'core/paragraph' => array( + 'typography' => array( + 'lineHeight' => false, + ), + ), + 'core/group' => array( + 'typography' => array( + 'lineHeight' => false, + ), + ), + ), + ), + ) + ); + + $actual = $theme_json->get_settings(); + $expected = array( + 'appearanceTools' => false, + 'border' => array( + 'width' => true, + ), + 'blocks' => array( + 'core/paragraph' => array( + 'typography' => array( + 'lineHeight' => false, + ), + ), + 'core/group' => array( + 'typography' => array( + 'lineHeight' => false, + ), + ), + ), + ); + + $this->assertEqualSetsWithIndex( $expected, $actual ); + } + function test_get_stylesheet_support_for_shorthand_and_longhand_values() { $theme_json = new WP_Theme_JSON_Gutenberg( array(