Changeset 40605
- Timestamp:
- 05/10/2017 06:51:28 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r40602 r40605 2131 2131 'default' => 'date', 2132 2132 'enum' => array( 2133 'author', 2133 2134 'date', 2134 'relevance',2135 2135 'id', 2136 2136 'include', 2137 'modified', 2138 'parent', 2139 'relevance', 2140 'slug', 2137 2141 'title', 2138 'slug',2139 2142 ), 2140 2143 ); -
trunk/tests/phpunit/includes/testcase.php
r40564 r40605 869 869 return $id; 870 870 } 871 872 /** 873 * There's no way to change post_modified through WP functions. 874 */ 875 protected function update_post_modified( $post_id, $date ) { 876 global $wpdb; 877 return $wpdb->update( 878 $wpdb->posts, 879 array( 880 'post_modified' => $date, 881 'post_modified_gmt' => $date, 882 ), 883 array( 884 'ID' => $post_id, 885 ), 886 array( 887 '%s', 888 '%s', 889 ), 890 array( 891 '%d', 892 ) 893 ); 894 } 871 895 } -
trunk/tests/phpunit/tests/query/dateQuery.php
r36789 r40605 999 999 $this->assertEqualSets( $expected, $q->posts ); 1000 1000 } 1001 1002 /** Helpers **********************************************************/1003 1004 /**1005 * There's no way to change post_modified through the API.1006 */1007 protected function update_post_modified( $post_id, $date ) {1008 global $wpdb;1009 return $wpdb->update(1010 $wpdb->posts,1011 array(1012 'post_modified' => $date,1013 'post_modified_gmt' => $date,1014 ),1015 array(1016 'ID' => $post_id,1017 ),1018 array(1019 '%s',1020 '%s',1021 ),1022 array(1023 '%d',1024 )1025 );1026 }1027 1001 } -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r40602 r40605 266 266 $response = $this->server->dispatch( $request ); 267 267 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 268 } 269 270 public function test_get_items_orderby_author_query() { 271 $id2 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_author' => self::$editor_id ) ); 272 $id3 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_author' => self::$editor_id ) ); 273 $id1 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_author' => self::$author_id ) ); 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', 'author' ); 278 279 $response = $this->server->dispatch( $request ); 280 $data = $response->get_data(); 281 282 $this->assertEquals( 200, $response->get_status() ); 283 $this->assertEquals( self::$author_id, $data[0]['author'] ); 284 $this->assertEquals( self::$editor_id, $data[1]['author'] ); 285 $this->assertEquals( self::$editor_id, $data[2]['author'] ); 286 287 $this->assertPostsOrderedBy( '{posts}.post_author DESC' ); 288 } 289 290 public function test_get_items_orderby_modified_query() { 291 $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 292 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 293 $id3 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 294 295 $this->update_post_modified( $id1, '2016-04-20 4:26:20' ); 296 $this->update_post_modified( $id2, '2016-02-01 20:24:02' ); 297 $this->update_post_modified( $id3, '2016-02-21 12:24:02' ); 298 299 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 300 $request->set_param( 'include', array( $id1, $id2, $id3 ) ); 301 $request->set_param( 'orderby', 'modified' ); 302 303 $response = $this->server->dispatch( $request ); 304 $data = $response->get_data(); 305 306 $this->assertEquals( 200, $response->get_status() ); 307 $this->assertEquals( $id1, $data[0]['id'] ); 308 $this->assertEquals( $id3, $data[1]['id'] ); 309 $this->assertEquals( $id2, $data[2]['id'] ); 310 311 $this->assertPostsOrderedBy( '{posts}.post_modified DESC' ); 312 } 313 314 public function test_get_items_orderby_parent_query() { 315 $id1 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page' ) ); 316 $id2 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page' ) ); 317 $id3 = $this->factory->post->create( array( 'post_status' => 'publish', 'post_type' => 'page', 'post_parent' => $id1 ) ); 318 319 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 320 $request->set_param( 'include', array( $id1, $id2, $id3 ) ); 321 $request->set_param( 'orderby', 'parent' ); 322 323 $response = $this->server->dispatch( $request ); 324 $data = $response->get_data(); 325 326 $this->assertEquals( 200, $response->get_status() ); 327 $this->assertEquals( $id3, $data[0]['id'] ); 328 // Check ordering. Default ORDER is DESC. 329 $this->assertEquals( $id1, $data[0]['parent'] ); 330 $this->assertEquals( 0, $data[1]['parent'] ); 331 $this->assertEquals( 0, $data[2]['parent'] ); 332 333 $this->assertPostsOrderedBy( '{posts}.post_parent DESC' ); 268 334 } 269 335 -
trunk/tests/qunit/fixtures/wp-api-generated.js
r40378 r40605 227 227 "default": "date", 228 228 "enum": [ 229 "author", 229 230 "date", 230 "relevance",231 231 "id", 232 232 "include", 233 "title", 234 "slug" 233 "modified", 234 "parent", 235 "relevance", 236 "slug", 237 "title" 235 238 ], 236 239 "description": "Sort collection by object attribute.", … … 845 848 "default": "date", 846 849 "enum": [ 850 "author", 847 851 "date", 848 "relevance",849 852 "id", 850 853 "include", 854 "modified", 855 "parent", 856 "relevance", 857 "slug", 851 858 "title", 852 "slug",853 859 "menu_order" 854 860 ], … … 1380 1386 "default": "date", 1381 1387 "enum": [ 1388 "author", 1382 1389 "date", 1383 "relevance",1384 1390 "id", 1385 1391 "include", 1386 "title", 1387 "slug" 1392 "modified", 1393 "parent", 1394 "relevance", 1395 "slug", 1396 "title" 1388 1397 ], 1389 1398 "description": "Sort collection by object attribute.",
Note: See TracChangeset
for help on using the changeset viewer.