Make WordPress Core

Ticket #35874: xmlrpc-based-fix-and-test-3.patch

File xmlrpc-based-fix-and-test-3.patch, 5.4 KB (added by redsweater, 8 years ago)

Update to remove cruft from the wp_editPost test case.

  • src/wp-includes/class-wp-xmlrpc-server.php

    diff --git src/wp-includes/class-wp-xmlrpc-server.php src/wp-includes/class-wp-xmlrpc-server.php
    index c331591..1fe530f 100644
    class wp_xmlrpc_server extends IXR_Server { 
    13511351                        $dateCreated = $post_data['post_date']->getIso();
    13521352                }
    13531353
     1354                // We need to pass along a value to wp_update_post for "edit_date", indicating whether
     1355                // an intentional edit is being made to the date. This drives logic that determines
     1356                // whether the value of post_date or post_date_gmt will be disregarded or not for
     1357                // draft posts.
     1358                $post_data['edit_date'] = false;
    13541359                if ( ! empty( $dateCreated ) ) {
    13551360                        $post_data['post_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
    13561361                        $post_data['post_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' );
     1362
     1363                        // If $dateCreated is not empty, it means that a specific date was supplied.
     1364                        $post_data['edit_date'] = true;
    13571365                }
    13581366
    13591367                if ( ! isset( $post_data['ID'] ) )
    class wp_xmlrpc_server extends IXR_Server { 
    53625370                elseif ( !empty( $content_struct['dateCreated']) )
    53635371                        $dateCreated = $content_struct['dateCreated']->getIso();
    53645372
     5373                // We need to pass along a value to wp_update_post for "edit_date", indicating whether
     5374                // an intentional edit is being made to the date. This drives logic that determines
     5375                // whether the value of post_date or post_date_gmt will be disregarded or not for
     5376                // draft posts.
     5377                $edit_date = false;
    53655378                if ( !empty( $dateCreated ) ) {
    53665379                        $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
    53675380                        $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
     5381
     5382                        // If $dateCreated is not empty, it means that a specific date was supplied.
     5383                        $edit_date = true;
    53685384                } else {
    53695385                        $post_date     = $postdata['post_date'];
    53705386                        $post_date_gmt = $postdata['post_date_gmt'];
    53715387                }
    53725388
    53735389                // We've got all the data -- post it.
    5374                 $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template');
     5390                $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'edit_date', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template');
    53755391
    53765392                $result = wp_update_post($newpost, true);
    53775393                if ( is_wp_error( $result ) )
  • tests/phpunit/tests/xmlrpc/mw/editPost.php

    diff --git tests/phpunit/tests/xmlrpc/mw/editPost.php tests/phpunit/tests/xmlrpc/mw/editPost.php
    index a62d239..8c26522 100644
    class Tests_XMLRPC_mw_editPost extends WP_XMLRPC_UnitTestCase { 
    241241                $tags2 = get_the_tags( $post_id );
    242242                $this->assertEmpty( $tags2 );
    243243        }
     244
     245        /**
     246         * @ticket 35874
     247         */
     248        function test_draft_not_prematurely_published() {
     249                $editor_id = $this->make_user_by_role( 'editor' );
     250
     251                $post = array (
     252                        'title' => 'Title'
     253                );
     254
     255                // We have to use mw_newPost method, rather than the factory
     256                // post->create method to create the database conditions that exhibit the bug.
     257                $post_id = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) );
     258
     259                // Change the post's status to publish and date to future
     260                $future_time = strtotime( '+1 day' );
     261                $future_date = new IXR_Date( $future_time );
     262                $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', array(
     263                        'dateCreated' => $future_date,
     264                        'post_status' => 'publish'
     265                ) ) );
     266
     267                $after = get_post( $post_id );
     268                $this->assertEquals( 'future', $after->post_status );
     269
     270                $future_date_string = strftime( "%Y-%m-%d %H:%M:%S", $future_time );
     271                $this->assertEquals( $future_date_string, $after->post_date );
     272        }
    244273}
  • tests/phpunit/tests/xmlrpc/wp/editPost.php

    diff --git tests/phpunit/tests/xmlrpc/wp/editPost.php tests/phpunit/tests/xmlrpc/wp/editPost.php
    index 20ba377..6e84ae0 100644
    class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { 
    401401                // Check that the old enclosure is in the enclosure meta
    402402                $this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ) ) );
    403403        }
     404
     405        /**
     406         * @ticket 35874
     407         */
     408        function test_draft_not_prematurely_published() {
     409                $editor_id = $this->make_user_by_role( 'editor' );
     410
     411                // We have to use wp_newPost method, rather than the factory
     412                // post->create method to create the database conditions that exhibit the bug.
     413                $post = array(
     414                        'post_title' => 'Test',
     415                        'post_status' => 'draft'
     416                );
     417                $post_id = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     418
     419                // Change the post's status to publish and date to future
     420                $future_time = strtotime( '+1 day' );
     421                $future_date = new IXR_Date( $future_time );
     422                $new_post_content = array(
     423                        'ID' => $post_id,
     424                        'post_title' => "Updated",
     425                        'post_status' => "publish",
     426                        'post_date' => $future_date,
     427                );
     428
     429                $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $new_post_content ) );
     430
     431                $after = get_post( $post_id );
     432                $this->assertEquals( 'future', $after->post_status );
     433
     434                $future_date_string = strftime( "%Y-%m-%d %H:%M:%S", $future_time );
     435                $this->assertEquals( $future_date_string, $after->post_date );
     436        }
    404437}