summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-07-31 04:01:51 +0000
committerDries Buytaert <dries@buytaert.net>2010-07-31 04:01:51 +0000
commit699afdd1be4b8034c36474c7191972604bf5f54e (patch)
tree45bccf4fee92adc12e1e78ba2b30f9f5cdc3cf1d /modules
parent137011df918d911c9811b8d503ca5af037284c4c (diff)
downloadbrdo-699afdd1be4b8034c36474c7191972604bf5f54e.tar.gz
brdo-699afdd1be4b8034c36474c7191972604bf5f54e.tar.bz2
- Patch #690980 by seutje, sun, seanyo, aaroncouch: disabled form elements not properly rendered.
Diffstat (limited to 'modules')
-rw-r--r--modules/profile/profile.test2
-rw-r--r--modules/simpletest/tests/form.test68
-rw-r--r--modules/simpletest/tests/form_test.module58
3 files changed, 125 insertions, 3 deletions
diff --git a/modules/profile/profile.test b/modules/profile/profile.test
index 7216a522f..27b32d3db 100644
--- a/modules/profile/profile.test
+++ b/modules/profile/profile.test
@@ -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.
diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test
index 2e1564a6e..525a8a291 100644
--- a/modules/simpletest/tests/form.test
+++ b/modules/simpletest/tests/form.test
@@ -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.
@@ -226,6 +231,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.
*
* @see _form_test_input_forgery()
diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module
index 2fb4937de..ab0642fee 100644
--- a/modules/simpletest/tests/form_test.module
+++ b/modules/simpletest/tests/form_test.module
@@ -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'),