Commit e3b019f4 authored by webchick's avatar webchick

#299186 by boombatower: Fix assertFieldByXPath so that it recognizes select and textarea values.

parent 7f9344c4
......@@ -1445,7 +1445,25 @@ function assertFieldByXPath($xpath, $value, $message, $group = 'Other') {
$found = FALSE;
if ($fields) {
foreach ($fields as $field) {
if ($field['value'] == $value) {
if (isset($field['value']) && $field['value'] == $value) {
// Input element with correct value.
$found = TRUE;
}
else if (isset($field->option)) {
// Select element found.
if ($this->getSelectedItem($field) == $value) {
$found = TRUE;
}
else {
// No item selected so use first item.
$items = $this->getAllOptions($field);
if (!empty($items) && $items[0]['value'] == $value) {
$found = TRUE;
}
}
}
else if (isset($field[0]) && $field[0] == $value) {
// Text area with correct text.
$found = TRUE;
}
}
......@@ -1454,6 +1472,28 @@ function assertFieldByXPath($xpath, $value, $message, $group = 'Other') {
return $this->assertTrue($fields && $found, $message, $group);
}
/**
* Get the selected value from a select field.
*
* @param $element
* SimpleXMLElement select element.
* @return
* The selected value or FALSE.
*/
function getSelectedItem(SimpleXMLElement $element) {
foreach ($element->children() as $item) {
if (isset($item['selected'])) {
return $item['value'];
}
else if ($item->getName() == 'optgroup') {
if ($value = $this->getSelectedItem($item)) {
return $value;
}
}
}
return FALSE;
}
/**
* Assert that a field does not exist in the current page by the given XPath.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment