Changeset 1214 in tests
- Timestamp:
- 02/14/2013 04:43:55 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/post/revisions.php
r1213 r1214 38 38 wp_set_current_user( $admin_user_id ); 39 39 $revisions = wp_get_post_revisions( $post_id ); 40 $this->assert Equals( count( $revisions ), 1);40 $this->assertCount( 1, $revisions ); 41 41 42 42 $lastrevision = end( $revisions ); 43 $this->assertEquals( $lastrevision->post_content, 'I cant spel werds.');43 $this->assertEquals( 'I cant spel werds.', $lastrevision->post_content ); 44 44 // #16215 45 $this->assertEquals( $ lastrevision->post_author, $author_user_id);45 $this->assertEquals( $author_user_id , $lastrevision->post_author); 46 46 47 47 wp_restore_post_revision( $lastrevision->ID ); 48 48 49 49 //is post_meta correctly set to revision author 50 $this->assertEquals( get_post_meta( $post_id, '_edit_last', true ), $author_user_id ); //after restoring user 50 $this->assertEquals( $author_user_id, get_post_meta( $post_id, '_edit_last', true ) ); //after restoring user 51 52 wp_set_current_user( 0 ); 51 53 } 52 54 … … 59 61 60 62 wp_update_post( array( 'post_content' => 'some updated content', 'ID' => $post_id ) ); //1st revision 61 $this->assert Equals( 1, count( wp_get_post_revisions( $post_id )) ); //should be 1 revision so far63 $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); //should be 1 revision so far 62 64 63 65 //update the post 64 66 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //2nd revision 65 $this->assert Equals( 2, count( wp_get_post_revisions( $post_id )) ); //should be 2 revision so far67 $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); //should be 2 revision so far 66 68 67 69 //next try to save another identical update, tests for patch that prevents storing duplicates 68 70 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save 69 $this->assert Equals( 2, count( wp_get_post_revisions( $post_id )) ); //should still be 2 revision71 $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); //should still be 2 revision 70 72 71 73 //next try to save another update, same content, but new ttile, should save revision 72 74 wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); 73 $this->assert Equals( 3, count( wp_get_post_revisions( $post_id )) ); //should be 3 revision75 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); //should be 3 revision 74 76 75 77 //next try to save another identical update 76 78 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 77 $this->assertEquals( 3, count( wp_get_post_revisions( $post_id ) ) ); //should still be 3 revision 79 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); //should still be 3 revision 80 } 81 82 /** 83 * @ticket 7392 84 * @ticket 9843 85 */ 86 function test_revision_force_save_revision_even_if_unchanged() { 87 add_filter( 'wp_save_post_revision_check_for_changes', '__return_false' ); 88 89 $post_id = $this->factory->post->create( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) ); 90 91 wp_update_post( array( 'post_content' => 'some updated content', 'ID' => $post_id ) ); //1st revision 92 $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); 93 94 //update the post 95 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //2nd revision 96 $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); 97 98 //next try to save another identical update, tests for patch that prevents storing duplicates 99 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save 100 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); 101 102 //next try to save another update, same content, but new ttile, should save revision 103 wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); 104 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); 105 106 //next try to save another identical update 107 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 108 $this->assertCount( 5, wp_get_post_revisions( $post_id ) ); 109 110 remove_filter( 'wp_save_post_revision_check_for_changes', '__return_false' ); 78 111 } 79 112 … … 86 119 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 87 120 88 //create a post as Editor 89 wp_set_current_user( $editor_user_id ); 90 $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) ); 91 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 92 93 $revisions = wp_get_post_revisions( $post_id ); 94 $this->assertEquals( count( $revisions ), 1 ); 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 ) ); 121 $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => $editor_user_id ) ); 122 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 123 124 $revisions = wp_get_post_revisions( $post_id ); 125 $this->assertCount( 1, $revisions ); 126 $this->assertTrue( user_can( $editor_user_id, 'read_post', $post_id ) ); 127 128 foreach ( $revisions as $revision ) { 129 $this->assertTrue( user_can( $editor_user_id, 'read_post', $revision->ID ) ); 99 130 } 100 131 101 132 // Author should be able to view the revisions fine 102 wp_set_current_user( $author_user_id ); 103 foreach ( $revisions as $revision ) { 104 $this->assertTrue( current_user_can( 'read_post', $revision->ID ) ); 133 foreach ( $revisions as $revision ) { 134 $this->assertTrue( user_can( $author_user_id, 'read_post', $revision->ID ) ); 105 135 } 106 136 } … … 114 144 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 115 145 116 //create a post as Editor 117 wp_set_current_user( $editor_user_id ); 118 $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) ); 119 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 120 121 $revisions = wp_get_post_revisions( $post_id ); 122 $this->assertEquals( count( $revisions ), 1 ); 123 foreach ( $revisions as $revision ) { 124 $this->assertTrue( current_user_can( 'edit_post', $revision->post_parent ) ); 146 $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => $editor_user_id ) ); 147 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 148 149 $revisions = wp_get_post_revisions( $post_id ); 150 $this->assertCount( 1, $revisions ); 151 foreach ( $revisions as $revision ) { 152 $this->assertTrue( user_can( $editor_user_id, 'edit_post', $revision->post_parent ) ); 125 153 } 126 154 127 155 // Author shouldn't be able to restore the revisions 128 wp_set_current_user( $author_user_id ); 129 foreach ( $revisions as $revision ) { 130 $this->assertFalse( current_user_can( 'edit_post', $revision->post_parent ) ); 156 foreach ( $revisions as $revision ) { 157 $this->assertFalse( user_can( $author_user_id, 'edit_post', $revision->post_parent ) ); 131 158 } 132 159 } … … 140 167 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 141 168 142 //create a post as Editor 143 wp_set_current_user( $editor_user_id ); 144 $post_id = $this->factory->post->create( array( 'post_type' => 'post' ) ); 169 $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => $editor_user_id ) ); 145 170 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 146 171 wp_update_post( array( 'post_content' => 'This content is even better', 'ID' => $post_id ) ); … … 148 173 // Diff checks if you can read both left and right revisions 149 174 $revisions = wp_get_post_revisions( $post_id ); 150 $this->assert Equals( count( $revisions ), 2);151 foreach ( $revisions as $revision ) { 152 $this->assertTrue( current_user_can('read_post', $revision->ID ) );175 $this->assertCount( 2, $revisions ); 176 foreach ( $revisions as $revision ) { 177 $this->assertTrue( user_can( $editor_user_id, 'read_post', $revision->ID ) ); 153 178 } 154 179 155 180 // Author should be able to diff the revisions fine 156 wp_set_current_user( $author_user_id ); 157 foreach ( $revisions as $revision ) { 158 $this->assertTrue( current_user_can( 'read_post', $revision->ID ) ); 181 foreach ( $revisions as $revision ) { 182 $this->assertTrue( user_can( $author_user_id, 'read_post', $revision->ID ) ); 159 183 } 160 184 } … … 174 198 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 175 199 176 //create a post as Editor 177 wp_set_current_user( $editor_user_id ); 178 $post_id = $this->factory->post->create( array( 'post_type' => $this->post_type ) ); 179 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 180 181 $revisions = wp_get_post_revisions( $post_id ); 182 $this->assertEquals( count( $revisions ), 1 ); 183 $this->assertTrue( current_user_can( 'read_post', $post_id ) ); 184 185 foreach ( $revisions as $revision ) { 186 $this->assertTrue( current_user_can( 'read_post', $revision->ID ) ); 200 $post_id = $this->factory->post->create( array( 'post_type' => $this->post_type, 'post_author' => $editor_user_id ) ); 201 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 202 203 $revisions = wp_get_post_revisions( $post_id ); 204 $this->assertCount( 1, $revisions ); 205 $this->assertTrue( user_can( $editor_user_id, 'read_post', $post_id ) ); 206 207 foreach ( $revisions as $revision ) { 208 $this->assertTrue( user_can( $editor_user_id, 'read_post', $revision->ID ) ); 187 209 } 188 210 189 211 // Author should be able to view the revisions fine 190 wp_set_current_user( $author_user_id ); 191 foreach ( $revisions as $revision ) { 192 $this->assertTrue( current_user_can( 'read_post', $revision->ID ) ); 212 foreach ( $revisions as $revision ) { 213 $this->assertTrue( user_can( $author_user_id, 'read_post', $revision->ID ) ); 193 214 } 194 215 } … … 209 230 210 231 // The minimum extra caps needed for this test normally you would give the role all the relevant caps. 211 $cpt_cap_map = array(212 'edit_published_posts' => 'edit_published_events',213 );214 215 232 $editor_user = new WP_User( $editor_user_id ); 216 foreach( $cpt_cap_map as $post_cap => $cpt_cap ) { 217 if ( $editor_user->has_cap( $post_cap ) ) 218 $editor_user->add_cap( $cpt_cap ); 219 } 233 $editor_user->add_cap( 'edit_published_events' ); 220 234 221 235 //create a post as Editor 222 wp_set_current_user( $editor_user_id ); 223 $post_id = $this->factory->post->create( array( 'post_type' => $this->post_type ) ); 224 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 225 226 $revisions = wp_get_post_revisions( $post_id ); 227 $this->assertEquals( count( $revisions ), 1 ); 228 foreach ( $revisions as $revision ) { 229 $this->assertTrue( current_user_can( 'edit_post', $revision->post_parent ) ); 236 $post_id = $this->factory->post->create( array( 'post_type' => $this->post_type, 'post_author' => $editor_user_id ) ); 237 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 238 239 $revisions = wp_get_post_revisions( $post_id ); 240 $this->assertCount( 1, $revisions ); 241 foreach ( $revisions as $revision ) { 242 $this->assertTrue( user_can( $editor_user_id, 'edit_post', $revision->post_parent ) ); 230 243 } 231 244 … … 233 246 wp_set_current_user( $author_user_id ); 234 247 foreach ( $revisions as $revision ) { 235 $this->assertFalse( current_user_can('edit_post', $revision->post_parent ) );248 $this->assertFalse( user_can( $author_user_id, 'edit_post', $revision->post_parent ) ); 236 249 } 237 250 } … … 291 304 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 292 305 293 //create a post as Editor 294 wp_set_current_user( $editor_user_id ); 295 $post_id = $this->factory->post->create( array( 'post_type' => $this->post_type ) ); 306 $post_id = $this->factory->post->create( array( 'post_type' => $this->post_type, 'post_author' => $editor_user_id ) ); 296 307 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 297 308 wp_update_post( array( 'post_content' => 'This content is even better', 'ID' => $post_id ) ); … … 301 312 $this->assertEquals( count( $revisions ), 2 ); 302 313 foreach ( $revisions as $revision ) { 303 $this->assertTrue( current_user_can('read_post', $revision->ID ) );314 $this->assertTrue( user_can( $editor_user_id, 'read_post', $revision->ID ) ); 304 315 } 305 316 306 317 // Author should be able to diff the revisions fine 307 wp_set_current_user( $author_user_id ); 308 foreach ( $revisions as $revision ) { 309 $this->assertTrue( current_user_can( 'read_post', $revision->ID ) ); 318 foreach ( $revisions as $revision ) { 319 $this->assertTrue( user_can( $author_user_id, 'read_post', $revision->ID ) ); 310 320 } 311 321 }
Note: See TracChangeset
for help on using the changeset viewer.