Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions tests/test-rsscloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,58 @@ public function test_query_vars_adds_rsscloud() {
$this->assertContains( 'existing_var', $result );
$this->assertContains( 'rsscloud', $result );
}

public function test_add_rss_cloud_element_returns_early_when_not_feed() {
ob_start();
rsscloud_add_rss_cloud_element();
$output = ob_get_clean();

$this->assertEmpty( $output );
}

public function test_add_rss_cloud_element_outputs_cloud_tag_on_feed() {
$this->go_to( get_feed_link( 'rss2' ) );

ob_start();
rsscloud_add_rss_cloud_element();
$output = ob_get_clean();

$this->assertStringContainsString( '<cloud ', $output );
$this->assertStringContainsString( "protocol='http-post'", $output );
$this->assertStringContainsString( 'rsscloud=notify', $output );
}

public function test_add_rss_cloud_element_uses_correct_domain() {
$this->go_to( get_feed_link( 'rss2' ) );

ob_start();
rsscloud_add_rss_cloud_element();
$output = ob_get_clean();

$home = wp_parse_url( get_option( 'home' ) );
$this->assertStringContainsString( "domain='" . $home['host'] . "'", $output );
}

public function test_add_rss_cloud_element_uses_port_from_home_url() {
$this->go_to( get_feed_link( 'rss2' ) );

ob_start();
rsscloud_add_rss_cloud_element();
$output = ob_get_clean();

$home = wp_parse_url( get_option( 'home' ) );
$port = ! empty( $home['port'] ) ? (int) $home['port'] : 80;
$this->assertStringContainsString( "port='" . $port . "'", $output );
}

public function test_parse_request_does_nothing_without_rsscloud_var() {
$wp = new stdClass();
$wp->query_vars = array( 'p' => '1' );

// Should return without calling exit or any notification processing.
rsscloud_parse_request( $wp );

// If we reach this point, the function returned normally.
$this->assertTrue( true );
}
}
76 changes: 76 additions & 0 deletions tests/test-schedule-post-notifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,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' )
);
}
}
Loading