Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Apr 4, 2022
1 parent 7eaf5ac commit 176009e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ public function __construct() {
* @return void
*/
public function register_routes() {
register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/themes/(?P<stylesheet>[\/\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,
Expand Down Expand Up @@ -65,24 +83,6 @@ public function register_routes() {
)
);

register_rest_route(
$this->namespace,
'/' . $this->rest_base . '/themes/(?P<stylesheet>[\/\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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -493,6 +493,7 @@ public function test_get_theme_items() {
),
),
),
'title' => 'variation',
),
);
$this->assertSameSetsWithIndex( $data, $expected );
Expand Down

0 comments on commit 176009e

Please sign in to comment.