88namespace Activitypub \Tests \Transformer ;
99
1010use Activitypub \Transformer \Post ;
11- use ReflectionClass ;
1211
1312/**
1413 * Test class for Post Transformer.
@@ -19,7 +18,7 @@ class Test_Post extends \WP_UnitTestCase {
1918 /**
2019 * Reflection method for testing protected method.
2120 *
22- * @var ReflectionMethod
21+ * @var \ ReflectionMethod
2322 */
2423 private $ reflection_method ;
2524
@@ -32,7 +31,7 @@ public function set_up() {
3231 update_option ( 'activitypub_object_type ' , 'wordpress-post-format ' );
3332
3433 // Set up reflection method.
35- $ reflection = new ReflectionClass ( Post::class );
34+ $ reflection = new \ ReflectionClass ( Post::class );
3635 $ this ->reflection_method = $ reflection ->getMethod ( 'get_type ' );
3736 $ this ->reflection_method ->setAccessible ( true );
3837 }
@@ -654,4 +653,50 @@ public function test_preview_property() {
654653 // Check if the preview for a Note is null.
655654 $ this ->assertNull ( $ note_preview );
656655 }
656+
657+ /**
658+ * Test reply link generation.
659+ *
660+ * Pleroma prepends `acct:` to the webfinger identifier, which we'd want to normalize.
661+ *
662+ * @covers ::generate_reply_link
663+ */
664+ public function test_generate_reply_link () {
665+ \add_filter ( 'activitypub_pre_http_get_remote_object ' , array ( $ this , 'filter_pleroma_object ' ), 10 , 2 );
666+
667+ $ transformer = new Post ( self ::factory ()->post ->create_and_get () );
668+ $ reply_link = $ transformer ->generate_reply_link ( '' , array ( 'attrs ' => array ( 'url ' => 'https://devs.live/notice/AQ8N0Xl57y8bUQAb6e ' ) ) );
669+
670+ $ this ->
assertSame (
'<p class="ap-reply-mention"><a rel="mention ugc" href="https://devs.live/notice/AQ8N0Xl57y8bUQAb6e" title="[email protected] ">@tester</a></p> ' ,
$ reply_link );
671+
672+ \remove_filter ( 'activitypub_pre_http_get_remote_object ' , array ( $ this , 'filter_pleroma_object ' ) );
673+ }
674+
675+ /**
676+ * Filter pleroma object.
677+ *
678+ * @param array|string|null $response The response.
679+ * @param array|string|null $url The Object URL.
680+ * @return string[]
681+ */
682+ public function filter_pleroma_object ( $ response , $ url ) {
683+ if ( 'https://devs.live/notice/AQ8N0Xl57y8bUQAb6e ' === $ url ) {
684+ $ response = array (
685+ 'type ' => 'Note ' ,
686+ 'attributedTo ' => 'https://devs.live/users/tester ' ,
687+ 'content ' => 'Cake day it is ' ,
688+ );
689+ }
690+ if ( 'https://devs.live/users/tester ' === $ url ) {
691+ $ response = array (
692+ 'id ' => 'https://devs.live/users/tester ' ,
693+ 'type ' => 'Person ' ,
694+ 'preferredUsername ' => 'tester ' ,
695+ 'url ' => 'https://devs.live/users/tester ' ,
696+ 'webfinger ' =>
'acct:[email protected] ' ,
697+ );
698+ }
699+
700+ return $ response ;
701+ }
657702}
0 commit comments