function StateTest::testCanTransitionTo

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

@covers ::canTransitionTo

File

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

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 testCanTransitionTo() {
    $workflow_type = new TestType([], '', []);
    $workflow_type->addState('draft', 'Draft')
        ->addState('published', 'Published')
        ->addTransition('publish', 'Publish', [
        'draft',
    ], 'published');
    $state = $workflow_type->getState('draft');
    $this->assertTrue($state->canTransitionTo('published'));
    $this->assertFalse($state->canTransitionTo('some_other_state'));
    $workflow_type->deleteTransition('publish');
    $this->assertFalse($state->canTransitionTo('published'));
}

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