Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / system / tests / src / Functional / Form / EmailTest.php
diff --git a/web/core/modules/system/tests/src/Functional/Form/EmailTest.php b/web/core/modules/system/tests/src/Functional/Form/EmailTest.php
new file mode 100644 (file)
index 0000000..2fe6ebe
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+
+namespace Drupal\Tests\system\Functional\Form;
+
+use Drupal\Component\Serialization\Json;
+use Drupal\Tests\BrowserTestBase;
+
+/**
+ * Tests the form API email element.
+ *
+ * @group Form
+ */
+class EmailTest extends BrowserTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = ['form_test'];
+
+  /**
+   * Tests that #type 'email' fields are properly validated.
+   */
+  public function testFormEmail() {
+    $edit = [];
+    $edit['email'] = 'invalid';
+    $edit['email_required'] = ' ';
+    $this->drupalPostForm('form-test/email', $edit, 'Submit');
+    $this->assertRaw(t('The email address %mail is not valid.', ['%mail' => 'invalid']));
+    $this->assertRaw(t('@name field is required.', ['@name' => 'Address']));
+
+    $edit = [];
+    $edit['email_required'] = '  foo.bar@example.com ';
+    $this->drupalPostForm('form-test/email', $edit, 'Submit');
+    $values = Json::decode($this->getSession()->getPage()->getContent());
+    $this->assertIdentical($values['email'], '');
+    $this->assertEqual($values['email_required'], 'foo.bar@example.com');
+
+    $edit = [];
+    $edit['email'] = 'foo@example.com';
+    $edit['email_required'] = 'example@drupal.org';
+    $this->drupalPostForm('form-test/email', $edit, 'Submit');
+    $values = Json::decode($this->getSession()->getPage()->getContent());
+    $this->assertEqual($values['email'], 'foo@example.com');
+    $this->assertEqual($values['email_required'], 'example@drupal.org');
+  }
+
+}