Changeset 47122 for trunk/tests/phpunit/tests/cron.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/cron.php
r46586 r47122 19 19 function setUp() { 20 20 parent::setUp(); 21 // make sure the schedule is clear21 // Make sure the schedule is clear. 22 22 _set_cron_array( array() ); 23 23 $this->preflight_cron_array = array(); … … 26 26 27 27 function tearDown() { 28 // make sure the schedule is clear28 // Make sure the schedule is clear. 29 29 _set_cron_array( array() ); 30 30 parent::tearDown(); … … 32 32 33 33 function test_wp_get_schedule_empty() { 34 // nothing scheduled34 // Nothing scheduled. 35 35 $hook = __FUNCTION__; 36 36 $this->assertFalse( wp_get_schedule( $hook ) ); … … 38 38 39 39 function test_schedule_event_single() { 40 // schedule an event and make sure it's returned by wp_next_scheduled40 // Schedule an event and make sure it's returned by wp_next_scheduled(). 41 41 $hook = __FUNCTION__; 42 42 $timestamp = strtotime( '+1 hour' ); … … 46 46 $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) ); 47 47 48 // it's a non recurring event48 // It's a non-recurring event. 49 49 $this->assertEquals( '', wp_get_schedule( $hook ) ); 50 50 … … 52 52 53 53 function test_schedule_event_single_args() { 54 // schedule an event with arguments and make sure it's returned by wp_next_scheduled54 // Schedule an event with arguments and make sure it's returned by wp_next_scheduled(). 55 55 $hook = 'event'; 56 56 $timestamp = strtotime( '+1 hour' ); … … 59 59 $scheduled = wp_schedule_single_event( $timestamp, $hook, $args ); 60 60 $this->assertTrue( $scheduled ); 61 // this returns the timestamp only if we provide matching args61 // This returns the timestamp only if we provide matching args. 62 62 $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) ); 63 // these don't match so return nothing63 // These don't match so return nothing. 64 64 $this->assertEquals( false, wp_next_scheduled( $hook ) ); 65 65 $this->assertEquals( false, wp_next_scheduled( $hook, array( 'bar' ) ) ); 66 66 67 // it's a non recurring event67 // It's a non-recurring event. 68 68 $this->assertEquals( '', wp_get_schedule( $hook, $args ) ); 69 69 } 70 70 71 71 function test_schedule_event() { 72 // schedule an event and make sure it's returned by wp_next_scheduled72 // Schedule an event and make sure it's returned by wp_next_scheduled(). 73 73 $hook = __FUNCTION__; 74 74 $recur = 'hourly'; … … 77 77 $scheduled = wp_schedule_event( $timestamp, $recur, $hook ); 78 78 $this->assertTrue( $scheduled ); 79 // it's scheduled for the right time79 // It's scheduled for the right time. 80 80 $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) ); 81 // it's a recurring event81 // It's a recurring event. 82 82 $this->assertEquals( $recur, wp_get_schedule( $hook ) ); 83 83 } 84 84 85 85 function test_schedule_event_args() { 86 // schedule an event and make sure it's returned by wp_next_scheduled86 // Schedule an event and make sure it's returned by wp_next_scheduled(). 87 87 $hook = 'event'; 88 88 $timestamp = strtotime( '+1 hour' ); … … 92 92 $scheduled = wp_schedule_event( $timestamp, 'hourly', $hook, $args ); 93 93 $this->assertTrue( $scheduled ); 94 // this returns the timestamp only if we provide matching args94 // This returns the timestamp only if we provide matching args. 95 95 $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) ); 96 // these don't match so return nothing96 // These don't match so return nothing. 97 97 $this->assertEquals( false, wp_next_scheduled( $hook ) ); 98 98 $this->assertEquals( false, wp_next_scheduled( $hook, array( 'bar' ) ) ); … … 103 103 104 104 function test_unschedule_event() { 105 // schedule an event and make sure it's returned by wp_next_scheduled105 // Schedule an event and make sure it's returned by wp_next_scheduled(). 106 106 $hook = __FUNCTION__; 107 107 $timestamp = strtotime( '+1 hour' ); … … 110 110 $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) ); 111 111 112 // now unschedule it and make sure it's gone112 // Now unschedule it and make sure it's gone. 113 113 $unscheduled = wp_unschedule_event( $timestamp, $hook ); 114 114 $this->assertTrue( $unscheduled ); … … 120 120 $args = array( 'arg1' ); 121 121 122 // schedule several events with and without arguments122 // Schedule several events with and without arguments. 123 123 wp_schedule_single_event( strtotime( '+1 hour' ), $hook ); 124 124 wp_schedule_single_event( strtotime( '+2 hour' ), $hook ); … … 126 126 wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args ); 127 127 128 // make sure they're returned by wp_next_scheduled()128 // Make sure they're returned by wp_next_scheduled(). 129 129 $this->assertTrue( wp_next_scheduled( $hook ) > 0 ); 130 130 $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); 131 131 132 // clear the schedule for the no args events and make sure it's gone132 // Clear the schedule for the no args events and make sure it's gone. 133 133 $hook_unscheduled = wp_clear_scheduled_hook( $hook ); 134 134 $this->assertSame( 2, $hook_unscheduled ); 135 135 $this->assertFalse( wp_next_scheduled( $hook ) ); 136 // the args events should still be there136 // The args events should still be there. 137 137 $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); 138 138 139 // clear the schedule for the args events and make sure they're gone too140 // note: wp_clear_scheduled_hook() expects args passed directly, rather than as an array139 // Clear the schedule for the args events and make sure they're gone too. 140 // Note: wp_clear_scheduled_hook() expects args passed directly, rather than as an array. 141 141 wp_clear_scheduled_hook( $hook, $args ); 142 142 $this->assertFalse( wp_next_scheduled( $hook, $args ) ); … … 150 150 wp_schedule_single_event( strtotime( '+2 hour' ), $hook, $args ); 151 151 152 // clear the schedule for no args events and ensure no events are cleared.152 // Clear the schedule for no args events and ensure no events are cleared. 153 153 $hook_unscheduled = wp_clear_scheduled_hook( $hook ); 154 154 $this->assertSame( 0, $hook_unscheduled ); … … 159 159 $args = array( 'arg1', 'arg2' ); 160 160 161 // schedule several events with and without arguments161 // Schedule several events with and without arguments. 162 162 wp_schedule_single_event( strtotime( '+1 hour' ), $hook ); 163 163 wp_schedule_single_event( strtotime( '+2 hour' ), $hook ); … … 165 165 wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args ); 166 166 167 // make sure they're returned by wp_next_scheduled()167 // Make sure they're returned by wp_next_scheduled(). 168 168 $this->assertTrue( wp_next_scheduled( $hook ) > 0 ); 169 169 $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); 170 170 171 // clear the schedule for the no args events and make sure it's gone171 // Clear the schedule for the no args events and make sure it's gone. 172 172 wp_clear_scheduled_hook( $hook ); 173 173 $this->assertFalse( wp_next_scheduled( $hook ) ); 174 // the args events should still be there174 // The args events should still be there. 175 175 $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); 176 176 177 // clear the schedule for the args events and make sure they're gone too178 // note: wp_clear_scheduled_hook() used to expect args passed directly, rather than as an array pre WP 3.0177 // Clear the schedule for the args events and make sure they're gone too. 178 // Note: wp_clear_scheduled_hook() used to expect args passed directly, rather than as an array pre WP 3.0. 179 179 wp_clear_scheduled_hook( $hook, $args ); 180 180 $this->assertFalse( wp_next_scheduled( $hook, $args ) ); … … 190 190 $multi_args = array( 'arg2', 'arg3' ); 191 191 192 // schedule several events with and without arguments192 // Schedule several events with and without arguments. 193 193 wp_schedule_single_event( strtotime( '+1 hour' ), $hook ); 194 194 wp_schedule_single_event( strtotime( '+2 hour' ), $hook ); … … 198 198 wp_schedule_single_event( strtotime( '+6 hour' ), $multi_hook, $multi_args ); 199 199 200 // make sure they're returned by wp_next_scheduled()200 // Make sure they're returned by wp_next_scheduled(). 201 201 $this->assertTrue( wp_next_scheduled( $hook ) > 0 ); 202 202 $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); 203 203 204 // clear the schedule for the no args events and make sure it's gone204 // Clear the schedule for the no args events and make sure it's gone. 205 205 wp_clear_scheduled_hook( $hook ); 206 206 $this->assertFalse( wp_next_scheduled( $hook ) ); 207 // the args events should still be there207 // The args events should still be there. 208 208 $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); 209 209 210 // clear the schedule for the args events and make sure they're gone too210 // Clear the schedule for the args events and make sure they're gone too. 211 211 // wp_clear_scheduled_hook() should take args as an array like the other functions. 212 212 wp_clear_scheduled_hook( $hook, $args ); 213 213 $this->assertFalse( wp_next_scheduled( $hook, $args ) ); 214 214 215 // clear the schedule for the args events and make sure they're gone too216 // wp_clear_scheduled_hook() should take args as an array like the other functions and does from WP 3.0 215 // Clear the schedule for the args events and make sure they're gone too. 216 // wp_clear_scheduled_hook() should take args as an array like the other functions and does from WP 3.0. 217 217 wp_clear_scheduled_hook( $multi_hook, $multi_args ); 218 218 $this->assertFalse( wp_next_scheduled( $multi_hook, $multi_args ) ); … … 226 226 $args = array( rand_str() ); 227 227 228 // schedule several events with and without arguments.228 // Schedule several events with and without arguments. 229 229 wp_schedule_single_event( strtotime( '+1 hour' ), $hook ); 230 230 wp_schedule_single_event( strtotime( '+2 hour' ), $hook ); … … 232 232 wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args ); 233 233 234 // make sure they're returned by wp_next_scheduled().234 // Make sure they're returned by wp_next_scheduled(). 235 235 $this->assertTrue( wp_next_scheduled( $hook ) > 0 ); 236 236 $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); 237 237 238 // clear the schedule and make sure it's gone.238 // Clear the schedule and make sure it's gone. 239 239 $unschedule_hook = wp_unschedule_hook( $hook ); 240 240 $this->assertSame( 4, $unschedule_hook ); … … 264 264 */ 265 265 function test_duplicate_event() { 266 // duplicate events close together should be skipped266 // Duplicate events close together should be skipped. 267 267 $hook = __FUNCTION__; 268 268 $args = array( 'arg1' ); … … 270 270 $ts2 = strtotime( '+3 minutes' ); 271 271 272 // first one works273 $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) ); 274 // second one is ignored272 // First one works. 273 $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) ); 274 // Second one is ignored. 275 275 $this->assertFalse( wp_schedule_single_event( $ts2, $hook, $args ) ); 276 276 277 // the next event should be at +5 minutes, not +3277 // The next event should be at +5 minutes, not +3. 278 278 $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) ); 279 279 } … … 283 283 */ 284 284 function test_not_duplicate_event() { 285 // duplicate events far apart should work normally285 // Duplicate events far apart should work normally. 286 286 $hook = __FUNCTION__; 287 287 $args = array( 'arg1' ); … … 289 289 $ts2 = strtotime( '+3 minutes' ); 290 290 291 // first one works292 $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) ); 293 // second works too291 // First one works. 292 $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) ); 293 // Second works too. 294 294 $this->assertTrue( wp_schedule_single_event( $ts2, $hook, $args ) ); 295 295 296 // the next event should be at +3 minutes, even though that one was scheduled second296 // The next event should be at +3 minutes, even though that one was scheduled second. 297 297 $this->assertEquals( $ts2, wp_next_scheduled( $hook, $args ) ); 298 298 wp_unschedule_event( $ts2, $hook, $args ); 299 // following event at +30 minutes should be there too299 // Following event at +30 minutes should be there too. 300 300 $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) ); 301 301 } 302 302 303 303 function test_not_duplicate_event_reversed() { 304 // duplicate events far apart should work normally regardless of order304 // Duplicate events far apart should work normally regardless of order. 305 305 $hook = __FUNCTION__; 306 306 $args = array( 'arg1' ); … … 308 308 $ts2 = strtotime( '+30 minutes' ); 309 309 310 // first one works311 $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) ); 312 // second works too310 // First one works. 311 $this->assertTrue( wp_schedule_single_event( $ts1, $hook, $args ) ); 312 // Second works too. 313 313 $this->assertTrue( wp_schedule_single_event( $ts2, $hook, $args ) ); 314 314 315 // the next event should be at +3 minutes315 // The next event should be at +3 minutes. 316 316 $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) ); 317 317 wp_unschedule_event( $ts1, $hook, $args ); 318 // following event should be there too318 // Following event should be there too. 319 319 $this->assertEquals( $ts2, wp_next_scheduled( $hook, $args ) ); 320 320 } … … 382 382 $ts1 = strtotime( '+30 minutes' ); 383 383 384 // Add an event 384 // Add an event. 385 385 $this->assertTrue( wp_schedule_event( $ts1, 'hourly', $hook ) ); 386 386 $expected = _get_cron_array(); … … 406 406 $ts1 = strtotime( '+30 minutes' ); 407 407 408 // Add an event 408 // Add an event. 409 409 $this->assertTrue( wp_schedule_event( $ts1, 'hourly', $hook ) ); 410 410 $expected = _get_cron_array(); … … 430 430 $ts1 = strtotime( '+30 minutes' ); 431 431 432 // Add an event 432 // Add an event. 433 433 $this->assertTrue( wp_schedule_event( $ts1, 'hourly', $hook ) ); 434 434 $expected = _get_cron_array(); … … 584 584 585 585 // No scheduled events. 586 // - With timestamp 586 // - With timestamp. 587 587 $this->assertFalse( wp_get_scheduled_event( $hook, $args, $ts ) ); 588 588 // - Get next, none scheduled. … … 591 591 // Schedule an event. 592 592 wp_schedule_event( $ts, $hook, $args ); 593 // - unregistered timestamp593 // - Unregistered timestamp. 594 594 $this->assertFalse( wp_get_scheduled_event( $hook, $args, strtotime( '+30 minutes' ) ) ); 595 // - invalid timestamp.595 // - Invalid timestamp. 596 596 $this->assertFalse( wp_get_scheduled_event( $hook, $args, 'Words Fail!' ) ); 597 597
Note: See TracChangeset
for help on using the changeset viewer.