1 | <?php |
---|
2 | /** |
---|
3 | * @group revisions |
---|
4 | */ |
---|
5 | class Tests_Revisions extends WP_UnitTestCase { |
---|
6 | |
---|
7 | function setUp() { |
---|
8 | parent::setUp(); |
---|
9 | |
---|
10 | } |
---|
11 | |
---|
12 | function tearDown() { |
---|
13 | parent::tearDown(); |
---|
14 | } |
---|
15 | //function to get correctly stored user_ud if available (patch) |
---|
16 | protected function _get_revision_author( $revision ) { |
---|
17 | if ( ! $revision_author_id = get_post_meta( $revision->ID, '_edit_last', true ) ) { |
---|
18 | $revision_author_id = $revision->post_author; |
---|
19 | } |
---|
20 | return $revision_author_id; |
---|
21 | } |
---|
22 | /** |
---|
23 | * bug 16215 |
---|
24 | */ |
---|
25 | function test_revision_user_correct() { |
---|
26 | $user_id_1 = $this->factory->user->create( array( 'role' => 'administrator', 'user_login' => 'user 1' ) ); |
---|
27 | |
---|
28 | wp_set_current_user( $user_id_1 ); |
---|
29 | $post = array( 'post_author' => $user_id_1, 'post_title' => 'revisions' ); |
---|
30 | $post_id = wp_insert_post($post); //create a new post |
---|
31 | wp_publish_post( $post_id ); //and publish it |
---|
32 | wp_update_post( array( 'post_content' => 'revised by user_1', 'ID' => $post_id ) ); //update content |
---|
33 | |
---|
34 | $on_user = 0; |
---|
35 | $revisions = wp_get_post_revisions( $post_id ); |
---|
36 | $expected_post_author_ids = $arrayName = array( $user_id_1, $user_id_1, ); //two revisions so far |
---|
37 | foreach ( $revisions as $revision ) { |
---|
38 | $this->assertEquals( $expected_post_author_ids[ $on_user++ ], $this->_get_revision_author( $revision )); |
---|
39 | } |
---|
40 | |
---|
41 | //second user revisions |
---|
42 | $user_id_2 = $this->factory->user->create( array( 'role' => 'administrator', 'user_login' => 'user 2' ) ); |
---|
43 | wp_set_current_user( $user_id_2 ); |
---|
44 | wp_update_post( array( 'post_content' => 'revised by user_2', 'ID' => $post_id ) ); |
---|
45 | $revisions = wp_get_post_revisions( $post_id ); |
---|
46 | $expected_post_author_ids = $arrayName = array( $user_id_2, $user_id_1, $user_id_1, ); //three revisions |
---|
47 | $on_user = 0; |
---|
48 | foreach ( $revisions as $revision ) { |
---|
49 | if ( wp_is_post_revision( $revision )&& !wp_is_post_autosave( $revision ) ) { |
---|
50 | $this->assertEquals( $expected_post_author_ids[ $on_user++ ], $this->_get_revision_author( $revision )); |
---|
51 | } |
---|
52 | } |
---|
53 | |
---|
54 | //third user revisions |
---|
55 | $user_id_3 = $this->factory->user->create( array( 'role' => 'administrator', 'user_login' => 'user 3' ) ); |
---|
56 | wp_set_current_user( $user_id_3 ); |
---|
57 | wp_update_post( array( 'post_content' => 'revised by user_3', 'ID' => $post_id ) ); |
---|
58 | //wp_save_post_revision( $post_id ); |
---|
59 | $revisions = wp_get_post_revisions( $post_id ); |
---|
60 | $expected_post_author_ids = $arrayName = array( $user_id_3, $user_id_2, $user_id_1, $user_id_1, ); //four revisions |
---|
61 | $on_user = 0; |
---|
62 | foreach ( $revisions as $revision ) { |
---|
63 | if ( wp_is_post_revision( $revision )&& !wp_is_post_autosave( $revision ) ) { |
---|
64 | $this->assertEquals( $expected_post_author_ids[ $on_user++ ], $this->_get_revision_author( $revision )); |
---|
65 | } |
---|
66 | } |
---|
67 | } |
---|
68 | } |
---|