Changeset 42343 for trunk/tests/phpunit/tests/xmlrpc/wp/editPost.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/xmlrpc/wp/editPost.php
r40417 r42343 15 15 $contributor_id = $this->make_user_by_role( 'contributor' ); 16 16 17 $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id ); 17 $post = array( 18 'post_title' => 'Post test', 19 'post_author' => $contributor_id, 20 ); 18 21 $post_id = wp_insert_post( $post ); 19 22 20 23 $new_title = 'Post test (updated)'; 21 $post2 = array( 'post_title' => $new_title );22 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) );23 $this->assertNotIXRError( $result ); 24 $this->assertTrue( $result);24 $post2 = array( 'post_title' => $new_title ); 25 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) ); 26 $this->assertNotIXRError( $result ); 27 $this->assertTrue( $result ); 25 28 26 29 $out = get_post( $post_id ); … … 32 35 $this->make_user_by_role( 'editor' ); 33 36 34 $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id ); 37 $post = array( 38 'post_title' => 'Post test', 39 'post_author' => $contributor_id, 40 ); 35 41 $post_id = wp_insert_post( $post ); 36 42 37 43 $new_title = 'Post test (updated)'; 38 $post2 = array( 'post_title' => $new_title );39 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );40 $this->assertNotIXRError( $result ); 41 $this->assertTrue( $result);44 $post2 = array( 'post_title' => $new_title ); 45 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) ); 46 $this->assertNotIXRError( $result ); 47 $this->assertTrue( $result ); 42 48 43 49 $out = get_post( $post_id ); … … 50 56 51 57 $original_title = 'Post test'; 52 $post = array( 'post_title' => $original_title, 'post_author' => $author_id ); 53 $post_id = wp_insert_post( $post ); 58 $post = array( 59 'post_title' => $original_title, 60 'post_author' => $author_id, 61 ); 62 $post_id = wp_insert_post( $post ); 54 63 55 64 $new_title = 'Post test (updated)'; 56 $post2 = array( 'post_title' => $new_title );57 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) );65 $post2 = array( 'post_title' => $new_title ); 66 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) ); 58 67 $this->assertIXRError( $result ); 59 68 $this->assertEquals( 401, $result->code ); … … 65 74 function test_capable_reassign_author() { 66 75 $contributor_id = $this->make_user_by_role( 'contributor' ); 67 $author_id = $this->make_user_by_role( 'author' );76 $author_id = $this->make_user_by_role( 'author' ); 68 77 $this->make_user_by_role( 'editor' ); 69 78 70 $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id ); 71 $post_id = wp_insert_post( $post ); 72 73 $post2 = array( 'post_author' => $author_id ); 79 $post = array( 80 'post_title' => 'Post test', 81 'post_author' => $contributor_id, 82 ); 83 $post_id = wp_insert_post( $post ); 84 85 $post2 = array( 'post_author' => $author_id ); 74 86 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) ); 75 87 $this->assertNotIXRError( $result ); 76 $this->assertTrue( $result);88 $this->assertTrue( $result ); 77 89 78 90 $out = get_post( $post_id ); … … 82 94 function test_incapable_reassign_author() { 83 95 $contributor_id = $this->make_user_by_role( 'contributor' ); 84 $author_id = $this->make_user_by_role( 'author' ); 85 86 $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id ); 87 $post_id = wp_insert_post( $post ); 88 89 $post2 = array( 'post_author' => $author_id ); 96 $author_id = $this->make_user_by_role( 'author' ); 97 98 $post = array( 99 'post_title' => 'Post test', 100 'post_author' => $contributor_id, 101 ); 102 $post_id = wp_insert_post( $post ); 103 104 $post2 = array( 'post_author' => $author_id ); 90 105 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) ); 91 106 $this->assertIXRError( $result ); … … 101 116 function test_capable_reassign_author_to_self() { 102 117 $contributor_id = $this->make_user_by_role( 'contributor' ); 103 $editor_id = $this->make_user_by_role( 'editor' ); 104 105 $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id ); 106 $post_id = wp_insert_post( $post ); 107 108 $post2 = array( 'post_author' => $editor_id ); 118 $editor_id = $this->make_user_by_role( 'editor' ); 119 120 $post = array( 121 'post_title' => 'Post test', 122 'post_author' => $contributor_id, 123 ); 124 $post_id = wp_insert_post( $post ); 125 126 $post2 = array( 'post_author' => $editor_id ); 109 127 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) ); 110 128 $this->assertNotIXRError( $result ); 111 $this->assertTrue( $result);129 $this->assertTrue( $result ); 112 130 113 131 $out = get_post( $post_id ); … … 120 138 $author_id = $this->make_user_by_role( 'author' ); 121 139 122 $post = array( 'post_title' => 'Post Thumbnail Test', 'post_author' => $author_id ); 140 $post = array( 141 'post_title' => 'Post Thumbnail Test', 142 'post_author' => $author_id, 143 ); 123 144 $post_id = wp_insert_post( $post ); 124 145 … … 126 147 127 148 // create attachment 128 $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );149 $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' ); 129 150 $attachment_id = self::factory()->attachment->create_upload_object( $filename, $post_id ); 130 151 131 152 // add post thumbnail to post that does not have one 132 $post2 = array( 'post_thumbnail' => $attachment_id );153 $post2 = array( 'post_thumbnail' => $attachment_id ); 133 154 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post2 ) ); 134 155 $this->assertNotIXRError( $result ); … … 143 164 144 165 // edit the post without supplying a post_thumbnail and check that it didn't change 145 $post3 = array( 'post_content' => 'Updated post' );166 $post3 = array( 'post_content' => 'Updated post' ); 146 167 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post3 ) ); 147 168 $this->assertNotIXRError( $result ); … … 152 173 153 174 // change the post's post_thumbnail 154 $post4 = array( 'post_thumbnail' => $attachment2_id );175 $post4 = array( 'post_thumbnail' => $attachment2_id ); 155 176 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post4 ) ); 156 177 $this->assertNotIXRError( $result ); … … 158 179 159 180 // unset the post's post_thumbnail 160 $post5 = array( 'post_thumbnail' => '' );181 $post5 = array( 'post_thumbnail' => '' ); 161 182 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post5 ) ); 162 183 $this->assertNotIXRError( $result ); … … 164 185 165 186 // use invalid ID 166 $post6 = array( 'post_thumbnail' => 398420983409 );187 $post6 = array( 'post_thumbnail' => 398420983409 ); 167 188 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'author', 'author', $post_id, $post6 ) ); 168 189 $this->assertIXRError( $result ); … … 175 196 $contributor_id = $this->make_user_by_role( 'contributor' ); 176 197 177 $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id ); 178 $post_id = wp_insert_post( $post ); 198 $post = array( 199 'post_title' => 'Post test', 200 'post_author' => $contributor_id, 201 ); 202 $post_id = wp_insert_post( $post ); 179 203 $mid_edit = add_post_meta( $post_id, 'custom_field_key', '12345678' ); 180 204 $mid_delete = add_post_meta( $post_id, 'custom_field_to_delete', '12345678' ); 181 205 182 206 $new_title = 'Post test (updated)'; 183 $post2 = array(184 'post_title' => $new_title,207 $post2 = array( 208 'post_title' => $new_title, 185 209 'custom_fields' => 186 210 array( 187 211 array( 'id' => $mid_delete ), 188 array( 'id' => $mid_edit, 'key' => 'custom_field_key', 'value' => '87654321' ), 189 array( 'key' => 'custom_field_to_create', 'value' => '12345678' ) 190 ) 212 array( 213 'id' => $mid_edit, 214 'key' => 'custom_field_key', 215 'value' => '87654321', 216 ), 217 array( 218 'key' => 'custom_field_to_create', 219 'value' => '12345678', 220 ), 221 ), 191 222 ); 192 223 193 224 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) ); 194 225 $this->assertNotIXRError( $result ); 195 $this->assertTrue( $result);226 $this->assertTrue( $result ); 196 227 197 228 $out = get_post( $post_id ); … … 212 243 stick_post( $post_id ); 213 244 214 $post2 = array( 'sticky' => false );245 $post2 = array( 'sticky' => false ); 215 246 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) ); 216 247 $this->assertNotIXRError( $result ); … … 221 252 // when transitioning to private status or adding a post password, post should be un-stuck 222 253 $editor_id = $this->make_user_by_role( 'editor' ); 223 $post_id = self::factory()->post->create( array( 'post_author' => $editor_id ) );254 $post_id = self::factory()->post->create( array( 'post_author' => $editor_id ) ); 224 255 stick_post( $post_id ); 225 256 226 $post2 = array( 'post_password' => 'foobar', 'sticky' => false ); 257 $post2 = array( 258 'post_password' => 'foobar', 259 'sticky' => false, 260 ); 227 261 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) ); 228 262 $this->assertNotIXRError( $result ); … … 235 269 $yesterday = strtotime( '-1 day' ); 236 270 237 $post_id = self::factory()->post->create( array( 238 'post_title' => 'Post Revision Test', 239 'post_content' => 'Not edited', 240 'post_author' => $editor_id, 241 'post_status' => 'publish', 242 'post_date' => date( 'Y-m-d H:i:s', $yesterday ), 243 ) ); 271 $post_id = self::factory()->post->create( 272 array( 273 'post_title' => 'Post Revision Test', 274 'post_content' => 'Not edited', 275 'post_author' => $editor_id, 276 'post_status' => 'publish', 277 'post_date' => date( 'Y-m-d H:i:s', $yesterday ), 278 ) 279 ); 244 280 245 281 // Modify the day old post. In this case, we think it was last modified yesterday. 246 $struct = array( 'post_content' => 'First edit', 'if_not_modified_since' => new IXR_Date( $yesterday ) ); 282 $struct = array( 283 'post_content' => 'First edit', 284 'if_not_modified_since' => new IXR_Date( $yesterday ), 285 ); 247 286 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $struct ) ); 248 287 $this->assertNotIXRError( $result ); … … 252 291 253 292 // Modify it again. We think it was last modified yesterday, but we actually just modified it above. 254 $struct = array( 'post_content' => 'Second edit', 'if_not_modified_since' => new IXR_Date( $yesterday ) ); 293 $struct = array( 294 'post_content' => 'Second edit', 295 'if_not_modified_since' => new IXR_Date( $yesterday ), 296 ); 255 297 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $struct ) ); 256 298 $this->assertIXRError( $result ); … … 264 306 $editor_id = $this->make_user_by_role( 'editor' ); 265 307 266 $post_id = self::factory()->post->create( array( 267 'post_title' => 'Post Revision Test', 268 'post_content' => 'Not edited', 269 'post_status' => 'inherit', 270 'post_type' => 'attachment', 271 'post_author' => $editor_id, 272 ) ); 308 $post_id = self::factory()->post->create( 309 array( 310 'post_title' => 'Post Revision Test', 311 'post_content' => 'Not edited', 312 'post_status' => 'inherit', 313 'post_type' => 'attachment', 314 'post_author' => $editor_id, 315 ) 316 ); 273 317 274 318 $struct = array( 'post_content' => 'First edit' ); … … 283 327 $editor_id = $this->make_user_by_role( 'editor' ); 284 328 285 $post_id = self::factory()->post->create( array( 286 'post_title' => 'Post Revision Test', 287 'post_content' => 'Not edited', 288 'post_author' => $editor_id, 289 ) ); 329 $post_id = self::factory()->post->create( 330 array( 331 'post_title' => 'Post Revision Test', 332 'post_content' => 'Not edited', 333 'post_author' => $editor_id, 334 ) 335 ); 290 336 291 337 $struct = array( 'post_status' => 'doesnt_exists' ); … … 303 349 $editor_id = $this->make_user_by_role( 'editor' ); 304 350 305 $post_id = self::factory()->post->create( array( 'post_author' 351 $post_id = self::factory()->post->create( array( 'post_author' => $editor_id ) ); 306 352 $term_id = self::factory()->category->create(); 307 353 self::factory()->term->add_post_terms( $post_id, $term_id, 'category', true ); … … 309 355 $this->assertContains( $term_id, $term_ids ); 310 356 311 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, array( 'ID' => $post_id, 'post_title' => 'Updated' ) ) ); 357 $result = $this->myxmlrpcserver->wp_editPost( 358 array( 359 1, 360 'editor', 361 'editor', 362 $post_id, 363 array( 364 'ID' => $post_id, 365 'post_title' => 'Updated', 366 ), 367 ) 368 ); 312 369 $this->assertNotIXRError( $result ); 313 370 $this->assertEquals( 'Updated', get_post( $post_id )->post_title ); … … 323 380 $editor_id = $this->make_user_by_role( 'editor' ); 324 381 325 $post_id = self::factory()->post->create( array( 'post_author' 382 $post_id = self::factory()->post->create( array( 'post_author' => $editor_id ) ); 326 383 $term_id = self::factory()->category->create(); 327 384 self::factory()->term->add_post_terms( $post_id, $term_id, 'category', true ); … … 330 387 331 388 $new_post_content = array( 332 'ID' => $post_id,389 'ID' => $post_id, 333 390 'post_title' => 'Updated', 334 'terms' => array(335 'category' => array() 336 ) 337 ); 338 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $new_post_content ) );391 'terms' => array( 392 'category' => array(), 393 ), 394 ); 395 $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $new_post_content ) ); 339 396 $this->assertNotIXRError( $result ); 340 397 $this->assertEquals( 'Updated', get_post( $post_id )->post_title ); … … 366 423 367 424 // Add a dummy post 368 $post_id = self::factory()->post->create( array( 369 'post_title' => 'Post Enclosure Test', 370 'post_content' => 'Fake content', 371 'post_author' => $editor_id, 372 'post_status' => 'publish', 373 ) ); 425 $post_id = self::factory()->post->create( 426 array( 427 'post_title' => 'Post Enclosure Test', 428 'post_content' => 'Fake content', 429 'post_author' => $editor_id, 430 'post_status' => 'publish', 431 ) 432 ); 374 433 375 434 // Add the enclosure as it is added in "do_enclose()" … … 414 473 * the bug. 415 474 */ 416 $post = array(475 $post = array( 417 476 'post_title' => 'Test', 418 477 'post_status' => 'draft', … … 421 480 422 481 // 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 );482 $future_time = strtotime( '+1 day' ); 483 $future_date = new IXR_Date( $future_time ); 425 484 $new_post_content = array( 426 485 'ID' => $post_id,
Note: See TracChangeset
for help on using the changeset viewer.