Make WordPress Core

Ticket #35874: 35874.2.diff

File 35874.2.diff, 4.9 KB (added by DrewAPicture, 9 years ago)

Improved inline comments

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

     
    13641364                        $dateCreated = $post_data['post_date']->getIso();
    13651365                }
    13661366
     1367                // Default to not flagging the post date to be edited unless it's intentional.
     1368                $post_data['edit_date'] = false;
     1369
    13671370                if ( ! empty( $dateCreated ) ) {
    13681371                        $post_data['post_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
    13691372                        $post_data['post_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' );
     1373
     1374                        // Flag the post date to be edited.
     1375                        $post_data['edit_date'] = true;
    13701376                }
    13711377
    13721378                if ( ! isset( $post_data['ID'] ) )
     
    53755381                elseif ( !empty( $content_struct['dateCreated']) )
    53765382                        $dateCreated = $content_struct['dateCreated']->getIso();
    53775383
     5384                // Default to not flagging the post date to be edited unless it's intentional.
     5385                $edit_date = false;
     5386
    53785387                if ( !empty( $dateCreated ) ) {
    53795388                        $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
    53805389                        $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
     5390
     5391                        // Flag the post date to be edited.
     5392                        $edit_date = true;
    53815393                } else {
    53825394                        $post_date     = $postdata['post_date'];
    53835395                        $post_date_gmt = $postdata['post_date_gmt'];
     
    53845396                }
    53855397
    53865398                // We've got all the data -- post it.
    5387                 $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');
     5399                $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');
    53885400
    53895401                $result = wp_update_post($newpost, true);
    53905402                if ( is_wp_error( $result ) )
  • tests/phpunit/tests/xmlrpc/mw/editPost.php

     
    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                /**
     256                 * We have to use wp_newPost method, rather than the factory
     257                 * post->create method to create the database conditions that exhibit
     258                 * the bug.
     259                 */
     260                $post_id = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) );
     261
     262                // Change the post's status to publish and date to future.
     263                $future_time = strtotime( '+1 day' );
     264                $future_date = new IXR_Date( $future_time );
     265                $this->myxmlrpcserver->mw_editPost( array(
     266                        $post_id,
     267                        'editor',
     268                        'editor',
     269                        array(
     270                                'dateCreated' => $future_date,
     271                                'post_status' => 'publish',
     272                        ),
     273                ) );
     274
     275                $after = get_post( $post_id );
     276                $this->assertEquals( 'future', $after->post_status );
     277
     278                $future_date_string = strftime( '%Y-%m-%d %H:%M:%S', $future_time );
     279                $this->assertEquals( $future_date_string, $after->post_date );
     280        }
    244281}
  • tests/phpunit/tests/xmlrpc/wp/editPost.php

     
    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                /**
     412                 * We have to use wp_newPost method, rather than the factory
     413                 * post->create method to create the database conditions that exhibit
     414                 * the bug.
     415                 */
     416                $post = array(
     417                        'post_title'  => 'Test',
     418                        'post_status' => 'draft',
     419                );
     420                $post_id = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     421
     422                // Change the post's status to publish and date to future.
     423                $future_time = strtotime( '+1 day' );
     424                $future_date = new IXR_Date( $future_time );
     425                $new_post_content = array(
     426                        'ID'          => $post_id,
     427                        'post_title'  => 'Updated',
     428                        'post_status' => 'publish',
     429                        'post_date'   => $future_date,
     430                );
     431
     432                $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $new_post_content ) );
     433
     434                $after = get_post( $post_id );
     435                $this->assertEquals( 'future', $after->post_status );
     436
     437                $future_date_string = strftime( '%Y-%m-%d %H:%M:%S', $future_time );
     438                $this->assertEquals( $future_date_string, $after->post_date );
     439        }
    404440}