You are here

protected function AssertContentTrait::getSelectedItem in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::getSelectedItem()
  2. 10 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.

1 call to AssertContentTrait::getSelectedItem()
AssertContentTrait::assertFieldsByValue in core/tests/Drupal/KernelTests/AssertContentTrait.php
Asserts that a field exists in the current page with a given Xpath result.

File

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

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;
}