Merge "[TASK][!!!] Fix localization handling to support XLIFF"
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Validation / Validator / 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 * @package Extbase
32 * @subpackage extbase
33 * @version $Id: EmailAddressValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
34 */
35 class Tx_Extbase_Tests_Unit_Validation_Validator_EmailAddressValidatorTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
36
37 /**
38 * Data provider with valid email addresses
39 *
40 * @return array
41 */
42 public function validAddresses() {
43 return array(
44 array('andreas.foerthner@netlogix.de'),
45 array('user@localhost'),
46 array('user@localhost.localdomain'),
47 array('info@guggenheim.museum'),
48 array('just@test.invalid'),
49 array('just+spam@test.de'),
50 array('local@192.168.0.2')
51 );
52 }
53
54 /**
55 * @test
56 * @dataProvider validAddresses
57 */
58 public function emailAddressValidatorReturnsTrueForAValidEmailAddress($address) {
59 $emailAddressValidator = new Tx_Extbase_Validation_Validator_EmailAddressValidator();
60 $this->assertTrue($emailAddressValidator->isValid($address), "$address was declared to be invalid, but it is valid.");
61 }
62
63 /**
64 * Data provider with invalid email addresses
65 *
66 * @return array
67 */
68 public function invalidAddresses() {
69 return array(
70 array('andreas.foerthner@'),
71 array('andreas@foerthner@example.com'),
72 array('@typo3.org'),
73 array('someone@typo3.'),
74 array('local@192.168.2'),
75 array('local@192.168.270.1')
76 );
77 }
78
79 /**
80 * @test
81 * @dataProvider invalidAddresses
82 */
83 public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address) {
84 $emailAddressValidator = $this->getMock('Tx_Extbase_Validation_Validator_EmailAddressValidator', array('addError'), array(), '', FALSE);
85 $this->assertFalse($emailAddressValidator->isValid($address));
86 }
87
88 /**
89 * @test
90 */
91 public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress() {
92 $emailAddressValidator = $this->getMock('Tx_Extbase_Validation_Validator_EmailAddressValidator', array('addError'), array(), '', FALSE);
93 $emailAddressValidator->expects($this->once())->method('addError')->with('The given subject was not a valid email address.', 1221559976);
94 $emailAddressValidator->isValid('notAValidMail@Address');
95 }
96
97 }
98
99 ?>