[BUGFIX] email validator
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Validation / Validator / BeforeExtbase14 / EmailAddressValidatorTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Testcase for the email address validator
30 *
31 * This testcase checks the expected behavior for Extbase < 1.4.0, to make sure
32 * we do not break backwards compatibility.
33 *
34 * @package Extbase
35 * @subpackage extbase
36 * @version $Id: EmailAddressValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
37 */
38 class Tx_Extbase_Tests_Unit_Validation_Validator_BeforeExtbase14_EmailAddressValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
39
40 /**
41 * Data provider with valid email addresses
42 *
43 * @return array
44 */
45 public function validAddresses() {
46 return array(
47 array('andreas.foerthner@netlogix.de'),
48 array('user@localhost.localdomain'),
49 array('info@guggenheim.museum'),
50 array('just@test.invalid'),
51 array('just+spam@test.de')
52 );
53 }
54
55 /**
56 * @test
57 * @dataProvider validAddresses
58 * @param mixed $address
59 */
60 public function emailAddressValidatorReturnsTrueForAValidEmailAddress($address) {
61 $emailAddressValidator = new Tx_Extbase_Validation_Validator_EmailAddressValidator();
62 $this->assertTrue($emailAddressValidator->isValid($address), "$address was declared to be invalid, but it is valid.");
63 }
64
65 /**
66 * Data provider with invalid email addresses
67 *
68 * @return array
69 */
70 public function invalidAddresses() {
71 return array(
72 array('andreas.foerthner@'),
73 array('andreas@foerthner@example.com'),
74 array('@typo3.org'),
75 array('someone@typo3.'),
76 array('local@192.168.2'),
77 array('local@192.168.270.1'),
78 array('just@test.invalid ')
79 );
80 }
81
82 /**
83 * @test
84 * @dataProvider invalidAddresses
85 * @param mixed $address
86 */
87 public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address) {
88 $emailAddressValidator = $this->getMock('Tx_Extbase_Validation_Validator_EmailAddressValidator', array('addError'), array(), '', FALSE);
89 $this->assertFalse($emailAddressValidator->isValid($address));
90 }
91
92 /**
93 * @test
94 */
95 public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress() {
96 $emailAddressValidator = $this->getMock('Tx_Extbase_Validation_Validator_EmailAddressValidator', array('addError'), array(), '', FALSE);
97 $emailAddressValidator->expects($this->once())->method('addError')->with('The given subject was not a valid email address.', 1221559976);
98 $emailAddressValidator->isValid('notAValidMail@Address');
99 }
100
101 }
102
103 ?>