1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Automattic\Jetpack\Sync\Actions; |
4
|
|
|
use Automattic\Jetpack\Sync\Modules; |
5
|
|
|
use Automattic\Jetpack\Sync\Modules\Full_Sync; |
6
|
|
|
use Automattic\Jetpack\Sync\Settings; |
7
|
|
|
use Automattic\Jetpack\Sync\Health; |
8
|
|
|
|
9
|
|
|
if ( ! function_exists( 'jetpack_foo_full_sync_callable' ) ) { |
10
|
|
|
function jetpack_foo_full_sync_callable() { |
11
|
|
|
return 'the value'; |
12
|
|
|
} |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
class WP_Test_Jetpack_Sync_Full_Immediately extends WP_Test_Jetpack_Sync_Base { |
16
|
|
|
private $full_sync; |
17
|
|
|
|
18
|
|
|
private $full_sync_end_checksum; |
19
|
|
|
private $full_sync_start_config; |
20
|
|
|
private $synced_user_ids; |
21
|
|
|
|
22
|
|
|
private $test_posts_count = 20; |
23
|
|
|
private $test_comments_count = 11; |
24
|
|
|
|
25
|
|
View Code Duplication |
public function setUp() { |
26
|
|
|
parent::setUp(); |
27
|
|
|
Settings::reset_data(); |
28
|
|
|
|
29
|
|
|
$this->full_sync = Modules::get_module( 'full-sync' ); |
30
|
|
|
|
31
|
|
|
$this->server_replica_storage->reset(); |
32
|
|
|
$this->sender->reset_data(); |
33
|
|
|
$this->sender->set_enqueue_wait_time( 0 ); |
34
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
function test_sync_start_action_with_ranges() { |
38
|
|
|
$post = $this->factory->post->create(); |
39
|
|
|
$this->factory->comment->create_post_comments( $post, 11 ); |
40
|
|
|
|
41
|
|
|
$this->full_sync->start(); |
|
|
|
|
42
|
|
|
$this->sender->do_full_sync(); |
43
|
|
|
|
44
|
|
|
$start_event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_start' ); |
45
|
|
|
$this->assertTrue( $start_event !== false ); |
46
|
|
|
|
47
|
|
|
list( $config, $range ) = $start_event->args; |
48
|
|
|
|
49
|
|
|
$this->assertTrue( $config !== false ); |
50
|
|
|
|
51
|
|
|
$this->assertTrue( isset( $range['posts']->max ) ); |
52
|
|
|
$this->assertTrue( isset( $range['posts']->min ) ); |
53
|
|
|
$this->assertTrue( isset( $range['posts']->count ) ); |
54
|
|
|
|
55
|
|
|
$this->assertTrue( isset( $range['comments']->max ) ); |
56
|
|
|
$this->assertTrue( isset( $range['comments']->min ) ); |
57
|
|
|
$this->assertTrue( isset( $range['comments']->count ) ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
function test_sync_health_in_sync_on_full_sync_end() { |
61
|
|
|
Health::update_status( Health::STATUS_OUT_OF_SYNC ); |
62
|
|
|
$this->assertEquals( Health::get_status(), Health::STATUS_OUT_OF_SYNC ); |
63
|
|
|
$post = $this->factory->post->create(); |
64
|
|
|
$this->factory->comment->create_post_comments( $post, 11 ); |
65
|
|
|
|
66
|
|
|
$this->full_sync->start(); |
|
|
|
|
67
|
|
|
$this->sender->do_full_sync(); |
68
|
|
|
$this->assertEquals( Health::get_status(), Health::STATUS_IN_SYNC ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
// this only applies to the test replicastore - in production we overlay data |
72
|
|
View Code Duplication |
function test_sync_start_resets_storage() { |
73
|
|
|
$this->factory->post->create(); |
74
|
|
|
$this->sender->do_sync(); |
75
|
|
|
|
76
|
|
|
$this->assertEquals( 1, $this->server_replica_storage->post_count() ); |
77
|
|
|
|
78
|
|
|
$this->sender->send_action( 'jetpack_full_sync_start' ); |
79
|
|
|
$this->assertEquals( 0, $this->server_replica_storage->post_count() ); |
80
|
|
|
|
81
|
|
|
$this->full_sync->start(); |
|
|
|
|
82
|
|
|
$this->sender->do_full_sync(); |
83
|
|
|
|
84
|
|
|
$this->assertEquals( 1, $this->server_replica_storage->post_count() ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
function test_sync_start_resets_previous_sync_and_sends_full_sync_cancelled() { |
88
|
|
|
$this->factory->post->create(); |
89
|
|
|
$this->full_sync->start(); |
|
|
|
|
90
|
|
|
|
91
|
|
|
// if we start again, it should reset the status back to its original state, |
92
|
|
|
// plus a "full_sync_cancelled" action |
93
|
|
|
$this->full_sync->start(); |
|
|
|
|
94
|
|
|
|
95
|
|
|
$this->sender->do_full_sync(); |
96
|
|
|
|
97
|
|
|
$cancelled_event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_cancelled' ); |
98
|
|
|
|
99
|
|
|
$this->assertTrue( $cancelled_event !== false ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
View Code Duplication |
function test_full_sync_lock_has_one_hour_timeout() { |
103
|
|
|
$this->started_sync_count = 0; |
104
|
|
|
|
105
|
|
|
add_action( 'jetpack_full_sync_start', array( $this, 'count_full_sync_start' ) ); |
106
|
|
|
|
107
|
|
|
$this->full_sync->start(); |
|
|
|
|
108
|
|
|
|
109
|
|
|
$this->assertEquals( 1, $this->started_sync_count ); |
110
|
|
|
|
111
|
|
|
// fake the last sync being over an hour ago |
112
|
|
|
$prefix = Full_Sync::STATUS_OPTION_PREFIX; |
113
|
|
|
update_option( "{$prefix}_started", time() - 3700 ); |
114
|
|
|
|
115
|
|
|
$this->full_sync->start(); |
|
|
|
|
116
|
|
|
|
117
|
|
|
$this->assertEquals( 2, $this->started_sync_count ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
function count_full_sync_start() { |
121
|
|
|
$this->started_sync_count += 1; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
function test_full_sync_can_select_modules() { |
125
|
|
|
$this->server_replica_storage->reset(); |
126
|
|
|
$this->sender->reset_data(); |
127
|
|
|
$this->factory->post->create(); |
128
|
|
|
|
129
|
|
|
$this->full_sync->start( array( 'options' => true ) ); |
|
|
|
|
130
|
|
|
|
131
|
|
|
$this->sender->do_full_sync(); |
132
|
|
|
|
133
|
|
|
$start_event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_start' ); |
134
|
|
|
|
135
|
|
|
$options_full_sync_actions = Modules::get_module( 'options' )->get_full_sync_actions(); |
136
|
|
|
$options_event = $this->server_event_storage->get_most_recent_event( $options_full_sync_actions[0] ); |
137
|
|
|
|
138
|
|
|
$posts_full_sync_actions = Modules::get_module( 'posts' )->get_full_sync_actions(); |
139
|
|
|
$posts_event = $this->server_event_storage->get_most_recent_event( $posts_full_sync_actions[0] ); |
140
|
|
|
|
141
|
|
|
$this->assertNotFalse( $start_event ); |
142
|
|
|
$this->assertNotFalse( $options_event ); |
143
|
|
|
$this->assertFalse( $posts_event ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
View Code Duplication |
function test_full_sync_sends_wp_version() { |
147
|
|
|
$this->server_replica_storage->reset(); |
148
|
|
|
$this->sender->reset_data(); |
149
|
|
|
|
150
|
|
|
$this->full_sync->start(); |
|
|
|
|
151
|
|
|
$this->sender->do_full_sync(); |
152
|
|
|
|
153
|
|
|
global $wp_version; |
154
|
|
|
$this->assertEquals( $wp_version, $this->server_replica_storage->get_callable( 'wp_version' ) ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
View Code Duplication |
function test_sync_post_filtered_content_was_filtered_when_syncing_all() { |
158
|
|
|
$post_id = $this->factory->post->create(); |
159
|
|
|
$post = get_post( $post_id ); |
160
|
|
|
add_shortcode( 'foo', array( $this, 'foo_shortcode' ) ); |
161
|
|
|
$post->post_content = "[foo]"; |
162
|
|
|
wp_update_post( $post ); |
163
|
|
|
$this->server_replica_storage->reset(); |
164
|
|
|
$this->sender->reset_data(); |
165
|
|
|
// this only applies to rendered content, which is off by default |
166
|
|
|
Settings::update_settings( array( 'render_filtered_content' => 1 ) ); |
167
|
|
|
|
168
|
|
|
$this->full_sync->start(); |
|
|
|
|
169
|
|
|
$this->sender->do_full_sync(); |
170
|
|
|
|
171
|
|
|
$post_on_server = $this->server_replica_storage->get_post( $post->ID ); |
172
|
|
|
$this->assertEquals( $post_on_server->post_content, '[foo]' ); |
173
|
|
|
$this->assertEquals( trim( $post_on_server->post_content_filtered ), 'bar' ); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
function foo_shortcode() { |
177
|
|
|
return 'bar'; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
View Code Duplication |
function test_full_sync_sends_all_comments() { |
181
|
|
|
$post = $this->factory->post->create(); |
182
|
|
|
$this->factory->comment->create_post_comments( $post, 11 ); |
183
|
|
|
|
184
|
|
|
// simulate emptying the server storage |
185
|
|
|
$this->server_replica_storage->reset(); |
186
|
|
|
$this->sender->reset_data(); |
187
|
|
|
|
188
|
|
|
$this->full_sync->start(); |
|
|
|
|
189
|
|
|
$this->sender->do_full_sync(); |
190
|
|
|
|
191
|
|
|
$comments = $this->server_replica_storage->get_comments(); |
192
|
|
|
$this->assertEquals( 11, count( $comments ) ); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
View Code Duplication |
function test_full_sync_sends_all_terms() { |
196
|
|
|
$NUMBER_OF_TERMS_TO_CREATE = 11; |
197
|
|
|
$this->server_replica_storage->reset(); |
198
|
|
|
$this->sender->reset_data(); |
199
|
|
|
for ( $i = 0; $i < $NUMBER_OF_TERMS_TO_CREATE; $i += 1 ) { |
200
|
|
|
wp_insert_term( 'category ' . $i, 'category' ); |
201
|
|
|
wp_insert_term( 'term ' . $i, 'post_tag' ); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
// simulate emptying the server storage |
205
|
|
|
$this->server_replica_storage->reset(); |
206
|
|
|
$this->sender->reset_data(); |
207
|
|
|
|
208
|
|
|
$this->full_sync->start(); |
|
|
|
|
209
|
|
|
$this->sender->do_full_sync(); |
210
|
|
|
|
211
|
|
|
$terms = $this->server_replica_storage->get_terms( 'post_tag' ); |
212
|
|
|
$this->assertEquals( $NUMBER_OF_TERMS_TO_CREATE, count( $terms ) ); |
213
|
|
|
|
214
|
|
|
$terms = $this->server_replica_storage->get_terms( 'category' ); |
215
|
|
|
$this->assertEquals( $NUMBER_OF_TERMS_TO_CREATE + 1, count( $terms ) ); // 11 + 1 (for uncategorized term) |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
function test_full_sync_sends_all_terms_with_previous_interval_end() { |
219
|
|
|
Settings::update_settings( array( 'max_full_sync_terms' => 1 ) ); |
220
|
|
|
|
221
|
|
View Code Duplication |
for ( $i = 0; $i < 25; $i += 1 ) { |
222
|
|
|
wp_insert_term( 'term' . $i, 'post_tag' ); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
// The first event is for full sync start. |
226
|
|
|
$this->full_sync->start( array( 'terms' => true ) ); |
|
|
|
|
227
|
|
|
$this->sender->do_full_sync(); |
228
|
|
|
|
229
|
|
|
$event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_terms' ); |
230
|
|
|
$previous_interval_end = $event->args['previous_end']; |
231
|
|
|
// The first batch has the previous_min_is not set. |
232
|
|
|
// We user ~0 to denote that the previous min id unknown. |
233
|
|
|
$this->assertEquals( '~0', $previous_interval_end ); |
234
|
|
|
|
235
|
|
|
$this->full_sync->reset_data(); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
function test_full_sync_send_immediately_skips_queue() { |
239
|
|
|
$posts_count = 100; |
240
|
|
|
$this->factory->post->create_many( $posts_count ); |
241
|
|
|
|
242
|
|
|
$this->full_sync->start( [ 'posts' => true ] ); |
|
|
|
|
243
|
|
|
$this->sender->do_full_sync(); |
244
|
|
|
// $this->sender->do_full_sync() is not necessary! |
245
|
|
|
|
246
|
|
|
$this->assertEquals( $posts_count, count( $this->server_replica_storage->get_posts() ) ); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
function test_full_sync_sends_all_term_relationships() { |
250
|
|
|
global $wpdb; |
251
|
|
|
$this->sender->reset_data(); |
252
|
|
|
|
253
|
|
|
$post_ids = $this->factory->post->create_many( 20 ); |
254
|
|
|
|
255
|
|
View Code Duplication |
foreach ( $post_ids as $post_id ) { |
256
|
|
|
wp_set_object_terms( $post_id, array( 'cat1', 'cat2', 'cat3' ), 'category', true ); |
257
|
|
|
wp_set_object_terms( $post_id, array( 'tag1', 'tag2', 'tag3' ), 'post_tag', true ); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
$original_number_of_term_relationships = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->term_relationships" ); |
261
|
|
|
|
262
|
|
|
// simulate emptying the server storage |
263
|
|
|
$this->server_replica_storage->reset(); |
264
|
|
|
|
265
|
|
|
$this->full_sync->start( array( 'term_relationships' => true ) ); |
|
|
|
|
266
|
|
|
$this->sender->do_full_sync(); |
267
|
|
|
|
268
|
|
|
$replica_number_of_term_relationships = count( $this->server_replica_storage->get_term_relationships() ); |
269
|
|
|
$this->assertEquals( $original_number_of_term_relationships, $replica_number_of_term_relationships ); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
function test_full_sync_sends_all_term_relationships_with_previous_interval_end() { |
273
|
|
|
$post_id = $this->factory->post->create(); |
274
|
|
|
|
275
|
|
|
$terms = array(); |
276
|
|
View Code Duplication |
for ( $i = 0; $i < 25; $i += 1 ) { |
277
|
|
|
$terms[] = wp_insert_term( 'term ' . $i, 'category' ); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
// Sync the posts and terms first. |
281
|
|
|
$this->full_sync->start( array( 'posts' => true, 'terms' => true ) ); |
|
|
|
|
282
|
|
|
$this->sender->do_full_sync(); |
283
|
|
|
|
284
|
|
|
// Simulate emptying the server storage. |
285
|
|
|
$this->server_replica_storage->reset(); |
286
|
|
|
$this->sender->reset_data(); |
287
|
|
|
|
288
|
|
|
Settings::update_settings( |
289
|
|
|
array( |
290
|
|
|
'term_relationships_full_sync_item_size' => 10 |
291
|
|
|
) |
292
|
|
|
); |
293
|
|
|
|
294
|
|
|
foreach ( $terms as $term ) { |
295
|
|
|
wp_set_object_terms( $post_id, array( $term['term_id'] ), 'category', true ); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
// The first event is for full sync start. |
299
|
|
|
$this->full_sync->start( array( 'term_relationships' => 1 ) ); |
|
|
|
|
300
|
|
|
$this->sender->do_full_sync(); |
301
|
|
|
|
302
|
|
|
$event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_term_relationships' ); |
303
|
|
|
$previous_interval_end = $event->args['previous_end']; |
304
|
|
|
|
305
|
|
|
$this->assertEquals( $previous_interval_end, array( |
306
|
|
|
'object_id' => Modules\Term_Relationships::MAX_INT, |
307
|
|
|
'term_taxonomy_id' => Modules\Term_Relationships::MAX_INT, |
308
|
|
|
) ); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
View Code Duplication |
function test_full_sync_sends_all_users() { |
312
|
|
|
$first_user_id = $this->factory->user->create(); |
313
|
|
|
for ( $i = 0; $i < 9; $i += 1 ) { |
314
|
|
|
$user_id = $this->factory->user->create(); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
update_user_meta( $user_id, 'locale', 'en_GB' ); |
|
|
|
|
318
|
|
|
// simulate emptying the server storage |
319
|
|
|
$this->server_replica_storage->reset(); |
320
|
|
|
$this->sender->reset_data(); |
321
|
|
|
|
322
|
|
|
$this->full_sync->start(); |
|
|
|
|
323
|
|
|
$this->sender->do_full_sync(); |
324
|
|
|
|
325
|
|
|
// 10 + 1 = 1 users gets always created. |
326
|
|
|
$this->assertEquals( 11, $this->server_replica_storage->user_count() ); |
327
|
|
|
$user = $this->server_replica_storage->get_user( $user_id ); |
328
|
|
|
$this->assertEquals( get_allowed_mime_types( $user_id ), $this->server_replica_storage->get_allowed_mime_types( $user_id ) ); |
329
|
|
|
|
330
|
|
|
$this->assertEquals( get_user_locale( $user_id ), $this->server_replica_storage->get_user_locale( $user_id ) ); |
331
|
|
|
$this->assertNull( $this->server_replica_storage->get_user_locale( $first_user_id ) ); |
332
|
|
|
|
333
|
|
|
// Lets make sure that we don't send users passwords around. |
334
|
|
|
$this->assertFalse( isset( $user->data->user_pass ) ); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
function test_full_sync_sends_previous_interval_end_for_users() { |
338
|
|
View Code Duplication |
for ( $i = 0; $i < 45; $i += 1 ) { |
339
|
|
|
$user_ids[] = $this->factory->user->create(); |
|
|
|
|
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
// The first event is for full sync start. |
343
|
|
|
$this->full_sync->start( array( 'users' => true ) ); |
|
|
|
|
344
|
|
|
$this->sender->do_full_sync(); |
345
|
|
|
|
346
|
|
|
$events = $this->server_event_storage->get_all_events( 'jetpack_full_sync_users' ); |
347
|
|
|
$previous_interval_end = $events[0]->args['previous_end']; |
348
|
|
|
|
349
|
|
|
// The first batch has the previous_min_is not set. |
350
|
|
|
// We user ~0 to denote that the previous min id unknown. |
351
|
|
|
$this->assertEquals( '~0', $previous_interval_end ); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
// phpunit -c tests/php.multisite.xml --filter test_full_sync_sends_only_current_blog_users_in_multisite |
355
|
|
|
function test_full_sync_sends_only_current_blog_users_in_multisite() { |
356
|
|
|
if ( ! is_multisite() ) { |
357
|
|
|
$this->markTestSkipped( 'Run it in multi site mode' ); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
$original_blog_id = get_current_blog_id(); |
361
|
|
|
|
362
|
|
|
$user_id = $this->factory->user->create(); |
363
|
|
|
|
364
|
|
|
// NOTE this is necessary because WPMU causes certain assumptions about transients |
365
|
|
|
// to be wrong, and tests to explode. @see: https://github.com/sheabunge/WordPress/commit/ff4f1bb17095c6af8a0f35ac304f79074f3c3ff6 |
366
|
|
|
global $wpdb; |
367
|
|
|
|
368
|
|
|
$suppress = $wpdb->suppress_errors(); |
369
|
|
|
$other_blog_id = wpmu_create_blog( 'foo.com', '', "My Blog", $this->user_id ); |
370
|
|
|
$wpdb->suppress_errors( $suppress ); |
371
|
|
|
|
372
|
|
|
// let's create some users on the other blog |
373
|
|
|
switch_to_blog( $other_blog_id ); |
374
|
|
|
$mu_blog_user_id = $this->factory->user->create(); |
375
|
|
|
$added_mu_blog_user_id = $this->factory->user->create(); |
376
|
|
|
restore_current_blog(); |
377
|
|
|
|
378
|
|
|
// add one of the users to our current blog |
379
|
|
|
add_user_to_blog( $original_blog_id, $added_mu_blog_user_id, 'administrator' ); |
380
|
|
|
|
381
|
|
|
// reset the storage, check value, and do full sync - storage should be set! |
382
|
|
|
$this->server_replica_storage->reset(); |
383
|
|
|
$this->full_sync->start(); |
|
|
|
|
384
|
|
|
$this->sender->do_full_sync(); |
385
|
|
|
|
386
|
|
|
// admin user, our current-blog-created user and our "added" user |
387
|
|
|
$this->assertEquals( 3, $this->server_replica_storage->user_count() ); |
388
|
|
|
|
389
|
|
|
$this->assertNotNull( $this->server_replica_storage->get_user( $user_id ) ); |
390
|
|
|
$this->assertNotNull( $this->server_replica_storage->get_user( $added_mu_blog_user_id ) ); |
391
|
|
|
$this->assertNull( $this->server_replica_storage->get_user( $mu_blog_user_id ) ); |
392
|
|
|
|
393
|
|
|
// now switch to the other site and sync, and ensure that only that site's users get synced. |
394
|
|
|
switch_to_blog( $other_blog_id ); |
395
|
|
|
$this->server_replica_storage->reset(); |
396
|
|
|
$this->synced_user_ids = null; |
397
|
|
|
|
398
|
|
|
$this->full_sync->start(); |
|
|
|
|
399
|
|
|
$this->sender->do_full_sync(); |
400
|
|
|
|
401
|
|
|
$user_count = $this->server_replica_storage->user_count(); |
402
|
|
|
$srs_added_mu_blog_user = $this->server_replica_storage->get_user( $added_mu_blog_user_id ); |
403
|
|
|
$srs_user = $this->server_replica_storage->get_user( $user_id ); |
404
|
|
|
$srs_mu_blog_user = $this->server_replica_storage->get_user( $mu_blog_user_id ); |
405
|
|
|
|
406
|
|
|
// restore context then run assertions. |
407
|
|
|
restore_current_blog(); |
408
|
|
|
|
409
|
|
|
$this->assertEquals( 2, $user_count ); |
410
|
|
|
|
411
|
|
|
// again, opposite users from previous sync. |
412
|
|
|
$this->assertNotNull( $srs_added_mu_blog_user ); |
413
|
|
|
$this->assertNull( $srs_user ); |
414
|
|
|
$this->assertNotNull( $srs_mu_blog_user ); |
415
|
|
|
|
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
function record_full_synced_users( $user_ids ) { |
419
|
|
|
$this->synced_user_ids = $user_ids; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
View Code Duplication |
function test_full_sync_sends_all_constants() { |
423
|
|
|
define( 'TEST_SYNC_ALL_CONSTANTS', 'foo' ); |
424
|
|
|
|
425
|
|
|
$helper = new Jetpack_Sync_Test_Helper(); |
426
|
|
|
$helper->array_override = array( 'TEST_SYNC_ALL_CONSTANTS' ); |
427
|
|
|
add_filter( 'jetpack_sync_constants_whitelist', array( $helper, 'filter_override_array' ) ); |
428
|
|
|
|
429
|
|
|
$this->sender->do_sync(); |
430
|
|
|
|
431
|
|
|
// reset the storage, check value, and do full sync - storage should be set! |
432
|
|
|
$this->server_replica_storage->reset(); |
433
|
|
|
|
434
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_constant( 'TEST_SYNC_ALL_CONSTANTS' ) ); |
435
|
|
|
|
436
|
|
|
$this->full_sync->start(); |
|
|
|
|
437
|
|
|
$this->sender->do_full_sync(); |
438
|
|
|
|
439
|
|
|
$this->assertEquals( 'foo', $this->server_replica_storage->get_constant( 'TEST_SYNC_ALL_CONSTANTS' ) ); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
View Code Duplication |
function test_full_sync_constants_updates_checksums() { |
443
|
|
|
define( 'FOO_SYNC_ALL_CONSTANTS', 'foo' ); |
444
|
|
|
$this->resetCallableAndConstantTimeouts(); |
445
|
|
|
$helper = new Jetpack_Sync_Test_Helper(); |
446
|
|
|
$helper->array_override = array( 'FOO_SYNC_ALL_CONSTANTS' ); |
447
|
|
|
add_filter( 'jetpack_sync_constants_whitelist', array( $helper, 'filter_override_array' ) ); |
448
|
|
|
$this->full_sync->start(); |
|
|
|
|
449
|
|
|
$this->sender->do_full_sync(); |
450
|
|
|
|
451
|
|
|
$this->assertEquals( 'foo', $this->server_replica_storage->get_constant( 'FOO_SYNC_ALL_CONSTANTS' ) ); |
452
|
|
|
|
453
|
|
|
// reset the storage, check value, and do full sync - storage should be set! |
454
|
|
|
$this->server_replica_storage->reset(); |
455
|
|
|
$this->server_event_storage->reset(); |
456
|
|
|
// Do Sync shouldn't send anything becuase the checksums are up to date. |
457
|
|
|
$this->sender->do_sync(); |
458
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_constant( 'FOO_SYNC_ALL_CONSTANTS' ) ); |
459
|
|
|
$events = $this->server_event_storage->get_all_events( 'jetpack_sync_constant' ); |
460
|
|
|
$this->assertTrue( empty( $events ) ); |
461
|
|
|
} |
462
|
|
|
|
463
|
|
View Code Duplication |
function test_full_sync_sends_all_functions() { |
464
|
|
|
Modules::get_module( "functions" )->set_callable_whitelist( array( 'jetpack_foo' => 'jetpack_foo_full_sync_callable' ) ); |
|
|
|
|
465
|
|
|
$this->sender->do_sync(); |
466
|
|
|
|
467
|
|
|
// reset the storage, check value, and do full sync - storage should be set! |
468
|
|
|
$this->server_replica_storage->reset(); |
469
|
|
|
|
470
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_callable( 'jetpack_foo' ) ); |
471
|
|
|
|
472
|
|
|
$this->full_sync->start(); |
|
|
|
|
473
|
|
|
$this->sender->do_full_sync(); |
474
|
|
|
|
475
|
|
|
$this->assertEquals( 'the value', $this->server_replica_storage->get_callable( 'jetpack_foo' ) ); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
View Code Duplication |
function test_full_sync_sends_all_functions_inverse() { |
479
|
|
|
Modules::get_module( "functions" )->set_callable_whitelist( array( 'jetpack_foo' => 'jetpack_foo_full_sync_callable' ) ); |
|
|
|
|
480
|
|
|
|
481
|
|
|
// reset the storage, check value, and do full sync - storage should be set! |
482
|
|
|
$this->server_replica_storage->reset(); |
483
|
|
|
|
484
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_callable( 'jetpack_foo' ) ); |
485
|
|
|
|
486
|
|
|
$this->full_sync->start(); |
|
|
|
|
487
|
|
|
$this->sender->do_full_sync(); |
488
|
|
|
$this->server_replica_storage->reset(); |
489
|
|
|
$this->server_event_storage->reset(); |
490
|
|
|
|
491
|
|
|
$this->resetCallableAndConstantTimeouts(); |
492
|
|
|
$this->sender->do_sync(); |
493
|
|
|
|
494
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_callable( 'jetpack_foo' ) ); |
495
|
|
|
$events = $this->server_event_storage->get_all_events( 'jetpack_sync_callable' ); |
496
|
|
|
$this->assertTrue( empty( $events ) ); |
497
|
|
|
|
498
|
|
|
} |
499
|
|
|
|
500
|
|
View Code Duplication |
function test_full_sync_sends_all_options() { |
501
|
|
|
delete_option( 'non_existant' ); |
502
|
|
|
Modules::get_module( "options" )->set_options_whitelist( array( |
|
|
|
|
503
|
|
|
'my_option', |
504
|
|
|
'my_prefix_value', |
505
|
|
|
'non_existant' |
506
|
|
|
) ); |
507
|
|
|
update_option( 'my_option', 'foo' ); |
508
|
|
|
update_option( 'my_prefix_value', 'bar' ); |
509
|
|
|
update_option( 'my_non_synced_option', 'baz' ); |
510
|
|
|
|
511
|
|
|
$this->sender->do_sync(); |
512
|
|
|
|
513
|
|
|
// confirm sync worked as expected |
514
|
|
|
$this->assertEquals( 'foo', $this->server_replica_storage->get_option( 'my_option' ) ); |
515
|
|
|
$this->assertEquals( 'bar', $this->server_replica_storage->get_option( 'my_prefix_value' ) ); |
516
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_option( 'my_non_synced_option' ) ); |
517
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_option( 'non_existant' ) ); |
518
|
|
|
|
519
|
|
|
// reset the storage, check value, and do full sync - storage should be set! |
520
|
|
|
$this->server_replica_storage->reset(); |
521
|
|
|
|
522
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_option( 'my_option' ) ); |
523
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_option( 'my_prefix_value' ) ); |
524
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_option( 'non_existant' ) ); |
525
|
|
|
|
526
|
|
|
$this->full_sync->start(); |
|
|
|
|
527
|
|
|
$this->sender->do_full_sync(); |
528
|
|
|
|
529
|
|
|
$synced_options_event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_options' ); |
530
|
|
|
$this->assertEquals( sizeof( $synced_options_event->args ), 2, 'Size of synced options not as expected' ); |
531
|
|
|
$this->assertEquals( 'foo', $synced_options_event->args['my_option'] ); |
532
|
|
|
$this->assertEquals( 'bar', $synced_options_event->args['my_prefix_value'] ); |
533
|
|
|
|
534
|
|
|
$this->assertEquals( 'foo', $this->server_replica_storage->get_option( 'my_option' ) ); |
535
|
|
|
$this->assertEquals( 'bar', $this->server_replica_storage->get_option( 'my_prefix_value' ) ); |
536
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_option( 'my_non_synced_option' ) ); |
537
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_option( 'non_existant' ) ); |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
// to test run phpunit -c tests/php.multisite.xml --filter test_full_sync_sends_all_network_options |
541
|
|
View Code Duplication |
function test_full_sync_sends_all_network_options() { |
542
|
|
|
if ( ! is_multisite() ) { |
543
|
|
|
$this->markTestSkipped( 'Run it in multi site mode' ); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
Modules::get_module( "network_options" )->set_network_options_whitelist( array( |
|
|
|
|
547
|
|
|
'my_option', |
548
|
|
|
'my_prefix_value' |
549
|
|
|
) ); |
550
|
|
|
update_site_option( 'my_option', 'foo' ); |
551
|
|
|
update_site_option( 'my_prefix_value', 'bar' ); |
552
|
|
|
update_site_option( 'my_non_synced_option', 'baz' ); |
553
|
|
|
|
554
|
|
|
$this->sender->do_sync(); |
555
|
|
|
|
556
|
|
|
// confirm sync worked as expected |
557
|
|
|
$this->assertEquals( 'foo', $this->server_replica_storage->get_site_option( 'my_option' ), '' ); |
558
|
|
|
$this->assertEquals( 'bar', $this->server_replica_storage->get_site_option( 'my_prefix_value' ) ); |
559
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_site_option( 'my_non_synced_option' ) ); |
560
|
|
|
|
561
|
|
|
// reset the storage, check value, and do full sync - storage should be set! |
562
|
|
|
$this->server_replica_storage->reset(); |
563
|
|
|
|
564
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_site_option( 'my_option' ) ); |
565
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_site_option( 'my_prefix_value' ) ); |
566
|
|
|
|
567
|
|
|
$this->full_sync->start(); |
|
|
|
|
568
|
|
|
$this->sender->do_full_sync(); |
569
|
|
|
|
570
|
|
|
$this->assertEquals( 'foo', $this->server_replica_storage->get_site_option( 'my_option' ), 'Network options not synced during full sync' ); |
571
|
|
|
$this->assertEquals( 'bar', $this->server_replica_storage->get_site_option( 'my_prefix_value' ) ); |
572
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_site_option( 'my_non_synced_option' ) ); |
573
|
|
|
} |
574
|
|
|
|
575
|
|
View Code Duplication |
function test_full_sync_sends_all_post_meta() { |
576
|
|
|
$post_id = $this->factory->post->create(); |
577
|
|
|
|
578
|
|
|
Settings::update_settings( array( 'post_meta_whitelist' => array( 'test_meta_key', 'test_meta_array' ) ) ); |
579
|
|
|
|
580
|
|
|
add_post_meta( $post_id, 'test_meta_key', 'foo' ); |
581
|
|
|
add_post_meta( $post_id, 'test_meta_array', array( 'foo', 'bar' ) ); |
582
|
|
|
|
583
|
|
|
$this->sender->do_sync(); |
584
|
|
|
|
585
|
|
|
$this->assertEquals( 'foo', $this->server_replica_storage->get_metadata( 'post', $post_id, 'test_meta_key', true ) ); |
586
|
|
|
$this->assertEquals( array( |
587
|
|
|
'foo', |
588
|
|
|
'bar' |
589
|
|
|
), $this->server_replica_storage->get_metadata( 'post', $post_id, 'test_meta_array', true ) ); |
590
|
|
|
|
591
|
|
|
// reset the storage, check value, and do full sync - storage should be set! |
592
|
|
|
$this->server_replica_storage->reset(); |
593
|
|
|
|
594
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'post', $post_id, 'test_meta_key', true ) ); |
595
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'post', $post_id, 'test_meta_array', true ) ); |
596
|
|
|
|
597
|
|
|
$this->full_sync->start(); |
|
|
|
|
598
|
|
|
$this->sender->do_full_sync(); |
599
|
|
|
|
600
|
|
|
$this->assertEquals( 'foo', $this->server_replica_storage->get_metadata( 'post', $post_id, 'test_meta_key', true ) ); |
601
|
|
|
$this->assertEquals( array( |
602
|
|
|
'foo', |
603
|
|
|
'bar' |
604
|
|
|
), $this->server_replica_storage->get_metadata( 'post', $post_id, 'test_meta_array', true ) ); |
605
|
|
|
} |
606
|
|
|
|
607
|
|
View Code Duplication |
function test_full_sync_doesnt_sends_forbiden_private_or_public_post_meta() { |
608
|
|
|
$post_id = $this->factory->post->create(); |
609
|
|
|
|
610
|
|
|
$meta_module = Modules::get_module( "meta" ); |
|
|
|
|
611
|
|
|
Settings::update_settings( array( 'post_meta_whitelist' => array( 'a_public_meta' ) ) ); |
612
|
|
|
|
613
|
|
|
// forbidden private meta |
614
|
|
|
add_post_meta( $post_id, '_test_meta_key', 'foo1' ); |
615
|
|
|
add_post_meta( $post_id, '_test_meta_array', array( 'foo2', 'bar' ) ); |
616
|
|
|
// forbidden public meta |
617
|
|
|
add_post_meta( $post_id, 'snapTW', 'foo3' ); |
618
|
|
|
// ok private meta |
619
|
|
|
add_post_meta( $post_id, '_wp_attachment_metadata', 'foo4' ); |
620
|
|
|
// ok public meta |
621
|
|
|
add_post_meta( $post_id, 'a_public_meta', 'foo5' ); |
622
|
|
|
|
623
|
|
|
$this->sender->do_sync(); |
624
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'post', $post_id, '_test_meta_key', true ) ); |
625
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'post', $post_id, '_test_meta_array', true ) ); |
626
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'post', $post_id, 'snapTW', true ) ); |
627
|
|
|
$this->assertEquals( 'foo4', $this->server_replica_storage->get_metadata( 'post', $post_id, '_wp_attachment_metadata', true ) ); |
628
|
|
|
$this->assertEquals( 'foo5', $this->server_replica_storage->get_metadata( 'post', $post_id, 'a_public_meta', true ) ); |
629
|
|
|
// reset the storage, check value, and do full sync - storage should be set! |
630
|
|
|
$this->server_replica_storage->reset(); |
631
|
|
|
|
632
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'post', $post_id, '_test_meta_key', true ) ); |
633
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'post', $post_id, '_test_meta_array', true ) ); |
634
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'post', $post_id, 'snapTW', true ) ); |
635
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'post', $post_id, '_wp_attachment_metadata', true ) ); |
636
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'post', $post_id, 'a_public_meta', true ) ); |
637
|
|
|
|
638
|
|
|
$this->full_sync->start(); |
|
|
|
|
639
|
|
|
$this->sender->do_full_sync(); |
640
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'post', $post_id, '_test_meta_key', true ) ); |
641
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'post', $post_id, '_test_meta_array', true ) ); |
642
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'post', $post_id, 'snapTW', true ) ); |
643
|
|
|
$this->assertEquals( 'foo4', $this->server_replica_storage->get_metadata( 'post', $post_id, '_wp_attachment_metadata', true ) ); |
644
|
|
|
$this->assertEquals( 'foo5', $this->server_replica_storage->get_metadata( 'post', $post_id, 'a_public_meta', true ) ); |
645
|
|
|
} |
646
|
|
|
|
647
|
|
View Code Duplication |
function test_full_sync_sends_all_post_terms() { |
648
|
|
|
$post_id = $this->factory->post->create(); |
649
|
|
|
wp_set_object_terms( $post_id, 'tag', 'post_tag' ); |
650
|
|
|
|
651
|
|
|
$this->sender->do_sync(); |
652
|
|
|
$terms = get_the_terms( $post_id, 'post_tag' ); |
653
|
|
|
|
654
|
|
|
$this->assertEqualsObject( $terms, $this->server_replica_storage->get_the_terms( $post_id, 'post_tag' ), 'Initial sync doesn\'t work' ); |
655
|
|
|
// reset the storage, check value, and do full sync - storage should be set! |
656
|
|
|
$this->server_replica_storage->reset(); |
657
|
|
|
|
658
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_the_terms( $post_id, 'post_tag', 'Not empty' ) ); |
|
|
|
|
659
|
|
|
$this->full_sync->start(); |
|
|
|
|
660
|
|
|
$this->sender->do_full_sync(); |
661
|
|
|
|
662
|
|
|
$this->assertEqualsObject( $terms, $this->server_replica_storage->get_the_terms( $post_id, 'post_tag' ), 'Full sync doesn\'t work' ); |
663
|
|
|
} |
664
|
|
|
|
665
|
|
View Code Duplication |
function test_full_sync_sends_all_comment_meta() { |
666
|
|
|
$post_id = $this->factory->post->create(); |
667
|
|
|
$comment_ids = $this->factory->comment->create_post_comments( $post_id ); |
668
|
|
|
$comment_id = $comment_ids[0]; |
669
|
|
|
|
670
|
|
|
Settings::update_settings( array( 'comment_meta_whitelist' => array( 'test_meta_key' ) ) ); |
671
|
|
|
|
672
|
|
|
add_comment_meta( $comment_id, 'test_meta_key', 'foo' ); |
673
|
|
|
|
674
|
|
|
$this->sender->do_sync(); |
675
|
|
|
|
676
|
|
|
$this->assertEquals( 'foo', $this->server_replica_storage->get_metadata( 'comment', $comment_id, 'test_meta_key', true ) ); |
677
|
|
|
|
678
|
|
|
// reset the storage, check value, and do full sync - storage should be set! |
679
|
|
|
$this->server_replica_storage->reset(); |
680
|
|
|
|
681
|
|
|
$this->assertEquals( null, $this->server_replica_storage->get_metadata( 'comment', $comment_id, 'test_meta_key', true ) ); |
682
|
|
|
|
683
|
|
|
$this->full_sync->start(); |
|
|
|
|
684
|
|
|
$this->sender->do_full_sync(); |
685
|
|
|
|
686
|
|
|
$this->assertEquals( 'foo', $this->server_replica_storage->get_metadata( 'comment', $comment_id, 'test_meta_key', true ) ); |
687
|
|
|
} |
688
|
|
|
|
689
|
|
|
function test_full_sync_sends_theme_info() { |
690
|
|
|
// make sure we don't already use this theme |
691
|
|
|
$this->assertNotEquals( 'twentyfourteen', get_option( 'stylesheet' ) ); |
692
|
|
|
|
693
|
|
|
switch_theme( 'twentyfourteen' ); |
694
|
|
|
set_theme_mod( 'foo', 'bar' ); |
695
|
|
|
$this->sender->do_sync(); |
696
|
|
|
|
697
|
|
|
$this->assertEquals( 'twentyfourteen', $this->server_replica_storage->get_option( 'stylesheet' ) ); |
698
|
|
|
|
699
|
|
|
// now reset the storage and confirm the value is reset |
700
|
|
|
$this->server_replica_storage->reset(); |
701
|
|
|
$this->assertNotEquals( 'twentyfourteen', $this->server_replica_storage->get_option( 'stylesheet' ) ); |
702
|
|
|
|
703
|
|
|
// full sync should restore the value |
704
|
|
|
$this->full_sync->start(); |
|
|
|
|
705
|
|
|
$this->sender->do_full_sync(); |
706
|
|
|
|
707
|
|
|
$this->assertEquals( 'twentyfourteen', $this->server_replica_storage->get_option( 'stylesheet' ) ); |
708
|
|
|
$local_option = get_option( 'theme_mods_twentyfourteen' ); |
709
|
|
|
$remote_option = $this->server_replica_storage->get_option( 'theme_mods_twentyfourteen' ); |
710
|
|
|
|
711
|
|
|
if ( isset( $local_option[0] ) ) { |
712
|
|
|
// this is a spurious value that sometimes gets set during tests, and is |
713
|
|
|
// actively removed before sending to WPCOM |
714
|
|
|
// it appears to be due to a bug which sets array( false ) as the default value for theme_mods |
715
|
|
|
unset( $local_option[0] ); |
716
|
|
|
} |
717
|
|
|
|
718
|
|
|
$this->assertEquals( $local_option, $remote_option ); |
719
|
|
|
|
720
|
|
|
$synced_theme_caps_event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_theme_data' ); |
721
|
|
|
$synced_theme_info = $synced_theme_caps_event->args[0]; |
722
|
|
|
|
723
|
|
|
$this->assertTrue( isset( $synced_theme_info['name'] ) ); |
724
|
|
|
$this->assertTrue( isset( $synced_theme_info['slug'] ) ); |
725
|
|
|
$this->assertTrue( isset( $synced_theme_info['uri'] ) ); |
726
|
|
|
$this->assertTrue( isset( $synced_theme_info['version'] ) ); |
727
|
|
|
|
728
|
|
|
$theme_support = $this->server_replica_storage->get_callable( 'theme_support' ); |
729
|
|
|
$this->assertTrue( isset( $theme_support['post-thumbnails'] ) ); |
730
|
|
|
|
731
|
|
|
$this->assertTrue( $theme_support['post-thumbnails'] ); |
732
|
|
|
|
733
|
|
|
$this->assertTrue( $this->server_replica_storage->current_theme_supports( 'post-thumbnails' ) ); |
734
|
|
|
} |
735
|
|
|
|
736
|
|
View Code Duplication |
function test_full_sync_sends_plugin_updates() { |
737
|
|
|
|
738
|
|
|
if ( is_multisite() ) { |
739
|
|
|
$this->markTestSkipped( 'Not compatible with multisite mode' ); |
740
|
|
|
} |
741
|
|
|
|
742
|
|
|
wp_update_plugins(); |
743
|
|
|
$this->check_for_updates_to_sync(); |
744
|
|
|
$this->sender->do_sync(); |
745
|
|
|
|
746
|
|
|
// check that an update just finished |
747
|
|
|
$updates = $this->server_replica_storage->get_updates( 'plugins' ); |
748
|
|
|
$this->assertTrue( $updates->last_checked > strtotime( "-10 seconds" ) ); |
|
|
|
|
749
|
|
|
|
750
|
|
|
$this->server_replica_storage->reset(); |
751
|
|
|
|
752
|
|
|
$this->assertNull( $this->server_replica_storage->get_updates( 'plugins' ) ); |
753
|
|
|
|
754
|
|
|
// full sync should re-check for plugin updates |
755
|
|
|
$this->full_sync->start(); |
|
|
|
|
756
|
|
|
$this->sender->do_full_sync(); |
757
|
|
|
|
758
|
|
|
$updates = $this->server_replica_storage->get_updates( 'plugins' ); |
759
|
|
|
$this->assertNotNull( $updates ); |
760
|
|
|
$this->assertTrue( $updates->last_checked > strtotime( "-10 seconds" ), 'Last checked is less then 2 seconds: ' . $updates->last_checked . ' - lest then 10 sec:' . strtotime( "-10 seconds" ) ); |
|
|
|
|
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
function check_for_updates_to_sync() { |
764
|
|
|
$updates_module = Modules::get_module( 'updates' ); |
765
|
|
|
$updates_module->sync_last_event(); |
766
|
|
|
} |
767
|
|
|
|
768
|
|
View Code Duplication |
function test_full_sync_sends_theme_updates() { |
769
|
|
|
|
770
|
|
|
if ( is_multisite() ) { |
771
|
|
|
$this->markTestSkipped( 'Not compatible with multisite mode' ); |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
wp_update_themes(); |
775
|
|
|
$this->check_for_updates_to_sync(); |
776
|
|
|
$this->sender->do_sync(); |
777
|
|
|
|
778
|
|
|
// check that an update just finished |
779
|
|
|
$updates = $this->server_replica_storage->get_updates( 'themes' ); |
780
|
|
|
$this->assertTrue( $updates->last_checked > strtotime( "-2 seconds" ) ); |
|
|
|
|
781
|
|
|
|
782
|
|
|
// we need to do this because there's a check for elapsed time since last update |
783
|
|
|
// in the wp_update_themes() function |
784
|
|
|
$this->server_replica_storage->reset(); |
785
|
|
|
|
786
|
|
|
$this->assertNull( $this->server_replica_storage->get_updates( 'themes' ) ); |
787
|
|
|
|
788
|
|
|
// full sync should re-check for plugin updates |
789
|
|
|
$this->full_sync->start(); |
|
|
|
|
790
|
|
|
$this->sender->do_full_sync(); |
791
|
|
|
|
792
|
|
|
$updates = $this->server_replica_storage->get_updates( 'themes' ); |
793
|
|
|
$this->assertNotNull( $updates ); |
794
|
|
|
$this->assertTrue( $updates->last_checked > strtotime( "-10 seconds" ) ); |
|
|
|
|
795
|
|
|
} |
796
|
|
|
|
797
|
|
|
function test_full_sync_start_sends_configuration() { |
798
|
|
|
$post_ids = $this->factory->post->create_many( 3 ); |
799
|
|
|
|
800
|
|
|
// this is so that on WPCOM we can tell what has been synchronized in the past |
801
|
|
|
add_action( 'jetpack_full_sync_start', array( $this, 'record_full_sync_start_config' ), 10, 1 ); |
802
|
|
|
|
803
|
|
|
$standard_config = array( |
804
|
|
|
'constants' => 1, |
805
|
|
|
'functions' => 1, |
806
|
|
|
'options' => 1, |
807
|
|
|
'terms' => 1, |
808
|
|
|
'term_relationships' => 1, |
809
|
|
|
'themes' => 1, |
810
|
|
|
'users' => 1, |
811
|
|
|
'updates' => 1, |
812
|
|
|
'posts' => 1, |
813
|
|
|
'comments' => 1, |
814
|
|
|
); |
815
|
|
|
|
816
|
|
|
if ( is_multisite() ) { |
817
|
|
|
$standard_config['network_options'] = 1; |
818
|
|
|
} |
819
|
|
|
|
820
|
|
|
$this->full_sync->start(); |
|
|
|
|
821
|
|
|
|
822
|
|
|
$this->assertEquals( $standard_config, $this->full_sync_start_config ); |
823
|
|
|
|
824
|
|
|
$custom_config = array( 'posts' => $post_ids ); |
825
|
|
|
|
826
|
|
|
$this->full_sync->start( $custom_config ); |
|
|
|
|
827
|
|
|
|
828
|
|
|
$this->assertEquals( $custom_config, $this->full_sync_start_config ); |
829
|
|
|
} |
830
|
|
|
|
831
|
|
View Code Duplication |
function test_full_sync_end_sends_checksums() { |
832
|
|
|
$this->markTestSkipped( "We don't send checksums in this version" ); |
833
|
|
|
add_action( 'jetpack_full_sync_end', array( $this, 'record_full_sync_end_checksum' ), 10, 1 ); |
834
|
|
|
|
835
|
|
|
$this->full_sync->start(); |
|
|
|
|
836
|
|
|
$this->sender->do_full_sync(); |
837
|
|
|
$this->sender->do_full_sync(); |
838
|
|
|
$this->sender->do_full_sync(); |
839
|
|
|
|
840
|
|
|
$this->assertTrue( isset( $this->full_sync_end_checksum ) ); |
841
|
|
|
$this->assertTrue( isset( $this->full_sync_end_checksum['posts'] ) ); |
842
|
|
|
$this->assertTrue( isset( $this->full_sync_end_checksum['comments'] ) ); |
843
|
|
|
} |
844
|
|
|
|
845
|
|
View Code Duplication |
function test_full_sync_end_sends_range() { |
846
|
|
|
$this->create_dummy_data_and_reset_sync_status(); |
847
|
|
|
add_action( 'jetpack_full_sync_end', array( $this, 'record_full_sync_end_checksum' ), 10, 2 ); |
848
|
|
|
|
849
|
|
|
$this->full_sync->start(); |
|
|
|
|
850
|
|
|
$this->sender->do_full_sync(); |
851
|
|
|
$this->sender->do_full_sync(); |
852
|
|
|
$this->sender->do_full_sync(); |
853
|
|
|
|
854
|
|
|
$this->assertTrue( isset( $this->full_sync_end_range ) ); |
855
|
|
|
$this->assertTrue( isset( $this->full_sync_end_range['posts']->max ) ); |
856
|
|
|
$this->assertTrue( isset( $this->full_sync_end_range['posts']->min ) ); |
857
|
|
|
$this->assertTrue( isset( $this->full_sync_end_range['posts']->count ) ); |
858
|
|
|
|
859
|
|
|
$this->assertTrue( isset( $this->full_sync_end_range['comments']->max ) ); |
860
|
|
|
$this->assertTrue( isset( $this->full_sync_end_range['comments']->min ) ); |
861
|
|
|
$this->assertTrue( isset( $this->full_sync_end_range['comments']->count ) ); |
862
|
|
|
|
863
|
|
|
$event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_end' ); |
864
|
|
|
|
865
|
|
|
list( $checksum, $range ) = $event->args; |
|
|
|
|
866
|
|
|
$this->assertTrue( isset( $range['posts']->max ) ); |
867
|
|
|
$this->assertTrue( isset( $range['posts']->min ) ); |
868
|
|
|
$this->assertTrue( isset( $range['posts']->count ) ); |
869
|
|
|
|
870
|
|
|
$this->assertTrue( isset( $range['comments']->max ) ); |
871
|
|
|
$this->assertTrue( isset( $range['comments']->min ) ); |
872
|
|
|
$this->assertTrue( isset( $range['comments']->count ) ); |
873
|
|
|
} |
874
|
|
|
|
875
|
|
View Code Duplication |
function create_dummy_data_and_reset_sync_status() { |
876
|
|
|
// lets create a bunch of posts |
877
|
|
|
for ( $i = 0; $i < $this->test_posts_count; $i += 1 ) { |
878
|
|
|
$post = $this->factory->post->create(); |
879
|
|
|
} |
880
|
|
|
// lets create a bunch of comments |
881
|
|
|
$this->factory->comment->create_post_comments( $post, $this->test_comments_count ); |
|
|
|
|
882
|
|
|
|
883
|
|
|
// reset the data before the full sync |
884
|
|
|
$this->sender->reset_data(); |
885
|
|
|
} |
886
|
|
|
|
887
|
|
|
function record_full_sync_end_checksum( $checksum, $range ) { |
888
|
|
|
// $checksum has been deprecated... |
889
|
|
|
$this->full_sync_end_range = $range; |
890
|
|
|
} |
891
|
|
|
|
892
|
|
|
function record_full_sync_start_config( $modules ) { |
893
|
|
|
$this->full_sync_start_config = $modules; |
894
|
|
|
} |
895
|
|
|
|
896
|
|
|
function test_full_sync_status_should_be_not_started_after_reset() { |
897
|
|
|
$this->create_dummy_data_and_reset_sync_status(); |
898
|
|
|
|
899
|
|
|
$full_sync_status = $this->full_sync->get_status(); |
|
|
|
|
900
|
|
|
|
901
|
|
|
$this->assertEquals( |
902
|
|
|
$full_sync_status, |
903
|
|
|
array( |
904
|
|
|
'started' => false, |
905
|
|
|
'finished' => false, |
906
|
|
|
'progress' => [], |
907
|
|
|
'config' => [], |
908
|
|
|
) |
909
|
|
|
); |
910
|
|
|
} |
911
|
|
|
|
912
|
|
|
function test_full_sync_status_after_start() { |
913
|
|
|
$this->create_dummy_data_and_reset_sync_status(); |
914
|
|
|
|
915
|
|
|
$this->full_sync->start(); |
|
|
|
|
916
|
|
|
|
917
|
|
|
$full_sync_status = $this->full_sync->get_status(); |
|
|
|
|
918
|
|
|
|
919
|
|
|
$this->assertInternalType( 'int', $full_sync_status['started'] ); |
920
|
|
|
$this->assertFalse( $full_sync_status['finished'] ); |
921
|
|
|
$this->assertInternalType( 'array', $full_sync_status['progress'] ); |
922
|
|
|
$this->assertEquals( count( \Automattic\Jetpack\Sync\Defaults::get_constants_whitelist() ), $full_sync_status['progress']['constants']['total'] ); |
923
|
|
|
} |
924
|
|
|
|
925
|
|
|
function test_full_sync_status_after_end() { |
926
|
|
|
$this->create_dummy_data_and_reset_sync_status(); |
927
|
|
|
|
928
|
|
|
$this->full_sync->start(); |
|
|
|
|
929
|
|
|
$this->sender->do_full_sync(); |
930
|
|
|
|
931
|
|
|
$status = $this->full_sync->get_status(); |
|
|
|
|
932
|
|
|
|
933
|
|
|
foreach( $status['progress'] as $module_status ) { |
934
|
|
|
if ( isset( $module_status['total'] ) ) { |
935
|
|
|
$this->assertEquals( $module_status['total'], $module_status['sent'] ); |
936
|
|
|
} |
937
|
|
|
$this->assertTrue( $module_status['finished'] ); // TODO: this could be a timestamp |
938
|
|
|
} |
939
|
|
|
|
940
|
|
|
$this->assertInternalType( 'int', $status['finished'] ); |
941
|
|
|
} |
942
|
|
|
|
943
|
|
View Code Duplication |
function test_full_sync_respects_post_and_comment_filters() { |
944
|
|
|
add_filter( 'jetpack_sync_prevent_sending_comment_data', '__return_true' ); |
945
|
|
|
add_filter( 'jetpack_sync_prevent_sending_post_data', '__return_true' ); |
946
|
|
|
|
947
|
|
|
$post_id = $this->factory->post->create(); |
948
|
|
|
$this->factory->comment->create_post_comments( $post_id, 3 ); |
949
|
|
|
|
950
|
|
|
$this->full_sync->start(); |
|
|
|
|
951
|
|
|
$this->sender->do_full_sync(); |
952
|
|
|
|
953
|
|
|
remove_filter( 'jetpack_sync_prevent_sending_comment_data', '__return_true' ); |
954
|
|
|
remove_filter( 'jetpack_sync_prevent_sending_post_data', '__return_true' ); |
955
|
|
|
|
956
|
|
|
$this->assertEquals( 3, $this->server_replica_storage->comment_count( 'jetpack_sync_blocked' ) ); |
957
|
|
|
$blocked_post = $this->server_replica_storage->get_post( $post_id ); |
958
|
|
|
$this->assertEquals( 'jetpack_sync_blocked', $blocked_post->post_status ); |
959
|
|
|
} |
960
|
|
|
|
961
|
|
View Code Duplication |
function test_full_sync_do_not_sync_events_if_no_data_to_sync() { |
962
|
|
|
$non_existent_id = 123123123123123213; |
963
|
|
|
$non_existent_post = get_post( $non_existent_id ); |
964
|
|
|
$non_existent_comment = get_comment( $non_existent_id ); |
965
|
|
|
$non_existent_user = get_user_by( 'id', $non_existent_id ); |
966
|
|
|
|
967
|
|
|
$this->assertTrue( empty( $non_existent_post ) ); |
968
|
|
|
$this->assertTrue( empty( $non_existent_comment ) ); |
969
|
|
|
$this->assertTrue( empty( $non_existent_user ) ); |
970
|
|
|
|
971
|
|
|
$this->full_sync->start( array( |
|
|
|
|
972
|
|
|
'posts' => array( $non_existent_id ), |
973
|
|
|
'comments' => array( $non_existent_id ), |
974
|
|
|
'users' => array( $non_existent_id ) |
975
|
|
|
) ); |
976
|
|
|
$this->sender->do_full_sync(); |
977
|
|
|
|
978
|
|
|
$this->assertFalse( $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_posts' ) ); |
979
|
|
|
$this->assertFalse( $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_comments' ) ); |
980
|
|
|
$this->assertFalse( $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_users' ) ); |
981
|
|
|
} |
982
|
|
|
|
983
|
|
View Code Duplication |
function test_full_sync_can_sync_individual_posts() { |
984
|
|
|
$sync_post_id = $this->factory->post->create(); |
985
|
|
|
$sync_post_id_2 = $this->factory->post->create(); |
986
|
|
|
$no_sync_post_id = $this->factory->post->create(); |
|
|
|
|
987
|
|
|
|
988
|
|
|
$this->full_sync->start( array( 'posts' => array( $sync_post_id, $sync_post_id_2 ) ) ); |
|
|
|
|
989
|
|
|
$this->sender->do_full_sync(); |
990
|
|
|
|
991
|
|
|
$synced_posts_event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_posts' ); |
992
|
|
|
|
993
|
|
|
$posts = $synced_posts_event->args[0]; |
994
|
|
|
|
995
|
|
|
$this->assertEquals( 2, count( $posts ) ); |
996
|
|
|
$this->assertEquals( $sync_post_id_2, $posts[0]->ID ); |
997
|
|
|
$this->assertEquals( $sync_post_id, $posts[1]->ID ); |
998
|
|
|
|
999
|
|
|
$sync_status = $this->full_sync->get_status(); |
|
|
|
|
1000
|
|
|
$this->assertEquals( array( $sync_post_id, $sync_post_id_2 ), $sync_status['config']['posts'] ); |
1001
|
|
|
} |
1002
|
|
|
|
1003
|
|
View Code Duplication |
function test_full_sync_can_sync_individual_comments() { |
1004
|
|
|
$post_id = $this->factory->post->create(); |
1005
|
|
|
list( $sync_comment_id, $no_sync_comment_id, $sync_comment_id_2 ) = $this->factory->comment->create_post_comments( $post_id, 3 ); |
|
|
|
|
1006
|
|
|
|
1007
|
|
|
$this->full_sync->start( array( 'comments' => array( $sync_comment_id, $sync_comment_id_2 ) ) ); |
|
|
|
|
1008
|
|
|
$this->sender->do_full_sync(); |
1009
|
|
|
|
1010
|
|
|
$synced_comments_event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_comments' ); |
1011
|
|
|
|
1012
|
|
|
$comments = $synced_comments_event->args[0]; |
1013
|
|
|
|
1014
|
|
|
$this->assertEquals( 2, count( $comments ) ); |
1015
|
|
|
$comment_IDs = array( $comments[0]->comment_ID, $comments[1]->comment_ID ); |
1016
|
|
|
|
1017
|
|
|
$this->assertContains( $sync_comment_id, $comment_IDs ); |
1018
|
|
|
$this->assertContains( $sync_comment_id_2, $comment_IDs ); |
1019
|
|
|
|
1020
|
|
|
$sync_status = $this->full_sync->get_status(); |
|
|
|
|
1021
|
|
|
$this->assertEquals( array( $sync_comment_id, $sync_comment_id_2 ), $sync_status['config']['comments'] ); |
1022
|
|
|
} |
1023
|
|
|
|
1024
|
|
View Code Duplication |
function test_full_sync_can_sync_individual_users() { |
1025
|
|
|
$sync_user_id = $this->factory->user->create(); |
1026
|
|
|
$sync_user_id_2 = $this->factory->user->create(); |
1027
|
|
|
$no_sync_user_id = $this->factory->user->create(); |
|
|
|
|
1028
|
|
|
|
1029
|
|
|
$this->full_sync->start( array( 'users' => array( $sync_user_id, $sync_user_id_2 ) ) ); |
|
|
|
|
1030
|
|
|
$this->sender->do_full_sync(); |
1031
|
|
|
|
1032
|
|
|
$synced_users_event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_users' ); |
1033
|
|
|
|
1034
|
|
|
$users = $synced_users_event->args['users']; |
1035
|
|
|
|
1036
|
|
|
$this->assertEquals( 2, count( $users ) ); |
1037
|
|
|
// The users are ordered in reverse order now. |
1038
|
|
|
$this->assertEquals( $sync_user_id_2, $users[0]->ID ); |
1039
|
|
|
$this->assertEquals( $sync_user_id, $users[1]->ID ); |
1040
|
|
|
|
1041
|
|
|
$sync_status = $this->full_sync->get_status(); |
|
|
|
|
1042
|
|
|
$this->assertEquals( array( $sync_user_id, $sync_user_id_2 ), $sync_status['config']['users'] ); |
1043
|
|
|
} |
1044
|
|
|
|
1045
|
|
View Code Duplication |
function test_full_sync_doesnt_send_deleted_posts() { |
1046
|
|
|
// previously, the behavior was to send false or throw errors - we |
1047
|
|
|
// should actively detect false values and remove them |
1048
|
|
|
$keep_post_id = $this->factory->post->create(); |
1049
|
|
|
$delete_post_id = $this->factory->post->create(); |
1050
|
|
|
|
1051
|
|
|
$this->full_sync->start(); |
|
|
|
|
1052
|
|
|
|
1053
|
|
|
wp_delete_post( $delete_post_id, true ); |
1054
|
|
|
|
1055
|
|
|
$this->sender->do_full_sync(); |
1056
|
|
|
|
1057
|
|
|
$synced_posts_event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_posts' ); |
1058
|
|
|
|
1059
|
|
|
$posts = $synced_posts_event->args[0]; |
1060
|
|
|
$this->assertEquals( 1, count( $posts ) ); |
1061
|
|
|
$this->assertEquals( $keep_post_id, $posts[0]->ID ); |
1062
|
|
|
} |
1063
|
|
|
|
1064
|
|
View Code Duplication |
function test_full_sync_doesnt_send_deleted_comments() { |
1065
|
|
|
// previously, the behavior was to send false or throw errors - we |
1066
|
|
|
// should actively detect false values and remove them |
1067
|
|
|
$post_id = $this->factory->post->create(); |
1068
|
|
|
list( $keep_comment_id, $delete_comment_id ) = $this->factory->comment->create_post_comments( $post_id, 2 ); |
1069
|
|
|
|
1070
|
|
|
$this->full_sync->start(); |
|
|
|
|
1071
|
|
|
|
1072
|
|
|
wp_delete_comment( $delete_comment_id, true ); |
1073
|
|
|
|
1074
|
|
|
$this->sender->do_full_sync(); |
1075
|
|
|
|
1076
|
|
|
$synced_comments_event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_comments' ); |
1077
|
|
|
|
1078
|
|
|
$comments = $synced_comments_event->args[0]; |
1079
|
|
|
$this->assertEquals( 1, count( $comments ) ); |
1080
|
|
|
$this->assertEquals( $keep_comment_id, $comments[0]->comment_ID ); |
1081
|
|
|
} |
1082
|
|
|
|
1083
|
|
View Code Duplication |
function test_full_sync_doesnt_send_deleted_users() { |
1084
|
|
|
$user_counts = count_users(); |
1085
|
|
|
$existing_user_count = $user_counts['total_users']; |
1086
|
|
|
|
1087
|
|
|
// previously, the behavior was to send false or throw errors - we |
1088
|
|
|
// should actively detect false values and remove them |
1089
|
|
|
$keep_user_id = $this->factory->user->create(); |
1090
|
|
|
$delete_user_id = $this->factory->user->create(); |
1091
|
|
|
|
1092
|
|
|
$this->full_sync->start(); |
|
|
|
|
1093
|
|
|
|
1094
|
|
|
wp_delete_user( $delete_user_id ); |
1095
|
|
|
|
1096
|
|
|
$this->sender->do_full_sync(); |
1097
|
|
|
|
1098
|
|
|
$synced_users_event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_users' ); |
1099
|
|
|
$users = $synced_users_event->args['users']; |
1100
|
|
|
|
1101
|
|
|
$this->assertEquals( $existing_user_count + 1, count( $users ) ); |
1102
|
|
|
// the last created user should be the fist sent out. |
1103
|
|
|
$this->assertEquals( $keep_user_id, $users[0]->ID ); |
1104
|
|
|
} |
1105
|
|
|
|
1106
|
|
|
function test_full_sync_has_correct_sent_count_even_if_some_actions_unsent() { |
1107
|
|
|
add_filter( 'jetpack_sync_before_send_jetpack_full_sync_users', array( $this, 'dont_sync_users' ) ); |
1108
|
|
|
|
1109
|
|
|
foreach ( range( 1, 3 ) as $i ) { |
1110
|
|
|
$this->factory->user->create(); |
1111
|
|
|
} |
1112
|
|
|
|
1113
|
|
|
$this->full_sync->start( array( 'users' => true ) ); |
|
|
|
|
1114
|
|
|
|
1115
|
|
|
$this->sender->do_full_sync(); |
1116
|
|
|
$this->sender->do_full_sync(); |
1117
|
|
|
$this->sender->do_full_sync(); |
1118
|
|
|
|
1119
|
|
|
$full_sync_status = $this->full_sync->get_status(); |
|
|
|
|
1120
|
|
|
|
1121
|
|
|
$this->assertEquals( $full_sync_status['progress']['users']['total'], $full_sync_status['progress']['users']['sent'] ); |
1122
|
|
|
} |
1123
|
|
|
|
1124
|
|
|
function dont_sync_users( $args ) { |
1125
|
|
|
return false; |
1126
|
|
|
} |
1127
|
|
|
|
1128
|
|
View Code Duplication |
function test_sync_call_ables_does_not_modify_globals() { |
1129
|
|
|
global $wp_taxonomies; |
1130
|
|
|
// assert that $wp_taxonomy object stays an array. |
1131
|
|
|
$this->assertTrue( is_array( $wp_taxonomies['category']->rewrite ) ); |
1132
|
|
|
$this->setSyncClientDefaults(); |
1133
|
|
|
$this->full_sync->start(); |
|
|
|
|
1134
|
|
|
$this->sender->do_full_sync(); |
1135
|
|
|
$this->assertTrue( is_array( $wp_taxonomies['category']->rewrite ) ); |
1136
|
|
|
} |
1137
|
|
|
|
1138
|
|
View Code Duplication |
function test_initial_sync_doesnt_sync_subscribers() { |
1139
|
|
|
$this->factory->user->create( array( 'user_login' => 'theauthor', 'role' => 'author' ) ); |
1140
|
|
|
$this->factory->user->create( array( 'user_login' => 'theadmin', 'role' => 'administrator' ) ); |
1141
|
|
|
foreach ( range( 1, 10 ) as $i ) { |
1142
|
|
|
$this->factory->user->create( array( 'role' => 'subscriber' ) ); |
1143
|
|
|
} |
1144
|
|
|
$this->full_sync->start(); |
|
|
|
|
1145
|
|
|
$this->sender->do_full_sync(); |
1146
|
|
|
$this->assertEquals( 13, $this->server_replica_storage->user_count() ); |
1147
|
|
|
$this->server_replica_storage->reset(); |
1148
|
|
|
$this->assertEquals( 0, $this->server_replica_storage->user_count() ); |
1149
|
|
|
$user_ids = Modules::get_module( 'users' )->get_initial_sync_user_config(); |
|
|
|
|
1150
|
|
|
$this->assertEquals( 3, count( $user_ids ) ); |
1151
|
|
|
$this->full_sync->start( array( 'users' => 'initial' ) ); |
|
|
|
|
1152
|
|
|
$this->sender->do_full_sync(); |
1153
|
|
|
$this->assertEquals( 3, $this->server_replica_storage->user_count() ); |
1154
|
|
|
// finally, let's make sure that the initial sync method actually invokes our initial sync user config |
1155
|
|
|
Actions::do_initial_sync(); |
1156
|
|
|
$current_user = wp_get_current_user(); |
1157
|
|
|
|
1158
|
|
|
$expected_sync_config = array( |
1159
|
|
|
'options' => true, |
1160
|
|
|
'functions' => true, |
1161
|
|
|
'constants' => true, |
1162
|
|
|
'users' => array( $current_user->ID ), |
1163
|
|
|
'network_options' => true, |
1164
|
|
|
); |
1165
|
|
|
|
1166
|
|
|
$full_sync_status = $this->full_sync->get_status(); |
|
|
|
|
1167
|
|
|
$this->assertEquals( |
1168
|
|
|
$expected_sync_config, |
1169
|
|
|
$full_sync_status['config'] |
1170
|
|
|
); |
1171
|
|
|
} |
1172
|
|
|
|
1173
|
|
|
|
1174
|
|
|
function test_full_sync_sends_previous_interval_end_on_posts() { |
1175
|
|
|
$this->factory->post->create_many( 25 ); |
1176
|
|
|
|
1177
|
|
|
// The first event is for full sync start. |
1178
|
|
|
$this->full_sync->start( array( 'posts' => true ) ); |
|
|
|
|
1179
|
|
|
$this->sender->do_full_sync(); |
1180
|
|
|
|
1181
|
|
|
$this->full_sync->continue_sending(); |
|
|
|
|
1182
|
|
|
$this->sender->do_full_sync(); |
1183
|
|
|
|
1184
|
|
|
$events = $this->server_event_storage->get_all_events( 'jetpack_full_sync_posts' ); |
1185
|
|
|
list( $posts, $meta, $taxonomy, $previous_interval_end ) = $events[0]->args; |
|
|
|
|
1186
|
|
|
|
1187
|
|
|
// The first batch has the previous_min_is not set. |
1188
|
|
|
// We user ~0 to denote that the previous min id unknown. |
1189
|
|
|
$this->assertEquals( '~0', $previous_interval_end ); |
1190
|
|
|
} |
1191
|
|
|
|
1192
|
|
|
function test_full_sync_sends_previous_interval_end_on_comments() { |
1193
|
|
|
$this->post_id = $this->factory->post->create(); |
1194
|
|
|
for ( $i = 0; $i < 25; $i ++ ) { |
1195
|
|
|
$this->factory->comment->create_post_comments( $this->post_id ); |
1196
|
|
|
} |
1197
|
|
|
// The first event is for full sync start. |
1198
|
|
|
$this->full_sync->start( array( 'comments' => true ) ); |
|
|
|
|
1199
|
|
|
$this->sender->do_full_sync(); |
1200
|
|
|
|
1201
|
|
|
$this->full_sync->continue_sending(); |
|
|
|
|
1202
|
|
|
$this->sender->do_full_sync(); |
1203
|
|
|
|
1204
|
|
|
$events = $this->server_event_storage->get_all_events( 'jetpack_full_sync_comments' ); |
1205
|
|
|
list( $comments, $meta, $previous_interval_end ) = $events[0]->args; |
|
|
|
|
1206
|
|
|
|
1207
|
|
|
// The first batch has the previous_min_is not set. |
1208
|
|
|
// We user ~0 to denote that the previous min id unknown. |
1209
|
|
|
$this->assertEquals( $previous_interval_end, '~0' ); |
1210
|
|
|
} |
1211
|
|
|
|
1212
|
|
View Code Duplication |
function test_disable_sending_full_sync() { |
1213
|
|
|
$this->factory->post->create_many( 2 ); |
1214
|
|
|
|
1215
|
|
|
$this->sender->reset_data(); |
1216
|
|
|
$this->server_event_storage->reset(); |
1217
|
|
|
|
1218
|
|
|
Settings::update_settings( array( 'full_sync_sender_enabled' => 0 ) ); |
1219
|
|
|
|
1220
|
|
|
$this->full_sync->start(); |
|
|
|
|
1221
|
|
|
$this->sender->do_full_sync(); |
1222
|
|
|
|
1223
|
|
|
$start_event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_start' ); |
1224
|
|
|
$this->assertTrue( ! $start_event ); |
1225
|
|
|
} |
1226
|
|
|
|
1227
|
|
|
function test_full_sync_send_max_chunks() { |
1228
|
|
|
$this->factory->post->create_many( 10 ); |
1229
|
|
|
|
1230
|
|
|
$this->sender->reset_data(); |
1231
|
|
|
$this->server_event_storage->reset(); |
1232
|
|
|
|
1233
|
|
|
$limits = \Automattic\Jetpack\Sync\Defaults::$default_full_sync_limits; |
1234
|
|
|
$limits['posts'] = array( |
1235
|
|
|
'chunk_size' => 1, |
1236
|
|
|
'max_chunks' => 5, |
1237
|
|
|
); |
1238
|
|
|
|
1239
|
|
|
Settings::update_settings( array( 'full_sync_limits' => $limits ) ); |
1240
|
|
|
|
1241
|
|
|
$this->full_sync->start(); |
|
|
|
|
1242
|
|
|
$this->sender->do_full_sync(); |
1243
|
|
|
|
1244
|
|
|
$this->assertEquals( 5, $this->server_replica_storage->post_count() ); |
1245
|
|
|
} |
1246
|
|
|
|
1247
|
|
View Code Duplication |
function test_enable_sending_full_sync() { |
1248
|
|
|
$this->factory->post->create_many( 2 ); |
1249
|
|
|
|
1250
|
|
|
$this->sender->reset_data(); |
1251
|
|
|
$this->server_event_storage->reset(); |
1252
|
|
|
|
1253
|
|
|
Settings::update_settings( array( 'full_sync_sender_enabled' => 1 ) ); |
1254
|
|
|
|
1255
|
|
|
$this->full_sync->start(); |
|
|
|
|
1256
|
|
|
$this->sender->do_full_sync(); |
1257
|
|
|
|
1258
|
|
|
$start_event = $this->server_event_storage->get_most_recent_event( 'jetpack_full_sync_start' ); |
1259
|
|
|
$this->assertTrue( ! empty( $start_event ) ); |
1260
|
|
|
} |
1261
|
|
|
|
1262
|
|
|
function _do_cron() { |
1263
|
|
|
$_GET['check'] = wp_hash( '187425' ); |
1264
|
|
|
require( ABSPATH . '/wp-cron.php' ); |
1265
|
|
|
} |
1266
|
|
|
} |
1267
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: