function AssertContentTrait::getSelectedItem
Same name in other branches
- 9 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::getSelectedItem()
- 8.9.x core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::getSelectedItem()
- 11.x 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 863
Class
- AssertContentTrait
- Provides test methods to assert content.
Namespace
Drupal\KernelTestsCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.