Ticket #38693: 38693.7.diff
File 38693.7.diff, 8.6 KB (added by , 8 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 23017d7..4862fae 100644
a b class WP_REST_Posts_Controller extends WP_REST_Controller { 2130 2130 'type' => 'string', 2131 2131 'default' => 'date', 2132 2132 'enum' => array( 2133 'author', 2133 2134 'date', 2134 'relevance',2135 2135 'id', 2136 2136 'include', 2137 'title', 2137 'modified', 2138 'parent', 2139 'relevance', 2138 2140 'slug', 2141 'title', 2139 2142 ), 2140 2143 ); 2141 2144 -
tests/phpunit/includes/testcase.php
diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index ba1c47f..c8c4857 100644
a b class WP_UnitTestCase extends PHPUnit_Framework_TestCase { 868 868 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) ); 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 } -
tests/phpunit/tests/query/dateQuery.php
diff --git a/tests/phpunit/tests/query/dateQuery.php b/tests/phpunit/tests/query/dateQuery.php index 4af981c..9e3bca6 100644
a b class Tests_Query_DateQuery extends WP_UnitTestCase { 998 998 $expected = array( $p1, $p4, $p5, ); 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 } -
tests/phpunit/tests/rest-api/rest-posts-controller.php
diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 43e7275..c86879c 100644
a b class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te 267 267 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 268 268 } 269 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' ); 334 } 335 270 336 public function test_get_items_exclude_query() { 271 337 $id1 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); 272 338 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) ); -
tests/qunit/fixtures/wp-api-generated.js
diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 0df5b9e..3f1f304 100644
a b mockedApiResponse.Schema = { 226 226 "required": false, 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.", 237 240 "type": "string" … … mockedApiResponse.Schema = { 844 847 "required": false, 845 848 "default": "date", 846 849 "enum": [ 850 "author", 847 851 "date", 848 "relevance",849 852 "id", 850 853 "include", 851 "title", 854 "modified", 855 "parent", 856 "relevance", 852 857 "slug", 858 "title", 853 859 "menu_order" 854 860 ], 855 861 "description": "Sort collection by object attribute.", … … mockedApiResponse.Schema = { 1379 1385 "required": false, 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.", 1390 1399 "type": "string"