[TASK] Shorten the extend class in all unit tests
[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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25
26 /**
27 * Test case
28 */
29 class EmailAddressValidatorTest extends UnitTestCase
30 {
31 /**
32 * Data provider with valid email addresses
33 *
34 * @return array
35 */
36 public function validAddresses()
37 {
38 return [
39 ['andreas.foerthner@netlogix.de'],
40 ['user@localhost.localdomain'],
41 ['info@guggenheim.museum'],
42 ['just@test.invalid'],
43 ['just+spam@test.de'],
44 ];
45 }
46
47 /**
48 * @test
49 * @dataProvider validAddresses
50 * @param mixed $address
51 */
52 public function emailAddressValidatorReturnsNoErrorsForAValidEmailAddress($address)
53 {
54 /** @var \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator|\PHPUnit_Framework_MockObject_MockObject $subject */
55 $subject = $this->getMockBuilder(\TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator::class)
56 ->setMethods(['translateErrorMessage'])
57 ->getMock();
58 $this->assertFalse($subject->validate($address)->hasErrors());
59 }
60
61 /**
62 * Data provider with invalid email addresses
63 *
64 * @return array
65 */
66 public function invalidAddresses()
67 {
68 return [
69 ['andreas.foerthner@'],
70 ['@typo3.org'],
71 ['someone@typo3.'],
72 ['local@192.168.2'],
73 ['local@192.168.270.1'],
74 ['foo@bar.com' . "\0"],
75 ['foo@bar.org' . chr(10)],
76 ['andreas@foerthner@example.com'],
77 ['some@one.net ']
78 ];
79 }
80
81 /**
82 * @test
83 * @dataProvider invalidAddresses
84 * @param mixed $address
85 */
86 public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address)
87 {
88 /** @var \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator|\PHPUnit_Framework_MockObject_MockObject $subject */
89 $subject = $this->getMockBuilder(\TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator::class)
90 ->setMethods(['translateErrorMessage'])
91 ->getMock();
92 $this->assertTrue($subject->validate($address)->hasErrors());
93 }
94
95 /**
96 * @test
97 */
98 public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress()
99 {
100 /** @var \TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator|\PHPUnit_Framework_MockObject_MockObject $subject */
101 $subject = $this->getMockBuilder(\TYPO3\CMS\Extbase\Validation\Validator\EmailAddressValidator::class)
102 ->setMethods(['translateErrorMessage'])
103 ->getMock();
104 $this->assertEquals(1, count($subject->validate('notAValidMail@Address')->getErrors()));
105 }
106 }