Ticket #38883: 38883.diff
File 38883.diff, 4.9 KB (added by , 8 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
1324 1324 } 1325 1325 1326 1326 if ( ! empty( $schema['properties']['date_gmt'] ) ) { 1327 $data['date_gmt'] = $this->prepare_date_response( $post->post_date_gmt ); 1327 // For drafts, date_gmt will not be set, in which case shim the value based off 1328 // the date field with offsets applied. 1329 if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) { 1330 $post_date_gmt = date( 'Y-m-d H:i:s', strtotime( $post->post_date ) + ( get_option( 'gmt_offset' ) * 3600 ) ); 1331 } else { 1332 $post_date_gmt = $post->post_date_gmt; 1333 } 1334 $data['date_gmt'] = $this->prepare_date_response( $post_date_gmt ); 1328 1335 } 1329 1336 1330 1337 if ( ! empty( $schema['properties']['guid'] ) ) { … … 1340 1347 } 1341 1348 1342 1349 if ( ! empty( $schema['properties']['modified_gmt'] ) ) { 1343 $data['modified_gmt'] = $this->prepare_date_response( $post->post_modified_gmt ); 1350 // For drafts, date_gmt will not be set, in which case shim the value based off 1351 // the date field with offsets applied. 1352 if ( '0000-00-00 00:00:00' === $post->post_modified_gmt ) { 1353 $post_modified_gmt = date( 'Y-m-d H:i:s', strtotime( $post->post_modified ) + ( get_option( 'gmt_offset' ) * 3600 ) ); 1354 } else { 1355 $post_modified_gmt = $post->post_modified_gmt; 1356 } 1357 $data['modified_gmt'] = $this->prepare_date_response( $post_modified_gmt ); 1344 1358 } 1345 1359 1346 1360 if ( ! empty( $schema['properties']['password'] ) ) { -
tests/phpunit/includes/testcase-rest-post-type-controller.php
10 10 $this->assertEquals( $post->post_name, $data['slug'] ); 11 11 $this->assertEquals( get_permalink( $post->ID ), $data['link'] ); 12 12 if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) { 13 $this->assertNull( $data['date_gmt'] ); 13 $post_date_gmt = date( 'Y-m-d H:i:s', strtotime( $post->post_date ) + ( get_option( 'gmt_offset' ) * 3600 ) ); 14 $this->assertEquals( mysql_to_rfc3339( $post_date_gmt ), $data['date_gmt'] ); 14 15 } 15 16 $this->assertEquals( mysql_to_rfc3339( $post->post_date ), $data['date'] ); 16 17 17 18 if ( '0000-00-00 00:00:00' === $post->post_modified_gmt ) { 18 $this->assertNull( $data['modified_gmt'] ); 19 $post_modified_gmt = date( 'Y-m-d H:i:s', strtotime( $post->post_modified ) + ( get_option( 'gmt_offset' ) * 3600 ) ); 20 $this->assertEquals( mysql_to_rfc3339( $post_modified_gmt ), $data['modified_gmt'] ); 19 21 } 20 22 $this->assertEquals( mysql_to_rfc3339( $post->post_modified ), $data['modified'] ); 21 23 … … 141 143 $this->assertEquals( $post->post_status, $data['status'] ); 142 144 143 145 if ( '0000-00-00 00:00:00' === $post->post_date_gmt ) { 144 $this->assertNull( $data['date_gmt'] ); 146 $post_date_gmt = date( 'Y-m-d H:i:s', strtotime( $post->post_date ) + ( get_option( 'gmt_offset' ) * 3600 ) ); 147 $this->assertEquals( mysql_to_rfc3339( $post_date_gmt ), $data['date_gmt'] ); 145 148 } else { 146 149 $this->assertEquals( mysql_to_rfc3339( $post->post_date_gmt ), $data['date_gmt'] ); 147 150 } 148 151 149 152 if ( '0000-00-00 00:00:00' === $post->post_modified_gmt ) { 150 $this->assertNull( $data['modified_gmt'] ); 153 $post_modified_gmt = date( 'Y-m-d H:i:s', strtotime( $post->post_modified ) + ( get_option( 'gmt_offset' ) * 3600 ) ); 154 $this->assertEquals( mysql_to_rfc3339( $post_modified_gmt ), $data['modified_gmt'] ); 151 155 } else { 152 156 $this->assertEquals( mysql_to_rfc3339( $post->post_modified_gmt ), $data['modified_gmt'] ); 153 157 } -
tests/phpunit/tests/rest-api/rest-posts-controller.php
1176 1176 $new_post = get_post( $data['id'] ); 1177 1177 $this->assertEquals( 'draft', $data['status'] ); 1178 1178 $this->assertEquals( 'draft', $new_post->post_status ); 1179 // Confirm dates are null 1180 $this->assertNull( $data['date_gmt'] ); 1181 $this->assertNull( $data['modified_gmt'] ); 1179 // Confirm dates are shimmed for gmt_offset 1180 $post_modified_gmt = date( 'Y-m-d H:i:s', strtotime( $new_post->post_modified ) + ( get_option( 'gmt_offset' ) * 3600 ) ); 1181 $post_date_gmt = date( 'Y-m-d H:i:s', strtotime( $new_post->post_date ) + ( get_option( 'gmt_offset' ) * 3600 ) ); 1182 1183 $this->assertEquals( mysql_to_rfc3339( $post_modified_gmt ), $data['modified_gmt'] ); 1184 $this->assertEquals( mysql_to_rfc3339( $post_date_gmt ), $data['date_gmt'] ); 1182 1185 } 1183 1186 1184 1187 public function test_create_post_private() {