Skip to content

Commit 0fae040

Browse files
westonruterCopilot
andauthored
Add additional test cases
Co-authored-by: Copilot <[email protected]>
1 parent d1c3ba6 commit 0fae040

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

tests/phpunit/tests/cron.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,72 @@ static function ( $schedules ) {
890890
$this->assertSame( 'invalid_interval', $rescheduled_event->get_error_code() );
891891
}
892892

893+
/**
894+
* @ticket 64404
895+
*
896+
* @covers ::wp_schedule_event
897+
* @covers ::wp_reschedule_event
898+
*/
899+
public function test_zero_schedule_interval_returns_error() {
900+
add_filter(
901+
'cron_schedules',
902+
static function ( $schedules ) {
903+
$schedules['zero_interval'] = array(
904+
'interval' => 0,
905+
'display' => 'Zero interval',
906+
);
907+
return $schedules;
908+
}
909+
);
910+
911+
$event = wp_schedule_event( time(), 'zero_interval', 'hook', array(), true );
912+
$this->assertWPError( $event );
913+
$this->assertSame( 'invalid_interval', $event->get_error_code() );
914+
915+
$rescheduled_event = wp_reschedule_event( time(), 'zero_interval', 'hook', array(), true );
916+
$this->assertWPError( $rescheduled_event );
917+
$this->assertSame( 'invalid_interval', $rescheduled_event->get_error_code() );
918+
}
919+
920+
/**
921+
* @ticket 64404
922+
*
923+
* @covers ::wp_schedule_event
924+
* @covers ::wp_reschedule_event
925+
*/
926+
public function test_non_numeric_schedule_interval_returns_error() {
927+
add_filter(
928+
'cron_schedules',
929+
static function ( $schedules ) {
930+
$schedules['non_numeric_interval_string'] = array(
931+
'interval' => 'invalid',
932+
'display' => 'Non numeric interval (string)',
933+
);
934+
$schedules['non_numeric_interval_null'] = array(
935+
'interval' => null,
936+
'display' => 'Non numeric interval (null)',
937+
);
938+
return $schedules;
939+
}
940+
);
941+
942+
$string_event = wp_schedule_event( time(), 'non_numeric_interval_string', 'hook', array(), true );
943+
$this->assertWPError( $string_event );
944+
$this->assertSame( 'invalid_interval', $string_event->get_error_code() );
945+
946+
$string_rescheduled_event = wp_reschedule_event( time(), 'non_numeric_interval_string', 'hook', array(), true );
947+
$this->assertWPError( $string_rescheduled_event );
948+
$this->assertSame( 'invalid_interval', $string_rescheduled_event->get_error_code() );
949+
950+
$null_event = wp_schedule_event( time(), 'non_numeric_interval_null', 'hook', array(), true );
951+
$this->assertWPError( $null_event );
952+
$this->assertSame( 'invalid_interval', $null_event->get_error_code() );
953+
954+
$null_rescheduled_event = wp_reschedule_event( time(), 'non_numeric_interval_null', 'hook', array(), true );
955+
$this->assertWPError( $null_rescheduled_event );
956+
$this->assertSame( 'invalid_interval', $null_rescheduled_event->get_error_code() );
957+
}
958+
893959
/**
894960
* @ticket 49961
895961
*

0 commit comments

Comments
 (0)