REST API: Add route for single styles revisions.

Adds a route for single global styles revisions: /wp/v2/global-styles/${ parentId }/revisions/${ revisionsId }
This fixes the `getRevision` actions in the core-data package.

Props ramonopoly, get_dave.
Fixes #59810.

git-svn-id: https://develop.svn.wordpress.org/trunk@57494 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Riad Benguella
2024-01-31 10:39:04 +00:00
parent 1a5ff3fc6d
commit c45f527fbd
4 changed files with 152 additions and 7 deletions
@@ -226,6 +226,7 @@ class WP_REST_Global_Styles_Revisions_Controller_Test extends WP_Test_REST_Contr
/**
* @ticket 58524
* @ticket 59810
*
* @covers WP_REST_Global_Styles_Controller::register_routes
*/
@@ -236,6 +237,11 @@ class WP_REST_Global_Styles_Revisions_Controller_Test extends WP_Test_REST_Contr
$routes,
'Global style revisions based on the given parentID route does not exist.'
);
$this->assertArrayHasKey(
'/wp/v2/global-styles/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)',
$routes,
'Single global style revisions based on the given parentID and revision ID route does not exist.'
);
}
/**
@@ -304,6 +310,38 @@ class WP_REST_Global_Styles_Revisions_Controller_Test extends WP_Test_REST_Contr
$this->check_get_revision_response( $data[2], $this->revision_1 );
}
/**
* @ticket 59810
*
* @covers WP_REST_Global_Styles_Controller::get_item
*/
public function test_get_item() {
wp_set_current_user( self::$admin_id );
$request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions/' . $this->revision_1_id );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$this->assertSame( 200, $response->get_status(), 'Response status is 200.' );
$this->check_get_revision_response( $data, $this->revision_1 );
}
/**
* @ticket 59810
*
* @covers WP_REST_Global_Styles_Controller::get_revision
*/
public function test_get_item_invalid_revision_id_should_error() {
wp_set_current_user( self::$admin_id );
$expected_error = 'rest_post_invalid_id';
$expected_status = 404;
$request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions/20000001' );
$response = rest_get_server()->dispatch( $request );
$this->assertErrorResponse( $expected_error, $response, $expected_status );
}
/**
* @ticket 58524
*
@@ -794,13 +832,6 @@ class WP_REST_Global_Styles_Revisions_Controller_Test extends WP_Test_REST_Contr
// Controller does not implement test_context_param().
}
/**
* @doesNotPerformAssertions
*/
public function test_get_item() {
// Controller does not implement get_item().
}
/**
* @doesNotPerformAssertions
*/
@@ -135,6 +135,7 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase {
'/wp/v2/comments/(?P<id>[\\d]+)',
'/wp/v2/global-styles/(?P<id>[\/\w-]+)',
'/wp/v2/global-styles/(?P<parent>[\d]+)/revisions',
'/wp/v2/global-styles/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)',
'/wp/v2/global-styles/themes/(?P<stylesheet>[\/\s%\w\.\(\)\[\]\@_\-]+)/variations',
'/wp/v2/global-styles/themes/(?P<stylesheet>[^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)',
'/wp/v2/search',