@@ -25,9 +25,13 @@ class Test_Mention extends \WP_UnitTestCase {
2525 */
2626 public static $ actors = array (
272728- 'id ' => 'https://example.org/users/username ' ,
29- 'url ' => 'https://example.org/users/username ' ,
30- 'name ' => 'username ' ,
28+ '@context ' => 'https://www.w3.org/ns/activitystreams ' ,
29+ 'id ' => 'https://example.org/users/username ' ,
30+ 'type ' => 'Person ' ,
31+ 'url ' => 'https://example.org/users/username ' ,
32+ 'name ' => 'username ' ,
33+ 'preferredUsername ' => 'username ' ,
34+ 'inbox ' => 'https://example.org/users/username/inbox ' ,
3135 ),
3236 );
3337
@@ -36,7 +40,6 @@ class Test_Mention extends \WP_UnitTestCase {
3640 */
3741 public function set_up () {
3842 parent ::set_up ();
39- add_filter ( 'pre_get_remote_metadata_by_actor ' , array ( get_called_class (), 'pre_get_remote_metadata_by_actor ' ), 10 , 2 );
4043 add_filter ( 'pre_http_request ' , array ( $ this , 'pre_http_request ' ), 10 , 3 );
4144 add_filter ( 'activitypub_pre_http_get_remote_object ' , array ( $ this , 'activitypub_pre_http_get_remote_object ' ), 10 , 2 );
4245 }
@@ -45,7 +48,6 @@ public function set_up() {
4548 * Tear down the test case.
4649 */
4750 public function tear_down () {
48- remove_filter ( 'pre_get_remote_metadata_by_actor ' , array ( get_called_class (), 'pre_get_remote_metadata_by_actor ' ) );
4951 remove_filter ( 'pre_http_request ' , array ( $ this , 'pre_http_request ' ) );
5052 remove_filter ( 'activitypub_pre_http_get_remote_object ' , array ( $ this , 'activitypub_pre_http_get_remote_object ' ) );
5153 parent ::tear_down ();
@@ -103,6 +105,26 @@ public function the_content_provider() {
103105 * @return array|false|\WP_Error
104106 */
105107 public function pre_http_request ( $ response , $ parsed_args , $ url ) {
108+ // Mock webfinger for test actors.
109+ if ( 'https://example.org/.well-known/webfinger?resource=acct%3Ausername%40example.org ' === $ url ) {
110+ return array (
111+ 'headers ' => array ( 'content-type ' => 'application/jrd+json ' ),
112+ 'body ' => wp_json_encode (
113+ array (
114+ 'subject ' =>
'acct:[email protected] ' ,
115+ 'links ' => array (
116+ array (
117+ 'rel ' => 'self ' ,
118+ 'type ' => 'application/activity+json ' ,
119+ 'href ' => 'https://example.org/users/username ' ,
120+ ),
121+ ),
122+ )
123+ ),
124+ 'response ' => array ( 'code ' => 200 ),
125+ );
126+ }
127+
106128 // Mock responses for remote users.
107129 if ( 'https://notiz.blog/.well-known/webfinger?resource=acct%3Apfefferle%40notiz.blog ' === $ url ) {
108130 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
@@ -137,6 +159,16 @@ public function pre_http_request( $response, $parsed_args, $url ) {
137159 public function activitypub_pre_http_get_remote_object ( $ pre , $ url_or_object ) {
138160 $ url = object_to_uri ( $ url_or_object );
139161
162+ // Check if this is a URL from our test actors.
163+ foreach ( self ::$ actors as $ actor_data ) {
164+ if ( isset ( $ actor_data ['id ' ] ) && $ actor_data ['id ' ] === $ url ) {
165+ return $ actor_data ;
166+ }
167+ if ( isset ( $ actor_data ['url ' ] ) && $ actor_data ['url ' ] === $ url ) {
168+ return $ actor_data ;
169+ }
170+ }
171+
140172 // Return parsed object data for ActivityPub actors.
141173 if ( 'https://notiz.blog/author/matthias-pfefferle/ ' === $ url ) {
142174 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
@@ -152,21 +184,4 @@ public function activitypub_pre_http_get_remote_object( $pre, $url_or_object ) {
152184
153185 return $ pre ;
154186 }
155-
156- /**
157- * Filters remote metadata by actor.
158- *
159- * @param array|string $pre The pre-filtered value.
160- * @param string $actor The actor.
161- * @return array|string
162- */
163- public static function pre_get_remote_metadata_by_actor ( $ pre , $ actor ) {
164- $ actor = ltrim ( $ actor , '@ ' );
165-
166- if ( isset ( self ::$ actors [ $ actor ] ) ) {
167- return self ::$ actors [ $ actor ];
168- }
169-
170- return $ pre ;
171- }
172187}
0 commit comments