You are here

protected function AssertContentTrait::getSelectedItem in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::getSelectedItem()
  2. 9 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::getSelectedItem()

Get the selected value from a select field.

Parameters

\SimpleXMLElement $element: SimpleXMLElement select element.

Return value

bool The selected value or FALSE.

File

core/tests/Drupal/KernelTests/AssertContentTrait.php, line 956

Class

AssertContentTrait
Provides test methods to assert content.

Namespace

Drupal\KernelTests

Code

protected function getSelectedItem(\SimpleXMLElement $element) {
  foreach ($element
    ->children() as $item) {
    if (isset($item['selected'])) {
      return $item['value'];
    }
    elseif ($item
      ->getName() == 'optgroup') {
      if ($value = $this
        ->getSelectedItem($item)) {
        return $value;
      }
    }
  }
  return FALSE;
}