Merge "[TASK] Extbase (Persistence): Remove duplicate registration in identity map"
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Validation / Validator / EmailAddressValidatorTest.php
1 <?php
2
3 /* *
4 * This script belongs to the Extbase framework. *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 require_once('AbstractValidatorTestcase.php');
24
25 /**
26 * Testcase for the email address validator
27 *
28 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
29 */
30 class Tx_Extbase_Tests_Unit_Validation_Validator_EmailAddressValidatorTest extends Tx_Extbase_Tests_Unit_Validation_Validator_AbstractValidatorTestcase {
31
32 protected $validatorClassName = 'Tx_Extbase_Validation_Validator_EmailAddressValidator';
33
34 /**
35 * Data provider with valid email addresses
36 *
37 * @return array
38 * @author Karsten Dambekalns <karsten@typo3.org>
39 */
40 public function validAddresses() {
41 return array(
42 array('andreas.foerthner@netlogix.de'),
43 array('user@localhost'),
44 array('user@localhost.localdomain'),
45 array('info@guggenheim.museum'),
46 array('just@test.invalid'),
47 array('just+spam@test.de'),
48 array('just+spam@192.168.249.100'),
49 array('local@192.168.0.2')
50 );
51 }
52
53 /**
54 * @author Karsten Dambekalns <karsten@typo3.org>
55 * @test
56 * @dataProvider validAddresses
57 */
58 public function emailAddressValidatorReturnsNoErrorsForAValidEmailAddress($address) {
59 $this->assertFalse($this->validator->validate($address)->hasErrors());
60 }
61
62 /**
63 * Data provider with invalid email addresses
64 *
65 * @return array
66 * @author Karsten Dambekalns <karsten@typo3.org>
67 */
68 public function invalidAddresses() {
69 return array(
70 array('andreas.foerthner@'),
71 array('@typo3.org'),
72 array('someone@typo3.'),
73 array('local@192.168.2'),
74 array('local@192.168.270.1'),
75 array('foo@bar.com' . chr(0)),
76 array('foo@bar.org' . chr(10)),
77 array('andreas@foerthner@example.com'),
78 array('some@one.net ')
79 );
80 }
81
82 /**
83 * @author Karsten Dambekalns <karsten@typo3.org>
84 * @test
85 * @dataProvider invalidAddresses
86 */
87 public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address) {
88 $this->assertTrue($this->validator->validate($address)->hasErrors());
89 }
90
91 /**
92 * @test
93 * @author Andreas Förthner <andreas.foerthner@netlogix.de>
94 */
95 public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress() {
96 $this->assertEquals(1, count($this->validator->validate('notAValidMail@Address')->getErrors()));
97 }
98 }
99 ?>