mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
REST API: Introduce date_floating property on status endpoint response objects.
Expose a date_floating property on all status objects to permit clients (including the block editor) to make correct decisions about date handling for posts of varying status. Props mnelson4, earnjam, kadamwhite, jnylen0, nerrad, pento. See #39953. git-svn-id: https://develop.svn.wordpress.org/trunk@46252 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -153,7 +153,7 @@ class WP_Test_REST_Post_Statuses_Controller extends WP_Test_REST_Controller_Test
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
$this->assertEquals( 7, count( $properties ) );
|
||||
$this->assertEquals( 8, count( $properties ) );
|
||||
$this->assertArrayHasKey( 'name', $properties );
|
||||
$this->assertArrayHasKey( 'private', $properties );
|
||||
$this->assertArrayHasKey( 'protected', $properties );
|
||||
@@ -161,6 +161,7 @@ class WP_Test_REST_Post_Statuses_Controller extends WP_Test_REST_Controller_Test
|
||||
$this->assertArrayHasKey( 'queryable', $properties );
|
||||
$this->assertArrayHasKey( 'show_in_list', $properties );
|
||||
$this->assertArrayHasKey( 'slug', $properties );
|
||||
$this->assertArrayhasKey( 'date_floating', $properties );
|
||||
}
|
||||
|
||||
public function test_get_additional_field_registration() {
|
||||
@@ -217,6 +218,7 @@ class WP_Test_REST_Post_Statuses_Controller extends WP_Test_REST_Controller_Test
|
||||
),
|
||||
array_keys( $links )
|
||||
);
|
||||
$this->assertEquals( $status_obj->date_floating, $data['date_floating'] );
|
||||
}
|
||||
|
||||
protected function check_post_status_object_response( $response ) {
|
||||
|
||||
@@ -4413,6 +4413,119 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
|
||||
|
||||
}
|
||||
|
||||
public function test_putting_same_publish_date_does_not_remove_floating_date() {
|
||||
|
||||
wp_set_current_user( self::$superadmin_id );
|
||||
|
||||
$time = date( 'Y-m-d H:i:s' );
|
||||
|
||||
$post = self::factory()->post->create_and_get(
|
||||
array(
|
||||
'post_status' => 'draft',
|
||||
'post_date' => $time,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
|
||||
|
||||
$get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" );
|
||||
$get->set_query_params( array( 'context' => 'edit' ) );
|
||||
|
||||
$get = rest_get_server()->dispatch( $get );
|
||||
$get_body = $get->get_data();
|
||||
|
||||
$put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" );
|
||||
$put->set_body_params( $get_body );
|
||||
|
||||
$response = rest_get_server()->dispatch( $put );
|
||||
$body = $response->get_data();
|
||||
|
||||
$this->assertEquals( $get_body['date'], $body['date'] );
|
||||
$this->assertEquals( $get_body['date_gmt'], $body['date_gmt'] );
|
||||
|
||||
$this->assertEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt );
|
||||
}
|
||||
|
||||
public function test_putting_different_publish_date_removes_floating_date() {
|
||||
|
||||
wp_set_current_user( self::$superadmin_id );
|
||||
|
||||
$time = date( 'Y-m-d H:i:s' );
|
||||
$new_time = date( 'Y-m-d H:i:s', strtotime( '+1 week' ) );
|
||||
|
||||
$post = self::factory()->post->create_and_get(
|
||||
array(
|
||||
'post_status' => 'draft',
|
||||
'post_date' => $time,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
|
||||
|
||||
$get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" );
|
||||
$get->set_query_params( array( 'context' => 'edit' ) );
|
||||
|
||||
$get = rest_get_server()->dispatch( $get );
|
||||
$get_body = $get->get_data();
|
||||
|
||||
$put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" );
|
||||
$put->set_body_params(
|
||||
array_merge(
|
||||
$get_body,
|
||||
array(
|
||||
'date' => mysql_to_rfc3339( $new_time ),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$response = rest_get_server()->dispatch( $put );
|
||||
$body = $response->get_data();
|
||||
|
||||
$this->assertEquals( mysql_to_rfc3339( $new_time ), $body['date'] );
|
||||
|
||||
$this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt );
|
||||
}
|
||||
|
||||
public function test_publishing_post_with_same_date_removes_floating_date() {
|
||||
|
||||
wp_set_current_user( self::$superadmin_id );
|
||||
|
||||
$time = date( 'Y-m-d H:i:s' );
|
||||
|
||||
$post = self::factory()->post->create_and_get(
|
||||
array(
|
||||
'post_status' => 'draft',
|
||||
'post_date' => $time,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
|
||||
|
||||
$get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" );
|
||||
$get->set_query_params( array( 'context' => 'edit' ) );
|
||||
|
||||
$get = rest_get_server()->dispatch( $get );
|
||||
$get_body = $get->get_data();
|
||||
|
||||
$put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" );
|
||||
$put->set_body_params(
|
||||
array_merge(
|
||||
$get_body,
|
||||
array(
|
||||
'status' => 'publish',
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$response = rest_get_server()->dispatch( $put );
|
||||
$body = $response->get_data();
|
||||
|
||||
$this->assertEquals( $get_body['date'], $body['date'] );
|
||||
$this->assertEquals( $get_body['date_gmt'], $body['date_gmt'] );
|
||||
|
||||
$this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt );
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
_unregister_post_type( 'private-post' );
|
||||
_unregister_post_type( 'youseeme' );
|
||||
|
||||
Reference in New Issue
Block a user