You are here

public function WorkflowTest::testGetTransitions in State Machine 8

@covers ::getTransitions @covers ::getTransition

File

tests/src/Unit/Plugin/Workflow/WorkflowTest.php, line 75

Class

WorkflowTest
@coversDefaultClass \Drupal\state_machine\Plugin\Workflow\Workflow @group state_machine

Namespace

Drupal\Tests\state_machine\Unit\Plugin\Workflow

Code

public function testGetTransitions() {
  $guard_factory = $this
    ->prophesize(GuardFactoryInterface::class);
  $plugin_definition = [
    'states' => [
      'draft' => [
        'label' => 'Draft',
      ],
      'published' => [
        'label' => 'Published',
      ],
    ],
    'transitions' => [
      'publish' => [
        'label' => 'Publish',
        'from' => [
          'draft',
        ],
        'to' => 'published',
      ],
    ],
  ];
  $workflow = new Workflow([], 'test', $plugin_definition, $guard_factory
    ->reveal());
  $transition = $workflow
    ->getTransition('publish');
  $this
    ->assertEquals('publish', $transition
    ->getId());
  $this
    ->assertEquals('Publish', $transition
    ->getLabel());
  $this
    ->assertEquals([
    'draft' => $workflow
      ->getState('draft'),
  ], $transition
    ->getFromStates());
  $this
    ->assertEquals($workflow
    ->getState('published'), $transition
    ->getToState());
  $this
    ->assertEquals([
    'publish' => $transition,
  ], $workflow
    ->getTransitions());
}