You are here

public function TimeStepTest::testTimeSteps in Lightning Scheduler 8

Tests the time steps.

File

tests/src/FunctionalJavascript/TimeStepTest.php, line 26

Class

TimeStepTest
@group lightning_scheduler

Namespace

Drupal\Tests\lightning_scheduler\FunctionalJavascript

Code

public function testTimeSteps() {
  $assert_session = $this
    ->assertSession();
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->createContentType([
    'type' => 'page',
  ]);
  $workflow = $this
    ->createEditorialWorkflow();
  $workflow
    ->getTypePlugin()
    ->addEntityTypeAndBundle('node', 'page');
  $workflow
    ->save();
  $steps = [
    '1 second' => [
      'time_step' => 1,
      'expected_format' => '%d%d:%d%d:%d%d',
    ],
    '1 minute' => [
      'time_step' => 60,
      'expected_format' => '%d%d:%d%d',
    ],
    '5 minutes' => [
      'time_step' => 300,
      'expected_format' => '%d%d:%d%d',
    ],
    '10 minutes' => [
      'time_step' => 600,
      'expected_format' => '%d%d:%d%d',
    ],
    '15 minutes' => [
      'time_step' => 900,
      'expected_format' => '%d%d:%d%d',
    ],
    '30 minutes' => [
      'time_step' => 1800,
      'expected_format' => '%d%d:%d%d',
    ],
    '1 hour' => [
      'time_step' => 3600,
      'expected_format' => '%d%d:00',
    ],
  ];
  $this
    ->drupalLogin($this
    ->createUser([], NULL, TRUE));
  foreach ($steps as $step) {
    $this
      ->drupalGet('/admin/config');
    $page
      ->clickLink('Scheduler');
    $page
      ->selectFieldOption('time_step', $step['time_step']);
    $page
      ->pressButton('Save configuration');
    $this
      ->drupalGet('/node/add/page');
    $link = $assert_session
      ->waitForLink('Schedule a status change');
    $this
      ->assertNotEmpty($link);
    $link
      ->click();
    $field = $assert_session
      ->fieldExists('Scheduled transition time');
    $this
      ->assertEquals($step['time_step'], $field
      ->getAttribute('step'));
    $this
      ->assertStringMatchesFormat($step['expected_format'], $field
      ->getValue());
  }
}