@@ -244,20 +244,28 @@ public function test_pre_update_cron_option() {
244244 $ update_result = Cron_Control \pre_update_cron_option ( 'not array ' , [ 'old array ' ] );
245245 $ this ->assertEquals ( [ 'old array ' ], $ update_result );
246246
247- // Schedule an event, and leave one unsaved.
247+ // Schedule one event, and leave two unsaved.
248248 $ default_args = [ 'timestamp ' => time () + 100 , 'args ' => [ 'some ' , 'args ' ] ];
249- $ event_to_add = $ this ->create_unsaved_event ( array_merge ( $ default_args , [ 'action ' => 'test_pre_update_cron_option_new ' ] ) );
250249 $ existing_event = $ this ->create_unsaved_event ( array_merge ( $ default_args , [ 'action ' => 'test_pre_update_cron_option_existing ' ] ) );
251250 $ existing_event ->save ();
252251
253- // Mock the scenario of sending a fresh event into the mix.
252+ $ event_to_add = $ this ->create_unsaved_event ( array_merge ( $ default_args , [ 'action ' => 'test_pre_update_cron_option_new ' ] ) );
253+ $ recurring_event_to_add = $ this ->create_unsaved_event ( array_merge ( $ default_args , [
254+ 'action ' => 'test_pre_update_cron_option_new_recurring ' ,
255+ 'schedule ' => 'hourly ' ,
256+ 'interval ' => HOUR_IN_SECONDS ,
257+ ] ) );
258+
259+ // Mock the scenario of sending a fresh events into the mix.
254260 $ existing_option = Events::format_events_for_wp ( [ $ existing_event ] );
255- $ new_option = Events::format_events_for_wp ( [ $ existing_event , $ event_to_add ] );
261+ $ new_option = Events::format_events_for_wp ( [ $ existing_event , $ event_to_add, $ recurring_event_to_add ] );
256262 $ update_result = Cron_Control \pre_update_cron_option ( $ new_option , $ existing_option );
257263
258264 $ this ->assertEquals ( $ existing_option , $ update_result , 'return value is always the prev value ' );
259265 $ added_event = Event::find ( [ 'action ' => 'test_pre_update_cron_option_new ' ] );
260- $ this ->assertEquals ( $ event_to_add ->get_action (), $ added_event ->get_action (), 'event was registered ' );
266+ $ this ->assertEquals ( $ event_to_add ->get_action (), $ added_event ->get_action (), 'single event was registered ' );
267+ $ added_recurring_event = Event::find ( [ 'action ' => 'test_pre_update_cron_option_new_recurring ' ] );
268+ $ this ->assertEquals ( $ recurring_event_to_add ->get_schedule (), $ added_recurring_event ->get_schedule (), 'recurring event was registered ' );
261269
262270 // Mock the scenario of deleting an event from the mix.
263271 $ existing_option = Events::format_events_for_wp ( [ $ existing_event , $ added_event ] );
@@ -308,6 +316,10 @@ private function create_unsaved_event( array $args ) {
308316 $ event ->set_timestamp ( $ args ['timestamp ' ] );
309317 $ event ->set_args ( $ args ['args ' ] );
310318
319+ if ( isset ( $ args ['schedule ' ] ) ) {
320+ $ event ->set_schedule ( $ args ['schedule ' ], $ args ['interval ' ] );
321+ }
322+
311323 return $ event ;
312324 }
313325}
0 commit comments