Skip to content

Commit 06627e8

Browse files
committed
Cron API: Add tests for associative and indexed array arguments when rescheduling a cron event.
Props johnbillion, peterwilsoncc See #57271 git-svn-id: https://develop.svn.wordpress.org/trunk@58109 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f08a369 commit 06627e8

1 file changed

Lines changed: 51 additions & 1 deletion

File tree

tests/phpunit/tests/cron.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,10 @@ public function test_pre_reschedule_event_filter() {
488488
add_filter( 'pre_reschedule_event', '__return_true' );
489489

490490
// Reschedule event with preflight filter in place.
491-
wp_reschedule_event( $ts1, 'daily', $hook );
491+
$rescheduled = wp_reschedule_event( $ts1, 'daily', $hook );
492+
493+
// Check return value.
494+
$this->assertTrue( $rescheduled );
492495

493496
// Check cron option is unchanged.
494497
$this->assertSame( $expected, _get_cron_array() );
@@ -1022,6 +1025,53 @@ public function test_schedule_short_circuit_with_false_returns_error_when_wp_err
10221025
$this->assertSame( 'pre_reschedule_event_false', $rescheduled_event->get_error_code() );
10231026
}
10241027

1028+
/**
1029+
* @ticket 57271
1030+
*
1031+
* @dataProvider data_wp_reschedule_event_works_with_args
1032+
*
1033+
* @covers ::wp_reschedule_event
1034+
*/
1035+
public function test_wp_reschedule_event_works_with_args( array $args ) {
1036+
$time = time();
1037+
1038+
// Schedule events with the `$wp_error` parameter:
1039+
$event = wp_schedule_event( $time, 'daily', 'hook', $args, true );
1040+
$rescheduled_event = wp_reschedule_event( $time, 'daily', 'hook', $args, true );
1041+
$unscheduled_event = wp_unschedule_event( $time, 'hook', $args, true );
1042+
$next_timestamp = wp_next_scheduled( 'hook', $args );
1043+
1044+
// Ensure the events were added and updated correctly:
1045+
$this->assertNotWPError( $event );
1046+
$this->assertNotWPError( $rescheduled_event );
1047+
$this->assertNotWPError( $unscheduled_event );
1048+
$this->assertSame( $time + DAY_IN_SECONDS, $next_timestamp );
1049+
}
1050+
1051+
/**
1052+
* Data provider for test_wp_reschedule_event_works_with_args().
1053+
*
1054+
* @return array[]
1055+
*/
1056+
public function data_wp_reschedule_event_works_with_args() {
1057+
return array(
1058+
'indexed' => array(
1059+
array(
1060+
1,
1061+
2,
1062+
3,
1063+
),
1064+
),
1065+
'associative' => array(
1066+
array(
1067+
'one' => 1,
1068+
'two' => 2,
1069+
'three' => 3,
1070+
),
1071+
),
1072+
);
1073+
}
1074+
10251075
/**
10261076
* @ticket 49961
10271077
* @expectedDeprecated wp_clear_scheduled_hook

0 commit comments

Comments
 (0)