You are here

protected function AssertContentTrait::getSelectedItem in Drupal 8

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

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 1023

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