Skip to content

Commit e65d625

Browse files
authored
Adding tests for notification-request (#7)
1 parent 0149d45 commit e65d625

3 files changed

Lines changed: 412 additions & 8 deletions

File tree

rsscloud/rsscloud.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,16 @@ function rsscloud_parse_request( $wp ) {
5959
}
6060
}
6161

62-
function rsscloud_notify_result( $success, $msg ) {
63-
$success = esc_attr( ent2ncr( wp_strip_all_tags( $success ) ) );
64-
$msg = esc_attr( ent2ncr( wp_strip_all_tags( $msg ) ) );
65-
66-
header( 'Content-Type: text/xml' );
67-
echo "<?xml version='1.0'?>\n";
68-
echo "<notifyResult success='" . esc_attr( $success ) . "' msg='" . esc_attr( $msg ) . "' />\n";
69-
exit;
62+
if ( ! function_exists( 'rsscloud_notify_result' ) ) {
63+
function rsscloud_notify_result( $success, $msg ) {
64+
$success = esc_attr( ent2ncr( wp_strip_all_tags( $success ) ) );
65+
$msg = esc_attr( ent2ncr( wp_strip_all_tags( $msg ) ) );
66+
67+
header( 'Content-Type: text/xml' );
68+
echo "<?xml version='1.0'?>\n";
69+
echo "<notifyResult success='" . esc_attr( $success ) . "' msg='" . esc_attr( $msg ) . "' />\n";
70+
exit;
71+
}
7072
}
7173

7274
add_action( 'rss2_head', 'rsscloud_add_rss_cloud_element' );

tests/bootstrap.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@
2525
// Give access to tests_add_filter() function.
2626
require_once "{$_tests_dir}/includes/functions.php";
2727

28+
/**
29+
* Exception used to capture rsscloud_notify_result() calls in tests
30+
* instead of calling exit().
31+
*/
32+
class RsscloudNotifyResultException extends Exception {
33+
public $success;
34+
public $msg;
35+
36+
public function __construct( $success, $msg ) {
37+
$this->success = $success;
38+
$this->msg = $msg;
39+
parent::__construct( "notify_result: success=$success msg=$msg" );
40+
}
41+
}
42+
43+
/**
44+
* Test-friendly override of rsscloud_notify_result() that throws
45+
* instead of calling exit.
46+
*/
47+
function rsscloud_notify_result( $success, $msg ) {
48+
throw new RsscloudNotifyResultException( $success, $msg );
49+
}
50+
2851
/**
2952
* Manually load the plugin being tested.
3053
*/

0 commit comments

Comments
 (0)