mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-01 11:14:36 +00:00
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 git-svn-id: https://develop.svn.wordpress.org/trunk@50024 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -198,6 +198,8 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
'include',
|
||||
'media_type',
|
||||
'mime_type',
|
||||
'modified_after',
|
||||
'modified_before',
|
||||
'offset',
|
||||
'order',
|
||||
'orderby',
|
||||
@@ -566,6 +568,60 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
|
||||
$this->assertSame( $id2, $data[0]['id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50617
|
||||
*/
|
||||
public function test_get_items_invalid_modified_date() {
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/media' );
|
||||
$request->set_param( 'modified_after', rand_str() );
|
||||
$request->set_param( 'modified_before', rand_str() );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50617
|
||||
*/
|
||||
public function test_get_items_valid_modified_date() {
|
||||
$id1 = $this->factory->attachment->create_object(
|
||||
$this->test_file,
|
||||
0,
|
||||
array(
|
||||
'post_date' => '2016-01-01 00:00:00',
|
||||
'post_mime_type' => 'image/jpeg',
|
||||
'post_excerpt' => 'A sample caption',
|
||||
)
|
||||
);
|
||||
$id2 = $this->factory->attachment->create_object(
|
||||
$this->test_file,
|
||||
0,
|
||||
array(
|
||||
'post_date' => '2016-01-02 00:00:00',
|
||||
'post_mime_type' => 'image/jpeg',
|
||||
'post_excerpt' => 'A sample caption',
|
||||
)
|
||||
);
|
||||
$id3 = $this->factory->attachment->create_object(
|
||||
$this->test_file,
|
||||
0,
|
||||
array(
|
||||
'post_date' => '2016-01-03 00:00:00',
|
||||
'post_mime_type' => 'image/jpeg',
|
||||
'post_excerpt' => 'A sample caption',
|
||||
)
|
||||
);
|
||||
$this->update_post_modified( $id1, '2016-01-15 00:00:00' );
|
||||
$this->update_post_modified( $id2, '2016-01-16 00:00:00' );
|
||||
$this->update_post_modified( $id3, '2016-01-17 00:00:00' );
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/media' );
|
||||
$request->set_param( 'modified_after', '2016-01-15T00:00:00Z' );
|
||||
$request->set_param( 'modified_before', '2016-01-17T00:00:00Z' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertCount( 1, $data );
|
||||
$this->assertSame( $id2, $data[0]['id'] );
|
||||
}
|
||||
|
||||
public function test_get_item() {
|
||||
$attachment_id = $this->factory->attachment->create_object(
|
||||
$this->test_file,
|
||||
|
||||
@@ -76,6 +76,8 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te
|
||||
'exclude',
|
||||
'include',
|
||||
'menu_order',
|
||||
'modified_after',
|
||||
'modified_before',
|
||||
'offset',
|
||||
'order',
|
||||
'orderby',
|
||||
@@ -361,6 +363,51 @@ class WP_Test_REST_Pages_Controller extends WP_Test_REST_Post_Type_Controller_Te
|
||||
$this->assertSame( $post2, $data[0]['id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50617
|
||||
*/
|
||||
public function test_get_items_invalid_modified_date() {
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/pages' );
|
||||
$request->set_param( 'modified_after', rand_str() );
|
||||
$request->set_param( 'modified_before', rand_str() );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50617
|
||||
*/
|
||||
public function test_get_items_valid_modified_date() {
|
||||
$post1 = $this->factory->post->create(
|
||||
array(
|
||||
'post_date' => '2016-01-01 00:00:00',
|
||||
'post_type' => 'page',
|
||||
)
|
||||
);
|
||||
$post2 = $this->factory->post->create(
|
||||
array(
|
||||
'post_date' => '2016-01-02 00:00:00',
|
||||
'post_type' => 'page',
|
||||
)
|
||||
);
|
||||
$post3 = $this->factory->post->create(
|
||||
array(
|
||||
'post_date' => '2016-01-03 00:00:00',
|
||||
'post_type' => 'page',
|
||||
)
|
||||
);
|
||||
$this->update_post_modified( $post1, '2016-01-15 00:00:00' );
|
||||
$this->update_post_modified( $post2, '2016-01-16 00:00:00' );
|
||||
$this->update_post_modified( $post3, '2016-01-17 00:00:00' );
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/pages' );
|
||||
$request->set_param( 'modified_after', '2016-01-15T00:00:00Z' );
|
||||
$request->set_param( 'modified_before', '2016-01-17T00:00:00Z' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertCount( 1, $data );
|
||||
$this->assertSame( $post2, $data[0]['id'] );
|
||||
}
|
||||
|
||||
public function test_get_item() {
|
||||
|
||||
}
|
||||
|
||||
@@ -181,6 +181,8 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
|
||||
'context',
|
||||
'exclude',
|
||||
'include',
|
||||
'modified_after',
|
||||
'modified_before',
|
||||
'offset',
|
||||
'order',
|
||||
'orderby',
|
||||
@@ -1490,6 +1492,36 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
|
||||
$this->assertSame( $post2, $data[0]['id'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50617
|
||||
*/
|
||||
public function test_get_items_invalid_modified_date() {
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
|
||||
$request->set_param( 'modified_after', rand_str() );
|
||||
$request->set_param( 'modified_before', rand_str() );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 50617
|
||||
*/
|
||||
public function test_get_items_valid_modified_date() {
|
||||
$post1 = $this->factory->post->create( array( 'post_date' => '2016-01-01 00:00:00' ) );
|
||||
$post2 = $this->factory->post->create( array( 'post_date' => '2016-01-02 00:00:00' ) );
|
||||
$post3 = $this->factory->post->create( array( 'post_date' => '2016-01-03 00:00:00' ) );
|
||||
$this->update_post_modified( $post1, '2016-01-15 00:00:00' );
|
||||
$this->update_post_modified( $post2, '2016-01-16 00:00:00' );
|
||||
$this->update_post_modified( $post3, '2016-01-17 00:00:00' );
|
||||
$request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
|
||||
$request->set_param( 'modified_after', '2016-01-15T00:00:00Z' );
|
||||
$request->set_param( 'modified_before', '2016-01-17T00:00:00Z' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$this->assertCount( 1, $data );
|
||||
$this->assertSame( $post2, $data[0]['id'] );
|
||||
}
|
||||
|
||||
public function test_get_items_all_post_formats() {
|
||||
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' );
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
|
||||
Reference in New Issue
Block a user