function WorkflowUiTest::testSorting

Same name and namespace in other branches
  1. 9 core/modules/workflows/tests/src/Functional/WorkflowUiTest.php \Drupal\Tests\workflows\Functional\WorkflowUiTest::testSorting()
  2. 8.9.x core/modules/workflows/tests/src/Functional/WorkflowUiTest.php \Drupal\Tests\workflows\Functional\WorkflowUiTest::testSorting()
  3. 10 core/modules/workflows/tests/src/Functional/WorkflowUiTest.php \Drupal\Tests\workflows\Functional\WorkflowUiTest::testSorting()

Tests the sorting of states and transitions by weight and label.

File

core/modules/workflows/tests/src/Functional/WorkflowUiTest.php, line 346

Class

WorkflowUiTest
Tests workflow creation UI.

Namespace

Drupal\Tests\workflows\Functional

Code

public function testSorting() : void {
    $workflow = Workflow::create([
        'id' => 'test',
        'type' => 'workflow_type_complex_test',
        'label' => 'Test',
    ]);
    $workflow->getTypePlugin()
        ->setConfiguration([
        'states' => [
            'two_a' => [
                'label' => 'two a',
                'weight' => 2,
            ],
            'three' => [
                'label' => 'three',
                'weight' => 3,
            ],
            'two_b' => [
                'label' => 'two b',
                'weight' => 2,
            ],
            'one' => [
                'label' => 'one',
                'weight' => 1,
            ],
        ],
        'transitions' => [
            'three' => [
                'label' => 'three',
                'from' => [
                    'three',
                ],
                'to' => 'three',
                'weight' => 3,
            ],
            'two_a' => [
                'label' => 'two a',
                'from' => [
                    'two_a',
                ],
                'to' => 'two_a',
                'weight' => 2,
            ],
            'one' => [
                'label' => 'one',
                'from' => [
                    'one',
                ],
                'to' => 'one',
                'weight' => 1,
            ],
            'two_b' => [
                'label' => 'two b',
                'from' => [
                    'two_b',
                ],
                'to' => 'two_b',
                'weight' => 2,
            ],
        ],
    ]);
    $workflow->save();
    $this->drupalLogin($this->createUser([
        'administer workflows',
    ]));
    $this->drupalGet('admin/config/workflow/workflows/manage/test');
    $expected_states = [
        'one',
        'two a',
        'two b',
        'three',
    ];
    $elements = $this->xpath('//details[@id="edit-states-container"]//table/tbody/tr');
    foreach ($elements as $key => $element) {
        $this->assertEquals($expected_states[$key], $element->find('xpath', 'td')
            ->getText());
    }
    $expected_transitions = [
        'one',
        'two a',
        'two b',
        'three',
    ];
    $elements = $this->xpath('//details[@id="edit-transitions-container"]//table/tbody/tr');
    foreach ($elements as $key => $element) {
        $this->assertEquals($expected_transitions[$key], $element->find('xpath', 'td')
            ->getText());
    }
    // Ensure that there are enough weights to satisfy the potential number of
    // states and transitions.
    $this->assertSession()
        ->selectExists('states[three][weight]')
        ->selectOption('2');
    $this->assertSession()
        ->selectExists('states[three][weight]')
        ->selectOption('-2');
    $this->assertSession()
        ->selectExists('transitions[three][weight]')
        ->selectOption('2');
    $this->assertSession()
        ->selectExists('transitions[three][weight]')
        ->selectOption('-2');
}

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