Changeset 42343 for trunk/tests/phpunit/tests/post/revisions.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/revisions.php
r42228 r42343 11 11 12 12 public static function wpSetUpBeforeClass( $factory ) { 13 self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) );13 self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) ); 14 14 self::$editor_user_id = $factory->user->create( array( 'role' => 'editor' ) ); 15 15 self::$author_user_id = $factory->user->create( array( 'role' => 'author' ) ); … … 28 28 /** 29 29 * Note: Test needs reviewing when #16215 is fixed because I'm not sure the test current tests the "correct" behavior 30 * 30 31 * @ticket 20982 31 32 * @ticket 16215 … … 34 35 //create a post as Author 35 36 wp_set_current_user( self::$author_user_id ); 36 $post = get_default_post_to_edit( 'post', true );37 $post = get_default_post_to_edit( 'post', true ); 37 38 $post_id = $post->ID; 38 39 39 wp_update_post( array( 'post_status' => 'draft', 'post_content' => 'I cant spel werds.', 'ID' => $post_id ) ); 40 wp_update_post( 41 array( 42 'post_status' => 'draft', 43 'post_content' => 'I cant spel werds.', 44 'ID' => $post_id, 45 ) 46 ); 40 47 41 48 //update post as Editor 42 49 wp_set_current_user( self::$editor_user_id ); 43 wp_update_post( array( 'post_content' => 'The Editor was in fixing your typos.', 'ID' => $post_id ) ); 50 wp_update_post( 51 array( 52 'post_content' => 'The Editor was in fixing your typos.', 53 'ID' => $post_id, 54 ) 55 ); 44 56 45 57 //restore back as Admin … … 51 63 $this->assertEquals( 'I cant spel werds.', $lastrevision->post_content ); 52 64 // #16215 53 $this->assertEquals( self::$author_user_id , $lastrevision->post_author);65 $this->assertEquals( self::$author_user_id, $lastrevision->post_author ); 54 66 55 67 wp_restore_post_revision( $lastrevision->ID ); … … 60 72 61 73 /** 62 * @ticket 739263 * @ticket 984364 */74 * @ticket 7392 75 * @ticket 9843 76 */ 65 77 function test_revision_dont_save_revision_if_unchanged() { 66 $post = get_default_post_to_edit( 'post', true );78 $post = get_default_post_to_edit( 'post', true ); 67 79 $post_id = $post->ID; 68 80 69 81 $this->assertCount( 0, wp_get_post_revisions( $post_id ) ); // No revisions on auto-draft creation. 70 82 71 wp_update_post( array( 'post_status' => 'draft', 'post_title' => 'some-post', 'post_content' => 'some_content', 'ID' => $post_id ) ); 83 wp_update_post( 84 array( 85 'post_status' => 'draft', 86 'post_title' => 'some-post', 87 'post_content' => 'some_content', 88 'ID' => $post_id, 89 ) 90 ); 72 91 73 92 $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); // Just the initial revision 74 93 75 94 // First update 76 wp_update_post( array( 'post_content' => 'some updated content', 'ID' => $post_id ) ); 95 wp_update_post( 96 array( 97 'post_content' => 'some updated content', 98 'ID' => $post_id, 99 ) 100 ); 77 101 78 102 $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); // should be 2 revisions so far 79 103 80 104 //update the post 81 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //2nd revision 105 wp_update_post( 106 array( 107 'post_content' => 'new update for some updated content', 108 'ID' => $post_id, 109 ) 110 ); //2nd revision 82 111 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // should be 3 revision so far 83 112 84 113 //next try to save another identical update, tests for patch that prevents storing duplicates 85 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save 114 wp_update_post( 115 array( 116 'post_content' => 'new update for some updated content', 117 'ID' => $post_id, 118 ) 119 ); //content unchanged, shouldn't save 86 120 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); //should still be 3 revision 87 121 88 122 //next try to save another update, same content, but new ttile, should save revision 89 wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); 123 wp_update_post( 124 array( 125 'post_title' => 'some-post-changed', 126 'post_content' => 'new update for some updated content', 127 'ID' => $post_id, 128 ) 129 ); 90 130 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should be 4 revision 91 131 92 132 //next try to save another identical update 93 wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save 133 wp_update_post( 134 array( 135 'post_title' => 'some-post-changed', 136 'post_content' => 'new update for some updated content', 137 'ID' => $post_id, 138 ) 139 ); //content unchanged, shouldn't save 94 140 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should still be 4 revision 95 141 } 96 142 97 143 /** 98 * @ticket 739299 * @ticket 9843100 */144 * @ticket 7392 145 * @ticket 9843 146 */ 101 147 function test_revision_force_save_revision_even_if_unchanged() { 102 148 add_filter( 'wp_save_post_revision_check_for_changes', '__return_false' ); 103 149 104 $post = get_default_post_to_edit( 'post', true );150 $post = get_default_post_to_edit( 'post', true ); 105 151 $post_id = $post->ID; 106 152 107 153 $this->assertCount( 0, wp_get_post_revisions( $post_id ) ); // No revisions on auto-draft creation. 108 154 109 wp_update_post( array( 'post_status' => 'draft', 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content', 'ID' => $post_id ) ); 155 wp_update_post( 156 array( 157 'post_status' => 'draft', 158 'post_title' => 'some-post', 159 'post_type' => 'post', 160 'post_content' => 'some_content', 161 'ID' => $post_id, 162 ) 163 ); 110 164 111 165 $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); 112 166 113 wp_update_post( array( 'post_content' => 'some updated content', 'ID' => $post_id ) ); //1st revision 167 wp_update_post( 168 array( 169 'post_content' => 'some updated content', 170 'ID' => $post_id, 171 ) 172 ); //1st revision 114 173 $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); 115 174 116 175 //update the post 117 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //2nd revision 176 wp_update_post( 177 array( 178 'post_content' => 'new update for some updated content', 179 'ID' => $post_id, 180 ) 181 ); //2nd revision 118 182 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); 119 183 120 184 //next try to save another identical update, tests for patch that prevents storing duplicates 121 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save 185 wp_update_post( 186 array( 187 'post_content' => 'new update for some updated content', 188 'ID' => $post_id, 189 ) 190 ); //content unchanged, shouldn't save 122 191 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); 123 192 124 193 //next try to save another update, same content, but new ttile, should save revision 125 wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); 194 wp_update_post( 195 array( 196 'post_title' => 'some-post-changed', 197 'post_content' => 'new update for some updated content', 198 'ID' => $post_id, 199 ) 200 ); 126 201 $this->assertCount( 5, wp_get_post_revisions( $post_id ) ); 127 202 128 203 //next try to save another identical update 129 wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save 204 wp_update_post( 205 array( 206 'post_title' => 'some-post-changed', 207 'post_content' => 'new update for some updated content', 208 'ID' => $post_id, 209 ) 210 ); //content unchanged, shouldn't save 130 211 $this->assertCount( 6, wp_get_post_revisions( $post_id ) ); 131 212 … … 135 216 /** 136 217 * Tests the Caps used in the action=view case of wp-admin/revision.php 218 * 137 219 * @ticket 16847 138 220 */ 139 221 function test_revision_view_caps_post() { 140 $post_id = self::factory()->post->create( array( 'post_type' => 'post', 'post_author' => self::$editor_user_id ) ); 141 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 222 $post_id = self::factory()->post->create( 223 array( 224 'post_type' => 'post', 225 'post_author' => self::$editor_user_id, 226 ) 227 ); 228 wp_update_post( 229 array( 230 'post_content' => 'This content is much better', 231 'ID' => $post_id, 232 ) 233 ); 142 234 143 235 $revisions = wp_get_post_revisions( $post_id ); … … 157 249 /** 158 250 * Tests the Caps used in the action=restore case of wp-admin/revision.php 251 * 159 252 * @ticket 16847 160 253 */ 161 254 function test_revision_restore_caps_post() { 162 $post_id = self::factory()->post->create( array( 'post_type' => 'post', 'post_author' => self::$editor_user_id ) ); 163 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 255 $post_id = self::factory()->post->create( 256 array( 257 'post_type' => 'post', 258 'post_author' => self::$editor_user_id, 259 ) 260 ); 261 wp_update_post( 262 array( 263 'post_content' => 'This content is much better', 264 'ID' => $post_id, 265 ) 266 ); 164 267 165 268 $revisions = wp_get_post_revisions( $post_id ); … … 177 280 /** 178 281 * Tests the Caps used in the action=diff case of wp-admin/revision.php 282 * 179 283 * @ticket 16847 180 284 */ 181 285 function test_revision_diff_caps_post() { 182 $post_id = self::factory()->post->create( array( 'post_type' => 'post', 'post_author' => self::$editor_user_id ) ); 183 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 184 wp_update_post( array( 'post_content' => 'This content is even better', 'ID' => $post_id ) ); 286 $post_id = self::factory()->post->create( 287 array( 288 'post_type' => 'post', 289 'post_author' => self::$editor_user_id, 290 ) 291 ); 292 wp_update_post( 293 array( 294 'post_content' => 'This content is much better', 295 'ID' => $post_id, 296 ) 297 ); 298 wp_update_post( 299 array( 300 'post_content' => 'This content is even better', 301 'ID' => $post_id, 302 ) 303 ); 185 304 186 305 // Diff checks if you can read both left and right revisions … … 199 318 /** 200 319 * Tests the Caps used in the action=view case of wp-admin/revision.php with a CPT with Custom Capabilities 320 * 201 321 * @ticket 16847 202 322 */ 203 323 function test_revision_view_caps_cpt() { 204 register_post_type( $this->post_type, array( 205 'capability_type' => 'event', 206 'map_meta_cap' => true, 207 'supports' => array( 'revisions' ), 208 ) ); 209 210 $post_id = self::factory()->post->create( array( 'post_type' => $this->post_type, 'post_author' => self::$editor_user_id ) ); 211 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 324 register_post_type( 325 $this->post_type, array( 326 'capability_type' => 'event', 327 'map_meta_cap' => true, 328 'supports' => array( 'revisions' ), 329 ) 330 ); 331 332 $post_id = self::factory()->post->create( 333 array( 334 'post_type' => $this->post_type, 335 'post_author' => self::$editor_user_id, 336 ) 337 ); 338 wp_update_post( 339 array( 340 'post_content' => 'This content is much better', 341 'ID' => $post_id, 342 ) 343 ); 212 344 213 345 $revisions = wp_get_post_revisions( $post_id ); … … 227 359 /** 228 360 * Tests the Caps used in the action=restore case of wp-admin/revision.php 361 * 229 362 * @ticket 16847 230 363 */ 231 364 function test_revision_restore_caps_cpt() { 232 register_post_type( $this->post_type, array( 233 'capability_type' => 'event', 234 'map_meta_cap' => true, 235 'supports' => array( 'revisions' ), 236 ) ); 365 register_post_type( 366 $this->post_type, array( 367 'capability_type' => 'event', 368 'map_meta_cap' => true, 369 'supports' => array( 'revisions' ), 370 ) 371 ); 237 372 238 373 // The minimum extra caps needed for this test normally you would give the role all the relevant caps. … … 241 376 242 377 //create a post as Editor 243 $post_id = self::factory()->post->create( array( 'post_type' => $this->post_type, 'post_author' => self::$editor_user_id ) ); 244 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 378 $post_id = self::factory()->post->create( 379 array( 380 'post_type' => $this->post_type, 381 'post_author' => self::$editor_user_id, 382 ) 383 ); 384 wp_update_post( 385 array( 386 'post_content' => 'This content is much better', 387 'ID' => $post_id, 388 ) 389 ); 245 390 246 391 $revisions = wp_get_post_revisions( $post_id ); … … 259 404 /** 260 405 * Tests the Caps used in the action=restore case of wp-admin/revision.php 406 * 261 407 * @ticket 16847 262 408 */ 263 409 function test_revision_restore_caps_before_publish() { 264 register_post_type( $this->post_type, array( 265 'capability_type' => 'post', 266 'capabilities' => array( 267 // No one can edit this post type once published. 268 // So, revisions cannot be restored, either. 269 'edit_published_posts' => 'do_not_allow', 270 ), 271 'map_meta_cap' => true, 272 'supports' => array( 'revisions' ), 273 ) ); 410 register_post_type( 411 $this->post_type, array( 412 'capability_type' => 'post', 413 'capabilities' => array( 414 // No one can edit this post type once published. 415 // So, revisions cannot be restored, either. 416 'edit_published_posts' => 'do_not_allow', 417 ), 418 'map_meta_cap' => true, 419 'supports' => array( 'revisions' ), 420 ) 421 ); 274 422 275 423 $old_id = get_current_user_id(); 276 424 wp_set_current_user( self::$editor_user_id ); 277 425 278 $post_id = self::factory()->post->create( array( 'post_type' => $this->post_type, 'post_status' => 'draft' ) ); 279 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 426 $post_id = self::factory()->post->create( 427 array( 428 'post_type' => $this->post_type, 429 'post_status' => 'draft', 430 ) 431 ); 432 wp_update_post( 433 array( 434 'post_content' => 'This content is much better', 435 'ID' => $post_id, 436 ) 437 ); 280 438 281 439 $revisions = wp_get_post_revisions( $post_id ); … … 286 444 } 287 445 288 wp_update_post( array( 'post_status' => 'publish', 'ID' => $post_id, 'post_content' => rand_str() ) ); 446 wp_update_post( 447 array( 448 'post_status' => 'publish', 449 'ID' => $post_id, 450 'post_content' => rand_str(), 451 ) 452 ); 289 453 290 454 $revisions = wp_get_post_revisions( $post_id ); … … 299 463 /** 300 464 * Tests the Caps used in the action=diff case of wp-admin/revision.php 465 * 301 466 * @ticket 16847 302 467 */ 303 468 function test_revision_diff_caps_cpt() { 304 register_post_type( $this->post_type, array( 305 'capability_type' => 'event', 306 'map_meta_cap' => true, 307 'supports' => array( 'revisions' ), 308 ) ); 309 310 $post_id = self::factory()->post->create( array( 'post_type' => $this->post_type, 'post_author' => self::$editor_user_id ) ); 311 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 312 wp_update_post( array( 'post_content' => 'This content is even better', 'ID' => $post_id ) ); 469 register_post_type( 470 $this->post_type, array( 471 'capability_type' => 'event', 472 'map_meta_cap' => true, 473 'supports' => array( 'revisions' ), 474 ) 475 ); 476 477 $post_id = self::factory()->post->create( 478 array( 479 'post_type' => $this->post_type, 480 'post_author' => self::$editor_user_id, 481 ) 482 ); 483 wp_update_post( 484 array( 485 'post_content' => 'This content is much better', 486 'ID' => $post_id, 487 ) 488 ); 489 wp_update_post( 490 array( 491 'post_content' => 'This content is even better', 492 'ID' => $post_id, 493 ) 494 ); 313 495 314 496 // Diff checks if you can read both left and right revisions … … 331 513 global $wpdb; 332 514 333 $post = self::factory()->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) ); 334 335 $post = (array) $post; 515 $post = self::factory()->post->create_and_get( 516 array( 517 'post_title' => 'some-post', 518 'post_type' => 'post', 519 'post_content' => 'some_content', 520 ) 521 ); 522 523 $post = (array) $post; 336 524 $post_revision_fields = _wp_post_revision_data( $post ); 337 525 $post_revision_fields = wp_slash( $post_revision_fields ); 338 526 339 527 $revision_ids = array(); 340 $now = time();528 $now = time(); 341 529 for ( $j = 1; $j < 3; $j++ ) { 342 530 // Manually modify dates to ensure they're different. 343 $date = date( 'Y-m-d H:i:s', $now - ( $j * 10 ) );344 $post_revision_fields['post_date'] = $date;531 $date = date( 'Y-m-d H:i:s', $now - ( $j * 10 ) ); 532 $post_revision_fields['post_date'] = $date; 345 533 $post_revision_fields['post_date_gmt'] = $date; 346 534 … … 359 547 */ 360 548 function test_wp_get_post_revisions_should_order_by_ID_when_post_date_matches() { 361 $post = self::factory()->post->create_and_get( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) ); 362 363 $post = (array) $post; 549 $post = self::factory()->post->create_and_get( 550 array( 551 'post_title' => 'some-post', 552 'post_type' => 'post', 553 'post_content' => 'some_content', 554 ) 555 ); 556 557 $post = (array) $post; 364 558 $post_revision_fields = _wp_post_revision_data( $post ); 365 559 $post_revision_fields = wp_slash( $post_revision_fields ); 366 560 367 561 $revision_ids = array(); 368 $date = date( 'Y-m-d H:i:s', time() - 10 );562 $date = date( 'Y-m-d H:i:s', time() - 10 ); 369 563 for ( $j = 1; $j < 3; $j++ ) { 370 564 // Manually modify dates to ensure they're the same. 371 $post_revision_fields['post_date'] = $date;565 $post_revision_fields['post_date'] = $date; 372 566 $post_revision_fields['post_date_gmt'] = $date; 373 567
Note: See TracChangeset
for help on using the changeset viewer.