3 namespace Drupal\Tests\system\Functional\Form;
5 use Drupal\Component\Serialization\Json;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests the form API email element.
13 class EmailTest extends BrowserTestBase {
20 public static $modules = ['form_test'];
23 * Tests that #type 'email' fields are properly validated.
25 public function testFormEmail() {
27 $edit['email'] = 'invalid';
28 $edit['email_required'] = ' ';
29 $this->drupalPostForm('form-test/email', $edit, 'Submit');
30 $this->assertRaw(t('The email address %mail is not valid.', ['%mail' => 'invalid']));
31 $this->assertRaw(t('@name field is required.', ['@name' => 'Address']));
34 $edit['email_required'] = ' foo.bar@example.com ';
35 $this->drupalPostForm('form-test/email', $edit, 'Submit');
36 $values = Json::decode($this->getSession()->getPage()->getContent());
37 $this->assertIdentical($values['email'], '');
38 $this->assertEqual($values['email_required'], 'foo.bar@example.com');
41 $edit['email'] = 'foo@example.com';
42 $edit['email_required'] = 'example@drupal.org';
43 $this->drupalPostForm('form-test/email', $edit, 'Submit');
44 $values = Json::decode($this->getSession()->getPage()->getContent());
45 $this->assertEqual($values['email'], 'foo@example.com');
46 $this->assertEqual($values['email_required'], 'example@drupal.org');