Changeset 50024
- Timestamp:
- 01/26/2021 06:26:13 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r49942 r50024 217 217 $args['date_query'] = array(); 218 218 219 // Set before into date query. Date query must be specified as an array of an array.220 219 if ( isset( $registered['before'], $request['before'] ) ) { 221 $args['date_query'][0]['before'] = $request['before']; 222 } 223 224 // Set after into date query. Date query must be specified as an array of an array. 220 $args['date_query'][] = array( 221 'before' => $request['before'], 222 'column' => 'post_date', 223 ); 224 } 225 226 if ( isset( $registered['modified_before'], $request['modified_before'] ) ) { 227 $args['date_query'][] = array( 228 'before' => $request['modified_before'], 229 'column' => 'post_modified', 230 ); 231 } 232 225 233 if ( isset( $registered['after'], $request['after'] ) ) { 226 $args['date_query'][0]['after'] = $request['after']; 234 $args['date_query'][] = array( 235 'after' => $request['after'], 236 'column' => 'post_date', 237 ); 238 } 239 240 if ( isset( $registered['modified_after'], $request['modified_after'] ) ) { 241 $args['date_query'][] = array( 242 'after' => $request['modified_after'], 243 'column' => 'post_modified', 244 ); 227 245 } 228 246 … … 2629 2647 * 2630 2648 * @since 4.7.0 2649 * @since 5.4.0 The `tax_relation` query parameter was added. 2650 * @since 5.7.0 The `modified_after` and `modified_before` query parameters were added. 2631 2651 * 2632 2652 * @return array Collection parameters. … … 2639 2659 $query_params['after'] = array( 2640 2660 'description' => __( 'Limit response to posts published after a given ISO8601 compliant date.' ), 2661 'type' => 'string', 2662 'format' => 'date-time', 2663 ); 2664 2665 $query_params['modified_after'] = array( 2666 'description' => __( 'Limit response to posts modified after a given ISO8601 compliant date.' ), 2641 2667 'type' => 'string', 2642 2668 'format' => 'date-time', … … 2664 2690 $query_params['before'] = array( 2665 2691 'description' => __( 'Limit response to posts published before a given ISO8601 compliant date.' ), 2692 'type' => 'string', 2693 'format' => 'date-time', 2694 ); 2695 2696 $query_params['modified_before'] = array( 2697 'description' => __( 'Limit response to posts modified before a given ISO8601 compliant date.' ), 2666 2698 'type' => 'string', 2667 2699 'format' => 'date-time', -
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r49603 r50024 199 199 'media_type', 200 200 'mime_type', 201 'modified_after', 202 'modified_before', 201 203 'offset', 202 204 'order', … … 561 563 $request->set_param( 'after', '2016-01-15T00:00:00Z' ); 562 564 $request->set_param( 'before', '2016-01-17T00:00:00Z' ); 565 $response = rest_get_server()->dispatch( $request ); 566 $data = $response->get_data(); 567 $this->assertCount( 1, $data ); 568 $this->assertSame( $id2, $data[0]['id'] ); 569 } 570 571 /** 572 * @ticket 50617 573 */ 574 public function test_get_items_invalid_modified_date() { 575 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 576 $request->set_param( 'modified_after', rand_str() ); 577 $request->set_param( 'modified_before', rand_str() ); 578 $response = rest_get_server()->dispatch( $request ); 579 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 580 } 581 582 /** 583 * @ticket 50617 584 */ 585 public function test_get_items_valid_modified_date() { 586 $id1 = $this->factory->attachment->create_object( 587 $this->test_file, 588 0, 589 array( 590 'post_date' => '2016-01-01 00:00:00', 591 'post_mime_type' => 'image/jpeg', 592 'post_excerpt' => 'A sample caption', 593 ) 594 ); 595 $id2 = $this->factory->attachment->create_object( 596 $this->test_file, 597 0, 598 array( 599 'post_date' => '2016-01-02 00:00:00', 600 'post_mime_type' => 'image/jpeg', 601 'post_excerpt' => 'A sample caption', 602 ) 603 ); 604 $id3 = $this->factory->attachment->create_object( 605 $this->test_file, 606 0, 607 array( 608 'post_date' => '2016-01-03 00:00:00', 609 'post_mime_type' => 'image/jpeg', 610 'post_excerpt' => 'A sample caption', 611 ) 612 ); 613 $this->update_post_modified( $id1, '2016-01-15 00:00:00' ); 614 $this->update_post_modified( $id2, '2016-01-16 00:00:00' ); 615 $this->update_post_modified( $id3, '2016-01-17 00:00:00' ); 616 $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); 617 $request->set_param( 'modified_after', '2016-01-15T00:00:00Z' ); 618 $request->set_param( 'modified_before', '2016-01-17T00:00:00Z' ); 563 619 $response = rest_get_server()->dispatch( $request ); 564 620 $data = $response->get_data(); -
trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php
r49603 r50024 77 77 'include', 78 78 'menu_order', 79 'modified_after', 80 'modified_before', 79 81 'offset', 80 82 'order', … … 356 358 $request->set_param( 'after', '2016-01-15T00:00:00Z' ); 357 359 $request->set_param( 'before', '2016-01-17T00:00:00Z' ); 360 $response = rest_get_server()->dispatch( $request ); 361 $data = $response->get_data(); 362 $this->assertCount( 1, $data ); 363 $this->assertSame( $post2, $data[0]['id'] ); 364 } 365 366 /** 367 * @ticket 50617 368 */ 369 public function test_get_items_invalid_modified_date() { 370 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 371 $request->set_param( 'modified_after', rand_str() ); 372 $request->set_param( 'modified_before', rand_str() ); 373 $response = rest_get_server()->dispatch( $request ); 374 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 375 } 376 377 /** 378 * @ticket 50617 379 */ 380 public function test_get_items_valid_modified_date() { 381 $post1 = $this->factory->post->create( 382 array( 383 'post_date' => '2016-01-01 00:00:00', 384 'post_type' => 'page', 385 ) 386 ); 387 $post2 = $this->factory->post->create( 388 array( 389 'post_date' => '2016-01-02 00:00:00', 390 'post_type' => 'page', 391 ) 392 ); 393 $post3 = $this->factory->post->create( 394 array( 395 'post_date' => '2016-01-03 00:00:00', 396 'post_type' => 'page', 397 ) 398 ); 399 $this->update_post_modified( $post1, '2016-01-15 00:00:00' ); 400 $this->update_post_modified( $post2, '2016-01-16 00:00:00' ); 401 $this->update_post_modified( $post3, '2016-01-17 00:00:00' ); 402 $request = new WP_REST_Request( 'GET', '/wp/v2/pages' ); 403 $request->set_param( 'modified_after', '2016-01-15T00:00:00Z' ); 404 $request->set_param( 'modified_before', '2016-01-17T00:00:00Z' ); 358 405 $response = rest_get_server()->dispatch( $request ); 359 406 $data = $response->get_data(); -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r49603 r50024 182 182 'exclude', 183 183 'include', 184 'modified_after', 185 'modified_before', 184 186 'offset', 185 187 'order', … … 1485 1487 $request->set_param( 'after', '2016-01-15T00:00:00Z' ); 1486 1488 $request->set_param( 'before', '2016-01-17T00:00:00Z' ); 1489 $response = rest_get_server()->dispatch( $request ); 1490 $data = $response->get_data(); 1491 $this->assertCount( 1, $data ); 1492 $this->assertSame( $post2, $data[0]['id'] ); 1493 } 1494 1495 /** 1496 * @ticket 50617 1497 */ 1498 public function test_get_items_invalid_modified_date() { 1499 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1500 $request->set_param( 'modified_after', rand_str() ); 1501 $request->set_param( 'modified_before', rand_str() ); 1502 $response = rest_get_server()->dispatch( $request ); 1503 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 1504 } 1505 1506 /** 1507 * @ticket 50617 1508 */ 1509 public function test_get_items_valid_modified_date() { 1510 $post1 = $this->factory->post->create( array( 'post_date' => '2016-01-01 00:00:00' ) ); 1511 $post2 = $this->factory->post->create( array( 'post_date' => '2016-01-02 00:00:00' ) ); 1512 $post3 = $this->factory->post->create( array( 'post_date' => '2016-01-03 00:00:00' ) ); 1513 $this->update_post_modified( $post1, '2016-01-15 00:00:00' ); 1514 $this->update_post_modified( $post2, '2016-01-16 00:00:00' ); 1515 $this->update_post_modified( $post3, '2016-01-17 00:00:00' ); 1516 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 1517 $request->set_param( 'modified_after', '2016-01-15T00:00:00Z' ); 1518 $request->set_param( 'modified_before', '2016-01-17T00:00:00Z' ); 1487 1519 $response = rest_get_server()->dispatch( $request ); 1488 1520 $data = $response->get_data(); -
trunk/tests/qunit/fixtures/wp-api-generated.js
r49925 r50024 299 299 "required": false 300 300 }, 301 "modified_after": { 302 "description": "Limit response to posts modified after a given ISO8601 compliant date.", 303 "type": "string", 304 "format": "date-time", 305 "required": false 306 }, 301 307 "author": { 302 308 "description": "Limit result set to posts assigned to specific authors.", … … 319 325 "before": { 320 326 "description": "Limit response to posts published before a given ISO8601 compliant date.", 327 "type": "string", 328 "format": "date-time", 329 "required": false 330 }, 331 "modified_before": { 332 "description": "Limit response to posts modified before a given ISO8601 compliant date.", 321 333 "type": "string", 322 334 "format": "date-time", … … 1477 1489 "required": false 1478 1490 }, 1491 "modified_after": { 1492 "description": "Limit response to posts modified after a given ISO8601 compliant date.", 1493 "type": "string", 1494 "format": "date-time", 1495 "required": false 1496 }, 1479 1497 "author": { 1480 1498 "description": "Limit result set to posts assigned to specific authors.", … … 1497 1515 "before": { 1498 1516 "description": "Limit response to posts published before a given ISO8601 compliant date.", 1517 "type": "string", 1518 "format": "date-time", 1519 "required": false 1520 }, 1521 "modified_before": { 1522 "description": "Limit response to posts modified before a given ISO8601 compliant date.", 1499 1523 "type": "string", 1500 1524 "format": "date-time", … … 2540 2564 "required": false 2541 2565 }, 2566 "modified_after": { 2567 "description": "Limit response to posts modified after a given ISO8601 compliant date.", 2568 "type": "string", 2569 "format": "date-time", 2570 "required": false 2571 }, 2542 2572 "author": { 2543 2573 "description": "Limit result set to posts assigned to specific authors.", … … 2560 2590 "before": { 2561 2591 "description": "Limit response to posts published before a given ISO8601 compliant date.", 2592 "type": "string", 2593 "format": "date-time", 2594 "required": false 2595 }, 2596 "modified_before": { 2597 "description": "Limit response to posts modified before a given ISO8601 compliant date.", 2562 2598 "type": "string", 2563 2599 "format": "date-time", … … 3189 3225 "required": false 3190 3226 }, 3227 "modified_after": { 3228 "description": "Limit response to posts modified after a given ISO8601 compliant date.", 3229 "type": "string", 3230 "format": "date-time", 3231 "required": false 3232 }, 3191 3233 "before": { 3192 3234 "description": "Limit response to posts published before a given ISO8601 compliant date.", 3235 "type": "string", 3236 "format": "date-time", 3237 "required": false 3238 }, 3239 "modified_before": { 3240 "description": "Limit response to posts modified before a given ISO8601 compliant date.", 3193 3241 "type": "string", 3194 3242 "format": "date-time",
Note: See TracChangeset
for help on using the changeset viewer.