You are here

function EmailTest::testFormEmail in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Form/EmailTest.php \Drupal\system\Tests\Form\EmailTest::testFormEmail()

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

File

core/modules/system/src/Tests/Form/EmailTest.php, line 32
Contains \Drupal\system\Tests\Form\EmailTest.

Class

EmailTest
Tests the form API email element.

Namespace

Drupal\system\Tests\Form

Code

function testFormEmail() {
  $edit = array();
  $edit['email'] = 'invalid';
  $edit['email_required'] = ' ';
  $this
    ->drupalPostForm('form-test/email', $edit, 'Submit');
  $this
    ->assertRaw(t('The email 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 = Json::decode($this
    ->drupalPostForm('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@drupal.org';
  $values = Json::decode($this
    ->drupalPostForm('form-test/email', $edit, 'Submit'));
  $this
    ->assertEqual($values['email'], 'foo@example.com');
  $this
    ->assertEqual($values['email_required'], 'example@drupal.org');
}