WordPress.org

Make WordPress Core

Ticket #23497: 20982.16215.ut.diff

File 20982.16215.ut.diff, 4.8 KB (added by adamsilverstein, 5 years ago)

updated unit tests for

  • tests/post/revisions.php

     
    1717        }
    1818
    1919        /**
    20          * Note: Test needs reviewing when #16215 is fixed because I'm not sure the test current tests the "correct" behavior
    2120         * @ticket 20982
    22          * @ticket 16215
     21         * "Restoring post revisions does not update _edit_last"
    2322         */
    2423        function test_revision_restore_updates_edit_last_post_meta() {
    2524                $admin_user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
     
    2928                //create a post as Author
    3029                wp_set_current_user( $author_user_id );
    3130                $post_id = $this->factory->post->create( array( 'post_type' => 'post', 'post_content' => 'I cant spel werds.' ) );
     31                sleep( 1 );
    3232
    3333                //update post as Editor
    3434                wp_set_current_user( $editor_user_id );
    3535                wp_update_post( array( 'post_content' => 'The Editor was in fixing your typos.', 'ID' => $post_id ) );
     36                sleep( 1 );
    3637
    3738                //restore back as Admin
    3839                wp_set_current_user( $admin_user_id );
    3940                $revisions = wp_get_post_revisions( $post_id );
    40                 $this->assertCount( 1, $revisions );
    4141
    4242                $lastrevision = end( $revisions );
    43                 $this->assertEquals( 'I cant spel werds.', $lastrevision->post_content );
    44                 // #16215
    45                 $this->assertEquals( $author_user_id , $lastrevision->post_author);
    4643
    4744                wp_restore_post_revision( $lastrevision->ID );
    4845
    49                 //is post_meta correctly set to revision author
    50                 $this->assertEquals( $author_user_id, get_post_meta( $post_id, '_edit_last', true ) ); //after restoring user
     46                //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
    5148
    5249                wp_set_current_user( 0 );
    5350        }
    5451
    5552        /**
     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        /**
    5691        * @ticket 7392
    5792        * @ticket 9843
    5893        */
     
    87122                add_filter( 'wp_save_post_revision_check_for_changes', '__return_false' );
    88123
    89124                $post_id = $this->factory->post->create( array( 'post_title' => 'some-post', 'post_type' => 'post', 'post_content' => 'some_content' ) );
    90                
     125
    91126                wp_update_post( array( 'post_content'   => 'some updated content', 'ID' => $post_id ) );        //1st revision
    92127                $this->assertCount( 1, wp_get_post_revisions( $post_id ) );
    93                
     128
    94129                //update the post
    95130                wp_update_post( array( 'post_content'   => 'new update for some updated content', 'ID' => $post_id ) ); //2nd revision
    96131                $this->assertCount( 2, wp_get_post_revisions( $post_id ) );
    97                
     132
    98133                //next try to save another identical update, tests for patch that prevents storing duplicates
    99134                wp_update_post( array( 'post_content'   => 'new update for some updated content', 'ID' => $post_id ) ); //content unchanged, shouldn't save
    100135                $this->assertCount( 3, wp_get_post_revisions( $post_id ) );
    101                
     136
    102137                //next try to save another update, same content, but new ttile, should save revision
    103138                wp_update_post( array( 'post_title' => 'some-post-changed', 'post_content'      => 'new update for some updated content', 'ID' => $post_id ) );
    104139                $this->assertCount( 4, wp_get_post_revisions( $post_id ) );
    105                
     140
    106141                //next try to save another identical update
    107142                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
    108143                $this->assertCount( 5, wp_get_post_revisions( $post_id ) );