You are here

public function ScheduledTaskRunTest::testTaskRun in Webform Scheduled Tasks 8.2

Test creating and running a task.

File

tests/src/Functional/ScheduledTaskRunTest.php, line 48

Class

ScheduledTaskRunTest
An end to end integration test for creating and running a task.

Namespace

Drupal\Tests\webform_scheduled_tasks\Functional

Code

public function testTaskRun() {
  $this
    ->drupalGet('admin/structure/webform/manage/contact/scheduled-tasks');
  $this
    ->clickLink('Add scheduled task');
  $this
    ->submitForm([
    'label' => 'Test task',
    'id' => 'test_task',
    'task_type' => 'test_task',
    'result_set_type' => 'all_submissions',
  ], 'Save');
  $this
    ->submitForm([
    'interval[amount]' => 12,
    'interval[multiplier]' => 86400,
    // Test the next run date into the past, to ensure this gets executed
    // immediately.
    'next_run[date]' => '2005-07-15',
    'next_run[time]' => '20:41:35',
  ], 'Save');

  // Create three form submissions.
  foreach (range(1, 3) as $i) {
    $this
      ->drupalPostForm('webform/contact', [
      'subject' => 'Test submission',
      'message' => 'Test message',
    ], 'Send message');
  }

  // Run cron and visit the homepage to see all messages from the test
  // plugins.
  $this
    ->cronRun();
  $this
    ->drupalGet('<front>');
  $this
    ->assertSession()
    ->pageTextContains('Run test_task ::executeTask');
  $this
    ->assertSession()
    ->pageTextContains('Processed submission 1');
  $this
    ->assertSession()
    ->pageTextContains('Processed submission 2');
  $this
    ->assertSession()
    ->pageTextContains('Processed submission 3');
  $this
    ->assertSession()
    ->pageTextContains('Run test_task ::onSuccess');
}