forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmlrpc.php
More file actions
247 lines (215 loc) · 5.3 KB
/
xmlrpc.php
File metadata and controls
247 lines (215 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/**
* @group date
* @group datetime
* @group xmlrpc
* @covers IXR_Date
*/
class Tests_Date_XMLRPC extends WP_XMLRPC_UnitTestCase {
/**
* @ticket 30429
*
* @covers wp_xmlrpc_server::mw_newPost
*/
public function test_date_new_post() {
$timezone = 'Europe/Kiev';
update_option( 'timezone_string', $timezone );
$datetime = new DateTimeImmutable( 'now', new DateTimeZone( $timezone ) );
$datetimeutc = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
$this->make_user_by_role( 'editor' );
$post = get_post(
$this->myxmlrpcserver->mw_newPost(
array(
1,
'editor',
'editor',
array(
'title' => 'test',
'post_content' => 'test',
'dateCreated' => new IXR_Date( $datetimeutc->format( 'Ymd\TH:i:s\Z' ) ),
),
)
)
);
$this->assertSame(
$datetime->format( 'Y-m-d H:i:s' ),
$post->post_date,
'UTC time with explicit time zone into mw_newPost'
);
$post = get_post(
$this->myxmlrpcserver->mw_newPost(
array(
1,
'editor',
'editor',
array(
'title' => 'test',
'post_content' => 'test',
'dateCreated' => new IXR_Date( $datetime->format( 'Ymd\TH:i:s' ) ),
),
)
)
);
$this->assertSame(
$datetime->format( 'Y-m-d H:i:s' ),
$post->post_date,
'Local time w/o time zone into mw_newPost'
);
$post = get_post(
$this->myxmlrpcserver->mw_newPost(
array(
1,
'editor',
'editor',
array(
'title' => 'test',
'post_content' => 'test',
'date_created_gmt' => new IXR_Date( $datetimeutc->format( 'Ymd\TH:i:s' ) ),
),
)
)
);
$this->assertSame(
$datetime->format( 'Y-m-d H:i:s' ),
$post->post_date,
'UTC time into mw_newPost'
);
$post = get_post(
$this->myxmlrpcserver->wp_newPost(
array(
1,
'editor',
'editor',
array(
'title' => 'test',
'post_content' => 'test',
'post_date' => $datetime->format( 'Ymd\TH:i:s' ),
),
)
)
);
$this->assertSame(
$datetime->format( 'Y-m-d H:i:s' ),
$post->post_date,
'Local time into wp_newPost'
);
$post = get_post(
$this->myxmlrpcserver->wp_newPost(
array(
1,
'editor',
'editor',
array(
'title' => 'test',
'post_content' => 'test',
'post_date_gmt' => $datetimeutc->format( 'Ymd\TH:i:s' ),
),
)
)
);
$this->assertSame(
$datetime->format( 'Y-m-d H:i:s' ),
$post->post_date,
'UTC time into wp_newPost'
);
}
/**
* @ticket 30429
*
* @covers wp_xmlrpc_server::mw_editPost
*/
public function test_date_edit_post() {
$timezone = 'Europe/Kiev';
update_option( 'timezone_string', $timezone );
$datetime = new DateTimeImmutable( 'now', new DateTimeZone( $timezone ) );
$datetimeutc = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
$editor_id = $this->make_user_by_role( 'editor' );
$post_id = self::factory()->post->create(
array(
'post_author' => $editor_id,
'post_date' => $datetime->modify( '-1 hour' )->format( 'Y-m-d H:i:s' ),
)
);
$result = $this->myxmlrpcserver->mw_editPost(
array(
$post_id,
'editor',
'editor',
array(
'dateCreated' => new IXR_Date( $datetime->format( 'Ymd\TH:i:s' ) ),
),
)
);
$fetched_post = get_post( $post_id );
$this->assertTrue( $result );
$this->assertSame(
$datetime->format( 'Y-m-d H:i:s' ),
$fetched_post->post_date,
'Local time into mw_editPost'
);
$post_id = self::factory()->post->create(
array(
'post_author' => $editor_id,
'post_date' => $datetime->modify( '-1 hour' )->format( 'Y-m-d H:i:s' ),
)
);
$result = $this->myxmlrpcserver->mw_editPost(
array(
$post_id,
'editor',
'editor',
array(
'date_created_gmt' => new IXR_Date( $datetimeutc->format( 'Ymd\TH:i:s' ) ),
),
)
);
$fetched_post = get_post( $post_id );
$this->assertTrue( $result );
$this->assertSame(
$datetime->format( 'Y-m-d H:i:s' ),
$fetched_post->post_date,
'UTC time into mw_editPost'
);
}
/**
* @ticket 30429
*
* @covers wp_xmlrpc_server::wp_editComment
*/
function test_date_edit_comment() {
$timezone = 'Europe/Kiev';
update_option( 'timezone_string', $timezone );
$datetime = new DateTimeImmutable( 'now', new DateTimeZone( $timezone ) );
$datetime = $datetime->modify( '-1 hour' );
$datetimeutc = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
$this->make_user_by_role( 'administrator' );
$post_id = $this->factory->post->create();
$comment_data = array(
'comment_post_ID' => $post_id,
'comment_author' => 'Test commenter',
'comment_author_url' => 'http://example.com/',
'comment_author_email' => 'example@example.com',
'comment_content' => rand_str( 100 ),
'comment_approved' => '1',
);
$comment_id = wp_insert_comment( $comment_data );
$result = $this->myxmlrpcserver->wp_editComment(
array(
1,
'administrator',
'administrator',
$comment_id,
array(
'date_created_gmt' => new IXR_Date( $datetimeutc->format( 'Ymd\TH:i:s' ) ),
),
)
);
$fetched_comment = get_comment( $comment_id );
$this->assertTrue( $result );
$this->assertSame(
$datetime->format( 'Y-m-d H:i:s' ),
$fetched_comment->comment_date,
'UTC time into wp_editComment'
);
}
}