|
5 | 5 | use ActionScheduler_Action;
|
6 | 6 | use ActionScheduler_Callbacks;
|
7 | 7 | use ActionScheduler_IntervalSchedule;
|
| 8 | +use ActionScheduler_Mocker; |
8 | 9 | use ActionScheduler_SimpleSchedule;
|
9 | 10 | use ActionScheduler_Store;
|
10 | 11 | use ActionScheduler_UnitTestCase;
|
@@ -117,4 +118,46 @@ public function test_query_actions_by_array_status() {
|
117 | 118 | // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
|
118 | 119 | // End tests for \ActionScheduler_Store::query_actions().
|
119 | 120 |
|
| 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 | + } |
120 | 163 | }
|
0 commit comments