Changeset 42343 for trunk/tests/phpunit/tests/cron.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/tests/phpunit/tests/cron.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/cron.php
r40965 r42343 10 10 parent::setUp(); 11 11 // make sure the schedule is clear 12 _set_cron_array( array());12 _set_cron_array( array() ); 13 13 } 14 14 15 15 function tearDown() { 16 16 // make sure the schedule is clear 17 _set_cron_array( array());17 _set_cron_array( array() ); 18 18 parent::tearDown(); 19 19 } … … 22 22 // nothing scheduled 23 23 $hook = __FUNCTION__; 24 $this->assertFalse( wp_get_schedule($hook));24 $this->assertFalse( wp_get_schedule( $hook ) ); 25 25 } 26 26 27 27 function test_schedule_event_single() { 28 28 // schedule an event and make sure it's returned by wp_next_scheduled 29 $hook = __FUNCTION__;30 $timestamp = strtotime( '+1 hour');29 $hook = __FUNCTION__; 30 $timestamp = strtotime( '+1 hour' ); 31 31 32 32 wp_schedule_single_event( $timestamp, $hook ); 33 $this->assertEquals( $timestamp, wp_next_scheduled( $hook) );33 $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) ); 34 34 35 35 // it's a non recurring event 36 $this->assertEquals( '', wp_get_schedule( $hook) );36 $this->assertEquals( '', wp_get_schedule( $hook ) ); 37 37 38 38 } … … 40 40 function test_schedule_event_single_args() { 41 41 // schedule an event with arguments and make sure it's returned by wp_next_scheduled 42 $hook = 'event';43 $timestamp = strtotime( '+1 hour');44 $args = array('foo');42 $hook = 'event'; 43 $timestamp = strtotime( '+1 hour' ); 44 $args = array( 'foo' ); 45 45 46 46 wp_schedule_single_event( $timestamp, $hook, $args ); 47 47 // this returns the timestamp only if we provide matching args 48 $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args) );48 $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) ); 49 49 // these don't match so return nothing 50 $this->assertEquals( false, wp_next_scheduled( $hook) );51 $this->assertEquals( false, wp_next_scheduled( $hook, array('bar')) );50 $this->assertEquals( false, wp_next_scheduled( $hook ) ); 51 $this->assertEquals( false, wp_next_scheduled( $hook, array( 'bar' ) ) ); 52 52 53 53 // it's a non recurring event 54 $this->assertEquals( '', wp_get_schedule( $hook, $args) );54 $this->assertEquals( '', wp_get_schedule( $hook, $args ) ); 55 55 } 56 56 57 57 function test_schedule_event() { 58 58 // schedule an event and make sure it's returned by wp_next_scheduled 59 $hook = __FUNCTION__;60 $recur = 'hourly';61 $timestamp = strtotime( '+1 hour');59 $hook = __FUNCTION__; 60 $recur = 'hourly'; 61 $timestamp = strtotime( '+1 hour' ); 62 62 63 63 wp_schedule_event( $timestamp, $recur, $hook ); 64 64 // it's scheduled for the right time 65 $this->assertEquals( $timestamp, wp_next_scheduled( $hook) );65 $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) ); 66 66 // it's a recurring event 67 $this->assertEquals( $recur, wp_get_schedule( $hook) );67 $this->assertEquals( $recur, wp_get_schedule( $hook ) ); 68 68 } 69 69 70 70 function test_schedule_event_args() { 71 71 // schedule an event and make sure it's returned by wp_next_scheduled 72 $hook = 'event';73 $timestamp = strtotime( '+1 hour');74 $recur = 'hourly';75 $args = array('foo');72 $hook = 'event'; 73 $timestamp = strtotime( '+1 hour' ); 74 $recur = 'hourly'; 75 $args = array( 'foo' ); 76 76 77 77 wp_schedule_event( $timestamp, 'hourly', $hook, $args ); 78 78 // this returns the timestamp only if we provide matching args 79 $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args) );79 $this->assertEquals( $timestamp, wp_next_scheduled( $hook, $args ) ); 80 80 // these don't match so return nothing 81 $this->assertEquals( false, wp_next_scheduled( $hook) );82 $this->assertEquals( false, wp_next_scheduled( $hook, array('bar')) );83 84 $this->assertEquals( $recur, wp_get_schedule( $hook, $args) );81 $this->assertEquals( false, wp_next_scheduled( $hook ) ); 82 $this->assertEquals( false, wp_next_scheduled( $hook, array( 'bar' ) ) ); 83 84 $this->assertEquals( $recur, wp_get_schedule( $hook, $args ) ); 85 85 86 86 } … … 88 88 function test_unschedule_event() { 89 89 // schedule an event and make sure it's returned by wp_next_scheduled 90 $hook = __FUNCTION__;91 $timestamp = strtotime( '+1 hour');90 $hook = __FUNCTION__; 91 $timestamp = strtotime( '+1 hour' ); 92 92 93 93 wp_schedule_single_event( $timestamp, $hook ); 94 $this->assertEquals( $timestamp, wp_next_scheduled( $hook) );94 $this->assertEquals( $timestamp, wp_next_scheduled( $hook ) ); 95 95 96 96 // now unschedule it and make sure it's gone 97 97 wp_unschedule_event( $timestamp, $hook ); 98 $this->assertEquals( false, wp_next_scheduled( $hook) );98 $this->assertEquals( false, wp_next_scheduled( $hook ) ); 99 99 } 100 100 … … 104 104 105 105 // schedule several events with and without arguments 106 wp_schedule_single_event( strtotime( '+1 hour'), $hook );107 wp_schedule_single_event( strtotime( '+2 hour'), $hook );108 wp_schedule_single_event( strtotime( '+3 hour'), $hook, $args );109 wp_schedule_single_event( strtotime( '+4 hour'), $hook, $args );106 wp_schedule_single_event( strtotime( '+1 hour' ), $hook ); 107 wp_schedule_single_event( strtotime( '+2 hour' ), $hook ); 108 wp_schedule_single_event( strtotime( '+3 hour' ), $hook, $args ); 109 wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args ); 110 110 111 111 // make sure they're returned by wp_next_scheduled() 112 $this->assertTrue( wp_next_scheduled( $hook) > 0 );113 $this->assertTrue( wp_next_scheduled( $hook, $args) > 0 );112 $this->assertTrue( wp_next_scheduled( $hook ) > 0 ); 113 $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); 114 114 115 115 // clear the schedule for the no args events and make sure it's gone 116 wp_clear_scheduled_hook( $hook);117 $this->assertFalse( wp_next_scheduled( $hook) );116 wp_clear_scheduled_hook( $hook ); 117 $this->assertFalse( wp_next_scheduled( $hook ) ); 118 118 // the args events should still be there 119 $this->assertTrue( wp_next_scheduled( $hook, $args) > 0 );119 $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); 120 120 121 121 // clear the schedule for the args events and make sure they're gone too 122 122 // note: wp_clear_scheduled_hook() expects args passed directly, rather than as an array 123 wp_clear_scheduled_hook( $hook, $args);124 $this->assertFalse( wp_next_scheduled( $hook, $args) );123 wp_clear_scheduled_hook( $hook, $args ); 124 $this->assertFalse( wp_next_scheduled( $hook, $args ) ); 125 125 } 126 126 … … 130 130 131 131 // schedule several events with and without arguments 132 wp_schedule_single_event( strtotime( '+1 hour'), $hook );133 wp_schedule_single_event( strtotime( '+2 hour'), $hook );134 wp_schedule_single_event( strtotime( '+3 hour'), $hook, $args );135 wp_schedule_single_event( strtotime( '+4 hour'), $hook, $args );132 wp_schedule_single_event( strtotime( '+1 hour' ), $hook ); 133 wp_schedule_single_event( strtotime( '+2 hour' ), $hook ); 134 wp_schedule_single_event( strtotime( '+3 hour' ), $hook, $args ); 135 wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args ); 136 136 137 137 // make sure they're returned by wp_next_scheduled() 138 $this->assertTrue( wp_next_scheduled( $hook) > 0 );139 $this->assertTrue( wp_next_scheduled( $hook, $args) > 0 );138 $this->assertTrue( wp_next_scheduled( $hook ) > 0 ); 139 $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); 140 140 141 141 // clear the schedule for the no args events and make sure it's gone 142 wp_clear_scheduled_hook( $hook);143 $this->assertFalse( wp_next_scheduled( $hook) );142 wp_clear_scheduled_hook( $hook ); 143 $this->assertFalse( wp_next_scheduled( $hook ) ); 144 144 // the args events should still be there 145 $this->assertTrue( wp_next_scheduled( $hook, $args) > 0 );145 $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); 146 146 147 147 // clear the schedule for the args events and make sure they're gone too 148 148 // note: wp_clear_scheduled_hook() used to expect args passed directly, rather than as an array pre WP 3.0 149 wp_clear_scheduled_hook( $hook, $args);150 $this->assertFalse( wp_next_scheduled( $hook, $args) );149 wp_clear_scheduled_hook( $hook, $args ); 150 $this->assertFalse( wp_next_scheduled( $hook, $args ) ); 151 151 } 152 152 … … 155 155 */ 156 156 function test_clear_schedule_new_args() { 157 $hook = __FUNCTION__;158 $args = array( 'arg1' );157 $hook = __FUNCTION__; 158 $args = array( 'arg1' ); 159 159 $multi_hook = __FUNCTION__ . '_multi'; 160 160 $multi_args = array( 'arg2', 'arg3' ); 161 161 162 162 // schedule several events with and without arguments 163 wp_schedule_single_event( strtotime( '+1 hour'), $hook );164 wp_schedule_single_event( strtotime( '+2 hour'), $hook );165 wp_schedule_single_event( strtotime( '+3 hour'), $hook, $args );166 wp_schedule_single_event( strtotime( '+4 hour'), $hook, $args );167 wp_schedule_single_event( strtotime( '+5 hour'), $multi_hook, $multi_args );168 wp_schedule_single_event( strtotime( '+6 hour'), $multi_hook, $multi_args );163 wp_schedule_single_event( strtotime( '+1 hour' ), $hook ); 164 wp_schedule_single_event( strtotime( '+2 hour' ), $hook ); 165 wp_schedule_single_event( strtotime( '+3 hour' ), $hook, $args ); 166 wp_schedule_single_event( strtotime( '+4 hour' ), $hook, $args ); 167 wp_schedule_single_event( strtotime( '+5 hour' ), $multi_hook, $multi_args ); 168 wp_schedule_single_event( strtotime( '+6 hour' ), $multi_hook, $multi_args ); 169 169 170 170 // make sure they're returned by wp_next_scheduled() 171 $this->assertTrue( wp_next_scheduled( $hook) > 0 );172 $this->assertTrue( wp_next_scheduled( $hook, $args) > 0 );171 $this->assertTrue( wp_next_scheduled( $hook ) > 0 ); 172 $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); 173 173 174 174 // clear the schedule for the no args events and make sure it's gone 175 wp_clear_scheduled_hook( $hook);176 $this->assertFalse( wp_next_scheduled( $hook) );175 wp_clear_scheduled_hook( $hook ); 176 $this->assertFalse( wp_next_scheduled( $hook ) ); 177 177 // the args events should still be there 178 $this->assertTrue( wp_next_scheduled( $hook, $args) > 0 );178 $this->assertTrue( wp_next_scheduled( $hook, $args ) > 0 ); 179 179 180 180 // clear the schedule for the args events and make sure they're gone too 181 181 // wp_clear_scheduled_hook() should take args as an array like the other functions. 182 wp_clear_scheduled_hook( $hook, $args);183 $this->assertFalse( wp_next_scheduled( $hook, $args) );182 wp_clear_scheduled_hook( $hook, $args ); 183 $this->assertFalse( wp_next_scheduled( $hook, $args ) ); 184 184 185 185 // clear the schedule for the args events and make sure they're gone too 186 186 // wp_clear_scheduled_hook() should take args as an array like the other functions and does from WP 3.0 187 wp_clear_scheduled_hook( $multi_hook, $multi_args);188 $this->assertFalse( wp_next_scheduled( $multi_hook, $multi_args) );187 wp_clear_scheduled_hook( $multi_hook, $multi_args ); 188 $this->assertFalse( wp_next_scheduled( $multi_hook, $multi_args ) ); 189 189 } 190 190 … … 218 218 $hook = __FUNCTION__; 219 219 $args = array( 'arg1' ); 220 $ts1 = strtotime('+5 minutes');221 $ts2 = strtotime('+3 minutes');220 $ts1 = strtotime( '+5 minutes' ); 221 $ts2 = strtotime( '+3 minutes' ); 222 222 223 223 // first one works … … 227 227 228 228 // the next event should be at +5 minutes, not +3 229 $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args) );229 $this->assertEquals( $ts1, wp_next_scheduled( $hook, $args ) ); 230 230 } 231 231 … … 237 237 $hook = __FUNCTION__; 238 238 $args = array( 'arg1' ); 239 $ts1 = strtotime( '+30 minutes' );240 $ts2 = strtotime( '+3 minutes' );239 $ts1 = strtotime( '+30 minutes' ); 240 $ts2 = strtotime( '+3 minutes' ); 241 241 242 242 // first one works … … 256 256 $hook = __FUNCTION__; 257 257 $args = array( 'arg1' ); 258 $ts1 = strtotime( '+3 minutes' );259 $ts2 = strtotime( '+30 minutes' );258 $ts1 = strtotime( '+3 minutes' ); 259 $ts2 = strtotime( '+30 minutes' ); 260 260 261 261 // first one works
Note: See TracChangeset
for help on using the changeset viewer.