diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2008-09-17 00:46:44 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2008-09-17 00:46:44 +0000 |
commit | e3b019f4809f5940446e4eb1a113f9dc0531884e (patch) | |
tree | 224856d06ab27deaa4cd76c8ddc1723f1e44f5ec /modules/simpletest/drupal_web_test_case.php | |
parent | 7f9344c4632957d8ea89797eb5ace3bac20c7cd7 (diff) | |
download | brdo-e3b019f4809f5940446e4eb1a113f9dc0531884e.tar.gz brdo-e3b019f4809f5940446e4eb1a113f9dc0531884e.tar.bz2 |
#299186 by boombatower: Fix assertFieldByXPath so that it recognizes select and textarea values.
Diffstat (limited to 'modules/simpletest/drupal_web_test_case.php')
-rw-r--r-- | modules/simpletest/drupal_web_test_case.php | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 20d708174..08927d7a7 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -1445,7 +1445,25 @@ class DrupalWebTestCase { $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; } } @@ -1455,6 +1473,28 @@ class DrupalWebTestCase { } /** + * 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. * * @param $xpath |