Verified Commit bd36c03e authored by Erick Hitter's avatar Erick Hitter
Browse files

Add test of unscheduling events

Uses Core functions to ensure the CPT hooks are performing as expected. Needs a corresponding test that checks the CPT directly.
parent 26888e85
......@@ -67,4 +67,30 @@ class WPCCR_Cron_Options_CPT_Test extends WP_UnitTestCase {
}
}
}
/**
* Test that events are unscheduled correctly using Core functions
*/
function test_event_unscheduling_using_core_functions() {
$first_event = WP_Cron_Control_Revisited_Tests\Utils::create_test_event();
$second_event = WP_Cron_Control_Revisited_Tests\Utils::create_test_event( true );
$first_event_ts = wp_next_scheduled( $first_event['action'], $first_event['args'] );
$this->assertEquals( $first_event_ts, $first_event['timestamp'] );
wp_unschedule_event( $first_event_ts, $first_event['action'], $first_event['args'] );
$first_event_ts = wp_next_scheduled( $first_event['action'], $first_event['args'] );
$second_event_ts = wp_next_scheduled( $second_event['action'], $second_event['args'] );
$this->assertFalse( $first_event_ts );
$this->assertEquals( $second_event_ts, $second_event['timestamp'] );
wp_unschedule_event( $second_event_ts, $second_event['action'], $second_event['args'] );
$second_event_ts = wp_next_scheduled( $second_event['action'], $second_event['args'] );
$this->assertFalse( $second_event_ts );
}
}
......@@ -6,13 +6,17 @@ class Utils {
/**
* Build a test event
*/
static function create_test_event() {
static function create_test_event( $allow_multiple = false ) {
$event = array(
'timestamp' => time(),
'action' => 'wpccr_test_event',
'args' => array(),
);
if ( $allow_multiple ) {
$event['action'] .= '_' . rand( 10, 100 );
}
$next = wp_next_scheduled( $event['action'], $event['args'] );
if ( $next ) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment