View source
<?php
namespace Drupal\Tests\webform_scheduled_tasks\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\webform_scheduled_tasks\Entity\WebformScheduledTask;
class ScheduledTaskAdminFormTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'block',
'webform_scheduled_tasks',
'webform_scheduled_tasks_test_types',
];
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('local_actions_block');
$this
->drupalLogin($this
->drupalCreateUser([
'administer webform',
]));
}
public function testAdminUi() {
$this
->drupalGet('admin/structure/webform/manage/contact/scheduled-tasks');
$this
->clickLink('Add scheduled task');
$this
->submitForm([
'label' => 'Foo',
'id' => 'foo',
'task_type' => 'test_task',
'result_set_type' => 'all_submissions',
], 'Save');
$this
->assertSession()
->pageTextContains('The scheduled task was saved successfully.');
$this
->submitForm([
'interval[amount]' => 12,
'interval[multiplier]' => 86400,
'task_settings[test_option]' => TRUE,
], 'Save');
$this
->assertSession()
->pageTextContains('The scheduled task was saved successfully.');
$schedule = WebformScheduledTask::load('foo');
$this
->assertEqualsWithDelta(time() + 1036800, $schedule
->getNextTaskRunDate(), 5);
}
public function testAdminUiManualScheduledRun() {
$this
->drupalGet('admin/structure/webform/manage/contact/scheduled-tasks');
$this
->clickLink('Add scheduled task');
$this
->submitForm([
'label' => 'Foo',
'id' => 'foo',
'task_type' => 'test_task',
'result_set_type' => 'all_submissions',
], 'Save');
$this
->assertSession()
->pageTextContains('The scheduled task was saved successfully.');
$this
->submitForm([
'interval[amount]' => 12,
'interval[multiplier]' => 86400,
'next_run[date]' => '2021-07-15',
'next_run[time]' => '20:41:35',
], 'Save');
$this
->assertSession()
->pageTextContains('The scheduled task was saved successfully.');
$schedule = WebformScheduledTask::load('foo');
$this
->assertEquals(1626345695, $schedule
->getNextTaskRunDate());
}
public function testResumeHaltedSchedule() {
$task = WebformScheduledTask::create([
'id' => 'foo',
'task_type' => 'test_task',
'result_set_type' => 'all_submissions',
'label' => 'Test task',
'webform' => 'contact',
'interval' => [
'amount' => 12,
'multiplier' => 86400,
],
]);
$task
->save();
$this
->drupalGet("admin/structure/webform/manage/contact/scheduled-tasks/{$task->id()}/edit");
$this
->assertSession()
->pageTextContains('Active');
$task
->halt('Something went really wrong.');
$this
->drupalGet("admin/structure/webform/manage/contact/scheduled-tasks/{$task->id()}/edit");
$this
->assertSession()
->pageTextContains('Halted');
$this
->assertSession()
->pageTextContains('Something went really wrong.');
$this
->submitForm([], 'Resume task');
$this
->assertSession()
->pageTextContains('The scheduled task was resumed and will run during the next scheduled interval.');
$schedule = WebformScheduledTask::load('foo');
$this
->assertFalse($schedule
->isHalted());
$this
->assertEqualsWithDelta(time() + 1036800, $schedule
->getNextTaskRunDate(), 5);
}
}