function WorkflowTest::testNumericIdSorting

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

Tests numeric IDs when added to a workflow.

File

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

Class

WorkflowTest
@coversDefaultClass \Drupal\workflows\Plugin\WorkflowTypeBase[[api-linebreak]]

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.