Ticket #35874: xmlrpc-based-fix-and-test-2.patch
File xmlrpc-based-fix-and-test-2.patch, 5.5 KB (added by , 9 years ago) |
---|
-
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 { 1351 1351 $dateCreated = $post_data['post_date']->getIso(); 1352 1352 } 1353 1353 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; 1354 1359 if ( ! empty( $dateCreated ) ) { 1355 1360 $post_data['post_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) ); 1356 1361 $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; 1357 1365 } 1358 1366 1359 1367 if ( ! isset( $post_data['ID'] ) ) … … class wp_xmlrpc_server extends IXR_Server { 5362 5370 elseif ( !empty( $content_struct['dateCreated']) ) 5363 5371 $dateCreated = $content_struct['dateCreated']->getIso(); 5364 5372 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; 5365 5378 if ( !empty( $dateCreated ) ) { 5366 5379 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); 5367 5380 $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; 5368 5384 } else { 5369 5385 $post_date = $postdata['post_date']; 5370 5386 $post_date_gmt = $postdata['post_date_gmt']; 5371 5387 } 5372 5388 5373 5389 // 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'); 5375 5391 5376 5392 $result = wp_update_post($newpost, true); 5377 5393 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 { 241 241 $tags2 = get_the_tags( $post_id ); 242 242 $this->assertEmpty( $tags2 ); 243 243 } 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 } 244 273 } -
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..c4e7be3 100644
class Tests_XMLRPC_wp_editPost extends WP_XMLRPC_UnitTestCase { 401 401 // Check that the old enclosure is in the enclosure meta 402 402 $this->assertTrue( in_array( $enclosure_string, get_post_meta( $post_id, 'enclosure' ) ) ); 403 403 } 404 405 /** 406 * @ticket 35874 407 */ 408 function test_draft_not_prematurely_published() { 409 $editor_id = $this->make_user_by_role( 'editor' ); 410 411 $post = array ( 412 'title' => 'Title' 413 ); 414 415 // We have to use wp_newPost method, rather than the factory 416 // post->create method to create the database conditions that exhibit the bug. 417 $post = array( 418 'post_title' => 'Test', 419 'post_status' => 'draft' 420 ); 421 $post_id = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) ); 422 423 // Change the post's status to publish and date to future 424 $future_time = strtotime( '+1 day' ); 425 $future_date = new IXR_Date( $future_time ); 426 $new_post_content = array( 427 'ID' => $post_id, 428 'post_title' => "Updated", 429 'post_status' => "publish", 430 'post_date' => $future_date, 431 ); 432 433 $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $new_post_content ) ); 434 435 $after = get_post( $post_id ); 436 $this->assertEquals( 'future', $after->post_status ); 437 438 $future_date_string = strftime( "%Y-%m-%d %H:%M:%S", $future_time ); 439 $this->assertEquals( $future_date_string, $after->post_date ); 440 } 404 441 }