[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Validation / Validator / EmailAddressValidatorTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator;
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
24 /**
25 * Test case
26 */
27 class EmailAddressValidatorTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
28 {
29 /**
30 * Data provider with valid email addresses
31 *
32 * @return array
33 */
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
45 /**
46 * @test
47 * @dataProvider validAddresses
48 * @param mixed $address
49 */
50 public function emailAddressValidatorReturnsNoErrorsForAValidEmailAddress($address)
51 {
52 /** @var \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator|\PHPUnit_Framework_MockObject_MockObject $subject */
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
59 /**
60 * Data provider with invalid email addresses
61 *
62 * @return array
63 */
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
79 /**
80 * @test
81 * @dataProvider invalidAddresses
82 * @param mixed $address
83 */
84 public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address)
85 {
86 /** @var \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator|\PHPUnit_Framework_MockObject_MockObject $subject */
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
93 /**
94 * @test
95 */
96 public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress()
97 {
98 /** @var \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator|\PHPUnit_Framework_MockObject_MockObject $subject */
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 }