You are here

public function WorkflowTest::testGetPossibleTransitions in State Machine 8

@covers ::getPossibleTransitions

File

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

Class

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

Namespace

Drupal\Tests\state_machine\Unit\Plugin\Workflow

Code

public function testGetPossibleTransitions() {
  $guard_factory = $this
    ->prophesize(GuardFactoryInterface::class);
  $plugin_definition = [
    'states' => [
      'draft' => [
        'label' => 'Draft',
      ],
      'review' => [
        'label' => 'Review',
      ],
      'published' => [
        'label' => 'Published',
      ],
    ],
    'transitions' => [
      'send_to_review' => [
        'label' => 'Send to review',
        'from' => [
          'draft',
        ],
        'to' => 'review',
      ],
      'publish' => [
        'label' => 'Publish',
        'from' => [
          'review',
        ],
        'to' => 'published',
      ],
    ],
  ];
  $workflow = new Workflow([], 'test', $plugin_definition, $guard_factory
    ->reveal());
  $transition = $workflow
    ->getTransition('send_to_review');
  $this
    ->assertEquals([
    'send_to_review' => $transition,
  ], $workflow
    ->getPossibleTransitions('draft'));
  $transition = $workflow
    ->getTransition('publish');
  $this
    ->assertEquals([
    'publish' => $transition,
  ], $workflow
    ->getPossibleTransitions('review'));
  $this
    ->assertEquals([], $workflow
    ->getPossibleTransitions('published'));

  // Passing an empty state should return all transitions.
  $this
    ->assertEquals($workflow
    ->getTransitions(), $workflow
    ->getPossibleTransitions(''));
}