class EmailValidatorTest

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php \Drupal\Tests\Component\Utility\EmailValidatorTest
  2. 8.9.x core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php \Drupal\Tests\Component\Utility\EmailValidatorTest
  3. 11.x core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php \Drupal\Tests\Component\Utility\EmailValidatorTest

Tests the EmailValidator utility class.

@coversDefaultClass \Drupal\Component\Utility\EmailValidator
@group Utility

Hierarchy

  • class \Drupal\Tests\Component\Utility\EmailValidatorTest implements \PHPUnit\Framework\TestCase

Expanded class hierarchy of EmailValidatorTest

File

core/tests/Drupal/Tests/Component/Utility/EmailValidatorTest.php, line 17

Namespace

Drupal\Tests\Component\Utility
View source
class EmailValidatorTest extends TestCase {
  
  /**
   * @covers ::isValid
   */
  public function testIsValid() : void {
    // Note that \Drupal\Component\Utility\EmailValidator wraps
    // \Egulias\EmailValidator\EmailValidator so we don't do anything more than
    // test that the wrapping works since the dependency has its own test
    // coverage.
    $validator = new EmailValidator();
    $this->assertTrue($validator->isValid('example@example.com'));
    $this->assertFalse($validator->isValid('example@example.com@'));
    $this->assertFalse($validator->isValid('example@example .com'));
  }
  
  /**
   * @covers ::isValid
   */
  public function testIsValidException() : void {
    $validator = new EmailValidator();
    $this->expectException(\BadMethodCallException::class);
    $this->expectExceptionMessage('Calling \\Drupal\\Component\\Utility\\EmailValidator::isValid() with the second argument is not supported. See https://www.drupal.org/node/2997196');
    $validator->isValid('example@example.com', new RFCValidation());
  }

}

Members

Title Sort descending Modifiers Object type Summary
EmailValidatorTest::testIsValid public function @covers ::isValid[[api-linebreak]]
EmailValidatorTest::testIsValidException public function @covers ::isValid[[api-linebreak]]

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