Skip to content

Commit f84d780

Browse files
committed
Merge branch 'trunk' into fix-forum-17945942
2 parents 4771986 + d686bbd commit f84d780

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/phpunit/jobstore/AbstractStoreTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use ActionScheduler_Action;
66
use ActionScheduler_Callbacks;
77
use ActionScheduler_IntervalSchedule;
8+
use ActionScheduler_Mocker;
89
use ActionScheduler_SimpleSchedule;
910
use ActionScheduler_Store;
1011
use ActionScheduler_UnitTestCase;
@@ -117,4 +118,46 @@ public function test_query_actions_by_array_status() {
117118
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
118119
// End tests for \ActionScheduler_Store::query_actions().
119120

121+
/**
122+
* The `has_pending_actions_due` method should return a boolean value depending on whether there are
123+
* pending actions.
124+
*
125+
* @return void
126+
*/
127+
public function test_has_pending_actions_due() {
128+
$store = $this->get_store();
129+
$runner = ActionScheduler_Mocker::get_queue_runner( $store );
130+
131+
for ( $i = - 3; $i <= 3; $i ++ ) {
132+
// Some past actions, some future actions.
133+
$time = as_get_datetime_object( $i . ' hours' );
134+
$schedule = new ActionScheduler_SimpleSchedule( $time );
135+
$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, [ $i ], $schedule, 'my_group' );
136+
137+
$store->save_action( $action );
138+
}
139+
$this->assertTrue( $store->has_pending_actions_due() );
140+
141+
$runner->run();
142+
$this->assertFalse( $store->has_pending_actions_due() );
143+
}
144+
145+
/**
146+
* The `has_pending_actions_due` method should return false when all pending actions are in the future.
147+
*
148+
* @return void
149+
*/
150+
public function test_has_pending_actions_due_only_future_actions() {
151+
$store = $this->get_store();
152+
153+
for ( $i = 1; $i <= 3; $i ++ ) {
154+
// Only future actions.
155+
$time = as_get_datetime_object( $i . ' hours' );
156+
$schedule = new ActionScheduler_SimpleSchedule( $time );
157+
$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, [ $i ], $schedule, 'my_group' );
158+
159+
$store->save_action( $action );
160+
}
161+
$this->assertFalse( $store->has_pending_actions_due() );
162+
}
120163
}

0 commit comments

Comments
 (0)