function WorkflowTest::testDeleteState

Same name in other branches
  1. 9 core/modules/workflows/tests/src/Unit/WorkflowTest.php \Drupal\Tests\workflows\Unit\WorkflowTest::testDeleteState()
  2. 8.9.x core/modules/workflows/tests/src/Unit/WorkflowTest.php \Drupal\Tests\workflows\Unit\WorkflowTest::testDeleteState()
  3. 11.x 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 250

Class

WorkflowTest
@coversDefaultClass \Drupal\workflows\Plugin\WorkflowTypeBase

Namespace

Drupal\Tests\workflows\Unit

Code

public function testDeleteState() : void {
    $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());
}

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