-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathclass-test-migration.php
695 lines (575 loc) · 21.1 KB
/
class-test-migration.php
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
<?php
/**
* Test file for Activitypub Migrate.
*
* @package Activitypub
*/
namespace Activitypub\Tests;
use Activitypub\Collection\Outbox;
use Activitypub\Migration;
use Activitypub\Comment;
/**
* Test class for Activitypub Migrate.
*
* @coversDefaultClass \Activitypub\Migration
*/
class Test_Migration extends ActivityPub_TestCase_Cache_HTTP {
/**
* Test fixture.
*
* @var array
*/
public static $fixtures = array();
/**
* Set up the test.
*/
public static function set_up_before_class() {
\remove_action( 'wp_after_insert_post', array( \Activitypub\Scheduler\Post::class, 'schedule_post_activity' ), 33 );
\remove_action( 'transition_comment_status', array( \Activitypub\Scheduler\Comment::class, 'schedule_comment_activity' ), 20 );
\remove_action( 'wp_insert_comment', array( \Activitypub\Scheduler\Comment::class, 'schedule_comment_activity_on_insert' ) );
// Create test posts.
self::$fixtures['posts'] = self::factory()->post->create_many(
3,
array(
'post_author' => 1,
'meta_input' => array( 'activitypub_status' => 'federated' ),
)
);
$modified_post_id = self::factory()->post->create(
array(
'post_author' => 1,
'post_content' => 'Test post 2',
'post_status' => 'publish',
'post_type' => 'post',
'post_date' => '2020-01-01 00:00:00',
'meta_input' => array( 'activitypub_status' => 'federated' ),
)
);
self::factory()->post->update_object( $modified_post_id, array( 'post_content' => 'Test post 2 updated' ) );
self::$fixtures['posts'][] = $modified_post_id;
self::$fixtures['posts'][] = self::factory()->post->create(
array(
'post_author' => 1,
'post_content' => 'Test post 3',
'post_status' => 'publish',
'post_type' => 'page',
)
);
self::$fixtures['posts'][] = self::factory()->post->create(
array(
'post_author' => 1,
'post_content' => 'Test post 4',
'post_status' => 'publish',
'post_type' => 'post',
'meta_input' => array(
'activitypub_content_visibility' => ACTIVITYPUB_CONTENT_VISIBILITY_LOCAL,
),
)
);
// Create test comment.
self::$fixtures['comment'] = self::factory()->comment->create(
array(
'comment_post_ID' => self::$fixtures['posts'][0],
'user_id' => 1,
'comment_content' => 'Test comment',
'comment_approved' => '1',
)
);
\add_comment_meta( self::$fixtures['comment'], 'activitypub_status', 'federated' );
}
/**
* Tear down the test.
*/
public static function tear_down_after_class() {
// Clean up posts.
foreach ( self::$fixtures['posts'] as $post_id ) {
\wp_delete_post( $post_id, true );
}
// Clean up comment.
if ( isset( self::$fixtures['comment'] ) ) {
\wp_delete_comment( self::$fixtures['comment'], true );
}
}
/**
* Tear down the test.
*/
public function tear_down() {
\delete_option( 'activitypub_object_type' );
\delete_option( 'activitypub_custom_post_content' );
\delete_option( 'activitypub_post_content_type' );
// Clean up outbox items.
$outbox_items = \get_posts(
array(
'post_type' => Outbox::POST_TYPE,
'posts_per_page' => -1,
'post_status' => 'any',
'fields' => 'ids',
)
);
foreach ( $outbox_items as $item_id ) {
\wp_delete_post( $item_id, true );
}
}
/**
* Test migrate actor mode.
*
* @covers ::migrate_actor_mode
*/
public function test_migrate_actor_mode() {
\delete_option( 'activitypub_actor_mode' );
Migration::migrate_actor_mode();
$this->assertEquals( ACTIVITYPUB_ACTOR_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) );
\update_option( 'activitypub_enable_blog_user', '0' );
\update_option( 'activitypub_enable_users', '1' );
\delete_option( 'activitypub_actor_mode' );
Migration::migrate_actor_mode();
$this->assertEquals( ACTIVITYPUB_ACTOR_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) );
\update_option( 'activitypub_enable_blog_user', '1' );
\update_option( 'activitypub_enable_users', '1' );
\delete_option( 'activitypub_actor_mode' );
Migration::migrate_actor_mode();
$this->assertEquals( ACTIVITYPUB_ACTOR_AND_BLOG_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) );
\update_option( 'activitypub_enable_blog_user', '1' );
\update_option( 'activitypub_enable_users', '0' );
\delete_option( 'activitypub_actor_mode' );
Migration::migrate_actor_mode();
$this->assertEquals( ACTIVITYPUB_BLOG_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) );
\delete_option( 'activitypub_enable_blog_user' );
\update_option( 'activitypub_enable_users', '0' );
\delete_option( 'activitypub_actor_mode' );
Migration::migrate_actor_mode();
$this->assertEquals( ACTIVITYPUB_ACTOR_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) );
\update_option( 'activitypub_enable_blog_user', '0' );
\delete_option( 'activitypub_enable_users' );
\delete_option( 'activitypub_actor_mode' );
Migration::migrate_actor_mode();
$this->assertEquals( ACTIVITYPUB_ACTOR_MODE, \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) );
}
/**
* Tests scheduling of migration.
*
* @covers ::maybe_migrate
*/
public function test_migration_scheduling() {
update_option( 'activitypub_db_version', '0.0.1' );
Migration::maybe_migrate();
$schedule = \wp_next_scheduled( 'activitypub_migrate', array( '0.0.1' ) );
$this->assertNotFalse( $schedule );
// Clean up.
delete_option( 'activitypub_db_version' );
}
/**
* Test migrate to 4.1.0.
*
* @covers ::migrate_to_4_1_0
*/
public function test_migrate_to_4_1_0() {
$post1 = \wp_insert_post(
array(
'post_author' => 1,
'post_content' => 'activitypub_content_visibility test',
)
);
$post2 = \wp_insert_post(
array(
'post_author' => 1,
'post_content' => 'activitypub_content_visibility test',
)
);
\update_post_meta( $post1, 'activitypub_content_visibility', '' );
\update_post_meta( $post1, 'activitypub_content_123', '456' );
\update_post_meta( $post2, 'activitypub_content_visibility', 'local' );
\update_post_meta( $post2, 'activitypub_content_123', '' );
$metas1 = \get_post_meta( $post1 );
$this->assertEquals(
array(
'activitypub_content_123' => array( '456' ),
),
$metas1
);
$metas2 = \get_post_meta( $post2 );
$this->assertEquals(
array(
'activitypub_content_visibility' => array( 'local' ),
'activitypub_content_123' => array( '' ),
),
$metas2
);
$template = \get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
$object_type = \get_option( 'activitypub_object_type', ACTIVITYPUB_DEFAULT_OBJECT_TYPE );
$this->assertEquals( ACTIVITYPUB_CUSTOM_POST_CONTENT, $template );
$this->assertEquals( ACTIVITYPUB_DEFAULT_OBJECT_TYPE, $object_type );
\update_option( 'activitypub_post_content_type', 'title' );
Migration::migrate_to_4_1_0();
\clean_post_cache( $post1 );
$metas1 = \get_post_meta( $post1 );
$this->assertEquals(
array(
'activitypub_content_123' => array( '456' ),
),
$metas1
);
\clean_post_cache( $post2 );
$metas2 = \get_post_meta( $post2 );
$this->assertEquals(
array(
'activitypub_content_visibility' => array( 'local' ),
'activitypub_content_123' => array( '' ),
),
$metas2
);
$template = \get_option( 'activitypub_custom_post_content' );
$content_type = \get_option( 'activitypub_post_content_type' );
$object_type = \get_option( 'activitypub_object_type' );
$this->assertEquals( "[ap_title type=\"html\"]\n\n[ap_permalink type=\"html\"]", $template );
$this->assertFalse( $content_type );
$this->assertEquals( 'note', $object_type );
\update_option( 'activitypub_post_content_type', 'content' );
\update_option( 'activitypub_custom_post_content', '[ap_content]' );
Migration::migrate_to_4_1_0();
$template = \get_option( 'activitypub_custom_post_content' );
$content_type = \get_option( 'activitypub_post_content_type' );
$this->assertEquals( "[ap_content]\n\n[ap_permalink type=\"html\"]\n\n[ap_hashtags]", $template );
$this->assertFalse( $content_type );
$custom = '[ap_title] [ap_content] [ap_hashcats] [ap_authorurl]';
\update_option( 'activitypub_post_content_type', 'custom' );
\update_option( 'activitypub_custom_post_content', $custom );
Migration::migrate_to_4_1_0();
$template = \get_option( 'activitypub_custom_post_content' );
$content_type = \get_option( 'activitypub_post_content_type' );
$this->assertEquals( $custom, $template );
$this->assertFalse( $content_type );
\wp_delete_post( $post1, true );
\wp_delete_post( $post2, true );
}
/**
* Test migrate to 4.7.1.
*
* @covers ::migrate_to_4_7_1
*/
public function test_migrate_to_4_7_1() {
$post1 = self::$fixtures['posts'][0];
$post2 = self::$fixtures['posts'][1];
// Set up test meta data.
$meta_data = array(
'activitypub_actor_json' => '{"type":"Person"}',
'activitypub_canonical_url' => 'https://example.com/post-1',
'activitypub_errors' => 'Test error',
'activitypub_inbox' => 'https://example.com/inbox',
'activitypub_user_id' => '123',
'unrelated_meta' => 'should not change',
);
foreach ( $meta_data as $key => $value ) {
\update_post_meta( $post1, $key, $value );
\update_post_meta( $post2, $key, $value . '-2' );
}
// Run migration.
Migration::migrate_to_4_7_1();
// Clean post cache to ensure fresh meta data.
\clean_post_cache( $post1 );
\clean_post_cache( $post2 );
// Check post 1 meta.
$this->assertEmpty( \get_post_meta( $post1, 'activitypub_actor_json', true ), 'Old actor_json meta should be empty' );
$this->assertEmpty( \get_post_meta( $post1, 'activitypub_canonical_url', true ), 'Old canonical_url meta should be empty' );
$this->assertEmpty( \get_post_meta( $post1, 'activitypub_errors', true ), 'Old errors meta should be empty' );
$this->assertEmpty( \get_post_meta( $post1, 'activitypub_inbox', true ), 'Old inbox meta should be empty' );
$this->assertEmpty( \get_post_meta( $post1, 'activitypub_user_id', true ), 'Old user_id meta should be empty' );
$this->assertEquals( '{"type":"Person"}', \get_post_meta( $post1, '_activitypub_actor_json', true ), 'New actor_json meta should match' );
$this->assertEquals( 'https://example.com/post-1', \get_post_meta( $post1, '_activitypub_canonical_url', true ), 'New canonical_url meta should match' );
$this->assertEquals( 'Test error', \get_post_meta( $post1, '_activitypub_errors', true ), 'New errors meta should match' );
$this->assertEquals( 'https://example.com/inbox', \get_post_meta( $post1, '_activitypub_inbox', true ), 'New inbox meta should match' );
$this->assertEquals( '123', \get_post_meta( $post1, '_activitypub_user_id', true ), 'New user_id meta should match' );
// Check post 2 meta.
$this->assertEmpty( \get_post_meta( $post2, 'activitypub_actor_json', true ), 'Old actor_json meta should be empty' );
$this->assertEmpty( \get_post_meta( $post2, 'activitypub_canonical_url', true ), 'Old canonical_url meta should be empty' );
$this->assertEmpty( \get_post_meta( $post2, 'activitypub_errors', true ), 'Old errors meta should be empty' );
$this->assertEmpty( \get_post_meta( $post2, 'activitypub_inbox', true ), 'Old inbox meta should be empty' );
$this->assertEmpty( \get_post_meta( $post2, 'activitypub_user_id', true ), 'Old user_id meta should be empty' );
$this->assertEquals( '{"type":"Person"}-2', \get_post_meta( $post2, '_activitypub_actor_json', true ), 'New actor_json meta should match' );
$this->assertEquals( 'https://example.com/post-1-2', \get_post_meta( $post2, '_activitypub_canonical_url', true ), 'New canonical_url meta should match' );
$this->assertEquals( 'Test error-2', \get_post_meta( $post2, '_activitypub_errors', true ), 'New errors meta should match' );
$this->assertEquals( 'https://example.com/inbox-2', \get_post_meta( $post2, '_activitypub_inbox', true ), 'New inbox meta should match' );
$this->assertEquals( '123-2', \get_post_meta( $post2, '_activitypub_user_id', true ), 'New user_id meta should match' );
// Verify unrelated meta is unchanged.
$this->assertEquals( 'should not change', \get_post_meta( $post1, 'unrelated_meta', true ), 'Unrelated meta should not change' );
$this->assertEquals( 'should not change-2', \get_post_meta( $post2, 'unrelated_meta', true ), 'Unrelated meta should not change' );
}
/**
* Tests that a new migration lock can be successfully acquired when no lock exists.
*
* @covers ::lock
*/
public function test_lock_acquire_new() {
$this->assertFalse( get_option( 'activitypub_migration_lock' ) );
$this->assertTrue( Migration::lock() );
// Clean up.
delete_option( 'activitypub_migration_lock' );
}
/**
* Test retrieving the timestamp of an existing lock.
*
* @covers ::lock
*/
public function test_lock_get_existing() {
$lock_time = time() - MINUTE_IN_SECONDS; // Set lock to 1 minute ago.
update_option( 'activitypub_migration_lock', $lock_time );
$lock_result = Migration::lock();
$this->assertEquals( $lock_time, $lock_result );
// Clean up.
delete_option( 'activitypub_migration_lock' );
}
/**
* Test update_comment_counts() properly cleans up the lock.
*
* @covers ::update_comment_counts
*/
public function test_update_comment_counts_with_lock() {
// Register comment types.
Comment::register_comment_types();
// Create test comments.
$post_id = $this->factory->post->create(
array(
'post_author' => 1,
)
);
$comment_id = $this->factory->comment->create(
array(
'comment_post_ID' => $post_id,
'comment_approved' => '1',
'comment_type' => 'repost', // One of the registered comment types.
)
);
Migration::update_comment_counts( 10, 0 );
// Verify lock was cleaned up.
$this->assertFalse( get_option( 'activitypub_migration_lock' ) );
// Clean up.
wp_delete_comment( $comment_id, true );
wp_delete_post( $post_id, true );
}
/**
* Test update_comment_counts() with existing valid lock.
*
* @covers ::update_comment_counts
*/
public function test_update_comment_counts_with_existing_valid_lock() {
// Register comment types.
Comment::register_comment_types();
// Set a lock.
Migration::lock();
Migration::update_comment_counts( 10, 0 );
// Verify a scheduled event was created.
$next_scheduled = wp_next_scheduled(
'activitypub_update_comment_counts',
array(
'batch_size' => 10,
'offset' => 0,
)
);
$this->assertNotFalse( $next_scheduled );
// Clean up.
delete_option( 'activitypub_migration_lock' );
wp_clear_scheduled_hook(
'activitypub_update_comment_counts',
array(
'batch_size' => 10,
'offset' => 0,
)
);
}
/**
* Test create post outbox items.
*
* @covers ::create_post_outbox_items
*/
public function test_create_outbox_items() {
// Create additional post that should not be included in outbox.
$post_id = self::factory()->post->create( array( 'post_author' => 90210 ) );
// Run migration.
add_filter( 'pre_schedule_event', '__return_false' );
Migration::create_post_outbox_items( 10, 0 );
remove_filter( 'pre_schedule_event', '__return_false' );
// Get outbox items.
$outbox_items = \get_posts(
array(
'post_type' => Outbox::POST_TYPE,
'posts_per_page' => -1,
)
);
// Should now have 5 outbox items total, 4 post Create, 1 post Update.
$this->assertEquals( 5, count( $outbox_items ) );
\wp_delete_post( $post_id, true );
}
/**
* Test create post outbox items with batching.
*
* @covers ::create_post_outbox_items
*/
public function test_create_outbox_items_batching() {
// Run migration with batch size of 2.
$next = Migration::create_post_outbox_items( 2, 0 );
$this->assertSame(
array(
'batch_size' => 2,
'offset' => 2,
),
$next
);
// Get outbox items.
$outbox_items = \get_posts(
array(
'post_type' => Outbox::POST_TYPE,
'posts_per_page' => -1,
)
);
// Should have 2 outbox items.
$this->assertEquals( 2, count( $outbox_items ) );
// Run migration with next batch.
Migration::create_post_outbox_items( 2, 2 );
// Get outbox items again.
$outbox_items = \get_posts(
array(
'post_type' => Outbox::POST_TYPE,
'posts_per_page' => -1,
)
);
// Should now have 5 outbox items total, 4 post Create, 1 post Update.
$this->assertEquals( 5, count( $outbox_items ) );
}
/**
* Test async upgrade functionality.
*
* @covers ::async_upgrade
* @covers ::lock
* @covers ::unlock
* @covers ::create_post_outbox_items
*/
public function test_async_upgrade() {
// Test that lock prevents simultaneous upgrades.
Migration::lock();
Migration::async_upgrade( 'create_post_outbox_items' );
$scheduled = \wp_next_scheduled( 'activitypub_upgrade', array( 'create_post_outbox_items' ) );
$this->assertNotFalse( $scheduled );
Migration::unlock();
// Test scheduling next batch when callback returns more work.
Migration::async_upgrade( 'create_post_outbox_items', 1, 0 ); // Small batch size to force multiple batches.
$scheduled = \wp_next_scheduled( 'activitypub_upgrade', array( 'create_post_outbox_items', 1, 1 ) );
$this->assertNotFalse( $scheduled );
// Test no scheduling when callback returns null (no more work).
Migration::async_upgrade( 'create_post_outbox_items', 100, 1000 ); // Large offset to ensure no posts found.
$this->assertFalse(
\wp_next_scheduled( 'activitypub_upgrade', array( 'create_post_outbox_items', 100, 1100 ) )
);
}
/**
* Test async upgrade with multiple arguments.
*
* @covers ::async_upgrade
*/
public function test_async_upgrade_multiple_args() {
// Test that multiple arguments are passed correctly.
Migration::async_upgrade( 'update_comment_counts', 50, 100 );
$scheduled = \wp_next_scheduled( 'activitypub_upgrade', array( 'update_comment_counts', 50, 150 ) );
$this->assertFalse( $scheduled, 'Should not schedule next batch when no comments found' );
}
/**
* Test create_comment_outbox_items batch processing.
*
* @covers ::create_comment_outbox_items
*/
public function test_create_comment_outbox_items_batching() {
// Test with small batch size.
$result = Migration::create_comment_outbox_items( 1, 0 );
$this->assertIsArray( $result );
$this->assertEquals(
array(
'batch_size' => 1,
'offset' => 1,
),
$result
);
// Test with large offset (no more comments).
$result = Migration::create_comment_outbox_items( 1, 1000 );
$this->assertNull( $result );
}
/**
* Test update_comment_author_emails updates emails with webfinger addresses.
*
* @covers ::update_comment_author_emails
*/
public function test_update_comment_author_emails() {
$author_url = 'https://example.com/users/test';
$comment_id = self::factory()->comment->create(
array(
'comment_post_ID' => self::$fixtures['posts'][0],
'comment_author' => 'Test User',
'comment_author_url' => $author_url,
'comment_author_email' => '',
'comment_type' => 'comment',
'comment_meta' => array( 'protocol' => 'activitypub' ),
)
);
// Mock the HTTP request.
\add_filter( 'pre_http_request', array( $this, 'mock_webfinger' ) );
$result = Migration::update_comment_author_emails( 50, 0 );
$this->assertNull( $result );
$updated_comment = \get_comment( $comment_id );
// Clean up.
\remove_filter( 'pre_http_request', array( $this, 'mock_webfinger' ) );
\wp_delete_comment( $comment_id, true );
}
/**
* Test update_comment_author_emails handles batching correctly.
*
* @covers ::update_comment_author_emails
*/
public function test_update_comment_author_emails_batching() {
// Create multiple comments.
$comment_ids = array();
for ( $i = 0; $i < 3; $i++ ) {
$comment_ids[] = self::factory()->comment->create(
array(
'comment_post_ID' => self::$fixtures['posts'][0],
'comment_author' => "Test User $i",
'comment_author_url' => "https://example.com/users/test$i",
'comment_author_email' => '',
'comment_content' => "Test comment $i",
'comment_type' => 'comment',
'comment_meta' => array( 'protocol' => 'activitypub' ),
)
);
}
// Mock the HTTP request.
\add_filter( 'pre_http_request', array( $this, 'mock_webfinger' ) );
// Process first batch of 2 comments.
$result = Migration::update_comment_author_emails( 2, 0 );
$this->assertEqualSets(
array(
'batch_size' => 2,
'offset' => 2,
),
$result
);
// Process second batch with remaining comment.
$result = Migration::update_comment_author_emails( 2, 2 );
$this->assertNull( $result );
// Verify all comments were updated.
foreach ( $comment_ids as $comment_id ) {
$comment = \get_comment( $comment_id );
wp_delete_comment( $comment_id, true );
}
\remove_filter( 'pre_http_request', array( $this, 'mock_webfinger' ) );
}
/**
* Mock webfinger response.
*
* @return array
*/
public function mock_webfinger() {
return array(
'response' => array( 'code' => 200 ),
);
}
}