Changeset 43050 for trunk/tests/phpunit/tests/cron.php
- Timestamp:
- 05/01/2018 02:04:25 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/cron.php
r42343 r43050 30 30 $timestamp = strtotime( '+1 hour' ); 31 31 32 wp_schedule_single_event( $timestamp, $hook ); 32 $scheduled = wp_schedule_single_event( $timestamp, $hook ); 33 $this->assertTrue( $scheduled ); 33 34 $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) ); 34 35 … … 44 45 $args = array( 'foo' ); 45 46 46 wp_schedule_single_event( $timestamp, $hook, $args ); 47 $scheduled = wp_schedule_single_event( $timestamp, $hook, $args ); 48 $this->assertTrue( $scheduled ); 47 49 // this returns the timestamp only if we provide matching args 48 50 $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) ); … … 61 63 $timestamp = strtotime( '+1 hour' ); 62 64 63 wp_schedule_event( $timestamp, $recur, $hook ); 65 $scheduled = wp_schedule_event( $timestamp, $recur, $hook ); 66 $this->assertTrue( $scheduled ); 64 67 // it's scheduled for the right time 65 68 $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) ); … … 75 78 $args = array( 'foo' ); 76 79 77 wp_schedule_event( $timestamp, 'hourly', $hook, $args ); 80 $scheduled = wp_schedule_event( $timestamp, 'hourly', $hook, $args ); 81 $this->assertTrue( $scheduled ); 78 82 // this returns the timestamp only if we provide matching args 79 83 $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) ); … … 95 99 96 100 // now unschedule it and make sure it's gone 97 wp_unschedule_event( $timestamp, $hook ); 101 $unscheduled = wp_unschedule_event( $timestamp, $hook ); 102 $this->assertTrue( $unscheduled ); 98 103 $this->assertEquals( false, wp_next_scheduled( $hook ) ); 99 104 } … … 114 119 115 120 // clear the schedule for the no args events and make sure it's gone 116 wp_clear_scheduled_hook( $hook ); 121 $hook_unscheduled = wp_clear_scheduled_hook( $hook ); 122 $this->assertSame( 2, $hook_unscheduled ); 117 123 $this->assertFalse( wp_next_scheduled( $hook ) ); 118 124 // the args events should still be there … … 123 129 wp_clear_scheduled_hook( $hook, $args ); 124 130 $this->assertFalse( wp_next_scheduled( $hook, $args ) ); 131 } 132 133 function test_clear_undefined_schedule() { 134 $hook = __FUNCTION__; 135 $args = array( 'arg1' ); 136 137 wp_schedule_single_event( strtotime( '+1 hour' ), $hook, $args ); 138 wp_schedule_single_event( strtotime( '+2 hour' ), $hook, $args ); 139 140 // clear the schedule for no args events and ensure no events are cleared. 141 $hook_unscheduled = wp_clear_scheduled_hook( $hook ); 142 $this->assertSame( 0, $hook_unscheduled ); 125 143 } 126 144 … … 207 225 208 226 // clear the schedule and make sure it's gone. 209 wp_unschedule_hook( $hook ); 227 $unschedule_hook = wp_unschedule_hook( $hook ); 228 $this->assertSame( 4, $unschedule_hook ); 229 $this->assertFalse( wp_next_scheduled( $hook ) ); 230 } 231 232 function test_unschedule_undefined_hook() { 233 $hook = __FUNCTION__; 234 $unrelated_hook = __FUNCTION__ . '_two'; 235 236 // Attempt to clear schedule on non-existant hook. 237 $unschedule_hook = wp_unschedule_hook( $hook ); 238 $this->assertSame( 0, $unschedule_hook ); 239 $this->assertFalse( wp_next_scheduled( $hook ) ); 240 241 // Repeat tests with populated cron array. 242 wp_schedule_single_event( strtotime( '+1 hour' ), $unrelated_hook ); 243 wp_schedule_single_event( strtotime( '+2 hour' ), $unrelated_hook ); 244 245 $unschedule_hook = wp_unschedule_hook( $hook ); 246 $this->assertSame( 0, $unschedule_hook ); 210 247 $this->assertFalse( wp_next_scheduled( $hook ) ); 211 248 } … … 222 259 223 260 // first one works 224 wp_schedule_single_event( $ts1, $hook, $args);261 $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) ); 225 262 // second one is ignored 226 wp_schedule_single_event( $ts2, $hook, $args);263 $this->assertFalse( wp_schedule_single_event( $ts2, $hook, $args ) ); 227 264 228 265 // the next event should be at +5 minutes, not +3 … … 241 278 242 279 // first one works 243 wp_schedule_single_event( $ts1, $hook, $args);280 $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) ); 244 281 // second works too 245 wp_schedule_single_event( $ts2, $hook, $args);282 $this->assertTrue( wp_schedule_single_event( $ts2, $hook, $args ) ); 246 283 247 284 // the next event should be at +3 minutes, even though that one was scheduled second … … 260 297 261 298 // first one works 262 wp_schedule_single_event( $ts1, $hook, $args);299 $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) ); 263 300 // second works too 264 wp_schedule_single_event( $ts2, $hook, $args);301 $this->assertTrue( wp_schedule_single_event( $ts2, $hook, $args ) ); 265 302 266 303 // the next event should be at +3 minutes
Note: See TracChangeset
for help on using the changeset viewer.