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