TYPO3 CMS  TYPO3_8-7
EmailAddressValidatorTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script belongs to the Extbase framework. *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License as published by the *
9  * Free Software Foundation, either version 3 of the License, or (at your *
10  * option) any later version. *
11  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with the script. *
19  * If not, see http://www.gnu.org/licenses/lgpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
23 
27 class EmailAddressValidatorTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
28 {
34  public function validAddresses()
35  {
36  return [
37  ['andreas.foerthner@netlogix.de'],
38  ['user@localhost.localdomain'],
39  ['info@guggenheim.museum'],
40  ['just@test.invalid'],
41  ['just+spam@test.de'],
42  ];
43  }
44 
50  public function emailAddressValidatorReturnsNoErrorsForAValidEmailAddress($address)
51  {
53  $subject = $this->getMockBuilder(\TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator::class)
54  ->setMethods(['translateErrorMessage'])
55  ->getMock();
56  $this->assertFalse($subject->validate($address)->hasErrors());
57  }
58 
64  public function invalidAddresses()
65  {
66  return [
67  ['andreas.foerthner@'],
68  ['@typo3.org'],
69  ['someone@typo3.'],
70  ['local@192.168.2'],
71  ['local@192.168.270.1'],
72  ['foo@bar.com' . chr(0)],
73  ['foo@bar.org' . chr(10)],
74  ['andreas@foerthner@example.com'],
75  ['some@one.net ']
76  ];
77  }
78 
84  public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address)
85  {
87  $subject = $this->getMockBuilder(\TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator::class)
88  ->setMethods(['translateErrorMessage'])
89  ->getMock();
90  $this->assertTrue($subject->validate($address)->hasErrors());
91  }
92 
96  public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress()
97  {
99  $subject = $this->getMockBuilder(\TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator::class)
100  ->setMethods(['translateErrorMessage'])
101  ->getMock();
102  $this->assertEquals(1, count($subject->validate('notAValidMail@Address')->getErrors()));
103  }
104 }