| | 230 | public function test_get_items_orderby_author_query() { |
| | 231 | $id2 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_author' => self::$editor_id ) ); |
| | 232 | $id3 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_author' => self::$editor_id ) ); |
| | 233 | $id1 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_author' => self::$author_id ) ); |
| | 234 | |
| | 235 | $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); |
| | 236 | $request->set_param( 'include', array( $id1, $id2, $id3 ) ); |
| | 237 | $request->set_param( 'orderby', 'author' ); |
| | 238 | |
| | 239 | $response = $this->server->dispatch( $request ); |
| | 240 | $data = $response->get_data(); |
| | 241 | |
| | 242 | $this->assertEquals( 200, $response->get_status() ); |
| | 243 | $this->assertEquals( self::$author_id, $data[0]['author'] ); |
| | 244 | $this->assertEquals( self::$editor_id, $data[1]['author'] ); |
| | 245 | $this->assertEquals( self::$editor_id, $data[2]['author'] ); |
| | 246 | } |
| | 247 | |
| | 248 | public function test_get_items_orderby_modified_query() { |
| | 249 | $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); |
| | 250 | $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); |
| | 251 | $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); |
| | 252 | |
| | 253 | $this->update_post_modified( $id1, '2016-04-20 4:26:20' ); |
| | 254 | $this->update_post_modified( $id2, '2016-02-01 20:24:02' ); |
| | 255 | $this->update_post_modified( $id3, '2016-02-21 12:24:02' ); |
| | 256 | |
| | 257 | $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); |
| | 258 | $request->set_param( 'include', array( $id1, $id2, $id3 ) ); |
| | 259 | $request->set_param( 'orderby', 'modified' ); |
| | 260 | |
| | 261 | $response = $this->server->dispatch( $request ); |
| | 262 | $data = $response->get_data(); |
| | 263 | |
| | 264 | $this->assertEquals( 200, $response->get_status() ); |
| | 265 | $this->assertEquals( $id1, $data[0]['id'] ); |
| | 266 | $this->assertEquals( $id3, $data[1]['id'] ); |
| | 267 | $this->assertEquals( $id2, $data[2]['id'] ); |
| | 268 | } |
| | 269 | |
| | 270 | public function test_get_items_orderby_none_query() { |
| | 271 | $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); |
| | 272 | $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); |
| | 273 | $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); |
| | 274 | |
| | 275 | $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); |
| | 276 | $request->set_param( 'include', array( $id1, $id2, $id3 ) ); |
| | 277 | $request->set_param( 'orderby', 'none' ); |
| | 278 | |
| | 279 | $response = $this->server->dispatch( $request ); |
| | 280 | $data = $response->get_data(); |
| | 281 | |
| | 282 | $this->assertEquals( 200, $response->get_status() ); |
| | 283 | } |
| | 284 | |
| | 285 | public function test_get_items_orderby_parent_query() { |
| | 286 | $id1 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page' ) ); |
| | 287 | $id2 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page' ) ); |
| | 288 | $id3 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', 'post_parent' => $id1 ) ); |
| | 289 | |
| | 290 | $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); |
| | 291 | $request->set_param( 'include', array( $id1, $id2, $id3 ) ); |
| | 292 | $request->set_param( 'orderby', 'parent' ); |
| | 293 | |
| | 294 | $response = $this->server->dispatch( $request ); |
| | 295 | $data = $response->get_data(); |
| | 296 | |
| | 297 | $this->assertEquals( 200, $response->get_status() ); |
| | 298 | $this->assertEquals( $id3, $data[0]['id'] ); |
| | 299 | // Check ordering. Default ORDER is DESC. |
| | 300 | $this->assertEquals( $id1, $data[0]['parent'] ); |
| | 301 | $this->assertEquals( 0, $data[1]['parent'] ); |
| | 302 | $this->assertEquals( 0, $data[2]['parent'] ); |
| | 303 | } |
| | 304 | |