diff --git a/core/modules/simpletest/tests/form.test b/core/modules/simpletest/tests/form.test index 23bec0e..883237b 100644 --- a/core/modules/simpletest/tests/form.test +++ b/core/modules/simpletest/tests/form.test @@ -1075,9 +1075,11 @@ class FormsFormWrapperTestCase extends DrupalWebTestCase { } /** - * Test error class handling. + * Tests error class handling. */ class FormsErrorClassTestCase extends DrupalWebTestCase { + protected $profile = 'testing'; + public static function getInfo() { return array( 'name' => 'Form element error class', @@ -1094,29 +1096,32 @@ class FormsErrorClassTestCase extends DrupalWebTestCase { * Tests if the error class is applied to all three texfields on a form. */ function testErrorClasses() { + // Submitting with the default values should not pass validation. $edit = array(); - $this->drupalPost('form-test/error-classes', $edit, t('Submit')); - $this->assertFieldByXPath('//input[@name="title1" and contains(@class,"error")]', "DEFAULT", 'Error class added to title1.'); - $this->assertFieldByXPath('//input[@name="title2" and contains(@class,"error")]', "DEFAULT", 'Error class added to title2.'); - $this->assertFieldByXPath('//input[@name="title3" and contains(@class,"error")]', "DEFAULT", 'Error class added to title3.'); - $this->assertFieldByXPath('//input[@name="tree[trunk]" and contains(@class,"error")]', "", 'Error class added to tree[trunk].'); - $this->assertNoText('form_test_error_class success.', t('The form failed validation.')); - + $this->drupalPost('form-test/error-classes', $edit, 'Submit'); + $this->assertFieldByXPath('//input[@name="title1" and contains(@class,"error")]', 'DEFAULT', 'Error class added to title1.'); + $this->assertFieldByXPath('//input[@name="title2" and contains(@class,"error")]', 'DEFAULT', 'Error class added to title2.'); + $this->assertFieldByXPath('//input[@name="title3" and contains(@class,"error")]', 'DEFAULT', 'Error class added to title3.'); + $this->assertFieldByXPath('//input[@name="tree[trunk]" and contains(@class,"error")]', '', 'Error class added to tree[trunk].'); + $this->assertNoText('form_test_error_class success.', 'The form failed validation.'); + + // Submitting with non-unique random values should not pass validation. $edit['title3'] = $edit['title2'] = $edit['title1'] = $edit['tree[trunk]'] = $this->randomName(); - $this->drupalPost('form-test/error-classes', $edit, t('Submit')); + $this->drupalPost('form-test/error-classes', $edit, 'Submit'); $this->assertFieldByXPath('//input[@name="title1" and contains(@class,"error")]', $edit['title1'], 'Error class added to title1.'); $this->assertFieldByXPath('//input[@name="title2" and contains(@class,"error")]', $edit['title2'], 'Error class added to title2.'); $this->assertFieldByXPath('//input[@name="title3" and contains(@class,"error")]', $edit['title3'], 'Error class added to title3.'); - $this->assertNoText('form_test_error_class success.', t('The form failed validation.')); + $this->assertNoText('form_test_error_class success.', 'The form failed validation.'); + // Submitting with unique values should pass validation. $edit['title2'] = $edit['title1'] . $this->randomName(); $edit['title3'] = $edit['title2'] . $this->randomName(); - $this->drupalPost('form-test/error-classes', $edit, t('Submit')); + $this->drupalPost('form-test/error-classes', $edit, 'Submit'); $this->assertNoFieldByXPath('//input[@name="title1" and contains(@class,"error")]', $edit['title1'], 'Error class not added to title1.'); $this->assertNoFieldByXPath('//input[@name="title2" and contains(@class,"error")]', $edit['title2'], 'Error class not added to title2.'); $this->assertNoFieldByXPath('//input[@name="title3" and contains(@class,"error")]', $edit['title3'], 'Error class not added to title3.'); $this->assertNoFieldByXPath('//input[@name="tree[trunk]" and contains(@class,"error")]', $edit['tree[trunk]'], 'Error class not added to tree[trunk].'); - $this->assertText('form_test_error_class success.', t('The form passed validation.')); + $this->assertText('form_test_error_class success.', 'The form passed validation.'); } } diff --git a/core/modules/simpletest/tests/form_test.module b/core/modules/simpletest/tests/form_test.module index caa25f0..ea84dfa 100644 --- a/core/modules/simpletest/tests/form_test.module +++ b/core/modules/simpletest/tests/form_test.module @@ -1438,6 +1438,11 @@ function form_test_form_form_test_state_persist_alter(&$form, &$form_state) { /** * Form constructor for testing error classes. + * + * @see form_test_error_class_validate() + * @see form_test_error_class_tree_validate() + * @see form_test_error_class_submit() + * @ingroup forms */ function form_test_error_class($form, &$form_state) { // Three textfeilds with the same default value. @@ -1470,13 +1475,17 @@ function form_test_error_class($form, &$form_state) { ); $form['submit'] = array( '#type' => 'submit', - '#value' => t('Submit'), + '#value' => 'Submit', ); return $form; } /** - * Form validation handler which requires all title values to be unique. + * Form validation handler for form_test_error_class(). + * + * Requires all title values to be unique. + * + * @see form_test_error_class_submit() */ function form_test_error_class_validate($form, &$form_state) { $values[] = $form_state['values']['title1']; @@ -1491,7 +1500,11 @@ function form_test_error_class_validate($form, &$form_state) { } /** - * Element validation handler which requires the element value to be not empty. + * Form element validation handler for 'trunk' in form_test_error_class(). + * + * Requires the element value to be not empty. + * + * @see form_test_error_class_submit() */ function form_test_error_class_tree_validate($element, &$form_state) { if (empty($element['#value'])) { @@ -1500,7 +1513,12 @@ function form_test_error_class_tree_validate($element, &$form_state) { } /** - * Form submit handler that just sets a message. + * Form submission handler for form_test_error_class(). + * + * Justs sets a success message. + * + * @see form_test_error_class_validate() + * @see form_test_error_class_tree_validate() */ function form_test_error_class_submit($form, &$form_state) { drupal_set_message('form_test_error_class success.');