function WorkflowTest::testGetTransitions
Same name in other branches
- 9 core/modules/workflows/tests/src/Unit/WorkflowTest.php \Drupal\Tests\workflows\Unit\WorkflowTest::testGetTransitions()
- 8.9.x core/modules/workflows/tests/src/Unit/WorkflowTest.php \Drupal\Tests\workflows\Unit\WorkflowTest::testGetTransitions()
- 10 core/modules/workflows/tests/src/Unit/WorkflowTest.php \Drupal\Tests\workflows\Unit\WorkflowTest::testGetTransitions()
@covers ::getTransitions @covers ::setTransitionWeight
File
-
core/
modules/ workflows/ tests/ src/ Unit/ WorkflowTest.php, line 395
Class
- WorkflowTest
- @coversDefaultClass \Drupal\workflows\Plugin\WorkflowTypeBase
Namespace
Drupal\Tests\workflows\UnitCode
public function testGetTransitions() : void {
$workflow = new Workflow([
'id' => 'test',
'type' => 'test_type',
], 'workflow');
// Getting transitions works when there are none.
$this->assertSame([], $workflow->getTypePlugin()
->getTransitions());
$this->assertSame([], $workflow->getTypePlugin()
->getTransitions([]));
// By default states are ordered in the order added.
$workflow->getTypePlugin()
->addState('a', 'A')
->addState('b', 'B')
->addTransition('a_b', 'A to B', [
'a',
], 'b')
->addTransition('a_a', 'A to A', [
'a',
], 'a');
// Transitions are stored in alphabetical key order in configuration.
$this->assertEquals([
'a_a',
'a_b',
], array_keys($workflow->getTypePlugin()
->getConfiguration()['transitions']));
// Ensure we're returning transition objects.
$this->assertInstanceOf(Transition::class, $workflow->getTypePlugin()
->getTransitions()['a_a']);
// Passing in no IDs returns all transitions.
$this->assertEquals([
'a_b',
'a_a',
], array_keys($workflow->getTypePlugin()
->getTransitions()));
// The order of states is by weight.
$workflow->getTypePlugin()
->setTransitionWeight('a_a', -1);
$this->assertEquals([
'a_a',
'a_b',
], array_keys($workflow->getTypePlugin()
->getTransitions()));
// If all weights are equal it will fallback to labels.
$workflow->getTypePlugin()
->setTransitionWeight('a_a', 0);
$this->assertEquals([
'a_a',
'a_b',
], array_keys($workflow->getTypePlugin()
->getTransitions()));
$workflow->getTypePlugin()
->setTransitionLabel('a_b', 'A B');
$this->assertEquals([
'a_b',
'a_a',
], array_keys($workflow->getTypePlugin()
->getTransitions()));
// You can limit the states returned by passing in states IDs.
$this->assertEquals([
'a_a',
], array_keys($workflow->getTypePlugin()
->getTransitions([
'a_a',
])));
// An empty array does not load all states.
$this->assertSame([], $workflow->getTypePlugin()
->getTransitions([]));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.