Commit 699afdd1 authored by Dries's avatar Dries

- Patch #690980 by seutje, sun, seanyo, aaroncouch: disabled form elements not properly rendered.

parent 137011df
This diff is collapsed.
......@@ -335,7 +335,7 @@ class ProfileTestAutocomplete extends ProfileTestCase {
$this->setProfileField($field, $field['value']);
// Set some html for what we want to see in the page output later.
$autocomplete_html = '<input class="autocomplete" type="hidden" id="' . drupal_html_id('edit-' . $field['form_name'] . '-autocomplete') . '" value="' . url('profile/autocomplete/' . $field['fid'], array('absolute' => TRUE)) . '" disabled="disabled" />';
$autocomplete_html = '<input type="hidden" id="' . drupal_html_id('edit-' . $field['form_name'] . '-autocomplete') . '" value="' . url('profile/autocomplete/' . $field['fid'], array('absolute' => TRUE)) . '" disabled="disabled" class="autocomplete" />';
$field_html = '<input type="text" maxlength="255" name="' . $field['form_name'] . '" id="' . drupal_html_id('edit-' . $field['form_name']) . '" size="60" value="' . $field['value'] . '" class="form-text form-autocomplete required" />';
// Check that autocompletion html is found on the user's profile edit page.
......
......@@ -193,7 +193,7 @@ class FormsTestCase extends DrupalWebTestCase {
// All the elements should be marked as disabled, including the ones below
// the disabled container.
$this->assertEqual(count($disabled_elements), 20, t('The correct elements have the disabled property in the HTML code.'));
$this->assertEqual(count($disabled_elements), 32, t('The correct elements have the disabled property in the HTML code.'));
$this->drupalPost(NULL, $edit, t('Submit'));
$returned_values['hijacked'] = drupal_json_decode($this->content);
......@@ -211,7 +211,12 @@ class FormsTestCase extends DrupalWebTestCase {
function assertFormValuesDefault($values, $form) {
foreach (element_children($form) as $key) {
if (isset($form[$key]['#default_value'])) {
$expected_value = $form[$key]['#default_value'];
if (isset($form[$key]['#expected_value'])) {
$expected_value = $form[$key]['#expected_value'];
}
else {
$expected_value = $form[$key]['#default_value'];
}
if ($key == 'checkboxes_multiple') {
// Checkboxes values are not filtered out.
......@@ -225,6 +230,65 @@ class FormsTestCase extends DrupalWebTestCase {
}
}
/**
* Verify markup for disabled form elements.
*
* @see _form_test_disabled_elements()
*/
function testDisabledMarkup() {
$this->drupalGet('form-test/disabled-elements');
$form_state = array();
$form = _form_test_disabled_elements(array(), $form_state);
$type_map = array(
'textarea' => 'textarea',
'select' => 'select',
'weight' => 'select',
'date' => 'select',
);
foreach ($form as $name => $item) {
// Skip special #types.
if (!isset($item['#type']) || in_array($item['#type'], array('hidden', 'text_format'))) {
continue;
}
// Setup XPath and CSS class depending on #type.
if (in_array($item['#type'], array('image_button', 'button', 'submit'))) {
$path = "//!type[contains(@class, :div-class) and @value=:value]";
$class = 'form-button-disabled';
}
else {
// starts-with() required for checkboxes.
$path = "//div[contains(@class, :div-class)]/descendant::!type[starts-with(@name, :name)]";
$class = 'form-disabled';
}
// Replace DOM element name in $path according to #type.
$type = 'input';
if (isset($type_map[$item['#type']])) {
$type = $type_map[$item['#type']];
}
$path = strtr($path, array('!type' => $type));
// Verify that the element exists.
$element = $this->xpath($path, array(
':name' => check_plain($name),
':div-class' => $class,
':value' => isset($item['#value']) ? $item['#value'] : '',
));
$this->assertTrue(isset($element[0]), t('Disabled form element class found for #type %type.', array('%type' => $item['#type'])));
}
// Verify special element #type text-format.
$element = $this->xpath('//div[contains(@class, :div-class)]/descendant::textarea[@name=:name]', array(
':name' => 'text_format[value]',
':div-class' => 'form-disabled',
));
$this->assertTrue(isset($element[0]), t('Disabled form element class found for #type %type.', array('%type' => 'text_format[value]')));
$element = $this->xpath('//div[contains(@class, :div-class)]/descendant::select[@name=:name]', array(
':name' => 'text_format[format]',
':div-class' => 'form-disabled',
));
$this->assertTrue(isset($element[0]), t('Disabled form element class found for #type %type.', array('%type' => 'text_format[format]')));
}
/**
* Test Form API protections against input forgery.
*
......
......@@ -882,6 +882,64 @@ function _form_test_disabled_elements($form, &$form_state) {
);
}
// Text format.
$form['text_format'] = array(
'#type' => 'text_format',
'#title' => 'Text format',
'#disabled' => TRUE,
'#default_value' => 'Text value',
'#format' => 1,
'#expected_value' => array(
'value' => 'Text value',
'format' => 1,
),
'#test_hijack_value' => array(
'value' => 'HIJACK',
'format' => 2,
),
);
// Password fields.
$form['password'] = array(
'#type' => 'password',
'#title' => 'Password',
'#disabled' => TRUE,
);
$form['password_confirm'] = array(
'#type' => 'password_confirm',
'#title' => 'Password confirm',
'#disabled' => TRUE,
);
// Files.
$form['file'] = array(
'#type' => 'file',
'#title' => 'File',
'#disabled' => TRUE,
);
$form['managed_file'] = array(
'#type' => 'managed_file',
'#title' => 'Managed file',
'#disabled' => TRUE,
);
// Buttons.
$form['image_button'] = array(
'#type' => 'image_button',
'#value' => 'Image button',
'#disabled' => TRUE,
);
$form['button'] = array(
'#type' => 'button',
'#value' => 'Button',
'#disabled' => TRUE,
);
$form['submit_disabled'] = array(
'#type' => 'submit',
'#value' => 'Submit',
'#disabled' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
......
......@@ -627,6 +627,13 @@ div.teaser-checkbox .form-item,
.form-item label.option input {
vertical-align: middle;
}
.form-disabled input.form-autocomplete,
.form-disabled input.form-text,
.form-disabled textarea.form-textarea,
.form-disabled select.form-select {
background-color: #eee;
color: #777;
}
/* Filter */
.filter-wrapper {
......@@ -699,6 +706,13 @@ input.form-submit:active {
border-color: #555;
text-shadow: #222 0px -1px 0px;
}
input.form-button-disabled,
input.form-button-disabled:active {
background: #eee none;
border-color: #eee;
text-shadow: none;
color: #999;
}
form input#edit-delete {
background: #eee;
border-color: #fff #ddd #ccc;
......
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