@@ -105,4 +105,60 @@ function ( $value, $actor ) use ( $actor_url, $actor_data ) {
105
105
\remove_all_filters ( 'pre_get_remote_metadata_by_actor ' );
106
106
wp_delete_post ( $ actor_post_id , true );
107
107
}
108
+
109
+ /**
110
+ * Test prepare_items with actor having icon array of URLs.
111
+ *
112
+ * This test verifies that when an icon field contains an array of URLs,
113
+ * the object_to_uri() function correctly extracts the first URL from the array.
114
+ *
115
+ * @covers ::prepare_items
116
+ */
117
+ public function test_prepare_items_with_icon_array_of_urls () {
118
+ // Mock remote metadata for the actor with icon as direct array of URLs.
119
+ $ actor_url = 'https://example.com/users/arrayuser ' ;
120
+ $ actor_data = array (
121
+ 'name ' => 'Array User ' ,
122
+ 'icon ' => array (
123
+ 'url ' => array (
124
+ 'https://example.com/storage/profile.webp ' ,
125
+ ),
126
+ 'type ' => 'Image ' ,
127
+ 'mediaType ' => 'image/webp ' ,
128
+ ),
129
+ 'url ' => $ actor_url ,
130
+ 'id ' => 'https://example.com/users/arrayuser ' ,
131
+ 'preferredUsername ' => 'arrayuser ' ,
132
+ 'inbox ' => 'https://example.com/users/arrayuser/inbox ' ,
133
+ );
134
+
135
+ // Mock the remote metadata call using the correct filter.
136
+ add_filter (
137
+ 'pre_get_remote_metadata_by_actor ' ,
138
+ function ( $ value , $ actor ) use ( $ actor_url , $ actor_data ) {
139
+ if ( $ actor === $ actor_url ) {
140
+ return $ actor_data ;
141
+ }
142
+ return $ value ;
143
+ },
144
+ 10 ,
145
+ 2
146
+ );
147
+
148
+ // Add the actor first, then follow them.
149
+ $ actor_post_id = Actors::upsert ( $ actor_data );
150
+
151
+ // Follow the actor using the proper method.
152
+ Following_Collection::follow ( $ actor_post_id , get_current_user_id () );
153
+
154
+ // Use the real prepare_items() method.
155
+ $ this ->following_table ->prepare_items ();
156
+
157
+ // Verify that the icon array was processed correctly: from array to first URL.
158
+ $ this ->assertEquals ( 'https://example.com/storage/profile.webp ' , $ this ->following_table ->items [0 ]['icon ' ] );
159
+
160
+ // Clean up.
161
+ \remove_all_filters ( 'pre_get_remote_metadata_by_actor ' );
162
+ wp_delete_post ( $ actor_post_id , true );
163
+ }
108
164
}
0 commit comments