function FormTest::validateSelectSorting

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::validateSelectSorting()
  2. 10 core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::validateSelectSorting()
  3. 11.x core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::validateSelectSorting()

Validates that the options are in the right order in a select.

Parameters

string $select: Name of the select to verify.

string[] $order: Expected order of its options.

1 call to FormTest::validateSelectSorting()
FormTest::testSelectSorting in core/modules/system/tests/src/Functional/Form/FormTest.php
Tests sorting and not sorting of options in a select element.

File

core/modules/system/tests/src/Functional/Form/FormTest.php, line 587

Class

FormTest
Tests various form element validation mechanisms.

Namespace

Drupal\Tests\system\Functional\Form

Code

protected function validateSelectSorting($select, array $order) {
    $option_map_function = function (NodeElement $node) {
        return $node->getTagName() === 'optgroup' ? $node->getAttribute('label') : $node->getValue();
    };
    $option_nodes = $this->getSession()
        ->getPage()
        ->findField($select)
        ->findAll('css', 'option, optgroup');
    $options = array_map($option_map_function, $option_nodes);
    $this->assertIdentical($order, $options);
}

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