You are here

public function WorkflowTransitionEventTest::testTransitionEventTwoTransitions in State Machine 8

Tests the transition event with two identical to and from states.

File

tests/src/Kernel/WorkflowTransitionEventTest.php, line 110

Class

WorkflowTransitionEventTest
Tests the TransitionEvent.

Namespace

Drupal\Tests\state_machine\Kernel

Code

public function testTransitionEventTwoTransitions() {
  $entity = EntityTestWithBundle::create([
    'type' => 'third',
    'name' => 'Test entity',
    'field_state' => 'new',
  ]);
  $entity
    ->save();

  // Test that applying the second transition also throws the second transition's event.
  $entity
    ->get('field_state')
    ->first()
    ->applyTransitionById('complete2');
  $entity
    ->save();
  $messages = \Drupal::messenger()
    ->all();
  $message = reset($messages);
  $this
    ->assertCount(4, $message);
  $this
    ->assertEquals('Test entity (field_state) - Completed at group pre-transition (workflow: two_transitions, transition: complete2).', (string) $message[0]);
  $this
    ->assertEquals('Test entity (field_state) - Completed at generic pre-transition (workflow: two_transitions, transition: complete2).', (string) $message[1]);
  $this
    ->assertEquals('Test entity (field_state) - Completed at group post-transition (workflow: two_transitions, transition: complete2).', (string) $message[2]);
  $this
    ->assertEquals('Test entity (field_state) - Completed at generic post-transition (workflow: two_transitions, transition: complete2).', (string) $message[3]);
}