function WorkflowTest::testAddTransition

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

@covers ::addTransition @covers ::hasTransition

File

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

Class

WorkflowTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21workflows%21src%21Plugin%21WorkflowTypeBase.php/class/WorkflowTypeBase/8.9.x" title="A base class for Workflow type plugins." class="local">\Drupal\workflows\Plugin\WorkflowTypeBase</a>

Namespace

Drupal\Tests\workflows\Unit

Code

public function testAddTransition() {
    $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');
    $this->assertFalse($workflow->getTypePlugin()
        ->getState('draft')
        ->canTransitionTo('published'));
    $workflow->getTypePlugin()
        ->addTransition('publish', 'Publish', [
        'draft',
    ], 'published');
    $this->assertTrue($workflow->getTypePlugin()
        ->getState('draft')
        ->canTransitionTo('published'));
    $this->assertEquals(0, $workflow->getTypePlugin()
        ->getTransition('publish')
        ->weight());
    $this->assertTrue($workflow->getTypePlugin()
        ->hasTransition('publish'));
    $this->assertFalse($workflow->getTypePlugin()
        ->hasTransition('draft'));
    $workflow->getTypePlugin()
        ->addTransition('save_publish', 'Save', [
        'published',
    ], 'published');
    $this->assertEquals(1, $workflow->getTypePlugin()
        ->getTransition('save_publish')
        ->weight());
}

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