diff --git a/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php b/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php index b01ada9be28ff..ab9f980c9ee63 100644 --- a/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php +++ b/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php @@ -245,17 +245,33 @@ public function test_register_routes() { } /** + * @dataProvider data_readable_http_methods * @ticket 58524 + * @ticket 56481 * * @covers WP_REST_Global_Styles_Controller::get_items + * + * @param string $method The HTTP method to use. */ - public function test_get_items_missing_parent() { + public function test_get_items_missing_parent( $method ) { wp_set_current_user( self::$admin_id ); - $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions' ); + $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . REST_TESTS_IMPOSSIBLY_HIGH_NUMBER . '/revisions' ); $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( 'rest_post_invalid_parent', $response, 404 ); } + /** + * Data provider intended to provide HTTP method names for testing GET and HEAD requests. + * + * @return array + */ + public static function data_readable_http_methods() { + return array( + 'GET request' => array( 'GET' ), + 'HEAD request' => array( 'HEAD' ), + ); + } + /** * Utility function to check the items in WP_REST_Global_Styles_Controller::get_items * against the expected values. @@ -327,16 +343,20 @@ public function test_get_item() { } /** + * @dataProvider data_readable_http_methods * @ticket 59810 + * @ticket 56481 * * @covers WP_REST_Global_Styles_Controller::get_revision + * + * @param string $method The HTTP method to use. */ - public function test_get_item_invalid_revision_id_should_error() { + public function test_get_item_invalid_revision_id_should_error( $method ) { 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' ); + $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions/20000001' ); $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( $expected_error, $response, $expected_status ); @@ -419,14 +439,18 @@ public function test_get_item_schema() { } /** + * @dataProvider data_readable_http_methods * @ticket 58524 * @ticket 60131 + * @ticket 56481 * * @covers WP_REST_Global_Styles_Controller::get_item_permissions_check + * + * @param string $method The HTTP method to use. */ - public function test_get_item_permissions_check() { + public function test_get_item_permissions_check( $method ) { wp_set_current_user( self::$author_id ); - $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); + $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( 'rest_cannot_read', $response, 403 ); @@ -435,13 +459,15 @@ public function test_get_item_permissions_check() { /** * Tests the pagination header of the first page. * - * Duplicate of WP_Test_REST_Revisions_Controller::test_get_items_pagination_header_of_the_first_page - * + * @dataProvider data_readable_http_methods * @ticket 58524 + * @ticket 56481 * * @covers WP_REST_Global_Styles_Controller::get_items + * + * @param string $method The HTTP method to use. */ - public function test_get_items_pagination_header_of_the_first_page() { + public function test_get_items_pagination_header_of_the_first_page( $method ) { wp_set_current_user( self::$admin_id ); $rest_route = '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions'; @@ -449,7 +475,7 @@ public function test_get_items_pagination_header_of_the_first_page() { $total_pages = (int) ceil( $this->total_revisions / $per_page ); $page = 1; // First page. - $request = new WP_REST_Request( 'GET', $rest_route ); + $request = new WP_REST_Request( $method, $rest_route ); $request->set_query_params( array( 'per_page' => $per_page, @@ -476,11 +502,15 @@ 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 * + * @dataProvider data_readable_http_methods * @ticket 58524 + * @ticket 56481 * * @covers WP_REST_Global_Styles_Controller::get_items + * + * @param string $method The HTTP method to use. */ - public function test_get_items_pagination_header_of_the_last_page() { + public function test_get_items_pagination_header_of_the_last_page( $method ) { wp_set_current_user( self::$admin_id ); $rest_route = '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions'; @@ -488,7 +518,7 @@ public function test_get_items_pagination_header_of_the_last_page() { $total_pages = (int) ceil( $this->total_revisions / $per_page ); $page = 2; // Last page. - $request = new WP_REST_Request( 'GET', $rest_route ); + $request = new WP_REST_Request( $method, $rest_route ); $request->set_query_params( array( 'per_page' => $per_page, @@ -514,18 +544,22 @@ 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 * + * @dataProvider data_readable_http_methods * @ticket 58524 + * @ticket 56481 * * @covers WP_REST_Global_Styles_Controller::get_items + * + * @param string $method The HTTP method to use. */ - public function test_get_items_invalid_per_page_should_error() { + public function test_get_items_invalid_per_page_should_error( $method ) { wp_set_current_user( self::$admin_id ); $per_page = -1; // Invalid number. $expected_error = 'rest_invalid_param'; $expected_status = 400; - $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); + $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); $request->set_param( 'per_page', $per_page ); $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( $expected_error, $response, $expected_status ); @@ -536,11 +570,15 @@ 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 * + * @dataProvider data_readable_http_methods * @ticket 58524 + * @ticket 56481 * * @covers WP_REST_Global_Styles_Controller::get_items + * + * @param string $method The HTTP method to use. */ - public function test_get_items_out_of_bounds_page_should_error() { + public function test_get_items_out_of_bounds_page_should_error( $method ) { wp_set_current_user( self::$admin_id ); $per_page = 2; @@ -549,7 +587,7 @@ public function test_get_items_out_of_bounds_page_should_error() { $expected_error = 'rest_revision_invalid_page_number'; $expected_status = 400; - $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); + $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); $request->set_query_params( array( 'per_page' => $per_page, @@ -565,11 +603,15 @@ 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 * + * @dataProvider data_readable_http_methods * @ticket 58524 + * @ticket 56481 * * @covers WP_REST_Global_Styles_Controller::get_items + * + * @param string $method The HTTP method to use. */ - public function test_get_items_invalid_max_pages_should_error() { + public function test_get_items_invalid_max_pages_should_error( $method ) { wp_set_current_user( self::$admin_id ); $per_page = 2; @@ -577,7 +619,7 @@ public function test_get_items_invalid_max_pages_should_error() { $expected_error = 'rest_revision_invalid_page_number'; $expected_status = 400; - $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); + $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); $request->set_query_params( array( 'per_page' => $per_page, @@ -689,11 +731,15 @@ 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 * + * @dataProvider data_readable_http_methods * @ticket 58524 + * @ticket 56481 * * @covers WP_REST_Global_Styles_Controller::get_items + * + * @param string $method The HTTP method to use. */ - public function test_get_items_total_revisions_offset_should_return_empty_data() { + public function test_get_items_total_revisions_offset_should_return_empty_data( $method ) { wp_set_current_user( self::$admin_id ); $per_page = 2; @@ -701,7 +747,7 @@ public function test_get_items_total_revisions_offset_should_return_empty_data() $expected_error = 'rest_revision_invalid_offset_number'; $expected_status = 400; - $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); + $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); $request->set_query_params( array( 'offset' => $offset, @@ -717,11 +763,15 @@ 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 * + * @dataProvider data_readable_http_methods * @ticket 58524 + * @ticket 56481 * * @covers WP_REST_Global_Styles_Controller::get_items + * + * @param string $method The HTTP method to use. */ - public function test_get_items_out_of_bound_offset_should_error() { + public function test_get_items_out_of_bound_offset_should_error( $method ) { wp_set_current_user( self::$admin_id ); $per_page = 2; @@ -729,7 +779,7 @@ public function test_get_items_out_of_bound_offset_should_error() { $expected_error = 'rest_revision_invalid_offset_number'; $expected_status = 400; - $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); + $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); $request->set_query_params( array( 'offset' => $offset, @@ -745,11 +795,15 @@ 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 * + * @dataProvider data_readable_http_methods * @ticket 58524 + * @ticket 56481 * * @covers WP_REST_Global_Styles_Controller::get_items + * + * @param string $method The HTTP method to use. */ - public function test_get_items_impossible_high_number_offset_should_error() { + public function test_get_items_impossible_high_number_offset_should_error( $method ) { wp_set_current_user( self::$admin_id ); $per_page = 2; @@ -757,7 +811,7 @@ public function test_get_items_impossible_high_number_offset_should_error() { $expected_error = 'rest_revision_invalid_offset_number'; $expected_status = 400; - $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); + $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); $request->set_query_params( array( 'offset' => $offset, @@ -773,11 +827,15 @@ 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 * + * @dataProvider data_readable_http_methods * @ticket 58524 + * @ticket 56481 * * @covers WP_REST_Global_Styles_Controller::get_items + * + * @param string $method The HTTP method to use. */ - public function test_get_items_invalid_offset_should_error() { + public function test_get_items_invalid_offset_should_error( $method ) { wp_set_current_user( self::$admin_id ); $per_page = 2; @@ -785,7 +843,7 @@ public function test_get_items_invalid_offset_should_error() { $expected_error = 'rest_invalid_param'; $expected_status = 400; - $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); + $request = new WP_REST_Request( $method, '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); $request->set_query_params( array( 'offset' => $offset,