Changeset 47122 for trunk/tests/phpunit/tests/post/revisions.php
- Timestamp:
- 01/29/2020 12:43:23 AM (6 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/post/revisions.php (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/revisions.php
r46586 r47122 33 33 */ 34 34 function test_revision_restore_updates_edit_last_post_meta() { 35 // create a post as Author35 // Create a post as Author. 36 36 wp_set_current_user( self::$author_user_id ); 37 37 $post = get_default_post_to_edit( 'post', true ); … … 46 46 ); 47 47 48 // update post as Editor48 // Update post as Editor. 49 49 wp_set_current_user( self::$editor_user_id ); 50 50 wp_update_post( … … 55 55 ); 56 56 57 // restore back as Admin57 // Restore back as Admin. 58 58 wp_set_current_user( self::$admin_user_id ); 59 59 $revisions = wp_get_post_revisions( $post->ID ); … … 67 67 wp_restore_post_revision( $lastrevision->ID ); 68 68 69 // is post_meta correctly set to revision author70 $this->assertEquals( self::$admin_user_id, get_post_meta( $post_id, '_edit_last', true ) ); //after restoring user69 // Is post_meta correctly set to revision author after restoring user? 70 $this->assertEquals( self::$admin_user_id, get_post_meta( $post_id, '_edit_last', true ) ); 71 71 } 72 72 … … 90 90 ); 91 91 92 $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); // Just the initial revision 93 94 // First update 92 $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); // Just the initial revision. 93 94 // First update. 95 95 wp_update_post( 96 96 array( … … 98 98 'ID' => $post_id, 99 99 ) 100 ); 101 102 $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); // should be 2 revisions so far103 104 // update the post105 wp_update_post( 106 array( 107 'post_content' => 'new update for some updated content', 108 'ID' => $post_id, 109 ) 110 ); // 2nd revision111 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // should be 3 revision so far112 113 // next try to save another identical update, tests for patch that prevents storing duplicates114 wp_update_post( 115 array( 116 'post_content' => 'new update for some updated content', 117 'ID' => $post_id, 118 ) 119 ); // content unchanged, shouldn't save120 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // should still be 3 revision121 122 // next try to save another update, same content, but new ttile, should save revision100 ); // First revision. 101 102 $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); // Should be 2 revisions so far. 103 104 // Update the post. 105 wp_update_post( 106 array( 107 'post_content' => 'new update for some updated content', 108 'ID' => $post_id, 109 ) 110 ); // Second revision. 111 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // Should be 3 revisions so far. 112 113 // Next, try to save another identical update, tests for patch that prevents storing duplicates. 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. 120 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); // Should still be 3 revisions. 121 122 // Next, try to save another update, same content, but new title, should save revision. 123 123 wp_update_post( 124 124 array( … … 128 128 ) 129 129 ); 130 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); // should be 4 revision131 132 // next try to save another identical update130 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); // Should be 4 revisions. 131 132 // Next, try to save another identical update. 133 133 wp_update_post( 134 134 array( … … 137 137 'ID' => $post_id, 138 138 ) 139 ); // content unchanged, shouldn't save140 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); // should still be 4 revision139 ); // Content unchanged, shouldn't save. 140 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); // Should still be 4 revisions. 141 141 } 142 142 … … 165 165 $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); 166 166 167 // First update. 167 168 wp_update_post( 168 169 array( … … 170 171 'ID' => $post_id, 171 172 ) 172 ); //1st revision173 ); // First revision. 173 174 $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); 174 175 175 // update the post176 wp_update_post( 177 array( 178 'post_content' => 'new update for some updated content', 179 'ID' => $post_id, 180 ) 181 ); // 2nd revision176 // Update the post. 177 wp_update_post( 178 array( 179 'post_content' => 'new update for some updated content', 180 'ID' => $post_id, 181 ) 182 ); // Second revision. 182 183 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); 183 184 184 // next try to save another identical update, tests for patch that prevents storing duplicates185 wp_update_post( 186 array( 187 'post_content' => 'new update for some updated content', 188 'ID' => $post_id, 189 ) 190 ); // content unchanged, shouldn't save185 // Next, try to save another identical update, tests for patch that prevents storing duplicates. 186 wp_update_post( 187 array( 188 'post_content' => 'new update for some updated content', 189 'ID' => $post_id, 190 ) 191 ); // Content unchanged, shouldn't save. 191 192 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); 192 193 193 // next try to save another update, same content, but new ttile, should save revision194 // Next, try to save another update, same content, but new title, should save revision. 194 195 wp_update_post( 195 196 array( … … 201 202 $this->assertCount( 5, wp_get_post_revisions( $post_id ) ); 202 203 203 // next try to save another identical update204 // Next, try to save another identical update. 204 205 wp_update_post( 205 206 array( … … 208 209 'ID' => $post_id, 209 210 ) 210 ); // content unchanged, shouldn't save211 ); // Content unchanged, shouldn't save. 211 212 $this->assertCount( 6, wp_get_post_revisions( $post_id ) ); 212 213 … … 241 242 } 242 243 243 // Author should be able to view the revisions fine 244 // Author should be able to view the revisions fine. 244 245 foreach ( $revisions as $revision ) { 245 246 $this->assertTrue( user_can( self::$author_user_id, 'read_post', $revision->ID ) ); … … 272 273 } 273 274 274 // Author shouldn't be able to restore the revisions 275 // Author shouldn't be able to restore the revisions. 275 276 foreach ( $revisions as $revision ) { 276 277 $this->assertFalse( user_can( self::$author_user_id, 'edit_post', $revision->post_parent ) ); … … 303 304 ); 304 305 305 // Diff checks if you can read both left and right revisions 306 // Diff checks if you can read both left and right revisions. 306 307 $revisions = wp_get_post_revisions( $post_id ); 307 308 $this->assertCount( 2, $revisions ); … … 310 311 } 311 312 312 // Author should be able to diff the revisions fine 313 // Author should be able to diff the revisions fine. 313 314 foreach ( $revisions as $revision ) { 314 315 $this->assertTrue( user_can( self::$author_user_id, 'read_post', $revision->ID ) ); … … 352 353 } 353 354 354 // Author should be able to view the revisions fine 355 // Author should be able to view the revisions fine. 355 356 foreach ( $revisions as $revision ) { 356 357 $this->assertTrue( user_can( self::$author_user_id, 'read_post', $revision->ID ) ); … … 377 378 $editor_user->add_cap( 'edit_published_events' ); 378 379 379 // create a post as Editor380 // Create a post as Editor. 380 381 $post_id = self::factory()->post->create( 381 382 array( … … 397 398 } 398 399 399 // Author shouldn't be able to restore the revisions 400 // Author shouldn't be able to restore the revisions. 400 401 wp_set_current_user( self::$author_user_id ); 401 402 foreach ( $revisions as $revision ) { … … 498 499 ); 499 500 500 // Diff checks if you can read both left and right revisions 501 // Diff checks if you can read both left and right revisions. 501 502 $revisions = wp_get_post_revisions( $post_id ); 502 503 $this->assertCount( 2, $revisions ); … … 505 506 } 506 507 507 // Author should be able to diff the revisions fine 508 // Author should be able to diff the revisions fine. 508 509 foreach ( $revisions as $revision ) { 509 510 $this->assertTrue( user_can( self::$author_user_id, 'read_post', $revision->ID ) );
Note: See TracChangeset
for help on using the changeset viewer.