summaryrefslogtreecommitdiff
path: root/modules/simpletest
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest')
-rw-r--r--modules/simpletest/tests/form.test21
-rw-r--r--modules/simpletest/tests/form_test.module46
2 files changed, 65 insertions, 2 deletions
diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test
index ba6a5d622..108391777 100644
--- a/modules/simpletest/tests/form.test
+++ b/modules/simpletest/tests/form.test
@@ -231,6 +231,27 @@ class FormValidationTestCase extends DrupalWebTestCase {
$this->assertNoFieldByName('name', t('Form element was hidden.'));
$this->assertText('Name value: element_validate_access', t('Value for inaccessible form element exists.'));
}
+
+ /**
+ * Tests partial form validation through #limit_validation_errors.
+ */
+ function testValidateLimitErrors() {
+ $edit = array('test' => 'invalid');
+ $path = 'form-test/limit-validation-errors';
+
+ // Submit the form by pressing the button with #limit_validation_errors and
+ // ensure that the title field is not validated, but the #element_validate
+ // handler for the 'test' field is triggered.
+ $this->drupalPost($path, $edit, t('Partial validate'));
+ $this->assertNoText(t('!name field is required.', array('!name' => 'Title')));
+ $this->assertText('Test element is invalid');
+
+ // Now test full form validation and ensure that the #element_validate
+ // handler is still triggered.
+ $this->drupalPost($path, $edit, t('Full validate'));
+ $this->assertText(t('!name field is required.', array('!name' => 'Title')));
+ $this->assertText('Test element is invalid');
+ }
}
/**
diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module
index 2036204ba..c8f565938 100644
--- a/modules/simpletest/tests/form_test.module
+++ b/modules/simpletest/tests/form_test.module
@@ -17,6 +17,13 @@ function form_test_menu() {
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
+ $items['form-test/limit-validation-errors'] = array(
+ 'title' => 'Form validation with some error suppression',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('form_test_limit_validation_errors_form'),
+ 'access arguments' => array('access content'),
+ 'type' => MENU_CALLBACK,
+ );
$items['form_test/tableselect/multiple-true'] = array(
'title' => 'Tableselect checkboxes test',
@@ -204,6 +211,41 @@ function form_test_validate_form_validate(&$form, &$form_state) {
}
/**
+ * Builds a simple form with a button triggering partial validation.
+ */
+function form_test_limit_validation_errors_form($form, &$form_state) {
+ $form['title'] = array(
+ '#type' => 'textfield',
+ '#title' => 'Title',
+ '#required' => TRUE,
+ );
+ $form['test'] = array(
+ '#type' => 'textfield',
+ '#element_validate' => array('form_test_limit_validation_errors_element_validate_test'),
+ );
+ $form['actions']['partial'] = array(
+ '#type' => 'submit',
+ '#limit_validation_errors' => array(array('test')),
+ '#submit' => array(),
+ '#value' => t('Partial validate'),
+ );
+ $form['actions']['full'] = array(
+ '#type' => 'submit',
+ '#value' => t('Full validate'),
+ );
+ return $form;
+}
+
+/**
+ * Form element validation handler for the 'test' element.
+ */
+function form_test_limit_validation_errors_element_validate_test(&$element, &$form_state) {
+ if ($element['#value'] == 'invalid') {
+ form_error($element, 'Test element is invalid');
+ }
+}
+
+/**
* Create a header and options array. Helper function for callbacks.
*/
function _form_test_tableselect_get_data() {
@@ -895,7 +937,7 @@ function form_test_state_persist($form, &$form_state) {
/**
* Submit handler.
- *
+ *
* @see form_test_state_persist()
*/
function form_test_state_persist_submit($form, &$form_state) {
@@ -905,7 +947,7 @@ function form_test_state_persist_submit($form, &$form_state) {
/**
* Implements hook_form_FORM_ID_alter().
- *
+ *
* @see form_test_state_persist()
*/
function form_test_form_form_test_state_persist_alter(&$form, &$form_state) {