From 01d85a55710ddde81507e678cbf0a4fcc623f339 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Fri, 20 Nov 2009 05:14:13 +0000 Subject: #635202 by yched and sun: Remove #process pattern from option widgets (plus buckets of tests for option widgets). --- modules/simpletest/drupal_web_test_case.php | 73 ++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 12 deletions(-) (limited to 'modules/simpletest') 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; @@ -2506,6 +2521,40 @@ class DrupalWebTestCase extends DrupalTestCase { return $this->assertTrue(isset($elements[0]) && empty($elements[0]['checked']), $message ? $message : t('Checkbox field @id is not checked.', array('@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 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. * -- cgit v1.2.3