89269384cf0d38cc79259c7eb9f99d06c7b4b03b
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Validation / EmailValidatorTest.php
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Validation;
3 /***************************************************************
4 * Copyright notice
5 *
6 * (c) 2012-2013 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
7 *
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Test case for class \TYPO3\CMS\Form\Validation\EmailValidator.
29 *
30 * @author Andreas Lappe <a.lappe@kuehlhaus.com>
31 */
32 class EmailValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
33 /**
34 * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
35 */
36 protected $helper;
37
38 /**
39 * @var \TYPO3\CMS\Form\Validation\EmailValidator
40 */
41 protected $fixture;
42
43 public function setUp() {
44 $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
45 $this->fixture = new \TYPO3\CMS\Form\Validation\EmailValidator(array());
46 }
47
48 public function tearDown() {
49 unset($this->helper, $this->fixture);
50 }
51
52 public function validEmailProvider() {
53 return array(
54 'a@b.de' => array('a@b.de'),
55 'somebody@localhost' => array('somebody@localhost'),
56 'somebody@mymac.local' => array('somebody@mymac.local')
57 );
58 }
59
60 public function invalidEmailProvider() {
61 return array(
62 'myemail@' => array('myemail@'),
63 'myemail' => array('myemail'),
64 );
65 }
66
67 /**
68 * @test
69 * @dataProvider validEmailProvider
70 */
71 public function isValidForValidInputReturnsTrue($input) {
72 $this->fixture->setFieldName('myEmail');
73 $requestHandlerMock = $this->helper->getRequestHandler(array(
74 'myEmail' => $input
75 ));
76 $this->fixture->injectRequestHandler($requestHandlerMock);
77
78 $this->assertTrue(
79 $this->fixture->isValid()
80 );
81 }
82
83 /**
84 * @test
85 * @dataProvider invalidEmailProvider
86 */
87 public function isValidForInvalidInputReturnsFalse($input) {
88 $this->fixture->setFieldName('myEmail');
89 $requestHandlerMock = $this->helper->getRequestHandler(array(
90 'myEmail' => $input
91 ));
92 $this->fixture->injectRequestHandler($requestHandlerMock);
93
94 $this->assertFalse(
95 $this->fixture->isValid()
96 );
97 }
98 }
99 ?>