Make WordPress Core

Ticket #21397: 21397.7.unittests.diff

File 21397.7.unittests.diff, 5.0 KB (added by markoheijnen, 11 years ago)
Line 
1Index: tests/xmlrpc/wp/editPost.php
2===================================================================
3--- tests/xmlrpc/wp/editPost.php        (revision 1007)
4+++ tests/xmlrpc/wp/editPost.php        (working copy)
5@@ -221,4 +221,63 @@
6                $this->assertFalse( is_sticky( $post_id ) );
7        }
8 
9+       function test_only_if_modified_since() {
10+               $editor_id = $this->make_user_by_role( 'editor' );
11+
12+               $post = array(
13+                       'post_title' => 'Post Revision Test',
14+                       'post_author' => $editor_id,
15+                       'post_status' => 'publish',
16+                       'post_date'  => strftime("%Y-%m-%d %H:%M:%S", strtotime( '-1 day' ) ),
17+               );
18+               $post_id = wp_insert_post( $post );
19+
20+               $revision_date = new IXR_Date( mysql2date( 'Ymd\TH:i:s', 'now', false ) );
21+               $post2 = array( 'post_content' => 'Edit #3', 'only_if_modified_since' => $revision_date );
22+               $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );
23+               $this->assertNotInstanceOf( 'IXR_Error', $result );
24+
25+               $revision_date = new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date'], false ) );
26+               $post2 = array( 'post_content' => 'Edit #4', 'only_if_modified_since' => $revision_date );
27+               $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );
28+               $this->assertInstanceOf( 'IXR_Error', $result );
29+               $this->assertEquals( 409, $result->code );
30+       }
31 }
32Index: tests/xmlrpc/wp/restoreRevision.php
33===================================================================
34--- tests/xmlrpc/wp/restoreRevision.php (revision 0)
35+++ tests/xmlrpc/wp/restoreRevision.php (revision 0)
36@@ -0,0 +1,58 @@
37+<?php
38+
39+/**
40+ * @group xmlrpc
41+ */
42+class Tests_XMLRPC_wp_restoreRevision extends WP_XMLRPC_UnitTestCase {
43+       var $post_id;
44+       var $revision_id;
45+
46+       function setUp() {
47+               parent::setUp();
48+
49+               $post_data = array(
50+                       'post_title' => rand_str(),
51+                       'post_content' => 'edit1'
52+               );
53+               $this->post_id = wp_insert_post( $post_data );
54+               $post_data = get_post( $this->post_id, ARRAY_A );
55+               $post_data['post_content'] = 'edit2';
56+               wp_update_post( $post_data );
57+               $revisions = wp_get_post_revisions( $this->post_id );
58+               $revision = array_shift( $revisions );
59+               $this->revision_id = $revision->ID;
60+
61+       }
62+
63+       function test_invalid_username_password() {
64+               $result = $this->myxmlrpcserver->wp_restoreRevision( array( 1, 'username', 'password', $this->revision_id ) );
65+               $this->assertInstanceOf( 'IXR_Error', $result );
66+               $this->assertEquals( 403, $result->code );
67+       }
68+
69+       function test_incapable_user() {
70+               $this->make_user_by_role( 'subscriber' );
71+
72+               $result = $this->myxmlrpcserver->wp_restoreRevision( array( 1, 'subscriber', 'subscriber', $this->revision_id ) );
73+               $this->assertInstanceOf( 'IXR_Error', $result );
74+               $this->assertEquals( 401, $result->code );
75+       }
76+
77+       function test_capable_user() {
78+               $this->make_user_by_role( 'editor' );
79+
80+               $result = $this->myxmlrpcserver->wp_restoreRevision( array( 1, 'editor', 'editor', $this->revision_id ) );
81+               $this->assertNotInstanceOf( 'IXR_Error', $result );
82+       }
83+
84+       function test_revision_restored() {
85+               $this->make_user_by_role( 'editor' );
86+
87+               $result = $this->myxmlrpcserver->wp_restoreRevision( array( 1, 'editor', 'editor', $this->revision_id ) );
88+               $post = get_post( $this->post_id, ARRAY_A );
89+               $this->assertEquals( true, $result );
90+               $this->assertEquals( 'edit1', $post['post_content'] );
91+       }
92+}
93+
94+
95Index: tests/xmlrpc/wp/getRevisions.php
96===================================================================
97--- tests/xmlrpc/wp/getRevisions.php    (revision 0)
98+++ tests/xmlrpc/wp/getRevisions.php    (revision 0)
99@@ -0,0 +1,48 @@
100+<?php
101+
102+/**
103+ * @group xmlrpc
104+ */
105+class Tests_XMLRPC_wp_getRevisions extends WP_XMLRPC_UnitTestCase {
106+
107+       function test_invalid_username_password() {
108+               $result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'username', 'password', 0 ) );
109+               $this->assertInstanceOf( 'IXR_Error', $result );
110+               $this->assertEquals( 403, $result->code );
111+       }
112+
113+       function test_incapable_user() {
114+               $this->make_user_by_role( 'subscriber' );
115+
116+               $result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'subscriber', 'subscriber', 0 ) );
117+               $this->assertInstanceOf( 'IXR_Error', $result );
118+               $this->assertEquals( 401, $result->code );
119+       }
120+
121+       function test_capable_user() {
122+               $this->make_user_by_role( 'editor' );
123+
124+               $result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'editor', 'editor', 0 ) );
125+               $this->assertNotInstanceOf( 'IXR_Error', $result );
126+       }
127+
128+       function test_revision_count() {
129+               $this->make_user_by_role( 'editor' );
130+
131+               $post = array( 'post_title' => 'Post test' );
132+               $post_id = wp_insert_post( $post );
133+
134+               $result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'editor', 'editor', $post_id ) );
135+               $this->assertInternalType( 'array', $result );
136+               $this->assertEquals( 0, count( $result ) );
137+
138+               $post = get_post( $post_id, ARRAY_A );
139+               $post['post_content'] = 'Edit #1';
140+               wp_update_post( $post );
141+
142+               $result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'editor', 'editor', $post_id ) );
143+               $this->assertInternalType( 'array', $result );
144+               $this->assertEquals( 1, count( $result ) );
145+       }
146+}
147+