Skip to content

Commit

Permalink
REST API: updates test annotations for global styles revisions
Browse files Browse the repository at this point in the history
Adds `@covers` annotations to tests and fixes incorrect spacing.

Props ramonopoly, mukesh27.
See #58524.


git-svn-id: https://develop.svn.wordpress.org/trunk@56105 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
tellthemachines committed Jun 29, 2023
1 parent b830d56 commit 41277f1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ protected function prepare_links( $id ) {
);

if ( post_type_supports( $this->post_type, 'revisions' ) ) {
$revisions = wp_get_latest_revision_id_and_total_count( $id );
$revisions_count = ! is_wp_error( $revisions ) ? $revisions['count'] : 0;
$revisions_base = sprintf( '/%s/%d/revisions', $base, $id );
$revisions = wp_get_latest_revision_id_and_total_count( $id );
$revisions_count = ! is_wp_error( $revisions ) ? $revisions['count'] : 0;
$revisions_base = sprintf( '/%s/%d/revisions', $base, $id );
$links['version-history'] = array(
'href' => rest_url( $revisions_base ),
'count' => $revisions_count,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class WP_REST_Global_Styles_Revisions_Controller_Test extends WP_Test_REST_Contr
*/
private $revision_3_id;


/**
* Create fake data before our tests run.
*
Expand Down Expand Up @@ -225,11 +224,10 @@ public function set_up() {
$this->revision_3_id = $this->revision_3->ID;
}


/**
* @covers WP_REST_Global_Styles_Controller::register_routes
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::register_routes
*/
public function test_register_routes() {
$routes = rest_get_server()->get_routes();
Expand All @@ -241,9 +239,9 @@ public function test_register_routes() {
}

/**
* @covers WP_REST_Global_Styles_Controller::get_items
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_missing_parent() {
wp_set_current_user( self::$admin_id );
Expand Down Expand Up @@ -281,9 +279,9 @@ protected function check_get_revision_response( $response_revision_item, $revisi
}

/**
* @covers WP_REST_Global_Styles_Controller::get_items
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items() {
wp_set_current_user( self::$admin_id );
Expand All @@ -307,9 +305,9 @@ public function test_get_items() {
}

/**
* @covers WP_REST_Global_Styles_Controller::get_items
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_eligible_roles() {
wp_set_current_user( self::$second_admin_id );
Expand Down Expand Up @@ -339,9 +337,9 @@ public function test_get_items_eligible_roles() {
}

/**
* @covers WP_REST_Global_Styles_Controller::get_items with context arg.
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items with context arg.
*/
public function test_get_item_embed_context() {
wp_set_current_user( self::$admin_id );
Expand All @@ -360,9 +358,9 @@ public function test_get_item_embed_context() {
}

/**
* @covers WP_REST_Global_Styles_Controller::get_item_schema
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_item_schema
*/
public function test_get_item_schema() {
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );
Expand All @@ -383,9 +381,9 @@ public function test_get_item_schema() {
}

/**
* @covers WP_REST_Global_Styles_Controller::get_item_permissions_check
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_item_permissions_check
*/
public function test_get_item_permissions_check() {
wp_set_current_user( self::$author_id );
Expand All @@ -401,6 +399,8 @@ public function test_get_item_permissions_check() {
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_pagination_header_of_the_first_page
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_pagination_header_of_the_first_page() {
wp_set_current_user( self::$admin_id );
Expand Down Expand Up @@ -438,6 +438,8 @@ public function test_get_items_pagination_header_of_the_first_page() {
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_pagination_header_of_the_last_page
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_pagination_header_of_the_last_page() {
wp_set_current_user( self::$admin_id );
Expand Down Expand Up @@ -474,6 +476,8 @@ public function test_get_items_pagination_header_of_the_last_page() {
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_invalid_per_page_should_error
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_invalid_per_page_should_error() {
wp_set_current_user( self::$admin_id );
Expand All @@ -494,6 +498,8 @@ public function test_get_items_invalid_per_page_should_error() {
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_out_of_bounds_page_should_error
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_out_of_bounds_page_should_error() {
wp_set_current_user( self::$admin_id );
Expand Down Expand Up @@ -521,6 +527,8 @@ public function test_get_items_out_of_bounds_page_should_error() {
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_invalid_max_pages_should_error
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_invalid_max_pages_should_error() {
wp_set_current_user( self::$admin_id );
Expand All @@ -547,6 +555,8 @@ public function test_get_items_invalid_max_pages_should_error() {
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_default_query_should_fetch_all_revisons
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_default_query_should_fetch_all_revisons() {
wp_set_current_user( self::$admin_id );
Expand All @@ -558,13 +568,14 @@ public function test_get_items_default_query_should_fetch_all_revisons() {
$this->assertCount( $expected_count, $response->get_data() );
}


/**
* Tests that 'offset' query shouldn't work without 'per_page' (fallback -1).
*
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_offset_should_not_work_without_per_page
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_offset_should_not_work_without_per_page() {
wp_set_current_user( self::$admin_id );
Expand All @@ -584,6 +595,8 @@ public function test_get_items_offset_should_not_work_without_per_page() {
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_offset_should_work_with_per_page
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_offset_should_work_with_per_page() {
wp_set_current_user( self::$admin_id );
Expand All @@ -609,6 +622,8 @@ public function test_get_items_offset_should_work_with_per_page() {
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_offset_should_take_priority_over_page
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_offset_should_take_priority_over_page() {
wp_set_current_user( self::$admin_id );
Expand Down Expand Up @@ -636,6 +651,8 @@ public function test_get_items_offset_should_take_priority_over_page() {
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_total_revisions_offset_should_return_empty_data
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_total_revisions_offset_should_return_empty_data() {
wp_set_current_user( self::$admin_id );
Expand All @@ -662,6 +679,8 @@ public function test_get_items_total_revisions_offset_should_return_empty_data()
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_out_of_bound_offset_should_error
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_out_of_bound_offset_should_error() {
wp_set_current_user( self::$admin_id );
Expand All @@ -688,6 +707,8 @@ public function test_get_items_out_of_bound_offset_should_error() {
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_impossible_high_number_offset_should_error
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_impossible_high_number_offset_should_error() {
wp_set_current_user( self::$admin_id );
Expand All @@ -714,6 +735,8 @@ public function test_get_items_impossible_high_number_offset_should_error() {
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_invalid_offset_should_error
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_invalid_offset_should_error() {
wp_set_current_user( self::$admin_id );
Expand Down Expand Up @@ -741,6 +764,8 @@ public function test_get_items_invalid_offset_should_error() {
* Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_out_of_bounds_page_should_not_error_if_offset
*
* @ticket 58524
*
* @covers WP_REST_Global_Styles_Controller::get_items
*/
public function test_get_items_out_of_bounds_page_should_not_error_if_offset() {
wp_set_current_user( self::$admin_id );
Expand Down

0 comments on commit 41277f1

Please sign in to comment.