public function ScheduleHaltResumeTest::testHaltResume in Webform Scheduled Tasks 8.2
Test the interval scheduling.
File
- tests/
src/ Kernel/ ScheduleHaltResumeTest.php, line 43
Class
- ScheduleHaltResumeTest
- Test halting and resume the schedule.
Namespace
Drupal\Tests\webform_scheduled_tasks\KernelCode
public function testHaltResume() {
$webform = Webform::create([
'id' => 'foo',
]);
$webform
->save();
$schedule = WebformScheduledTask::create([
'id' => 'foo',
'result_set_type' => 'all_submissions',
'task_type' => 'test_task',
'webform' => $webform
->id(),
]);
$schedule
->save();
$unrelated_schedule = WebformScheduledTask::create([
'id' => 'bar',
'result_set_type' => 'all_submissions',
'task_type' => 'test_task',
'webform' => $webform
->id(),
]);
$unrelated_schedule
->save();
// Tasks start out un-halted.
$this
->assertFalse($schedule
->isHalted());
$this
->assertFalse($unrelated_schedule
->isHalted());
// Halt with no reason.
$schedule
->halt();
$this
->assertTrue($schedule
->isHalted());
$this
->assertFalse($unrelated_schedule
->isHalted());
$this
->assertEquals('', $schedule
->getHaltedReason());
// Resume an ensure tasks are resumed.
$schedule
->resume();
$this
->assertFalse($schedule
->isHalted());
$this
->assertFalse($unrelated_schedule
->isHalted());
// Halting with a reason will store the reason.
$schedule
->halt(t('With a reason'));
$this
->assertTrue($schedule
->isHalted());
$this
->assertFalse($unrelated_schedule
->isHalted());
$this
->expectException(\Exception::class);
$schedule
->resume();
$schedule
->getHaltedReason();
}