EmailTest.php

Same filename and directory in other branches
  1. 9 core/modules/system/tests/src/Functional/Form/EmailTest.php
  2. 8.9.x core/modules/system/tests/src/Functional/Form/EmailTest.php
  3. 11.x core/modules/system/tests/src/Functional/Form/EmailTest.php

Namespace

Drupal\Tests\system\Functional\Form

File

core/modules/system/tests/src/Functional/Form/EmailTest.php

View source
<?php

declare (strict_types=1);
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 {
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'form_test',
  ];
  
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';
  
  /**
   * Tests that #type 'email' fields are properly validated.
   */
  public function testFormEmail() : void {
    $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'] = '  [email protected] ';
    $this->drupalGet('form-test/email');
    $this->submitForm($edit, 'Submit');
    $values = Json::decode($this->getSession()
      ->getPage()
      ->getContent());
    $this->assertSame('', $values['email']);
    $this->assertEquals('[email protected]', $values['email_required']);
    $edit = [];
    $edit['email'] = '[email protected]';
    $edit['email_required'] = '[email protected]';
    $this->drupalGet('form-test/email');
    $this->submitForm($edit, 'Submit');
    $values = Json::decode($this->getSession()
      ->getPage()
      ->getContent());
    $this->assertEquals('[email protected]', $values['email']);
    $this->assertEquals('[email protected]', $values['email_required']);
  }

}

Classes

Title Deprecated Summary
EmailTest Tests the form API email element.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.