function FormTest::validateSelectSorting
Same name in other branches
- 8.9.x core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::validateSelectSorting()
- 10 core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::validateSelectSorting()
- 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 596
Class
- FormTest
- Tests various form element validation mechanisms.
Namespace
Drupal\Tests\system\Functional\FormCode
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->assertSame($order, $options);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.