/Tests/Unit/Validation/Validator/EmailAddressValidatorTest.php
PHP | 95 lines | 44 code | 11 blank | 40 comment | 0 complexity | 6496006e2c63ea37ed836dd73e07ab5e MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
- <?php
- namespace TYPO3\FLOW3\Tests\Unit\Validation\Validator;
- /* *
- * This script belongs to the FLOW3 framework. *
- * *
- * It is free software; you can redistribute it and/or modify it under *
- * the terms of the GNU Lesser General Public License, either version 3 *
- * of the License, or (at your option) any later version. *
- * *
- * The TYPO3 project - inspiring people to share! *
- * */
- require_once('AbstractValidatorTestcase.php');
- /**
- * Testcase for the email address validator
- *
- */
- class EmailAddressValidatorTest extends \TYPO3\FLOW3\Tests\Unit\Validation\Validator\AbstractValidatorTestcase {
- protected $validatorClassName = 'TYPO3\FLOW3\Validation\Validator\EmailAddressValidator';
- /**
- * @test
- */
- public function validateReturnsNoErrorIfTheGivenValueIsNull() {
- $this->assertFalse($this->validator->validate(NULL)->hasErrors());
- }
- /**
- * @test
- */
- public function validateReturnsNoErrorIfTheGivenValueIsAnEmptyString() {
- $this->assertFalse($this->validator->validate('')->hasErrors());
- }
- /**
- * Data provider with valid email addresses
- *
- * @return array
- */
- public function validAddresses() {
- return array(
- array('andreas.foerthner@netlogix.de'),
- array('user@localhost.localdomain'),
- array('info@guggenheim.museum'),
- array('just@test.invalid'),
- array('just+spam@test.de')
- );
- }
- /**
- * @test
- * @dataProvider validAddresses
- */
- public function emailAddressValidatorReturnsNoErrorsForAValidEmailAddress($address) {
- $this->assertFalse($this->validator->validate($address)->hasErrors());
- }
- /**
- * Data provider with invalid email addresses
- *
- * @return array
- */
- public function invalidAddresses() {
- return array(
- array('andreas.foerthner@'),
- array('@typo3.org'),
- array('someone@typo3.'),
- array('local@192.168.2'),
- array('local@192.168.270.1'),
- array('foo@bar.com' . chr(0)),
- array('foo@bar.org' . chr(10)),
- array('andreas@foerthner@example.com'),
- array('some@one.net ')
- );
- }
- /**
- * @test
- * @dataProvider invalidAddresses
- */
- public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address) {
- $this->assertTrue($this->validator->validate($address)->hasErrors());
- }
- /**
- * @test
- */
- public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress() {
- $this->assertEquals(1, count($this->validator->validate('notAValidMail@Address')->getErrors()));
- }
- }
- ?>