7
7
8
8
namespace Activitypub \Tests \Scheduler ;
9
9
10
+ use Activitypub \Scheduler \Post ;
11
+
10
12
/**
11
13
* Test Post scheduler class.
12
14
*
@@ -24,23 +26,23 @@ public function test_transition_attachment_status() {
24
26
wp_set_current_user ( self ::$ user_id );
25
27
26
28
// Create.
27
- $ post_id = self ::factory ()->attachment ->create_upload_object ( dirname ( __DIR__ , 2 ) . '/assets/test.jpg ' );
28
- $ activitpub_id = \add_query_arg ( 'p ' , $ post_id , \home_url ( '/ ' ) );
29
- $ outbox_item = $ this ->get_latest_outbox_item ( $ activitpub_id );
29
+ $ post_id = self ::factory ()->attachment ->create_upload_object ( dirname ( __DIR__ , 2 ) . '/assets/test.jpg ' );
30
+ $ activitypub_id = \add_query_arg ( 'p ' , $ post_id , \home_url ( '/ ' ) );
31
+ $ outbox_item = $ this ->get_latest_outbox_item ( $ activitypub_id );
30
32
31
33
$ this ->assertNotNull ( $ outbox_item );
32
34
$ this ->assertSame ( 'Create ' , \get_post_meta ( $ outbox_item ->ID , '_activitypub_activity_type ' , true ) );
33
35
34
36
// Update.
35
37
self ::factory ()->attachment ->update_object ( $ post_id , array ( 'post_title ' => 'Updated title ' ) );
36
38
37
- $ outbox_item = $ this ->get_latest_outbox_item ( $ activitpub_id );
39
+ $ outbox_item = $ this ->get_latest_outbox_item ( $ activitypub_id );
38
40
$ this ->assertSame ( 'Update ' , \get_post_meta ( $ outbox_item ->ID , '_activitypub_activity_type ' , true ) );
39
41
40
42
// Delete.
41
43
\wp_delete_attachment ( $ post_id , true );
42
44
43
- $ outbox_item = $ this ->get_latest_outbox_item ( $ activitpub_id );
45
+ $ outbox_item = $ this ->get_latest_outbox_item ( $ activitypub_id );
44
46
$ this ->assertSame ( 'Delete ' , \get_post_meta ( $ outbox_item ->ID , '_activitypub_activity_type ' , true ) );
45
47
46
48
remove_post_type_support ( 'attachment ' , 'activitypub ' );
@@ -52,12 +54,31 @@ public function test_transition_attachment_status() {
52
54
* @covers ::schedule_post_activity
53
55
*/
54
56
public function test_schedule_post_activity_regular_post () {
55
- $ post_id = self ::factory ()->post ->create ( array ( 'post_author ' => self ::$ user_id ) );
56
- $ activitpub_id = \add_query_arg ( 'p ' , $ post_id , \home_url ( '/ ' ) );
57
+ $ post_id = self ::factory ()->post ->create ( array ( 'post_author ' => self ::$ user_id ) );
58
+ $ activitypub_id = \add_query_arg ( 'p ' , $ post_id , \home_url ( '/ ' ) );
57
59
58
- $ post = $ this ->get_latest_outbox_item ( $ activitpub_id );
60
+ $ post = $ this ->get_latest_outbox_item ( $ activitypub_id );
59
61
$ id = \get_post_meta ( $ post ->ID , '_activitypub_object_id ' , true );
60
- $ this ->assertSame ( $ activitpub_id , $ id );
62
+ $ this ->assertSame ( $ activitypub_id , $ id );
63
+
64
+ \wp_delete_post ( $ post_id , true );
65
+ }
66
+
67
+ /**
68
+ * Test post activity scheduling for regular posts.
69
+ *
70
+ * @covers ::schedule_post_activity
71
+ */
72
+ public function test_not_schedule_delete_activity_unfederated_post () {
73
+ \remove_action ( 'wp_after_insert_post ' , array ( Post::class, 'schedule_post_activity ' ), 33 );
74
+ $ post_id = self ::factory ()->post ->create ( array ( 'post_author ' => self ::$ user_id ) );
75
+ $ activitypub_id = \add_query_arg ( 'p ' , $ post_id , \home_url ( '/ ' ) );
76
+ \add_action ( 'wp_after_insert_post ' , array ( Post::class, 'schedule_post_activity ' ), 33 , 4 );
77
+
78
+ // Trash the post.
79
+ \wp_delete_post ( $ post_id );
80
+
81
+ $ this ->assertNull ( $ this ->get_latest_outbox_item ( $ activitypub_id ) );
61
82
62
83
\wp_delete_post ( $ post_id , true );
63
84
}
@@ -69,17 +90,17 @@ public function test_schedule_post_activity_regular_post() {
69
90
* @covers ::schedule_post_activity
70
91
*/
71
92
public function test_activity_type_on_publish () {
72
- $ post_id = self ::factory ()->post ->create (
93
+ $ post_id = self ::factory ()->post ->create (
73
94
array (
74
95
'post_author ' => self ::$ user_id ,
75
96
'post_status ' => 'draft ' ,
76
97
)
77
98
);
78
- $ activitpub_id = \add_query_arg ( 'p ' , $ post_id , \home_url ( '/ ' ) );
99
+ $ activitypub_id = \add_query_arg ( 'p ' , $ post_id , \home_url ( '/ ' ) );
79
100
80
101
\wp_publish_post ( $ post_id );
81
102
82
- $ post = $ this ->get_latest_outbox_item ( $ activitpub_id );
103
+ $ post = $ this ->get_latest_outbox_item ( $ activitypub_id );
83
104
$ type = \get_post_meta ( $ post ->ID , '_activitypub_activity_type ' , true );
84
105
$ this ->assertSame ( 'Create ' , $ type );
85
106
@@ -93,8 +114,8 @@ public function test_activity_type_on_publish() {
93
114
*/
94
115
public function test_schedule_post_activity_bulk_edit () {
95
116
wp_set_current_user ( self ::$ user_id );
96
- $ post_id = self ::factory ()->post ->create ( array ( 'post_author ' => self ::$ user_id ) );
97
- $ activitpub_id = \add_query_arg ( 'p ' , $ post_id , \home_url ( '/ ' ) );
117
+ $ post_id = self ::factory ()->post ->create ( array ( 'post_author ' => self ::$ user_id ) );
118
+ $ activitypub_id = \add_query_arg ( 'p ' , $ post_id , \home_url ( '/ ' ) );
98
119
99
120
// Test bulk edit that should bail (no author or status change).
100
121
$ _REQUEST ['bulk_edit ' ] = 1 ;
@@ -104,7 +125,7 @@ public function test_schedule_post_activity_bulk_edit() {
104
125
105
126
bulk_edit_posts ( $ _REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification
106
127
107
- $ outbox_item = $ this ->get_latest_outbox_item ( $ activitpub_id );
128
+ $ outbox_item = $ this ->get_latest_outbox_item ( $ activitypub_id );
108
129
$ this ->assertNotSame ( 'Update ' , \get_post_meta ( $ outbox_item ->ID , '_activitypub_activity_type ' , true ) );
109
130
110
131
// Test bulk edit with author change (should not bail).
@@ -116,7 +137,7 @@ public function test_schedule_post_activity_bulk_edit() {
116
137
117
138
bulk_edit_posts ( $ _REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification
118
139
119
- $ outbox_item = $ this ->get_latest_outbox_item ( $ activitpub_id );
140
+ $ outbox_item = $ this ->get_latest_outbox_item ( $ activitypub_id );
120
141
$ this ->assertNotNull ( $ outbox_item );
121
142
122
143
$ this ->assertSame ( 'Update ' , \get_post_meta ( $ outbox_item ->ID , '_activitypub_activity_type ' , true ) );
@@ -126,7 +147,7 @@ public function test_schedule_post_activity_bulk_edit() {
126
147
127
148
bulk_edit_posts ( $ _REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification
128
149
129
- $ outbox_item = $ this ->get_latest_outbox_item ( $ activitpub_id );
150
+ $ outbox_item = $ this ->get_latest_outbox_item ( $ activitypub_id );
130
151
$ this ->assertNotNull ( $ outbox_item );
131
152
$ this ->assertSame ( 'Delete ' , \get_post_meta ( $ outbox_item ->ID , '_activitypub_activity_type ' , true ) );
132
153
@@ -138,7 +159,7 @@ public function test_schedule_post_activity_bulk_edit() {
138
159
/**
139
160
* Data provider for no activity tests.
140
161
*
141
- * @return array[] Test parameters.
162
+ * @return array[][] Test parameters.
142
163
*/
143
164
public function no_activity_post_provider () {
144
165
return array (
@@ -166,10 +187,10 @@ public function no_activity_post_provider() {
166
187
* @param array $args Post data for creating the test post.
167
188
*/
168
189
public function test_no_activity_scheduled ( $ args ) {
169
- $ post_id = self ::factory ()->post ->create ( $ args );
170
- $ activitpub_id = \add_query_arg ( 'p ' , $ post_id , \home_url ( '/ ' ) );
190
+ $ post_id = self ::factory ()->post ->create ( $ args );
191
+ $ activitypub_id = \add_query_arg ( 'p ' , $ post_id , \home_url ( '/ ' ) );
171
192
172
- $ this ->assertNull ( $ this ->get_latest_outbox_item ( $ activitpub_id ) );
193
+ $ this ->assertNull ( $ this ->get_latest_outbox_item ( $ activitypub_id ) );
173
194
174
195
\wp_delete_post ( $ post_id , true );
175
196
}
0 commit comments