Changeset 1213 in tests for trunk/tests/post/revisions.php
- Timestamp:
- 02/14/2013 03:27:37 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/post/revisions.php
r1212 r1213 26 26 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 27 27 $author_user_id = $this->factory->user->create( array( 'role' => 'author' ) ); 28 28 29 29 //create a post as Author 30 30 wp_set_current_user( $author_user_id ); 31 31 $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_content' => 'I cant spel werds.' ) ); 32 32 33 33 //update post as Editor 34 34 wp_set_current_user( $editor_user_id ); 35 35 wp_update_post( array( 'post_content' => 'The Editor was in fixing your typos.', 'ID' => $post_id ) ); 36 36 37 37 //restore back as Admin 38 38 wp_set_current_user( $admin_user_id ); 39 39 $revisions = wp_get_post_revisions( $post_id ); 40 40 $this->assertEquals( count( $revisions ), 1 ); 41 41 42 42 $lastrevision = end( $revisions ); 43 43 $this->assertEquals( $lastrevision->post_content, 'I cant spel werds.' ); 44 44 // #16215 45 45 $this->assertEquals( $lastrevision->post_author, $author_user_id ); 46 46 47 47 wp_restore_post_revision( $lastrevision->ID ); 48 48 49 49 //is post_meta correctly set to revision author 50 50 $this->assertEquals( get_post_meta( $post_id, '_edit_last', true ), $author_user_id ); //after restoring user … … 57 57 function test_revision_dont_save_revision_if_unchanged() { 58 58 $post_id = $this->factory->post->create( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) ); 59 59 60 60 wp_update_post( array( 'post_content' => 'some updated content', 'ID' => $post_id ) ); //1st revision 61 61 $this->assertEquals( 1, count( wp_get_post_revisions( $post_id ) ) ); //should be 1 revision so far 62 62 63 63 //update the post 64 64 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //2nd revision 65 65 $this->assertEquals( 2, count( wp_get_post_revisions( $post_id ) ) ); //should be 2 revision so far 66 66 67 67 //next try to save another identical update, tests for patch that prevents storing duplicates 68 68 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save 69 69 $this->assertEquals( 2, count( wp_get_post_revisions( $post_id ) ) ); //should still be 2 revision 70 70 71 71 //next try to save another update, same content, but new ttile, should save revision 72 72 wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); 73 73 $this->assertEquals( 3, count( wp_get_post_revisions( $post_id ) ) ); //should be 3 revision 74 74 75 75 //next try to save another identical update 76 76 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 … … 85 85 $author_user_id = $this->factory->user->create( array( 'role' => 'author' ) ); 86 86 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 87 87 88 88 //create a post as Editor 89 89 wp_set_current_user( $editor_user_id ); 90 90 $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) ); 91 91 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 92 92 93 93 $revisions = wp_get_post_revisions( $post_id ); 94 94 $this->assertEquals( count( $revisions ), 1 ); 95 95 $this->assertTrue( current_user_can( 'read_post', $post_id ) ); 96 97 foreach ( $revisions as $revision ) { 98 $this->assertTrue( current_user_can( 'read_post', $revision->ID ) ); 99 } 100 96 97 foreach ( $revisions as $revision ) { 98 $this->assertTrue( current_user_can( 'read_post', $revision->ID ) ); 99 } 100 101 101 // Author should be able to view the revisions fine 102 102 wp_set_current_user( $author_user_id ); … … 113 113 $author_user_id = $this->factory->user->create( array( 'role' => 'author' ) ); 114 114 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 115 115 116 116 //create a post as Editor 117 117 wp_set_current_user( $editor_user_id ); 118 118 $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) ); 119 119 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 120 120 121 121 $revisions = wp_get_post_revisions( $post_id ); 122 122 $this->assertEquals( count( $revisions ), 1 ); … … 124 124 $this->assertTrue( current_user_can( 'edit_post', $revision->post_parent ) ); 125 125 } 126 126 127 127 // Author shouldn't be able to restore the revisions 128 128 wp_set_current_user( $author_user_id ); … … 139 139 $author_user_id = $this->factory->user->create( array( 'role' => 'author' ) ); 140 140 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 141 141 142 142 //create a post as Editor 143 143 wp_set_current_user( $editor_user_id ); … … 145 145 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 146 146 wp_update_post( array( 'post_content' => 'This content is even better', 'ID' => $post_id ) ); 147 147 148 148 // Diff checks if you can read both left and right revisions 149 149 $revisions = wp_get_post_revisions( $post_id ); … … 152 152 $this->assertTrue( current_user_can( 'read_post', $revision->ID ) ); 153 153 } 154 154 155 155 // Author should be able to diff the revisions fine 156 156 wp_set_current_user( $author_user_id ); … … 178 178 $post_id = $this->factory->post->create( array( 'post_type' => $this->post_type ) ); 179 179 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 180 180 181 181 $revisions = wp_get_post_revisions( $post_id ); 182 182 $this->assertEquals( count( $revisions ), 1 ); 183 183 $this->assertTrue( current_user_can( 'read_post', $post_id ) ); 184 184 185 185 foreach ( $revisions as $revision ) { 186 186 $this->assertTrue( current_user_can( 'read_post', $revision->ID ) ); 187 187 } 188 188 189 189 // Author should be able to view the revisions fine 190 190 wp_set_current_user( $author_user_id ); … … 223 223 $post_id = $this->factory->post->create( array( 'post_type' => $this->post_type ) ); 224 224 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 225 225 226 226 $revisions = wp_get_post_revisions( $post_id ); 227 227 $this->assertEquals( count( $revisions ), 1 ); … … 229 229 $this->assertTrue( current_user_can( 'edit_post', $revision->post_parent ) ); 230 230 } 231 231 232 232 // Author shouldn't be able to restore the revisions 233 233 wp_set_current_user( $author_user_id ); … … 235 235 $this->assertFalse( current_user_can( 'edit_post', $revision->post_parent ) ); 236 236 } 237 } 238 239 /** 240 * Tests the Caps used in the action=restore case of wp-admin/revision.php 241 * @ticket 16847 242 */ 243 function test_revision_restore_caps_before_publish() { 244 register_post_type( $this->post_type, array( 245 'capability_type' => 'post', 246 'capabilities' => array( 247 // No one can edit this post type once published. 248 // So, revisions cannot be restored, either. 249 'edit_published_posts' => 'do_not_allow', 250 ), 251 'map_meta_cap' => true, 252 'supports' => array( 'revisions' ), 253 ) ); 254 255 $old_id = get_current_user_id(); 256 wp_set_current_user( $this->factory->user->create( array( 'role' => 'editor' ) ) ); 257 258 $post_id = $this->factory->post->create( array( 'post_type' => $this->post_type, 'post_status' => 'draft' ) ); 259 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 260 261 $revisions = wp_get_post_revisions( $post_id ); 262 $this->assertCount( 1, $revisions ); 263 foreach ( $revisions as $revision ) { 264 $this->assertTrue( current_user_can( 'edit_post', $revision->post_parent ) ); 265 $this->assertTrue( current_user_can( 'edit_post', $revision->ID ) ); 266 } 267 268 wp_update_post( array( 'post_status' => 'publish', 'ID' => $post_id ) ); 269 270 $revisions = wp_get_post_revisions( $post_id ); 271 $this->assertCount( 2, $revisions ); 272 foreach ( $revisions as $revision ) { 273 $this->assertFalse( current_user_can( 'edit_post', $revision->post_parent ) ); 274 $this->assertFalse( current_user_can( 'edit_post', $revision->ID ) ); 275 } 276 wp_set_current_user( $old_id ); 237 277 } 238 278 … … 256 296 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 257 297 wp_update_post( array( 'post_content' => 'This content is even better', 'ID' => $post_id ) ); 258 298 259 299 // Diff checks if you can read both left and right revisions 260 300 $revisions = wp_get_post_revisions( $post_id ); … … 263 303 $this->assertTrue( current_user_can( 'read_post', $revision->ID ) ); 264 304 } 265 305 266 306 // Author should be able to diff the revisions fine 267 307 wp_set_current_user( $author_user_id );
Note: See TracChangeset
for help on using the changeset viewer.