summaryrefslogtreecommitdiff
path: root/modules/simpletest
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2012-11-04 14:18:03 -0500
committerDavid Rothstein <drothstein@gmail.com>2012-11-04 14:18:03 -0500
commit577bfdc670c59e4f8e5ac3e2bdcf994e897f4f79 (patch)
treeaef186141e1696df4c62758d36dc0830de16e999 /modules/simpletest
parent8355498584c27d1855c2411a2d58dd4c13fb455b (diff)
downloadbrdo-577bfdc670c59e4f8e5ac3e2bdcf994e897f4f79.tar.gz
brdo-577bfdc670c59e4f8e5ac3e2bdcf994e897f4f79.tar.bz2
Issue #1414510 by andypost, Spleshka, perelman.yuval, tim.plunkett: Fixed Remove drupal_reset_static() for drupal_html_id() when form validation fails.
Diffstat (limited to 'modules/simpletest')
-rw-r--r--modules/simpletest/tests/form.test31
-rw-r--r--modules/simpletest/tests/form_test.module32
2 files changed, 63 insertions, 0 deletions
diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test
index 675e8d189..620621a69 100644
--- a/modules/simpletest/tests/form.test
+++ b/modules/simpletest/tests/form.test
@@ -1750,3 +1750,34 @@ class FormCheckboxTestCase extends DrupalWebTestCase {
}
}
}
+
+/**
+ * Tests uniqueness of generated HTML IDs.
+ */
+class HTMLIdTestCase extends DrupalWebTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Unique HTML IDs',
+ 'description' => 'Tests functionality of drupal_html_id().',
+ 'group' => 'Form API',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('form_test');
+ }
+
+ /**
+ * Tests that HTML IDs do not get duplicated when form validation fails.
+ */
+ function testHTMLId() {
+ $this->drupalGet('form-test/double-form');
+ $this->assertNoDuplicateIds('There are no duplicate IDs');
+
+ // Submit second form with empty title.
+ $edit = array();
+ $this->drupalPost(NULL, $edit, 'Save', array(), array(), 'form-test-html-id--2');
+ $this->assertNoDuplicateIds('There are no duplicate IDs');
+ }
+}
diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module
index 5d6527680..6af18c6af 100644
--- a/modules/simpletest/tests/form_test.module
+++ b/modules/simpletest/tests/form_test.module
@@ -194,6 +194,12 @@ function form_test_menu() {
'type' => MENU_CALLBACK,
);
}
+ $items['form-test/double-form'] = array(
+ 'title' => 'Double form test',
+ 'page callback' => 'form_test_double_form',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
$items['form-test/load-include-menu'] = array(
'title' => 'FAPI test loading includes',
@@ -1787,3 +1793,29 @@ function form_test_checkboxes_zero($form, &$form_state, $json = TRUE) {
function _form_test_checkboxes_zero_no_redirect($form, &$form_state) {
$form_state['redirect'] = FALSE;
}
+
+/**
+ * Menu callback returns two instances of the same form.
+ */
+function form_test_double_form() {
+ return array(
+ 'form1' => drupal_get_form('form_test_html_id'),
+ 'form2' => drupal_get_form('form_test_html_id'),
+ );
+}
+
+/**
+ * Builds a simple form to test duplicate HTML IDs.
+ */
+function form_test_html_id($form, &$form_state) {
+ $form['name'] = array(
+ '#type' => 'textfield',
+ '#title' => 'name',
+ '#required' => TRUE,
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => 'Save',
+ );
+ return $form;
+}