2 /***************************************************************
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
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.
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * Testcase for the email address validator
33 * @version $Id: EmailAddressValidator_testcase.php 2428 2010-07-20 10:18:51Z jocrau $
35 class Tx_Extbase_Validation_Validator_EmailAddressValidator_testcase
extends Tx_Extbase_Tests_Unit_BaseTestCase
{
38 * Data provider with valid email addresses
42 public function validAddresses() {
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')
56 * @dataProvider validAddresses
58 public function emailAddressValidatorReturnsTrueForAValidEmailAddress($address) {
59 $emailAddressValidator = new Tx_Extbase_Validation_Validator_EmailAddressValidator();
60 foreach ($this->validAddresses
as $address) {
61 $this->assertTrue($emailAddressValidator->isValid($address), "$address was declared to be invalid, but it is valid.");
66 * Data provider with invalid email addresses
70 public function invalidAddresses() {
72 array('andreas.foerthner@'),
73 array('andreas@foerthner@example.com'),
75 array('someone@typo3.'),
76 array('local@192.168.2'),
77 array('local@192.168.270.1')
83 * @dataProvider invalidAddresses
85 public function emailAddressValidatorReturnsFalseForAnInvalidEmailAddress($address) {
86 $emailAddressValidator = $this->getMock('Tx_Extbase_Validation_Validator_EmailAddressValidator', array('addError'), array(), '', FALSE);
87 $this->assertFalse($emailAddressValidator->isValid($address));
93 public function emailValidatorCreatesTheCorrectErrorForAnInvalidEmailAddress() {
94 $emailAddressValidator = $this->getMock('Tx_Extbase_Validation_Validator_EmailAddressValidator', array('addError'), array(), '', FALSE);
95 $emailAddressValidator->expects($this->once())->method('addError')->with('The given subject was not a valid email address.', 1221559976);
96 $emailAddressValidator->isValid('notAValidMail@Address');