- Timestamp:
- 10/26/2016 09:36:29 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r38911 r38968 68 68 'context', 69 69 'exclude', 70 'filter',71 70 'include', 72 71 'offset', … … 98 97 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 99 98 $request->set_query_params( array( 100 'filter' => array( 'year' => 2008 ), 101 ) ); 102 $response = $this->server->dispatch( $request ); 103 $this->assertEquals( array(), $response->get_data() ); 99 'author' => REST_TESTS_IMPOSSIBLY_HIGH_NUMBER, 100 ) ); 101 $response = $this->server->dispatch( $request ); 102 103 $this->assertEmpty( $response->get_data() ); 104 104 $this->assertEquals( 200, $response->get_status() ); 105 105 } … … 310 310 // Permit stickies 311 311 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 312 $request->set_param( ' filter', array( 'ignore_sticky_posts' => false ));312 $request->set_param( 'ignore_sticky_posts', false ); 313 313 $response = $this->server->dispatch( $request ); 314 314 $data = $response->get_data(); … … 577 577 } 578 578 579 public function test_get_items_private_ filter_query_var() {579 public function test_get_items_private_status_query_var() { 580 580 // Private query vars inaccessible to unauthorized users 581 581 wp_set_current_user( 0 ); 582 582 $draft_id = $this->factory->post->create( array( 'post_status' => 'draft' ) ); 583 583 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 584 $request->set_param( 'filter', array( 'post_status' => 'draft' ) ); 585 $response = $this->server->dispatch( $request ); 586 $data = $response->get_data(); 587 $this->assertCount( 1, $data ); 588 $this->assertEquals( $this->post_id, $data[0]['id'] ); 584 $request->set_param( 'status', 'draft' ); 585 $response = $this->server->dispatch( $request ); 586 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 587 589 588 // But they are accessible to authorized users 590 589 wp_set_current_user( $this->editor_id ); … … 600 599 $response = $this->server->dispatch( $request ); 601 600 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 602 }603 604 public function test_get_items_invalid_posts_per_page_ignored() {605 // This test ensures that filter[posts_per_page] is ignored, and that -1606 // cannot be used to sidestep per_page's valid range to retrieve all posts607 for ( $i = 0; $i < 20; $i++ ) {608 $this->factory->post->create( array( 'post_status' => 'publish' ) );609 }610 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );611 $request->set_query_params( array( 'filter' => array( 'posts_per_page' => -1 ) ) );612 $response = $this->server->dispatch( $request );613 $this->assertCount( 10, $response->get_data() );614 601 } 615 602
Note: See TracChangeset
for help on using the changeset viewer.