function StateTest::testGetTransitions

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

@covers ::getTransitions

File

core/modules/workflows/tests/src/Unit/StateTest.php, line 81

Class

StateTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21workflows%21src%21State.php/class/State/8.9.x" title="A value object representing a workflow state." class="local">\Drupal\workflows\State</a>

Namespace

Drupal\Tests\workflows\Unit

Code

public function testGetTransitions() {
    $workflow_type = new TestType([], '', []);
    $workflow_type->addState('draft', 'Draft')
        ->addState('published', 'Published')
        ->addState('archived', 'Archived')
        ->addTransition('create_new_draft', 'Create new draft', [
        'draft',
    ], 'draft')
        ->addTransition('publish', 'Publish', [
        'draft',
    ], 'published')
        ->addTransition('archive', 'Archive', [
        'published',
    ], 'archived');
    $state = $workflow_type->getState('draft');
    $transitions = $state->getTransitions();
    $this->assertCount(2, $transitions);
    $this->assertEquals('Create new draft', $transitions['create_new_draft']->label());
    $this->assertEquals('Publish', $transitions['publish']->label());
}

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