class EmailTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Form/EmailTest.php \Drupal\Tests\system\Functional\Form\EmailTest
- 10 core/modules/system/tests/src/Functional/Form/EmailTest.php \Drupal\Tests\system\Functional\Form\EmailTest
- 8.9.x core/modules/system/tests/src/Functional/Form/EmailTest.php \Drupal\Tests\system\Functional\Form\EmailTest
Tests the form API email element.
@group Form
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Form\EmailTest implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of EmailTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Form/ EmailTest.php, line 13
Namespace
Drupal\Tests\system\Functional\FormView source
class EmailTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'form_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests that #type 'email' fields are properly validated.
*/
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']);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.