From 18c542346ba6e883cc929448896aefb7ea52226d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Mon, 11 Apr 2022 16:58:43 +0200 Subject: [PATCH 1/2] Update theme.json version to 3 --- src/wp-includes/class-wp-theme-json.php | 3 ++- src/wp-includes/theme.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 5566bcfa564c5..318ea025f6809 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -382,9 +382,10 @@ class WP_Theme_JSON { * * @since 5.8.0 * @since 5.9.0 Changed value from 1 to 2. + * @since 6.0.0 Changes value from 2 to 3. * @var int */ - const LATEST_SCHEMA = 2; + const LATEST_SCHEMA = 3; /** * Constructor. diff --git a/src/wp-includes/theme.json b/src/wp-includes/theme.json index 1ef000559b30b..7a8fd135701e3 100644 --- a/src/wp-includes/theme.json +++ b/src/wp-includes/theme.json @@ -1,5 +1,5 @@ { - "version": 2, + "version": 3, "settings": { "appearanceTools": false, "border": { From a255fa41a87c6b0005da033a9ccb855976b3fdd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Mon, 11 Apr 2022 18:27:55 +0200 Subject: [PATCH 2/2] Migrate to v3 and update tests to be version independent --- src/wp-includes/class-wp-theme-json-schema.php | 4 ++++ .../rest-api/rest-global-styles-controller.php | 2 +- tests/phpunit/tests/theme/wpThemeJson.php | 14 +++++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json-schema.php b/src/wp-includes/class-wp-theme-json-schema.php index 462af763763d3..244ebcc960d8a 100644 --- a/src/wp-includes/class-wp-theme-json-schema.php +++ b/src/wp-includes/class-wp-theme-json-schema.php @@ -50,6 +50,10 @@ public static function migrate( $theme_json ) { $theme_json = self::migrate_v1_to_v2( $theme_json ); } + if ( 2 === $theme_json['version'] ) { + $theme_json['version'] = 3; + } + return $theme_json; } diff --git a/tests/phpunit/tests/rest-api/rest-global-styles-controller.php b/tests/phpunit/tests/rest-api/rest-global-styles-controller.php index c8df046ca0771..34685d21eaf4f 100644 --- a/tests/phpunit/tests/rest-api/rest-global-styles-controller.php +++ b/tests/phpunit/tests/rest-api/rest-global-styles-controller.php @@ -470,7 +470,7 @@ public function test_get_theme_items() { $data = $response->get_data(); $expected = array( array( - 'version' => 2, + 'version' => WP_Theme_JSON::LATEST_SCHEMA, 'settings' => array( 'color' => array( 'palette' => array( diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index 93f98a6d7ed7b..fba7236941416 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -2366,7 +2366,7 @@ public function test_sanitization() { $actual = $theme_json->get_raw_data(); $expected = array( - 'version' => 2, + 'version' => WP_Theme_JSON::LATEST_SCHEMA, 'styles' => array( 'spacing' => array( 'blockGap' => 'valid value', @@ -2435,7 +2435,7 @@ function test_export_data() { $theme->merge( $user ); $actual = $theme->get_data(); $expected = array( - 'version' => 2, + 'version' => WP_Theme_JSON::LATEST_SCHEMA, 'settings' => array( 'color' => array( 'palette' => array( @@ -2490,7 +2490,7 @@ function test_export_data_deals_with_empty_user_data() { $actual = $theme->get_data(); $expected = array( - 'version' => 2, + 'version' => WP_Theme_JSON::LATEST_SCHEMA, 'settings' => array( 'color' => array( 'palette' => array( @@ -2541,7 +2541,7 @@ function test_export_data_deals_with_empty_theme_data() { $actual = $user->get_data(); $expected = array( - 'version' => 2, + 'version' => WP_Theme_JSON::LATEST_SCHEMA, 'settings' => array( 'color' => array( 'palette' => array( @@ -2574,7 +2574,7 @@ function test_export_data_deals_with_empty_data() { 'theme' ); $actual_v2 = $theme_v2->get_data(); - $expected_v2 = array( 'version' => 2 ); + $expected_v2 = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA ); $this->assertEqualSetsWithIndex( $expected_v2, $actual_v2 ); $theme_v1 = new WP_Theme_JSON( @@ -2584,7 +2584,7 @@ function test_export_data_deals_with_empty_data() { 'theme' ); $actual_v1 = $theme_v1->get_data(); - $expected_v1 = array( 'version' => 2 ); + $expected_v1 = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA ); $this->assertEqualSetsWithIndex( $expected_v1, $actual_v1 ); } @@ -2608,7 +2608,7 @@ function test_export_data_sets_appearance_tools() { $actual = $theme->get_data(); $expected = array( - 'version' => 2, + 'version' => WP_Theme_JSON::LATEST_SCHEMA, 'settings' => array( 'appearanceTools' => true, 'blocks' => array(