From 0167cea79170697eea78ce7b513fd0796649c627 Mon Sep 17 00:00:00 2001 From: Joe Hoyle Date: Thu, 26 Jan 2017 15:15:07 +0000 Subject: [PATCH] REST API: Fix unit tests for posts out of bounds errors Previously we were assuming pagination headers would be sent when the request for posts is out of bounds. Instead presume it will return an error. See #39061. git-svn-id: https://develop.svn.wordpress.org/trunk@39991 602fd350-edb4-49c9-b593-d223f7449a82 --- .../phpunit/tests/rest-api/rest-posts-controller.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index d907c68ea8..f48709ef15 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -543,7 +543,7 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $response = $this->server->dispatch( $request ); $this->assertCount( 2, $response->get_data() ); // 'offset' takes priority over 'page' - $request->set_param( 'page', 3 ); + $request->set_param( 'page', 2 ); $response = $this->server->dispatch( $request ); $this->assertCount( 2, $response->get_data() ); // Invalid 'offset' should error @@ -771,18 +771,13 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te ), rest_url( '/wp/v2/posts' ) ); $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) ); + // Out of bounds $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); $request->set_param( 'page', 8 ); $response = $this->server->dispatch( $request ); $headers = $response->get_headers(); - $this->assertEquals( 51, $headers['X-WP-Total'] ); - $this->assertEquals( 6, $headers['X-WP-TotalPages'] ); - $prev_link = add_query_arg( array( - 'page' => 6, - ), rest_url( '/wp/v2/posts' ) ); - $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] ); - $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) ); + $this->assertErrorResponse( 'rest_post_invalid_page_number', $response, 400 ); // With query params. $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );