9
9
10
10
use Activitypub \Mailer ;
11
11
use Activitypub \Collection \Actors ;
12
- use Activitypub \Notification ;
13
12
use WP_UnitTestCase ;
14
13
15
14
/**
@@ -410,9 +409,8 @@ function ( $args ) use ( $user_id, $activity ) {
410
409
} else {
411
410
add_filter (
412
411
'wp_mail ' ,
413
- function ( $ args ) {
412
+ function () {
414
413
$ this ->fail ( 'Email should not be sent for public activity ' );
415
- return $ args ;
416
414
}
417
415
);
418
416
@@ -428,6 +426,56 @@ function ( $args ) {
428
426
wp_delete_user ( $ user_id );
429
427
}
430
428
429
+ /**
430
+ * Test direct message notification from Bridgy.
431
+ *
432
+ * @covers ::direct_message
433
+ */
434
+ public function test_direct_message_from_bridgy () {
435
+ $ activity = array (
436
+ 'actor ' => 'https://example.com/author ' ,
437
+ 'object ' => array (
438
+ 'id ' => 'https://example.com/post/1 ' ,
439
+ 'content ' => 'Test direct message ' ,
440
+ ),
441
+ 'to ' => array ( Actors::get_by_id ( self ::$ user_id )->get_id () ),
442
+ );
443
+
444
+ // Mock remote metadata.
445
+ add_filter (
446
+ 'pre_get_remote_metadata_by_actor ' ,
447
+ function () {
448
+ return array (
449
+ 'name ' => 'Test Sender ' ,
450
+ 'url ' => array (
451
+ 'https://fed.brid.gy/r/https://example.com/author ' ,
452
+
453
+ ),
454
+ );
455
+ }
456
+ );
457
+
458
+ // Capture email.
459
+ add_filter (
460
+ 'wp_mail ' ,
461
+ function ( $ args ) {
462
+ $ this ->assertStringContainsString (
463
+ '<a href="https://fed.brid.gy/r/https://example.com/author">@Test [email protected] </a> ' ,
464
+ $ args ['message ' ]
465
+ );
466
+ return $ args ;
467
+ }
468
+ );
469
+
470
+ // Call the method.
471
+ Mailer::direct_message ( $ activity , self ::$ user_id );
472
+
473
+ // Clean up.
474
+ remove_all_filters ( 'wp_before_load_template ' );
475
+ remove_all_filters ( 'pre_get_remote_metadata_by_actor ' );
476
+ remove_all_filters ( 'wp_mail ' );
477
+ }
478
+
431
479
/**
432
480
* Data provider for direct message notification text.
433
481
*
0 commit comments