WordPress.org

Make WordPress Core

Changeset 34681


Ignore:
Timestamp:
09/29/2015 04:04:16 AM (4 years ago)
Author:
wonderboymusic
Message:

XML-RPC: calculate the proper offset for GMT in wp.newPost, mw.newPost, and mw.editPost when post_date is set, wp.editComment when comment_date is set. post|comment_date is assumed to be GMT. This is only true if the timezone string for the site matches GMT.

Adds unit tests for each.

Props smerriman, justdaiv, wonderboymusic.
Fixes #30429.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r34603 r34681  
    13251325
    13261326        if ( ! empty( $dateCreated ) ) {
    1327             $post_data['post_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
    1328             $post_data['post_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' );
     1327            $post_data['post_date'] = iso8601_to_datetime( $dateCreated );
     1328            $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
    13291329        }
    13301330
     
    33963396            // We know this is supposed to be GMT, so we're going to slap that Z on there by force
    33973397            $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
    3398             $comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
    3399             $comment_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
     3398            $comment_date = iso8601_to_datetime( $dateCreated );
     3399            $comment_date_gmt = get_gmt_from_date( $comment_date );
    34003400        }
    34013401
     
    49614961
    49624962        if ( !empty( $dateCreated ) ) {
    4963             $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
    4964             $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
     4963            $post_date = iso8601_to_datetime( $dateCreated );
     4964            $post_date_gmt = get_gmt_from_date( $post_date );
    49654965        } else {
    49664966            $post_date = '';
     
    53155315
    53165316        if ( !empty( $dateCreated ) ) {
    5317             $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
    5318             $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
     5317            $post_date = iso8601_to_datetime( $dateCreated );
     5318            $post_date_gmt = get_gmt_from_date( $post_date, 'GMT' );
    53195319        } else {
    53205320            $post_date     = $postdata['post_date'];
  • trunk/tests/phpunit/tests/xmlrpc/mw/editPost.php

    r33612 r34681  
    230230        $this->assertEquals( $result->code, 401 );
    231231    }
     232
     233    /**
     234     * @ticket 30429
     235     */
     236    function test_post_date_timezone_conversion() {
     237        $tz = get_option( 'timezone_string' );
     238        update_option( 'timezone_string', 'America/New_York' );
     239
     240        $editor_id = $this->make_user_by_role( 'editor' );
     241
     242        $post_id = $this->factory->post->create( array(
     243            'post_author' => $editor_id
     244        ) );
     245
     246        $date_string = '1984-01-11 05:00:00';
     247        $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', array(
     248            'dateCreated' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) ),
     249        ) ) );
     250
     251        $fetched_post = get_post( $post_id );
     252
     253        update_option( 'timezone_string', $tz );
     254
     255        $this->assertTrue( $result );
     256        $this->assertEquals( $date_string, $fetched_post->post_date );
     257    }
    232258}
  • trunk/tests/phpunit/tests/xmlrpc/mw/newPost.php

    r34572 r34681  
    181181        $this->assertEquals( '0000-00-00 00:00:00', $out->post_date_gmt );
    182182    }
     183
     184    /**
     185     * @ticket 30429
     186     */
     187    function test_post_date_timezone_conversion() {
     188        $tz = get_option( 'timezone_string' );
     189        update_option( 'timezone_string', 'America/New_York' );
     190
     191        $this->make_user_by_role( 'editor' );
     192        $date_string = '1984-01-11 05:00:00';
     193        $post = array(
     194            'title' => 'test',
     195            'post_content' => 'test',
     196            'dateCreated' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) )
     197        );
     198        $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) );
     199        $fetched_post = get_post( $result );
     200
     201        update_option( 'timezone_string', $tz );
     202
     203        $this->assertStringMatchesFormat( '%d', $result );
     204        $this->assertEquals( $date_string , $fetched_post->post_date );
     205    }
    183206}
  • trunk/tests/phpunit/tests/xmlrpc/wp/editComment.php

    r34570 r34681  
    7070        $this->assertEquals( 'trash', get_comment( $comment_id )->comment_approved );
    7171    }
     72
     73    /**
     74     * @ticket 30429
     75     */
     76    function test_post_date_timezone_conversion() {
     77        $tz = get_option( 'timezone_string' );
     78        update_option( 'timezone_string', 'America/New_York' );
     79
     80        $this->make_user_by_role( 'administrator' );
     81        $post_id = $this->factory->post->create();
     82
     83        $comment_data = array(
     84            'comment_post_ID' => $post_id,
     85            'comment_author' => 'Test commenter',
     86            'comment_author_url' => 'http://example.com/',
     87            'comment_author_email' => 'example@example.com',
     88            'comment_content' => rand_str( 100 ),
     89            'comment_approved' => '1',
     90        );
     91        $comment_id = wp_insert_comment( $comment_data );
     92
     93        $date_string = '1984-01-11 05:00:00';
     94        $result = $this->myxmlrpcserver->wp_editComment( array( 1, 'administrator', 'administrator', $comment_id, array(
     95            'date_created_gmt' => new IXR_Date( mysql2date( 'Ymd\TH:i:s', $date_string, false ) )
     96        ) ) );
     97        $fetched_comment = get_comment( $comment_id );
     98
     99        update_option( 'timezone_string', $tz );
     100
     101        $this->assertTrue( $result );
     102        $this->assertEquals( $date_string, $fetched_comment->comment_date );
     103    }
    72104}
  • trunk/tests/phpunit/tests/xmlrpc/wp/newPost.php

    r29063 r34681  
    384384    }
    385385
     386    /**
     387     * @ticket 30429
     388     */
     389    function test_post_date_timezone_conversion() {
     390        $tz = get_option( 'timezone_string' );
     391        update_option( 'timezone_string', 'America/New_York' );
     392
     393        $this->make_user_by_role( 'author' );
     394        $date_string = '1984-01-11 05:00:00';
     395        $post = array( 'post_title' => 'test', 'post_content' => 'test', 'post_date' => $date_string );
     396        $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
     397        $fetched_post = get_post( $result );
     398
     399        update_option( 'timezone_string', $tz );
     400
     401        $this->assertStringMatchesFormat( '%d', $result );
     402        $this->assertEquals( $date_string , $fetched_post->post_date );
     403    }
    386404}
Note: See TracChangeset for help on using the changeset viewer.