-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-schedule-post-notifications.php
More file actions
76 lines (65 loc) · 1.81 KB
/
test-schedule-post-notifications.php
File metadata and controls
76 lines (65 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Tests for schedule-post-notifications functions.
*
* @package Rsscloud
*/
class SchedulePostNotificationsTest extends WP_UnitTestCase {
public function set_up() {
parent::set_up();
// Clear any scheduled events from prior tests.
wp_clear_scheduled_hook( 'rsscloud_send_post_notifications_action' );
}
public function test_schedules_cron_event_by_default() {
rsscloud_schedule_post_notifications();
$next = wp_next_scheduled( 'rsscloud_send_post_notifications_action' );
$this->assertNotFalse( $next, 'Expected a cron event to be scheduled.' );
}
public function test_instant_mode_calls_send_directly() {
define( 'RSSCLOUD_NOTIFICATIONS_INSTANT', true );
// Set up a subscriber keyed to the actual feed URL the function will resolve.
$feed_url = get_bloginfo( 'rss2_url' );
$notify_url = 'http://subscriber.example.com/rpc';
rsscloud_update_hub_notifications(
array(
$feed_url => array(
$notify_url => array(
'protocol' => 'http-post',
'status' => 'active',
'failure_count' => 0,
),
),
)
);
$sent = false;
add_filter(
'pre_http_request',
function () use ( &$sent ) {
$sent = true;
return array(
'response' => array(
'code' => 200,
'message' => 'OK',
),
'body' => '',
);
},
10,
3
);
rsscloud_schedule_post_notifications();
$this->assertTrue( $sent, 'Expected notifications to be sent immediately in instant mode.' );
}
public function test_cron_action_hook_is_registered() {
$this->assertSame(
10,
has_action( 'rsscloud_send_post_notifications_action', 'rsscloud_send_post_notifications' )
);
}
public function test_publish_post_hook_is_registered() {
$this->assertSame(
10,
has_action( 'publish_post', 'rsscloud_schedule_post_notifications' )
);
}
}