4a2247aaeac7af8dc389b66354ef3f5911648cc1
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Tests / Unit / Validation / AlphabeticValidatorTest.php
1 <?php
2 namespace TYPO3\CMS\Form\Tests\Unit\Validation;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Andreas Lappe <a.lappe@kuehlhaus.com>, kuehlhaus AG
8 *
9 * All rights reserved
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 * Test case for class \TYPO3\CMS\Form\System\Validation\AlphabeticValidator.
30 *
31 * @author Andreas Lappe <a.lappe@kuehlhaus.com>
32 */
33 class AlphabeticValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
34 /**
35 * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
36 */
37 protected $helper;
38
39 /**
40 * @var \TYPO3\CMS\Form\Validation\AlphabeticValidator
41 */
42 protected $fixture;
43
44 public function setUp() {
45 $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
46 $this->fixture = new \TYPO3\CMS\Form\Validation\AlphabeticValidator();
47 }
48
49 public function tearDown() {
50 unset($this->helper, $this->fixture);
51 }
52
53 public function validDataProviderWithoutWhitespace() {
54 return array(
55 'ascii without spaces' => array('thisismyinput'),
56 'accents without spaces' => array('éóéàèò'),
57 'umlauts without spaces' => array('üöä'),
58 'empty string' => array('')
59 );
60 }
61
62 public function validDataProviderWithWhitespace() {
63 return array(
64 'ascii with spaces' => array('This is my input'),
65 'accents with spaces' => array('Sigur Rós'),
66 'umlauts with spaces' => array('Hürriyet Daily News'),
67 'space' => array(' '),
68 'empty string' => array('')
69 );
70 }
71
72 public function invalidDataProviderWithoutWhitespace() {
73 return array(
74 'ascii with dash' => array('my-name'),
75 'accents with underscore' => array('Sigur_Rós'),
76 'umlauts with periods' => array('Hürriyet.Daily.News'),
77 'space' => array(' '),
78 );
79 }
80
81 public function invalidDataProviderWithWhitespace() {
82 return array(
83 'ascii with spaces and dashes' => array('This is my-name'),
84 'accents with spaces and underscores' => array('Listen to Sigur_Rós_Band'),
85 'umlauts with spaces and periods' => array('Go get the Hürriyet.Daily.News')
86 );
87 }
88
89 /**
90 * @test
91 * @dataProvider validDataProviderWithoutWhitespace
92 */
93 public function isValidForValidInputWithoutAllowedWhitespaceReturnsTrue($input) {
94 $requestHandlerMock = $this->helper->getRequestHandler(array(
95 'name' => $input
96 ));
97
98 $this->fixture->setFieldName('name');
99 $this->fixture->injectRequestHandler($requestHandlerMock);
100
101 $this->assertTrue(
102 $this->fixture->isValid()
103 );
104 }
105
106 /**
107 * @test
108 * @dataProvider validDataProviderWithWhitespace
109 */
110 public function isValidForValidInputWithWhitespaceAllowedReturnsTrue($input) {
111 $requestHandlerMock = $this->helper->getRequestHandler(array(
112 'name' => $input
113 ));
114
115 $this->fixture->setAllowWhiteSpace(TRUE);
116 $this->fixture->setFieldName('name');
117 $this->fixture->injectRequestHandler($requestHandlerMock);
118
119 $this->assertTrue(
120 $this->fixture->isValid()
121 );
122 }
123
124 /**
125 * @test
126 * @dataProvider invalidDataProviderWithoutWhitespace
127 */
128 public function isValidForInvalidInputWithoutAllowedWhitespaceReturnsFalse($input) {
129 $requestHandlerMock = $this->helper->getRequestHandler(array(
130 'name' => $input
131 ));
132
133 $this->fixture->setFieldName('name');
134 $this->fixture->injectRequestHandler($requestHandlerMock);
135
136 $this->assertFalse(
137 $this->fixture->isValid()
138 );
139 }
140
141 /**
142 * @test
143 * @dataProvider invalidDataProviderWithWhitespace
144 */
145 public function isValidForInvalidInputWithWhitespaceAllowedReturnsFalse($input) {
146 $requestHandlerMock = $this->helper->getRequestHandler(array(
147 'name' => $input
148 ));
149
150 $this->fixture->setAllowWhiteSpace(TRUE);
151 $this->fixture->setFieldName('name');
152 $this->fixture->injectRequestHandler($requestHandlerMock);
153
154 $this->assertFalse(
155 $this->fixture->isValid()
156 );
157 }
158 }