| | 3995 | public function test_putting_same_publish_date_does_not_remove_floating_date() { |
| | 3996 | |
| | 3997 | wp_set_current_user( self::$superadmin_id ); |
| | 3998 | |
| | 3999 | $time = date( 'Y-m-d H:i:s' ); |
| | 4000 | |
| | 4001 | $post = self::factory()->post->create_and_get( array( |
| | 4002 | 'post_status' => 'draft', |
| | 4003 | 'post_date' => $time, |
| | 4004 | ) ); |
| | 4005 | |
| | 4006 | $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); |
| | 4007 | |
| | 4008 | $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" ); |
| | 4009 | $get->set_query_params( array( 'context' => 'edit' ) ); |
| | 4010 | |
| | 4011 | $get = rest_get_server()->dispatch( $get ); |
| | 4012 | $get_body = $get->get_data(); |
| | 4013 | |
| | 4014 | $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" ); |
| | 4015 | $put->set_body_params( $get_body ); |
| | 4016 | |
| | 4017 | $response = rest_get_server()->dispatch( $put ); |
| | 4018 | $body = $response->get_data(); |
| | 4019 | |
| | 4020 | $this->assertEquals( $get_body['date'], $body['date'] ); |
| | 4021 | $this->assertEquals( $get_body['date_gmt'], $body['date_gmt'] ); |
| | 4022 | |
| | 4023 | $this->assertEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); |
| | 4024 | } |
| | 4025 | |
| | 4026 | public function test_putting_different_publish_date_removes_floating_date() { |
| | 4027 | |
| | 4028 | wp_set_current_user( self::$superadmin_id ); |
| | 4029 | |
| | 4030 | $time = date( 'Y-m-d H:i:s' ); |
| | 4031 | $new_time = date( 'Y-m-d H:i:s', strtotime( '+1 week' ) ); |
| | 4032 | |
| | 4033 | $post = self::factory()->post->create_and_get( array( |
| | 4034 | 'post_status' => 'draft', |
| | 4035 | 'post_date' => $time, |
| | 4036 | ) ); |
| | 4037 | |
| | 4038 | $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); |
| | 4039 | |
| | 4040 | $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" ); |
| | 4041 | $get->set_query_params( array( 'context' => 'edit' ) ); |
| | 4042 | |
| | 4043 | $get = rest_get_server()->dispatch( $get ); |
| | 4044 | $get_body = $get->get_data(); |
| | 4045 | |
| | 4046 | $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" ); |
| | 4047 | $put->set_body_params( array_merge( $get_body, array( |
| | 4048 | 'date' => mysql_to_rfc3339( $new_time ), |
| | 4049 | ) ) ); |
| | 4050 | |
| | 4051 | $response = rest_get_server()->dispatch( $put ); |
| | 4052 | $body = $response->get_data(); |
| | 4053 | |
| | 4054 | $this->assertEquals( mysql_to_rfc3339( $new_time ), $body['date'] ); |
| | 4055 | |
| | 4056 | $this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); |
| | 4057 | } |
| | 4058 | |
| | 4059 | public function test_publishing_post_with_same_date_removes_floating_date() { |
| | 4060 | |
| | 4061 | wp_set_current_user( self::$superadmin_id ); |
| | 4062 | |
| | 4063 | $time = date( 'Y-m-d H:i:s' ); |
| | 4064 | |
| | 4065 | $post = self::factory()->post->create_and_get( array( |
| | 4066 | 'post_status' => 'draft', |
| | 4067 | 'post_date' => $time, |
| | 4068 | ) ); |
| | 4069 | |
| | 4070 | $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); |
| | 4071 | |
| | 4072 | $get = new WP_REST_Request( 'GET', "/wp/v2/posts/{$post->ID}" ); |
| | 4073 | $get->set_query_params( array( 'context' => 'edit' ) ); |
| | 4074 | |
| | 4075 | $get = rest_get_server()->dispatch( $get ); |
| | 4076 | $get_body = $get->get_data(); |
| | 4077 | |
| | 4078 | $put = new WP_REST_Request( 'PUT', "/wp/v2/posts/{$post->ID}" ); |
| | 4079 | $put->set_body_params( array_merge( $get_body, array( |
| | 4080 | 'status' => 'publish', |
| | 4081 | ) ) ); |
| | 4082 | |
| | 4083 | $response = rest_get_server()->dispatch( $put ); |
| | 4084 | $body = $response->get_data(); |
| | 4085 | |
| | 4086 | $this->assertEquals( $get_body['date'], $body['date'] ); |
| | 4087 | $this->assertEquals( $get_body['date_gmt'], $body['date_gmt'] ); |
| | 4088 | |
| | 4089 | $this->assertNotEquals( '0000-00-00 00:00:00', get_post( $post->ID )->post_date_gmt ); |
| | 4090 | } |
| | 4091 | |