Make WordPress Core

Ticket #38883: 38883.diff

File 38883.diff, 4.9 KB (added by joehoyle, 8 years ago)
  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

     
    13241324                }
    13251325
    13261326                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 );
    13281335                }
    13291336
    13301337                if ( ! empty( $schema['properties']['guid'] ) ) {
     
    13401347                }
    13411348
    13421349                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 );
    13441358                }
    13451359
    13461360                if ( ! empty( $schema['properties']['password'] ) ) {
  • tests/phpunit/includes/testcase-rest-post-type-controller.php

     
    1010                $this->assertEquals( $post->post_name, $data['slug'] );
    1111                $this->assertEquals( get_permalink( $post->ID ), $data['link'] );
    1212                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'] );
    1415                }
    1516                $this->assertEquals( mysql_to_rfc3339( $post->post_date ), $data['date'] );
    1617
    1718                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'] );
    1921                }
    2022                $this->assertEquals( mysql_to_rfc3339( $post->post_modified ), $data['modified'] );
    2123
     
    141143                        $this->assertEquals( $post->post_status, $data['status'] );
    142144
    143145                        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'] );
    145148                        } else {
    146149                                $this->assertEquals( mysql_to_rfc3339( $post->post_date_gmt ), $data['date_gmt'] );
    147150                        }
    148151
    149152                        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'] );
    151155                        } else {
    152156                                $this->assertEquals( mysql_to_rfc3339( $post->post_modified_gmt ), $data['modified_gmt'] );
    153157                        }
  • tests/phpunit/tests/rest-api/rest-posts-controller.php

     
    11761176                $new_post = get_post( $data['id'] );
    11771177                $this->assertEquals( 'draft', $data['status'] );
    11781178                $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'] );
    11821185        }
    11831186
    11841187        public function test_create_post_private() {