You are here

public function EmailTest::testFormEmail in Drupal 10

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

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

File

core/modules/system/tests/src/Functional/Form/EmailTest.php, line 30

Class

EmailTest
Tests the form API email element.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testFormEmail() {
  $edit = [];
  $edit['email'] = 'invalid';
  $edit['email_required'] = ' ';
  $this
    ->drupalGet('form-test/email');
  $this
    ->submitForm($edit, 'Submit');
  $this
    ->assertSession()
    ->pageTextContains("The email address invalid is not valid.");
  $this
    ->assertSession()
    ->pageTextContains("Address field is required.");
  $edit = [];
  $edit['email_required'] = '  foo.bar@example.com ';
  $this
    ->drupalGet('form-test/email');
  $this
    ->submitForm($edit, 'Submit');
  $values = Json::decode($this
    ->getSession()
    ->getPage()
    ->getContent());
  $this
    ->assertSame('', $values['email']);
  $this
    ->assertEquals('foo.bar@example.com', $values['email_required']);
  $edit = [];
  $edit['email'] = 'foo@example.com';
  $edit['email_required'] = 'example@drupal.org';
  $this
    ->drupalGet('form-test/email');
  $this
    ->submitForm($edit, 'Submit');
  $values = Json::decode($this
    ->getSession()
    ->getPage()
    ->getContent());
  $this
    ->assertEquals('foo@example.com', $values['email']);
  $this
    ->assertEquals('example@drupal.org', $values['email_required']);
}