WordPress.org

Make WordPress Core

Ticket #20982: 20982.ut.diff

File 20982.ut.diff, 1.3 KB (added by adamsilverstein, 7 years ago)

correction, this is unit test for #20982

  • tests/post/meta.php

     
    243243                $this->assertEquals($funky_meta, get_post_meta($this->post_id, 'test_funky_post_meta', true));
    244244
    245245        }
     246
     247        /**
     248        * @ticket 20982
     249        */
     250        function test_revision_restore_updates_edit_last_post_meta() {
     251                //create two users matching reported bug
     252                $user_id_1 = $this->factory->user->create( array( 'role' => 'administrator', 'user_login' => 'admin1' ) );
     253                $user_id_2 = $this->factory->user->create( array( 'role' => 'editor', 'user_login' => 'editor1' ) );
     254
     255                //create a post as user 1
     256                wp_set_current_user( $user_id_1 );
     257                $post_id = $this->factory->post->create( array( 'post_title' => 'some-post', 'post_type' => 'post' ) );
     258
     259                //update post as user 2
     260                wp_set_current_user( $user_id_2 );
     261                wp_update_post( array( 'post_content'   => 'some updated content', 'ID' => $post_id ) );
     262
     263                //switch back to user 1 and restore 1st revision
     264                wp_set_current_user( $user_id_1 );
     265                $revisions = wp_get_post_revisions( $post_id );
     266                $lastrevision = end( $revisions );
     267                wp_restore_post_revision( $lastrevision->ID );
     268
     269                //is post_meta correctly set to user 1?
     270                $this->assertEquals( get_post_meta( $post_id, '_edit_last', true ), $user_id_1 ); //after restoring user
     271        }
    246272}