[BUGFIX] email validator
[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.localdomain'),
44 array('info@guggenheim.museum'),
45 array('just@test.invalid'),
46 array('just+spam@test.de')
47 );
48 }
49
50 /**
51 * @author Karsten Dambekalns <karsten@typo3.org>
52 * @test
53 * @dataProvider validAddresses
54 * @param mixed $address
55 */
56 public function emailAddressValidatorReturnsNoErrorsForAValidEmailAddress($address) {
57 $this->assertFalse($this->validator->validate($address)->hasErrors());
58 }
59
60 /**
61 * Data provider with invalid email addresses
62 *
63 * @return array
64 * @author Karsten Dambekalns <karsten@typo3.org>
65 */
66 public function invalidAddresses() {
67 return array(
68 array('andreas.foerthner@'),
69 array('@typo3.org'),
70 array('someone@typo3.'),
71 array('local@192.168.2'),
72 array('local@192.168.270.1'),
73 array('foo@bar.com' . chr(0)),
74 array('foo@bar.org' . chr(10)),
75 array('andreas@foerthner@example.com'),
76 array('some@one.net ')
77 );
78 }
79
80 /**
81 * @author Karsten Dambekalns <karsten@typo3.org>
82 * @test
83 * @dataProvider invalidAddresses
84 * @param mixed $address
85 */
86 public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address) {
87 $this->assertTrue($this->validator->validate($address)->hasErrors());
88 }
89
90 /**
91 * @test
92 * @author Andreas Förthner <andreas.foerthner@netlogix.de>
93 */
94 public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress() {
95 $this->assertEquals(1, count($this->validator->validate('notAValidMail@Address')->getErrors()));
96 }
97 }
98 ?>