You are here

protected function FormTest::validateSelectSorting in Drupal 9

Same name and namespace in other branches
  1. 8 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 593

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
    ->assertSame($order, $options);
}