@@ -344,4 +344,84 @@ public function add_follower( $pre, $actor ) {
344344 'endpoints ' => array ( 'sharedInbox ' => 'https://example.org/sharedInbox ' ),
345345 );
346346 }
347+
348+ /**
349+ * Test that in_reply_to URLs from the same domain are ignored.
350+ *
351+ * @covers ::add_inboxes_of_replied_urls
352+ */
353+ public function test_ignore_same_domain_in_reply_to () {
354+ // Create a test activity with in_reply_to pointing to same domain.
355+ $ activity = new Activity ();
356+ $ activity ->set_type ( 'Create ' );
357+ $ activity ->set_id ( 'https://example.com/test-id ' );
358+ $ activity ->set_in_reply_to ( 'https://example.com/post/123 ' );
359+
360+ // Create a test actor.
361+ $ actor_id = self ::$ user_id ;
362+
363+ // Get inboxes for the activity.
364+ $ inboxes = Dispatcher::add_inboxes_of_replied_urls ( array (), $ actor_id , $ activity );
365+
366+ // Verify that no inboxes were added since the in_reply_to is from same domain.
367+ $ this ->assertEmpty ( $ inboxes , 'Inboxes should be empty for same domain in_reply_to URLs ' );
368+ }
369+
370+ /**
371+ * Test that in_reply_to URLs from different domains are processed.
372+ *
373+ * @covers ::add_inboxes_of_replied_urls
374+ */
375+ public function test_process_different_domain_in_reply_to () {
376+ // Create a test activity with in_reply_to pointing to different domain.
377+ $ activity = new Activity ();
378+ $ activity ->set_type ( 'Create ' );
379+ $ activity ->set_id ( 'https://example.com/test-id ' );
380+ $ activity ->set_in_reply_to ( 'https://mastodon.social/@user/123456789 ' );
381+
382+ // Create a test actor.
383+ $ actor_id = self ::$ user_id ;
384+
385+ $ callback = function ( $ pre , $ parsed_args , $ url ) {
386+ if ( 'https://mastodon.social/@user/123456789 ' === $ url ) {
387+ return array (
388+ 'response ' => array ( 'code ' => 200 ),
389+ 'body ' => \wp_json_encode (
390+ array (
391+ 'type ' => 'Note ' ,
392+ 'id ' => 'https://mastodon.social/@user/123456789 ' ,
393+ 'attributedTo ' => 'https://mastodon.social/@user ' ,
394+ )
395+ ),
396+ );
397+ }
398+
399+ if ( 'https://mastodon.social/@user ' === $ url ) {
400+ return array (
401+ 'response ' => array ( 'code ' => 200 ),
402+ 'body ' => \wp_json_encode (
403+ array (
404+ 'type ' => 'Person ' ,
405+ 'id ' => 'https://mastodon.social/@user ' ,
406+ 'inbox ' => 'https://mastodon.social/inbox ' ,
407+ )
408+ ),
409+ );
410+ }
411+
412+ return $ pre ;
413+ };
414+
415+ // Mock the HTTP response for the remote object.
416+ add_filter ( 'pre_http_request ' , $ callback , 10 , 3 );
417+
418+ // Get inboxes for the activity.
419+ $ inboxes = Dispatcher::add_inboxes_of_replied_urls ( array (), $ actor_id , $ activity );
420+
421+ // Verify that the inbox was added.
422+ $ this ->assertContains ( 'https://mastodon.social/inbox ' , $ inboxes , 'Inbox should be added for different domain in_reply_to URLs ' );
423+
424+ // Clean up.
425+ remove_filter ( 'pre_http_request ' , $ callback );
426+ }
347427}
0 commit comments