function WorkflowTest::testGetTransitionFromStateToState

Same name and namespace in other branches
  1. 9 core/modules/workflows/tests/src/Unit/WorkflowTest.php \Drupal\Tests\workflows\Unit\WorkflowTest::testGetTransitionFromStateToState()
  2. 8.9.x core/modules/workflows/tests/src/Unit/WorkflowTest.php \Drupal\Tests\workflows\Unit\WorkflowTest::testGetTransitionFromStateToState()
  3. 11.x core/modules/workflows/tests/src/Unit/WorkflowTest.php \Drupal\Tests\workflows\Unit\WorkflowTest::testGetTransitionFromStateToState()

@covers ::getTransitionFromStateToState
@covers ::hasTransitionFromStateToState

File

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

Class

WorkflowTest
@coversDefaultClass \Drupal\workflows\Plugin\WorkflowTypeBase[[api-linebreak]]

Namespace

Drupal\Tests\workflows\Unit

Code

public function testGetTransitionFromStateToState() : void {
  $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->assertTrue($workflow->getTypePlugin()
    ->hasTransitionFromStateToState('draft', 'published'));
  $this->assertFalse($workflow->getTypePlugin()
    ->hasTransitionFromStateToState('archived', 'archived'));
  $transition = $workflow->getTypePlugin()
    ->getTransitionFromStateToState('published', 'archived');
  $this->assertEquals('Archive', $transition->label());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.