ScheduleHaltResumeTest.php in Webform Scheduled Tasks 8.2
File
tests/src/Kernel/ScheduleHaltResumeTest.php
View source
<?php
namespace Drupal\Tests\webform_scheduled_tasks\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\webform\Entity\Webform;
use Drupal\webform_scheduled_tasks\Entity\WebformScheduledTask;
class ScheduleHaltResumeTest extends KernelTestBase {
public static $modules = [
'system',
'user',
'webform',
'webform_scheduled_tasks',
'webform_scheduled_tasks_test_types',
];
protected function setUp() {
parent::setUp();
$this
->installSchema('webform', [
'webform',
]);
$this
->installEntitySchema('webform_submission');
$this
->installEntitySchema('user');
}
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();
$this
->assertFalse($schedule
->isHalted());
$this
->assertFalse($unrelated_schedule
->isHalted());
$schedule
->halt();
$this
->assertTrue($schedule
->isHalted());
$this
->assertFalse($unrelated_schedule
->isHalted());
$this
->assertEquals('', $schedule
->getHaltedReason());
$schedule
->resume();
$this
->assertFalse($schedule
->isHalted());
$this
->assertFalse($unrelated_schedule
->isHalted());
$schedule
->halt(t('With a reason'));
$this
->assertTrue($schedule
->isHalted());
$this
->assertFalse($unrelated_schedule
->isHalted());
$this
->expectException(\Exception::class);
$schedule
->resume();
$schedule
->getHaltedReason();
}
}