[TASK] Better mocking of $GLOBALS['LANG']
[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
30 */
31 class AlphabeticValidatorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
32 /**
33 * @var \TYPO3\CMS\Form\Tests\Unit\Validation\Helper
34 */
35 protected $helper;
36
37 /**
38 * @var \TYPO3\CMS\Form\Validation\AlphabeticValidator
39 */
40 protected $subject;
41
42 /**
43 * Set up
44 */
45 public function setUp() {
46 $this->helper = new \TYPO3\CMS\Form\Tests\Unit\Validation\Helper();
47 $this->subject = $this->getMock('TYPO3\\CMS\\Form\\Validation\\AlphabeticValidator', array('dummy'), array(), '', FALSE);
48 }
49
50 /**
51 * Tear down
52 */
53 public function tearDown() {
54 unset($this->helper, $this->subject);
55 }
56
57 /**
58 * @return array
59 */
60 public function validDataProviderWithoutWhitespace() {
61 return array(
62 'ascii without spaces' => array('thisismyinput'),
63 'accents without spaces' => array('éóéàèò'),
64 'umlauts without spaces' => array('üöä'),
65 'empty string' => array('')
66 );
67 }
68
69 /**
70 * @return array
71 */
72 public function validDataProviderWithWhitespace() {
73 return array(
74 'ascii with spaces' => array('This is my input'),
75 'accents with spaces' => array('Sigur Rós'),
76 'umlauts with spaces' => array('Hürriyet Daily News'),
77 'space' => array(' '),
78 'empty string' => array('')
79 );
80 }
81
82 /**
83 * @return array
84 */
85 public function invalidDataProviderWithoutWhitespace() {
86 return array(
87 'ascii with dash' => array('my-name'),
88 'accents with underscore' => array('Sigur_Rós'),
89 'umlauts with periods' => array('Hürriyet.Daily.News'),
90 'space' => array(' '),
91 );
92 }
93
94 /**
95 * @return array
96 */
97 public function invalidDataProviderWithWhitespace() {
98 return array(
99 'ascii with spaces and dashes' => array('This is my-name'),
100 'accents with spaces and underscores' => array('Listen to Sigur_Rós_Band'),
101 'umlauts with spaces and periods' => array('Go get the Hürriyet.Daily.News')
102 );
103 }
104
105 /**
106 * @test
107 * @dataProvider validDataProviderWithoutWhitespace
108 */
109 public function isValidForValidInputWithoutAllowedWhitespaceReturnsTrue($input) {
110 $requestHandlerMock = $this->helper->getRequestHandler(array(
111 'name' => $input
112 ));
113
114 $this->subject->setFieldName('name');
115 $this->subject->injectRequestHandler($requestHandlerMock);
116
117 $this->assertTrue(
118 $this->subject->isValid()
119 );
120 }
121
122 /**
123 * @test
124 * @dataProvider validDataProviderWithWhitespace
125 */
126 public function isValidForValidInputWithWhitespaceAllowedReturnsTrue($input) {
127 $requestHandlerMock = $this->helper->getRequestHandler(array(
128 'name' => $input
129 ));
130
131 $this->subject->setAllowWhiteSpace(TRUE);
132 $this->subject->setFieldName('name');
133 $this->subject->injectRequestHandler($requestHandlerMock);
134
135 $this->assertTrue(
136 $this->subject->isValid()
137 );
138 }
139
140 /**
141 * @test
142 * @dataProvider invalidDataProviderWithoutWhitespace
143 */
144 public function isValidForInvalidInputWithoutAllowedWhitespaceReturnsFalse($input) {
145 $requestHandlerMock = $this->helper->getRequestHandler(array(
146 'name' => $input
147 ));
148
149 $this->subject->setFieldName('name');
150 $this->subject->injectRequestHandler($requestHandlerMock);
151
152 $this->assertFalse(
153 $this->subject->isValid()
154 );
155 }
156
157 /**
158 * @test
159 * @dataProvider invalidDataProviderWithWhitespace
160 */
161 public function isValidForInvalidInputWithWhitespaceAllowedReturnsFalse($input) {
162 $requestHandlerMock = $this->helper->getRequestHandler(array(
163 'name' => $input
164 ));
165
166 $this->subject->setAllowWhiteSpace(TRUE);
167 $this->subject->setFieldName('name');
168 $this->subject->injectRequestHandler($requestHandlerMock);
169
170 $this->assertFalse(
171 $this->subject->isValid()
172 );
173 }
174 }