WordPress.org

Make WordPress Core

Changeset 39991


Ignore:
Timestamp:
01/26/2017 03:15:07 PM (2 years ago)
Author:
joehoyle
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r39967 r39991  
    544544        $this->assertCount( 2, $response->get_data() );
    545545        // 'offset' takes priority over 'page'
    546         $request->set_param( 'page', 3 );
     546        $request->set_param( 'page', 2 );
    547547        $response = $this->server->dispatch( $request );
    548548        $this->assertCount( 2, $response->get_data() );
     
    772772        $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
    773773        $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) );
     774
    774775        // Out of bounds
    775776        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     
    777778        $response = $this->server->dispatch( $request );
    778779        $headers = $response->get_headers();
    779         $this->assertEquals( 51, $headers['X-WP-Total'] );
    780         $this->assertEquals( 6, $headers['X-WP-TotalPages'] );
    781         $prev_link = add_query_arg( array(
    782             'page'    => 6,
    783             ), rest_url( '/wp/v2/posts' ) );
    784         $this->assertContains( '<' . $prev_link . '>; rel="prev"', $headers['Link'] );
    785         $this->assertFalse( stripos( $headers['Link'], 'rel="next"' ) );
     780        $this->assertErrorResponse( 'rest_post_invalid_page_number', $response, 400 );
    786781
    787782        // With query params.
Note: See TracChangeset for help on using the changeset viewer.