You are here

public function WorkflowTest::testDeleteState in Drupal 10

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

@covers ::deleteState

File

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

Class

WorkflowTest
@coversDefaultClass \Drupal\workflows\Plugin\WorkflowTypeBase

Namespace

Drupal\Tests\workflows\Unit

Code

public function testDeleteState() {
  $workflow_type = new TestType([], '', []);
  $workflow_type
    ->addState('draft', 'Draft')
    ->addState('published', 'Published')
    ->addState('archived', 'Archived')
    ->addTransition('publish', 'Publish', [
    'draft',
    'published',
  ], 'published')
    ->addTransition('create_new_draft', 'Create new draft', [
    'draft',
    'published',
  ], 'draft')
    ->addTransition('archive', 'Archive', [
    'draft',
    'published',
  ], 'archived');
  $this
    ->assertCount(3, $workflow_type
    ->getStates());
  $this
    ->assertCount(3, $workflow_type
    ->getState('published')
    ->getTransitions());
  $workflow_type
    ->deleteState('draft');
  $this
    ->assertFalse($workflow_type
    ->hasState('draft'));
  $this
    ->assertCount(2, $workflow_type
    ->getStates());
  $this
    ->assertCount(2, $workflow_type
    ->getState('published')
    ->getTransitions());
  $workflow_type
    ->deleteState('published');
  $this
    ->assertCount(0, $workflow_type
    ->getTransitions());
}