2fe6ebe9078f2598d9813e418383d4648a927b9b
[yaffs-website] / web / core / modules / system / tests / src / Functional / Form / EmailTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Form;
4
5 use Drupal\Component\Serialization\Json;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Tests the form API email element.
10  *
11  * @group Form
12  */
13 class EmailTest extends BrowserTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['form_test'];
21
22   /**
23    * Tests that #type 'email' fields are properly validated.
24    */
25   public function testFormEmail() {
26     $edit = [];
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']));
32
33     $edit = [];
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');
39
40     $edit = [];
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');
47   }
48
49 }