From 176009e4d3e822c5e704249828d44c3f6a6c961e Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 4 Apr 2022 13:55:56 +0100 Subject: [PATCH] Fix tests --- .../class-wp-theme-json-resolver.php | 2 +- ...class-wp-rest-global-styles-controller.php | 36 +++++++++---------- .../styles/variation.json | 0 .../rest-global-styles-controller.php | 5 +-- 4 files changed, 22 insertions(+), 21 deletions(-) rename tests/phpunit/data/themedir1/{theme1 => block-theme}/styles/variation.json (100%) diff --git a/src/wp-includes/class-wp-theme-json-resolver.php b/src/wp-includes/class-wp-theme-json-resolver.php index ba066c8271eb5..ac3d28be6c7d3 100644 --- a/src/wp-includes/class-wp-theme-json-resolver.php +++ b/src/wp-includes/class-wp-theme-json-resolver.php @@ -467,7 +467,7 @@ public static function get_style_variations() { $decoded_file = wp_json_file_decode( $path, array( 'associative' => true ) ); if ( is_array( $decoded_file ) ) { $translated = static::translate( $decoded_file, wp_get_theme()->get( 'TextDomain' ) ); - $variation = ( new WP_Theme_JSON_Gutenberg( $translated ) )->get_raw_data(); + $variation = ( new WP_Theme_JSON( $translated ) )->get_raw_data(); if ( empty( $variation['title'] ) ) { $variation['title'] = basename( $path, '.json' ); } diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php index e621fd36bb1bf..5d0c4ede2bb3c 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php @@ -38,6 +38,24 @@ public function __construct() { * @return void */ public function register_routes() { + register_rest_route( + $this->namespace, + '/' . $this->rest_base . '/themes/(?P[\/\s%\w\.\(\)\[\]\@_\-]+)/variations', + array( + array( + 'methods' => WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_theme_items' ), + 'permission_callback' => array( $this, 'get_theme_items_permissions_check' ), + 'args' => array( + 'stylesheet' => array( + 'description' => __( 'The theme identifier' ), + 'type' => 'string', + ), + ), + ), + ) + ); + // List themes global styles. register_rest_route( $this->namespace, @@ -65,24 +83,6 @@ public function register_routes() { ) ); - register_rest_route( - $this->namespace, - '/' . $this->rest_base . '/themes/(?P[\/\s%\w\.\(\)\[\]\@_\-]+)/variations', - array( - array( - 'methods' => WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_theme_items' ), - 'permission_callback' => array( $this, 'get_theme_items_permissions_check' ), - 'args' => array( - 'stylesheet' => array( - 'description' => __( 'The theme identifier', 'gutenberg' ), - 'type' => 'string', - ), - ), - ), - ) - ); - // Lists/updates a single global style variation based on the given id. register_rest_route( $this->namespace, diff --git a/tests/phpunit/data/themedir1/theme1/styles/variation.json b/tests/phpunit/data/themedir1/block-theme/styles/variation.json similarity index 100% rename from tests/phpunit/data/themedir1/theme1/styles/variation.json rename to tests/phpunit/data/themedir1/block-theme/styles/variation.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 164d0bc1e15e0..7f4f2b06cb8bd 100644 --- a/tests/phpunit/tests/rest-api/rest-global-styles-controller.php +++ b/tests/phpunit/tests/rest-api/rest-global-styles-controller.php @@ -464,8 +464,8 @@ public function test_get_item_schema() { public function test_get_theme_items() { wp_set_current_user( self::$admin_id ); - switch_theme( 'theme1' ); - $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/themes/theme1/variations' ); + switch_theme( 'block-theme' ); + $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/themes/block-theme/variations' ); $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); $expected = array( @@ -493,6 +493,7 @@ public function test_get_theme_items() { ), ), ), + 'title' => 'variation', ), ); $this->assertSameSetsWithIndex( $data, $expected );