1 form.test FormEmailTestCase::testFormEmail()

Tests that #type 'email' fields are properly validated.

File

core/modules/simpletest/tests/form.test, line 2160
Unit tests for the Backdrop Form API.

Class

FormEmailTestCase
Tests email element.

Code

function testFormEmail() {
  $edit = array();
  $edit['email'] = 'invalid';
  $edit['email_required'] = ' ';
  $this->backdropPost('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 = backdrop_json_decode($this->backdropPost('form-test/email', $edit, 'Submit'));
  $this->assertIdentical($values['email'], '');
  $this->assertEqual($values['email_required'], 'foo.bar@example.com');

  $edit = array();
  $edit['email'] = 'foo@example.com';
  $edit['email_required'] = 'example@backdropcms.org';
  $values = backdrop_json_decode($this->backdropPost('form-test/email', $edit, 'Submit'));
  $this->assertEqual($values['email'], 'foo@example.com');
  $this->assertEqual($values['email_required'], 'example@backdropcms.org');
}