Ticket #23497: 20982.16215.ut.diff
File 20982.16215.ut.diff, 4.8 KB (added by , 12 years ago) |
---|
-
tests/post/revisions.php
17 17 } 18 18 19 19 /** 20 * Note: Test needs reviewing when #16215 is fixed because I'm not sure the test current tests the "correct" behavior21 20 * @ticket 20982 22 * @ticket 1621521 * "Restoring post revisions does not update _edit_last" 23 22 */ 24 23 function test_revision_restore_updates_edit_last_post_meta() { 25 24 $admin_user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); … … 29 28 //create a post as Author 30 29 wp_set_current_user( $author_user_id ); 31 30 $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_content' => 'I cant spel werds.' ) ); 31 sleep( 1 ); 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 sleep( 1 ); 36 37 37 38 //restore back as Admin 38 39 wp_set_current_user( $admin_user_id ); 39 40 $revisions = wp_get_post_revisions( $post_id ); 40 $this->assertCount( 1, $revisions );41 41 42 42 $lastrevision = end( $revisions ); 43 $this->assertEquals( 'I cant spel werds.', $lastrevision->post_content );44 // #1621545 $this->assertEquals( $author_user_id , $lastrevision->post_author);46 43 47 44 wp_restore_post_revision( $lastrevision->ID ); 48 45 49 //is post_meta correctly set to revision author50 $this->assertEquals( $a uthor_user_id, get_post_meta( $post_id, '_edit_last', true ) ); //after restoring user46 //is post_meta correctly set to the current admin - the user who restored the post 47 $this->assertEquals( $admin_user_id, get_post_meta( $post_id, '_edit_last', true ) ); //after restoring user 51 48 52 49 wp_set_current_user( 0 ); 53 50 } 54 51 55 52 /** 53 * @ticket 16215 54 * "Post Revision history displays the incorrect author" 55 */ 56 function test_revision_history_author_correct() { 57 $admin_user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); 58 $editor_user_id = $this->factory->user->create( array( 'role' => 'editor' ) ); 59 $author_user_id = $this->factory->user->create( array( 'role' => 'author' ) ); 60 61 //create a post as Author 62 wp_set_current_user( $author_user_id ); 63 $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_content' => 'I cant spel werds.' ) ); 64 //a pause is required because additional revivions will not be saved if the timestamp hasn't changed 65 sleep( 1 ); 66 67 //update post as Editor 68 wp_set_current_user( $editor_user_id ); 69 wp_update_post( array( 'post_content' => 'The Editor was in fixing your typos.', 'ID' => $post_id ) ); 70 sleep( 1 );//pause after saving 71 72 //update post as author_user_id 73 wp_set_current_user( $author_user_id ); 74 wp_update_post( array( 'post_content' => 'The User edited last.', 'ID' => $post_id ) ); 75 76 77 wp_set_current_user( $admin_user_id ); 78 $revisions = wp_get_post_revisions( $post_id ); 79 $this->assertCount( 3, $revisions ); //inital save, revision 1 and current version 80 81 //verify that the last revision in the revision table 82 //matches the current post content 83 $lastrevision = array_shift( $revisions ); 84 85 $this->assertEquals( 'The User edited last.', $lastrevision->post_content ); 86 87 wp_set_current_user( 0 ); 88 } 89 90 /** 56 91 * @ticket 7392 57 92 * @ticket 9843 58 93 */ … … 87 122 add_filter( 'wp_save_post_revision_check_for_changes', '__return_false' ); 88 123 89 124 $post_id = $this->factory->post->create( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) ); 90 125 91 126 wp_update_post( array( 'post_content' => 'some updated content', 'ID' => $post_id ) ); //1st revision 92 127 $this->assertCount( 1, wp_get_post_revisions( $post_id ) ); 93 128 94 129 //update the post 95 130 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //2nd revision 96 131 $this->assertCount( 2, wp_get_post_revisions( $post_id ) ); 97 132 98 133 //next try to save another identical update, tests for patch that prevents storing duplicates 99 134 wp_update_post( array( 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save 100 135 $this->assertCount( 3, wp_get_post_revisions( $post_id ) ); 101 136 102 137 //next try to save another update, same content, but new ttile, should save revision 103 138 wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content' => 'new update for some updated content', 'ID' => $post_id ) ); 104 139 $this->assertCount( 4, wp_get_post_revisions( $post_id ) ); 105 140 106 141 //next try to save another identical update 107 142 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 143 $this->assertCount( 5, wp_get_post_revisions( $post_id ) );