diff --git a/core/modules/simpletest/tests/form.test b/core/modules/simpletest/tests/form.test index 784da88..8c25e41 100644 --- a/core/modules/simpletest/tests/form.test +++ b/core/modules/simpletest/tests/form.test @@ -1628,3 +1628,40 @@ class FormCheckboxTestCase extends DrupalWebTestCase { } } } + +/** + * Tests email element. + */ +class FormEmailTestCase extends DrupalWebTestCase { + protected $profile = 'testing'; + + public static function getInfo() { + return array( + 'name' => 'Form API email', + 'description' => 'Tests the form API email element.', + 'group' => 'Form API', + ); + } + + function setUp() { + parent::setUp('form_test'); + } + + /** + * Tests that #type 'email' fields are properly validated. + */ + function testFormEmail() { + $edit = array(); + $edit['email'] = 'invalid'; + $edit['email_required'] = ' '; + $this->drupalPost('form-test/email', $edit, 'Submit'); + $this->assertRaw(t('The e-mail address %mail is not valid.', array('%mail' => 'invalid'))); + $this->assertRaw(t('!name field is required.', array('!name' => 'Address'))); + + $edit = array(); + $edit['email_required'] = ' foo.bar@example.com '; + $values = drupal_json_decode($this->drupalPost('form-test/email', $edit, 'Submit')); + $this->assertIdentical($values['email'], ''); + $this->assertEqual($values['email_required'], 'foo.bar@example.com'); + } +} diff --git a/core/modules/simpletest/tests/form_test.module b/core/modules/simpletest/tests/form_test.module index e1e2435..f01e63b 100644 --- a/core/modules/simpletest/tests/form_test.module +++ b/core/modules/simpletest/tests/form_test.module @@ -125,6 +125,12 @@ function form_test_menu() { 'page arguments' => array('form_test_checkboxes_radios'), 'access callback' => TRUE, ); + $items['form-test/email'] = array( + 'title' => 'E-Mail fields', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('form_test_email'), + 'access callback' => TRUE, + ); $items['form-test/disabled-elements'] = array( 'title' => t('Form test'), @@ -1098,6 +1104,39 @@ function form_test_checkboxes_radios($form, &$form_state, $customize = FALSE) { } /** + * Form constructor for testing #type 'email' elements. + * + * @see form_test_email_submit() + * @ingroup forms + */ +function form_test_email($form, &$form_state) { + $form['email'] = array( + '#type' => 'email', + '#title' => 'E-Mail address', + '#description' => 'An e-mail address.', + ); + $form['email_required'] = array( + '#type' => 'email', + '#title' => 'Address', + '#required' => TRUE, + '#description' => 'A required e-mail address field.', + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => 'Submit', + ); + return $form; +} + +/** + * Form submission handler for form_test_email(). + */ +function form_test_email_submit($form, &$form_state) { + drupal_json_output($form_state['values']); + exit(); +} + +/** * Build a form to test disabled elements. */ function _form_test_disabled_elements($form, &$form_state) {