You are here

public function ScheduledTransitionTest::testSingleTransition in Lightning Workflow 8.2

Same name and namespace in other branches
  1. 8.3 modules/lightning_scheduler/tests/src/Functional/ScheduledTransitionTest.php \Drupal\Tests\lightning_scheduler\Functional\ScheduledTransitionTest::testSingleTransition()

Tests a single scheduled workflow state transition.

@dataProvider providerSingleTransition

Parameters

int $offset: How many seconds in the past or future to schedule the transition. If negative, the transition will be in the past.

string $to_state: The workflow state to transition to.

string $expected_state_label: The label of the workflow state that is expected after the transition is executed.

File

modules/lightning_scheduler/tests/src/Functional/ScheduledTransitionTest.php, line 115

Class

ScheduledTransitionTest
@group lightning @group lightning_workflow @group lightning_scheduler

Namespace

Drupal\Tests\lightning_scheduler\Functional

Code

public function testSingleTransition($offset, $to_state, $expected_state_label) {
  $assert = $this
    ->assertSession();
  $this
    ->drupalGet('/node/add/page');
  $assert
    ->statusCodeEquals(200);
  $transitions = Json::encode([
    [
      'when' => date('c', time() + $offset),
      'state' => $to_state,
    ],
  ]);
  $assert
    ->fieldExists('Title')
    ->setValue('Schedule This');
  $field = $assert
    ->elementExists('css', 'input[name="moderation_state[0][scheduled_transitions][data]"]');
  $field
    ->setValue($transitions);
  $assert
    ->buttonExists('Save')
    ->press();
  $assert
    ->addressMatches('/^\\/node\\/[0-9]+$/');
  $edit_url = $this
    ->getUrl() . '/edit';
  if ($offset > 0) {
    sleep($offset + 2);
  }
  $this
    ->cronRun();
  $this
    ->drupalGet($edit_url);
  $assert
    ->statusCodeEquals(200);
  $assert
    ->pageTextContains("Current state {$expected_state_label}");
}