WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/26/2021 06:26:13 PM (3 months ago)
Author:
johnbillion
Message:

REST API: Introduce modified_before and modified_after query parameters for the posts endpoints.

These parameters work just the same as before and after except they operate on the post modified date instead of the post published date.

Props claytoncollie, TimothyBlynJacobs, hellofromTonya

Fixes #50617

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r49603 r50024  
    182182                'exclude',
    183183                'include',
     184                'modified_after',
     185                'modified_before',
    184186                'offset',
    185187                'order',
     
    14851487        $request->set_param( 'after', '2016-01-15T00:00:00Z' );
    14861488        $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' );
    14871519        $response = rest_get_server()->dispatch( $request );
    14881520        $data     = $response->get_data();
Note: See TracChangeset for help on using the changeset viewer.