Changeset 1309 in tests
- Timestamp:
- 07/10/2013 10:42:57 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/post/revisions.php
r1277 r1309 29 29 //create a post as Author 30 30 wp_set_current_user( $author_user_id ); 31 $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_content' => 'I cant spel werds.' ) ); 31 $post = get_default_post_to_edit( 'post', true ); 32 $post_id = $post->ID; 33 34 wp_update_post( array( 'post_status' => 'draft', 'post_content' => 'I cant spel werds.', 'ID' => $post_id ) ); 32 35 33 36 //update post as Editor … … 37 40 //restore back as Admin 38 41 wp_set_current_user( $admin_user_id ); 39 $revisions = wp_get_post_revisions( $post _id);42 $revisions = wp_get_post_revisions( $post->ID ); 40 43 $this->assertCount( 2, $revisions ); 41 44 … … 58 61 */ 59 62 function test_revision_dont_save_revision_if_unchanged() { 60 $post_id = $this->factory->post->create( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) ); 63 $post = get_default_post_to_edit( 'post', true ); 64 $post_id = $post->ID; 65 66 $this->assertCount( 0, wp_get_post_revisions( $post_id ) ); // No revisions on auto-draft creation. 67 68 wp_update_post( array( 'post_status' => 'draft', 'post_title' => 'some-post', 'post_content' => 'some_content', 'ID' => $post_id ) ); 69 61 70 $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); // Just the initial revision 62 71 … … 72 81 //next try to save another identical update, tests for patch that prevents storing duplicates 73 82 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save 74 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); //should still be 2revision83 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); //should still be 3 revision 75 84 76 85 //next try to save another update, same content, but new ttile, should save revision 77 86 wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); 78 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should be 3revision87 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should be 4 revision 79 88 80 89 //next try to save another identical update 81 90 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 82 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should still be 3revision91 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); //should still be 4 revision 83 92 } 84 93 … … 90 99 add_filter( 'wp_save_post_revision_check_for_changes', '__return_false' ); 91 100 92 $post_id = $this->factory->post->create( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) ); 101 $post = get_default_post_to_edit( 'post', true ); 102 $post_id = $post->ID; 103 104 $this->assertCount( 0, wp_get_post_revisions( $post_id ) ); // No revisions on auto-draft creation. 105 106 wp_update_post( array( 'post_status' => 'draft', 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content', 'ID' => $post_id ) ); 107 93 108 $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); 94 109 … … 127 142 128 143 $revisions = wp_get_post_revisions( $post_id ); 144 $this->assertCount( 1, $revisions ); 145 $this->assertTrue( user_can( $editor_user_id, 'read_post', $post_id ) ); 146 147 foreach ( $revisions as $revision ) { 148 $this->assertTrue( user_can( $editor_user_id, 'read_post', $revision->ID ) ); 149 } 150 151 // Author should be able to view the revisions fine 152 foreach ( $revisions as $revision ) { 153 $this->assertTrue( user_can( $author_user_id, 'read_post', $revision->ID ) ); 154 } 155 } 156 157 /** 158 * Tests the Caps used in the action=restore case of wp-admin/revision.php 159 * @ticket 16847 160 */ 161 function test_revision_restore_caps_post() { 162 $author_user_id = $this->factory->user->create( array( 'role' => 'author' ) ); 163 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 164 165 $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => $editor_user_id ) ); 166 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 167 168 $revisions = wp_get_post_revisions( $post_id ); 169 $this->assertCount( 1, $revisions ); 170 foreach ( $revisions as $revision ) { 171 $this->assertTrue( user_can( $editor_user_id, 'edit_post', $revision->post_parent ) ); 172 } 173 174 // Author shouldn't be able to restore the revisions 175 foreach ( $revisions as $revision ) { 176 $this->assertFalse( user_can( $author_user_id, 'edit_post', $revision->post_parent ) ); 177 } 178 } 179 180 /** 181 * Tests the Caps used in the action=diff case of wp-admin/revision.php 182 * @ticket 16847 183 */ 184 function test_revision_diff_caps_post() { 185 $author_user_id = $this->factory->user->create( array( 'role' => 'author' ) ); 186 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 187 188 $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => $editor_user_id ) ); 189 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) ); 190 wp_update_post( array( 'post_content' => 'This content is even better', 'ID' => $post_id ) ); 191 192 // Diff checks if you can read both left and right revisions 193 $revisions = wp_get_post_revisions( $post_id ); 129 194 $this->assertCount( 2, $revisions ); 130 $this->assertTrue( user_can( $editor_user_id, 'read_post', $post_id ) );131 132 foreach ( $revisions as $revision ) {133 $this->assertTrue( user_can( $editor_user_id, 'read_post', $revision->ID ) );134 }135 136 // Author should be able to view the revisions fine137 foreach ( $revisions as $revision ) {138 $this->assertTrue( user_can( $author_user_id, 'read_post', $revision->ID ) );139 }140 }141 142 /**143 * Tests the Caps used in the action=restore case of wp-admin/revision.php144 * @ticket 16847145 */146 function test_revision_restore_caps_post() {147 $author_user_id = $this->factory->user->create( array( 'role' => 'author' ) );148 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) );149 150 $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => $editor_user_id ) );151 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );152 153 $revisions = wp_get_post_revisions( $post_id );154 $this->assertCount( 2, $revisions );155 foreach ( $revisions as $revision ) {156 $this->assertTrue( user_can( $editor_user_id, 'edit_post', $revision->post_parent ) );157 }158 159 // Author shouldn't be able to restore the revisions160 foreach ( $revisions as $revision ) {161 $this->assertFalse( user_can( $author_user_id, 'edit_post', $revision->post_parent ) );162 }163 }164 165 /**166 * Tests the Caps used in the action=diff case of wp-admin/revision.php167 * @ticket 16847168 */169 function test_revision_diff_caps_post() {170 $author_user_id = $this->factory->user->create( array( 'role' => 'author' ) );171 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) );172 173 $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_author' => $editor_user_id ) );174 wp_update_post( array( 'post_content' => 'This content is much better', 'ID' => $post_id ) );175 wp_update_post( array( 'post_content' => 'This content is even better', 'ID' => $post_id ) );176 177 // Diff checks if you can read both left and right revisions178 $revisions = wp_get_post_revisions( $post_id );179 $this->assertCount( 3, $revisions );180 195 foreach ( $revisions as $revision ) { 181 196 $this->assertTrue( user_can( $editor_user_id, 'read_post', $revision->ID ) ); … … 206 221 207 222 $revisions = wp_get_post_revisions( $post_id ); 208 $this->assertCount( 2, $revisions );223 $this->assertCount( 1, $revisions ); 209 224 $this->assertTrue( user_can( $editor_user_id, 'read_post', $post_id ) ); 210 225 … … 242 257 243 258 $revisions = wp_get_post_revisions( $post_id ); 244 $this->assertCount( 2, $revisions );259 $this->assertCount( 1, $revisions ); 245 260 foreach ( $revisions as $revision ) { 246 261 $this->assertTrue( user_can( $editor_user_id, 'edit_post', $revision->post_parent ) ); … … 277 292 278 293 $revisions = wp_get_post_revisions( $post_id ); 279 $this->assertCount( 2, $revisions );294 $this->assertCount( 1, $revisions ); 280 295 foreach ( $revisions as $revision ) { 281 296 $this->assertTrue( current_user_can( 'edit_post', $revision->post_parent ) ); … … 286 301 287 302 $revisions = wp_get_post_revisions( $post_id ); 288 $this->assertCount( 3, $revisions );303 $this->assertCount( 2, $revisions ); 289 304 foreach ( $revisions as $revision ) { 290 305 $this->assertFalse( current_user_can( 'edit_post', $revision->post_parent ) ); … … 314 329 // Diff checks if you can read both left and right revisions 315 330 $revisions = wp_get_post_revisions( $post_id ); 316 $this->assert Equals( count( $revisions ), 3);331 $this->assertCount( 2, $revisions ); 317 332 foreach ( $revisions as $revision ) { 318 333 $this->assertTrue( user_can( $editor_user_id, 'read_post', $revision->ID ) );
Note: See TracChangeset
for help on using the changeset viewer.