File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,40 @@ Feature: Manage WP-Cron events and schedules
137137 """
138138 Error: Invalid cron event 'wp_cli_test_event_5'.
139139 """
140+ Scenario : Cron event with missing recurrence should be non-repeating.
141+ Given a wp-content/mu-plugins/schedule.php file:
142+ """
143+ <?php
144+ add_filter(
145+ 'cron_schedules',
146+ function( $schedules ) {
147+ $schedules['test_schedule'] = array(
148+ 'interval' => 3600,
149+ 'display' => __( 'Every Hour' ),
150+ );
151+ return $schedules;
152+ }
153+ );
154+ """
155+
156+ When I run `wp cron event schedule wp_cli_test_event "1 hour" test_schedule`
157+ Then STDOUT should contain:
158+ """
159+ Success: Scheduled event with hook 'wp_cli_test_event'
160+ """
161+
162+ When I run `wp cron event list --hook=wp_cli_test_event --fields=hook,recurrence`
163+ Then STDOUT should be a table containing rows:
164+ | hook | recurrence |
165+ | wp_cli_test_event | 1 hour |
166+
167+ When I run `rm wp-content/mu-plugins/schedule.php`
168+ Then the return code should be 0
169+
170+ When I run `wp cron event list --hook=wp_cli_test_event --fields=hook,recurrence`
171+ Then STDOUT should be a table containing rows:
172+ | hook | recurrence |
173+ | wp_cli_test_event | Non -repeating |
140174
141175 Scenario : Scheduling and then running a re-occurring event
142176 When I run `wp cron event schedule wp_cli_test_event_4 now hourly`
Original file line number Diff line number Diff line change @@ -436,10 +436,11 @@ protected static function delete_event( stdClass $event ) {
436436 */
437437 protected static function format_event ( stdClass $ event ) {
438438
439+ $ schedules = wp_get_schedules ();
440+ $ event ->recurrence = ( isset ( $ schedules [ $ event ->schedule ] ) ) ? self ::interval ( $ event ->interval ) : 'Non-repeating ' ;
439441 $ event ->next_run = get_date_from_gmt ( date ( 'Y-m-d H:i:s ' , $ event ->time ), self ::$ time_format ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
440442 $ event ->next_run_gmt = date ( self ::$ time_format , $ event ->time ); //phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
441443 $ event ->next_run_relative = self ::interval ( $ event ->time - time () );
442- $ event ->recurrence = ( $ event ->schedule ) ? self ::interval ( $ event ->interval ) : 'Non-repeating ' ;
443444
444445 return $ event ;
445446 }
You can’t perform that action at this time.
0 commit comments