diff options
Diffstat (limited to 'modules/simpletest/drupal_web_test_case.php')
-rw-r--r-- | modules/simpletest/drupal_web_test_case.php | 73 |
1 files changed, 61 insertions, 12 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index cb1deda30..c1642e5b6 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -1656,22 +1656,37 @@ class DrupalWebTestCase extends DrupalTestCase { break; case 'select': $new_value = $edit[$name]; - $index = 0; - $key = preg_replace('/\[\]$/', '', $name); $options = $this->getAllOptions($element); - foreach ($options as $option) { - if (is_array($new_value)) { - $option_value= (string)$option['value']; - if (in_array($option_value, $new_value)) { - $post[$key . '[' . $index++ . ']'] = $option_value; - $done = TRUE; - unset($edit[$name]); + if (is_array($new_value)) { + // Multiple select box. + if (!empty($new_value)) { + $index = 0; + $key = preg_replace('/\[\]$/', '', $name); + foreach ($options as $option) { + $option_value = (string)$option['value']; + if (in_array($option_value, $new_value)) { + $post[$key . '[' . $index++ . ']'] = $option_value; + $done = TRUE; + unset($edit[$name]); + } } } - elseif ($new_value == $option['value']) { - $post[$name] = $new_value; - unset($edit[$name]); + else { + // No options selected: do not include any POST data for the + // element. $done = TRUE; + unset($edit[$name]); + } + } + else { + // Single select box. + foreach ($options as $option) { + if ($new_value == $option['value']) { + $post[$name] = $new_value; + unset($edit[$name]); + $done = TRUE; + break; + } } } break; @@ -2507,6 +2522,40 @@ class DrupalWebTestCase extends DrupalTestCase { } /** + * Assert that a select option in the current page is not checked. + * + * @param $id + * Id of select field to assert. + * @param $option + * Option to assert. + * @param $message + * Message to display. + * @return + * TRUE on pass, FALSE on fail. + */ + protected function assertOptionSelected($id, $option, $message = '') { + $elements = $this->xpath('//select[@id="' . $id . '"]//option[@value="' . $option . '"]'); + return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['selected']), $message ? $message : t('Option @option for field @id is selected.', array('@option' => $option, '@id' => $id)), t('Browser')); + } + + /** + * Assert that a select option in the current page is not checked. + * + * @param $id + * Id of select field to assert. + * @param $option + * Option to assert. + * @param $message + * Message to display. + * @return + * TRUE on pass, FALSE on fail. + */ + protected function assertNoOptionSelected($id, $option, $message = '') { + $elements = $this->xpath('//select[@id="' . $id . '"]//option[@value="' . $option . '"]'); + return $this->assertTrue(isset($elements[0]) && empty($elements[0]['selected']), $message ? $message : t('Option @option for field @id is not selected.', array('@option' => $option, '@id' => $id)), t('Browser')); + } + + /** * Assert that a field exists with the given name or id. * * @param $field |