@@ -23,13 +23,6 @@ class Test_Announce extends \WP_UnitTestCase {
23
23
*/
24
24
public $ user_id ;
25
25
26
- /**
27
- * User URL.
28
- *
29
- * @var string
30
- */
31
- public $ user_url ;
32
-
33
26
/**
34
27
* Post ID.
35
28
*
@@ -49,9 +42,7 @@ class Test_Announce extends \WP_UnitTestCase {
49
42
*/
50
43
public function set_up () {
51
44
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 ;
55
46
56
47
$ this ->post_id = \wp_insert_post (
57
48
array (
@@ -61,14 +52,14 @@ public function set_up() {
61
52
);
62
53
$ this ->post_permalink = \get_permalink ( $ this ->post_id );
63
54
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 );
65
56
}
66
57
67
58
/**
68
59
* Tear down the test.
69
60
*/
70
61
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 ' ) );
72
63
parent ::tear_down ();
73
64
}
74
65
@@ -79,7 +70,7 @@ public function tear_down() {
79
70
* @param string $actor The actor.
80
71
* @return array The metadata.
81
72
*/
82
- public static function get_remote_metadata_by_actor ( $ value , $ actor ) {
73
+ public function get_remote_metadata_by_actor ( $ value , $ actor ) {
83
74
return array (
84
75
'name ' => 'Example User ' ,
85
76
'icon ' => array (
@@ -95,14 +86,14 @@ public static function get_remote_metadata_by_actor( $value, $actor ) {
95
86
*
96
87
* @return array The test object.
97
88
*/
98
- public function create_test_object () {
89
+ public static function create_test_object () {
99
90
return array (
100
- 'actor ' => $ this -> user_url ,
91
+ 'actor ' => ' https://example.com/user ' ,
101
92
'type ' => 'Announce ' ,
102
93
'id ' => 'https://example.com/id/ ' . microtime ( true ),
103
- 'to ' => array ( $ this -> user_url ),
94
+ 'to ' => array ( ' https://example.com/user ' ),
104
95
'cc ' => array ( 'https://www.w3.org/ns/activitystreams#Public ' ),
105
- 'object ' => $ this -> post_permalink ,
96
+ 'object ' => ' https://example.com/post/123 ' ,
106
97
);
107
98
}
108
99
@@ -112,7 +103,16 @@ public function create_test_object() {
112
103
* @covers ::handle_announce
113
104
*/
114
105
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
+ );
116
116
117
117
Announce::handle_announce ( $ object , $ this ->user_id );
118
118
@@ -149,16 +149,18 @@ public function test_handle_announces( $announce, $recursion, $message ) {
149
149
}
150
150
151
151
/**
152
- * Test handle announce with invalid object .
152
+ * Test maybe save announce .
153
153
*
154
- * @covers ::handle_announce
154
+ * @covers ::maybe_save_announce
155
155
*/
156
156
public function test_maybe_save_announce () {
157
+ $ user_url = \get_userdata ( $ this ->user_id )->user_url ;
158
+
157
159
$ activity = array (
158
- 'actor ' => $ this -> user_url ,
160
+ 'actor ' => $ user_url ,
159
161
'type ' => 'Announce ' ,
160
162
'id ' => 'https://example.com/id/ ' . microtime ( true ),
161
- 'to ' => array ( $ this -> user_url ),
163
+ 'to ' => array ( $ user_url ),
162
164
'object ' => $ this ->post_permalink ,
163
165
);
164
166
@@ -180,24 +182,24 @@ public function test_maybe_save_announce() {
180
182
*
181
183
* @return array The data provider.
182
184
*/
183
- public function data_handle_announces () {
185
+ public static function data_handle_announces () {
184
186
return array (
185
187
array (
186
- 'announce ' => $ this -> create_test_object (),
188
+ 'announce ' => self :: create_test_object (),
187
189
'recursion ' => 0 ,
188
190
'message ' => 'Simple Announce of an URL. ' ,
189
191
),
190
192
array (
191
193
'announce ' => array (
192
- 'actor ' => $ this -> user_url ,
194
+ 'actor ' => ' https://example.com/user ' ,
193
195
'type ' => 'Announce ' ,
194
196
'id ' => 'https://example.com/id/ ' . microtime ( true ),
195
- 'to ' => array ( $ this -> user_url ),
197
+ 'to ' => array ( ' https://example.com/user ' ),
196
198
'object ' => array (
197
- 'actor ' => $ this -> user_url ,
199
+ 'actor ' => ' https://example.com/user ' ,
198
200
'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 ' ),
201
203
'content ' => 'text ' ,
202
204
),
203
205
),
@@ -206,11 +208,11 @@ public function data_handle_announces() {
206
208
),
207
209
array (
208
210
'announce ' => array (
209
- 'actor ' => $ this -> user_url ,
211
+ 'actor ' => ' https://example.com/user ' ,
210
212
'type ' => 'Announce ' ,
211
213
'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 (),
214
216
),
215
217
'recursion ' => 1 ,
216
218
'message ' => 'Announce of an Announce-Object. ' ,
0 commit comments