| 447 | public function test_get_items_with_orderby_include_without_include_param() { |
| 448 | $this->factory->post->create( array( 'post_status' => 'publish' ) ); |
| 449 | $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); |
| 450 | $request->set_param( 'orderby', 'include' ); |
| 451 | |
| 452 | $response = $this->server->dispatch( $request ); |
| 453 | |
| 454 | $this->assertErrorResponse( 'rest_no_include_param_defined', $response, 400 ); |
| 455 | } |
| 456 | |
| 457 | public function test_get_items_with_orderby_id() { |
| 458 | $id1 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_date' => '2016-01-13 02:26:48' ) ); |
| 459 | $id2 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_date' => '2016-01-12 02:26:48' ) ); |
| 460 | $id3 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_date' => '2016-01-11 02:26:48' ) ); |
| 461 | |
| 462 | $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); |
| 463 | $request->set_param( 'orderby', 'id' ); |
| 464 | $request->set_param( 'include', array( $id1, $id2, $id3 ) ); |
| 465 | |
| 466 | $response = $this->server->dispatch( $request ); |
| 467 | $data = $response->get_data(); |
| 468 | |
| 469 | // Default ORDER is DESC. |
| 470 | $this->assertEquals( $id3, $data[0]['id'] ); |
| 471 | $this->assertEquals( $id2, $data[1]['id'] ); |
| 472 | $this->assertEquals( $id1, $data[2]['id'] ); |
| 473 | } |
| 474 | |
| 475 | public function test_get_items_with_orderby_slug() { |
| 476 | $id1 = $this->factory->post->create( array( 'post_title' => 'ABC', 'post_name' => 'xyz', 'post_status' => 'publish' ) ); |
| 477 | $id2 = $this->factory->post->create( array( 'post_title' => 'XYZ', 'post_name' => 'abc', 'post_status' => 'publish' ) ); |
| 478 | |
| 479 | $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); |
| 480 | $request->set_param( 'orderby', 'slug' ); |
| 481 | $request->set_param( 'include', array( $id1, $id2 ) ); |
| 482 | |
| 483 | $response = $this->server->dispatch( $request ); |
| 484 | $data = $response->get_data(); |
| 485 | |
| 486 | // Default ORDER is DESC. |
| 487 | $this->assertEquals( 'xyz', $data[0]['slug'] ); |
| 488 | $this->assertEquals( 'abc', $data[1]['slug'] ); |
| 489 | } |
| 490 | |