Commit 160b4281 authored by Dries's avatar Dries

- Patch #335035 by boombatower, Damien Tournoud, ksenzee, Berdir, Dave Reid,...

- Patch #335035 by boombatower, Damien Tournoud, ksenzee, Berdir, Dave Reid, effulgentsia: Simpletest drupalPost() incorrectly submits input for disabled elements, causing unreliable testing of forms that contain them.
parent d8e62ff2
......@@ -1658,7 +1658,10 @@ function form_type_checkboxes_value($element, $input = FALSE) {
}
return $value;
}
elseif (!isset($input)) {
// If the checkboxes are enabled, and NULL input is submitted, it means
// they're intentionally unchecked, so we need to return an empty array to
// prevent the default value from being used.
elseif (!isset($input) && empty($element['#disabled'])) {
return array();
}
}
......@@ -1698,7 +1701,15 @@ function form_type_password_confirm_value($element, $input = FALSE) {
function form_type_select_value($element, $input = FALSE) {
if ($input !== FALSE) {
if (isset($element['#multiple']) && $element['#multiple']) {
return (is_array($input)) ? drupal_map_assoc($input) : array();
// If an enabled multi-select submits NULL, it means all items are
// unselected. A disabled multi-select always submits NULL, and the
// default value should be used.
if (empty($element['#disabled'])) {
return (is_array($input)) ? drupal_map_assoc($input) : array();
}
else {
return (isset($element['#default_value']) && is_array($element['#default_value'])) ? $element['#default_value'] : array();
}
}
else {
return $input;
......@@ -1719,7 +1730,7 @@ function form_type_select_value($element, $input = FALSE) {
* for this element. Return nothing to use the default.
*/
function form_type_textfield_value($element, $input = FALSE) {
if ($input !== FALSE) {
if ($input !== FALSE && $input !== NULL) {
// Equate $input to the form value to ensure it's marked for
// validation.
return str_replace(array("\r", "\n"), '', $input);
......@@ -2206,6 +2217,7 @@ function form_process_radios($element) {
'#parents' => $element['#parents'],
'#id' => drupal_html_id('edit-' . implode('-', $parents_for_id)),
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
'#disabled' => isset($element['#disabled']) ? $element['#disabled'] : NULL,
);
}
}
......@@ -2308,6 +2320,7 @@ function form_process_checkboxes($element) {
'#default_value' => isset($value[$key]) ? $key : NULL,
'#attributes' => $element['#attributes'],
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
'#disabled' => isset($element['#disabled']) ? $element['#disabled'] : NULL,
);
}
}
......@@ -2459,6 +2472,7 @@ function form_process_tableselect($element) {
'#default_value' => isset($value[$key]) ? $key : NULL,
'#attributes' => $element['#attributes'],
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
'#disabled' => isset($element['#disabled']) ? $element['#disabled'] : NULL,
);
}
else {
......@@ -2474,6 +2488,7 @@ function form_process_tableselect($element) {
'#parents' => $element['#parents'],
'#id' => drupal_html_id('edit-' . implode('-', $parents_for_id)),
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
'#disabled' => isset($element['#disabled']) ? $element['#disabled'] : NULL,
);
}
}
......
......@@ -1747,7 +1747,7 @@ protected function drupalHead($path, array $options = array(), array $headers =
*/
protected function handleForm(&$post, &$edit, &$upload, $submit, $form) {
// Retrieve the form elements.
$elements = $form->xpath('.//input|.//textarea|.//select');
$elements = $form->xpath('.//input[not(@disabled)]|.//textarea[not(@disabled)]|.//select[not(@disabled)]');
$submit_matches = FALSE;
foreach ($elements as $element) {
// SimpleXML objects need string casting all the time.
......
......@@ -172,7 +172,7 @@ class FormsTestCase extends DrupalWebTestCase {
// Checkboxes values are not filtered out.
$returned_values[$key] = array_filter($returned_values[$key]);
}
$this->assertEqual($expected_value, $returned_values[$key], t('Default value for %type: expected %expected, returned %returned.', array('%type' => $key, '%expected' => var_export($expected_value, TRUE), '%returned' => var_export($returned_values[$key], TRUE))));
$this->assertIdentical($expected_value, $returned_values[$key], t('Default value for %type: expected %expected, returned %returned.', array('%type' => $key, '%expected' => var_export($expected_value, TRUE), '%returned' => var_export($returned_values[$key], TRUE))));
}
}
}
......
......@@ -110,11 +110,14 @@ class TranslationTestCase extends DrupalWebTestCase {
$this->assertRaw(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => $languages[$language_code]->name, '@locale-help' => url('admin/help/locale'))), t('Language has been created.'));
}
}
elseif ($this->xpath('//input[@type=\'checkbox\' and @name=\'enabled[' . $language_code . ']\' and @checked=\'checked\']')) {
// It's installed and enabled. No need to do anything.
$this->assertTrue(true, 'Language [' . $language_code . '] already installed and enabled.');
}
else {
// Ensure that it is enabled.
// It's installed but not enabled. Enable it.
$this->assertTrue(true, 'Language [' . $language_code . '] already installed.');
$this->drupalPost(NULL, array('enabled[' . $language_code . ']' => TRUE), t('Save configuration'));
$this->assertRaw(t('Configuration saved.'), t('Language successfully enabled.'));
}
}
......
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