You are here

public function WorkflowTest::testNumericIdSorting in Drupal 8

Same name and namespace in other branches
  1. 9 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 \Drupal\workflows\Plugin\WorkflowTypeBase

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()));
}