You are here

public function WorkflowTest::testAddAndHasState in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/workflows/tests/src/Unit/WorkflowTest.php \Drupal\Tests\workflows\Unit\WorkflowTest::testAddAndHasState()

@covers ::addState @covers ::hasState

File

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

Class

WorkflowTest
@coversDefaultClass \Drupal\workflows\Plugin\WorkflowTypeBase

Namespace

Drupal\Tests\workflows\Unit

Code

public function testAddAndHasState() {
  $workflow = new Workflow([
    'id' => 'test',
    'type' => 'test_type',
  ], 'workflow');
  $this
    ->assertFalse($workflow
    ->getTypePlugin()
    ->hasState('draft'));

  // By default states are ordered in the order added.
  $workflow
    ->getTypePlugin()
    ->addState('draft', 'Draft');
  $this
    ->assertTrue($workflow
    ->getTypePlugin()
    ->hasState('draft'));
  $this
    ->assertFalse($workflow
    ->getTypePlugin()
    ->hasState('published'));
  $this
    ->assertEquals(0, $workflow
    ->getTypePlugin()
    ->getState('draft')
    ->weight());

  // Adding a state does not set up a transition to itself.
  $this
    ->assertFalse($workflow
    ->getTypePlugin()
    ->hasTransitionFromStateToState('draft', 'draft'));

  // New states are added with a new weight 1 more than the current highest
  // weight.
  $workflow
    ->getTypePlugin()
    ->addState('published', 'Published');
  $this
    ->assertEquals(1, $workflow
    ->getTypePlugin()
    ->getState('published')
    ->weight());
}