You are here

public function WorkflowTest::testGetTransitionsForState in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/workflows/tests/src/Unit/WorkflowTest.php \Drupal\Tests\workflows\Unit\WorkflowTest::testGetTransitionsForState()

@covers ::getTransitionsForState

File

core/modules/workflows/tests/src/Unit/WorkflowTest.php, line 471

Class

WorkflowTest
@coversDefaultClass \Drupal\workflows\Plugin\WorkflowTypeBase

Namespace

Drupal\Tests\workflows\Unit

Code

public function testGetTransitionsForState() {
  $workflow = new Workflow([
    'id' => 'test',
    'type' => 'test_type',
  ], 'workflow');

  // By default states are ordered in the order added.
  $workflow
    ->getTypePlugin()
    ->addState('draft', 'Draft')
    ->addState('published', 'Published')
    ->addState('archived', 'Archived')
    ->addTransition('create_new_draft', 'Create new draft', [
    'archived',
    'draft',
  ], 'draft')
    ->addTransition('publish', 'Publish', [
    'draft',
    'published',
  ], 'published')
    ->addTransition('archive', 'Archive', [
    'published',
  ], 'archived');
  $this
    ->assertEquals([
    'create_new_draft',
    'publish',
  ], array_keys($workflow
    ->getTypePlugin()
    ->getTransitionsForState('draft')));
  $this
    ->assertEquals([
    'create_new_draft',
  ], array_keys($workflow
    ->getTypePlugin()
    ->getTransitionsForState('draft', 'to')));
  $this
    ->assertEquals([
    'publish',
    'archive',
  ], array_keys($workflow
    ->getTypePlugin()
    ->getTransitionsForState('published')));
  $this
    ->assertEquals([
    'publish',
  ], array_keys($workflow
    ->getTypePlugin()
    ->getTransitionsForState('published', 'to')));
  $this
    ->assertEquals([
    'create_new_draft',
  ], array_keys($workflow
    ->getTypePlugin()
    ->getTransitionsForState('archived', 'from')));
  $this
    ->assertEquals([
    'archive',
  ], array_keys($workflow
    ->getTypePlugin()
    ->getTransitionsForState('archived', 'to')));
}