mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-07 09:49:04 +00:00
Block Editor: Backport the Global Styles Variations endpoint.
This include the /global-styles/themes/{theme}/variations rest endpoint into core.
The endpoint will be used by the site editor to display alternative theme styles to the user.
Props gziolo, oandregal.
See #55505.
git-svn-id: https://develop.svn.wordpress.org/trunk@53072 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"version": 2,
|
||||
"settings": {
|
||||
"color": {
|
||||
"palette": [
|
||||
{
|
||||
"slug": "foreground",
|
||||
"color": "#3F67C6",
|
||||
"name": "Foreground"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"styles": {
|
||||
"blocks": {
|
||||
"core/post-title": {
|
||||
"typography": {
|
||||
"fontWeight": "700"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,11 @@ class WP_REST_Global_Styles_Controller_Test extends WP_Test_REST_Controller_Test
|
||||
$routes['/wp/v2/global-styles/themes/(?P<stylesheet>[^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)'],
|
||||
'Theme global styles route does not have exactly one element'
|
||||
);
|
||||
$this->assertArrayHasKey(
|
||||
'/wp/v2/global-styles/themes/(?P<stylesheet>[\/\s%\w\.\(\)\[\]\@_\-]+)/variations',
|
||||
$routes,
|
||||
'Theme global styles variations route does not exist'
|
||||
);
|
||||
}
|
||||
|
||||
public function test_context_param() {
|
||||
@@ -455,4 +460,42 @@ class WP_REST_Global_Styles_Controller_Test extends WP_Test_REST_Controller_Test
|
||||
$this->assertArrayHasKey( 'settings', $properties, 'Schema properties array does not have "settings" key' );
|
||||
$this->assertArrayHasKey( 'title', $properties, 'Schema properties array does not have "title" key' );
|
||||
}
|
||||
|
||||
|
||||
public function test_get_theme_items() {
|
||||
wp_set_current_user( self::$admin_id );
|
||||
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(
|
||||
array(
|
||||
'version' => 2,
|
||||
'settings' => array(
|
||||
'color' => array(
|
||||
'palette' => array(
|
||||
'theme' => array(
|
||||
array(
|
||||
'slug' => 'foreground',
|
||||
'color' => '#3F67C6',
|
||||
'name' => 'Foreground',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'styles' => array(
|
||||
'blocks' => array(
|
||||
'core/post-title' => array(
|
||||
'typography' => array(
|
||||
'fontWeight' => '700',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'title' => 'variation',
|
||||
),
|
||||
);
|
||||
$this->assertSameSetsWithIndex( $data, $expected );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase {
|
||||
'/wp/v2/comments',
|
||||
'/wp/v2/comments/(?P<id>[\\d]+)',
|
||||
'/wp/v2/global-styles/(?P<id>[\/\w-]+)',
|
||||
'/wp/v2/global-styles/themes/(?P<stylesheet>[\/\s%\w\.\(\)\[\]\@_\-]+)/variations',
|
||||
'/wp/v2/global-styles/themes/(?P<stylesheet>[^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)',
|
||||
'/wp/v2/search',
|
||||
'/wp/v2/block-renderer/(?P<name>[a-z0-9-]+/[a-z0-9-]+)',
|
||||
|
||||
Reference in New Issue
Block a user