function WorkflowTest::testNumericIdSorting

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

Test numeric IDs when added to a workflow.

File

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

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 testNumericIdSorting() {
    $workflow = new Workflow([
        'id' => 'test',
        'type' => 'test_type',
    ], 'workflow');
    $workflow_type = $workflow->getTypePlugin();
    $workflow_type->addState('1', 'One');
    $workflow_type->addState('2', 'Two');
    $workflow_type->addState('3', 'ZZZ');
    $workflow_type->addState('4', 'AAA');
    $workflow_type->setStateWeight('1', 1);
    $workflow_type->setStateWeight('2', 2);
    $workflow_type->setStateWeight('3', 3);
    $workflow_type->setStateWeight('4', 3);
    // Ensure numeric states are correctly sorted by weight first, label second.
    $this->assertEquals([
        1,
        2,
        4,
        3,
    ], array_keys($workflow_type->getStates()));
}

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