You are here

TimeStepTest.php in Lightning Scheduler 8

File

tests/src/FunctionalJavascript/TimeStepTest.php
View source
<?php

namespace Drupal\Tests\lightning_scheduler\FunctionalJavascript;

use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\Tests\lightning_scheduler\Traits\SchedulerUiTrait;

/**
 * @group lightning_scheduler
 */
class TimeStepTest extends WebDriverTestBase {
  use SchedulerUiTrait;

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'lightning_scheduler',
    'node',
  ];

  /**
   * Tests the time steps.
   */
  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());
    }
  }

}

Classes

Namesort descending Description
TimeStepTest @group lightning_scheduler