@@ -23,13 +23,6 @@ class Test_Announce extends \WP_UnitTestCase {
2323 */
2424 public $ user_id ;
2525
26- /**
27- * User URL.
28- *
29- * @var string
30- */
31- public $ user_url ;
32-
3326 /**
3427 * Post ID.
3528 *
@@ -49,9 +42,7 @@ class Test_Announce extends \WP_UnitTestCase {
4942 */
5043 public function set_up () {
5144 parent ::set_up ();
52- $ this ->user_id = 1 ;
53- $ authordata = \get_userdata ( $ this ->user_id );
54- $ this ->user_url = $ authordata ->user_url ;
45+ $ this ->user_id = 1 ;
5546
5647 $ this ->post_id = \wp_insert_post (
5748 array (
@@ -61,14 +52,14 @@ public function set_up() {
6152 );
6253 $ this ->post_permalink = \get_permalink ( $ this ->post_id );
6354
64- \add_filter ( 'pre_get_remote_metadata_by_actor ' , array ( get_called_class () , 'get_remote_metadata_by_actor ' ), 0 , 2 );
55+ \add_filter ( 'pre_get_remote_metadata_by_actor ' , array ( $ this , 'get_remote_metadata_by_actor ' ), 0 , 2 );
6556 }
6657
6758 /**
6859 * Tear down the test.
6960 */
7061 public function tear_down () {
71- \remove_filter ( 'pre_get_remote_metadata_by_actor ' , array ( get_called_class () , 'get_remote_metadata_by_actor ' ) );
62+ \remove_filter ( 'pre_get_remote_metadata_by_actor ' , array ( $ this , 'get_remote_metadata_by_actor ' ) );
7263 parent ::tear_down ();
7364 }
7465
@@ -79,7 +70,7 @@ public function tear_down() {
7970 * @param string $actor The actor.
8071 * @return array The metadata.
8172 */
82- public static function get_remote_metadata_by_actor ( $ value , $ actor ) {
73+ public function get_remote_metadata_by_actor ( $ value , $ actor ) {
8374 return array (
8475 'name ' => 'Example User ' ,
8576 'icon ' => array (
@@ -95,14 +86,14 @@ public static function get_remote_metadata_by_actor( $value, $actor ) {
9586 *
9687 * @return array The test object.
9788 */
98- public function create_test_object () {
89+ public static function create_test_object () {
9990 return array (
100- 'actor ' => $ this -> user_url ,
91+ 'actor ' => ' https://example.com/user ' ,
10192 'type ' => 'Announce ' ,
10293 'id ' => 'https://example.com/id/ ' . microtime ( true ),
103- 'to ' => array ( $ this -> user_url ),
94+ 'to ' => array ( ' https://example.com/user ' ),
10495 'cc ' => array ( 'https://www.w3.org/ns/activitystreams#Public ' ),
105- 'object ' => $ this -> post_permalink ,
96+ 'object ' => ' https://example.com/post/123 ' ,
10697 );
10798 }
10899
@@ -112,7 +103,16 @@ public function create_test_object() {
112103 * @covers ::handle_announce
113104 */
114105 public function test_handle_announce () {
115- $ object = $ this ->create_test_object ();
106+ $ user_url = \get_userdata ( $ this ->user_id )->user_url ;
107+
108+ $ object = array (
109+ 'actor ' => $ user_url ,
110+ 'type ' => 'Announce ' ,
111+ 'id ' => 'https://example.com/id/ ' . microtime ( true ),
112+ 'to ' => array ( $ user_url ),
113+ 'cc ' => array ( 'https://www.w3.org/ns/activitystreams#Public ' ),
114+ 'object ' => $ this ->post_permalink ,
115+ );
116116
117117 Announce::handle_announce ( $ object , $ this ->user_id );
118118
@@ -149,16 +149,18 @@ public function test_handle_announces( $announce, $recursion, $message ) {
149149 }
150150
151151 /**
152- * Test handle announce with invalid object .
152+ * Test maybe save announce .
153153 *
154- * @covers ::handle_announce
154+ * @covers ::maybe_save_announce
155155 */
156156 public function test_maybe_save_announce () {
157+ $ user_url = \get_userdata ( $ this ->user_id )->user_url ;
158+
157159 $ activity = array (
158- 'actor ' => $ this -> user_url ,
160+ 'actor ' => $ user_url ,
159161 'type ' => 'Announce ' ,
160162 'id ' => 'https://example.com/id/ ' . microtime ( true ),
161- 'to ' => array ( $ this -> user_url ),
163+ 'to ' => array ( $ user_url ),
162164 'object ' => $ this ->post_permalink ,
163165 );
164166
@@ -180,24 +182,24 @@ public function test_maybe_save_announce() {
180182 *
181183 * @return array The data provider.
182184 */
183- public function data_handle_announces () {
185+ public static function data_handle_announces () {
184186 return array (
185187 array (
186- 'announce ' => $ this -> create_test_object (),
188+ 'announce ' => self :: create_test_object (),
187189 'recursion ' => 0 ,
188190 'message ' => 'Simple Announce of an URL. ' ,
189191 ),
190192 array (
191193 'announce ' => array (
192- 'actor ' => $ this -> user_url ,
194+ 'actor ' => ' https://example.com/user ' ,
193195 'type ' => 'Announce ' ,
194196 'id ' => 'https://example.com/id/ ' . microtime ( true ),
195- 'to ' => array ( $ this -> user_url ),
197+ 'to ' => array ( ' https://example.com/user ' ),
196198 'object ' => array (
197- 'actor ' => $ this -> user_url ,
199+ 'actor ' => ' https://example.com/user ' ,
198200 'type ' => 'Note ' ,
199- 'id ' => $ this -> post_permalink ,
200- 'to ' => array ( $ this -> user_url ),
201+ 'id ' => ' https://example.com/post/123 ' ,
202+ 'to ' => array ( ' https://example.com/user ' ),
201203 'content ' => 'text ' ,
202204 ),
203205 ),
@@ -206,11 +208,11 @@ public function data_handle_announces() {
206208 ),
207209 array (
208210 'announce ' => array (
209- 'actor ' => $ this -> user_url ,
211+ 'actor ' => ' https://example.com/user ' ,
210212 'type ' => 'Announce ' ,
211213 'id ' => 'https://example.com/id/ ' . microtime ( true ),
212- 'to ' => array ( $ this -> user_url ),
213- 'object ' => $ this -> create_test_object (),
214+ 'to ' => array ( ' https://example.com/user ' ),
215+ 'object ' => self :: create_test_object (),
214216 ),
215217 'recursion ' => 1 ,
216218 'message ' => 'Announce of an Announce-Object. ' ,
0 commit comments