diff --git a/tests/test-rsscloud.php b/tests/test-rsscloud.php index 91af374..724634c 100644 --- a/tests/test-rsscloud.php +++ b/tests/test-rsscloud.php @@ -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( '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 ); + } } diff --git a/tests/test-schedule-post-notifications.php b/tests/test-schedule-post-notifications.php new file mode 100644 index 0000000..cc1262b --- /dev/null +++ b/tests/test-schedule-post-notifications.php @@ -0,0 +1,76 @@ +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' ) + ); + } +}