14e143e42697a5ccaa410c2045678d22503bdc9c
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Validation / ValidatorResolverTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Validation;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * This class is a backport of the corresponding class of TYPO3 Flow.
8 * All credits go to the TYPO3 Flow team.
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 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 /**
31 * Testcase for the validator resolver
32 */
33 class ValidatorResolverTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
34
35 /**
36 * @test
37 */
38 public function resolveValidatorObjectNameReturnsFalseIfValidatorCantBeResolved() {
39 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
40 /** @var \TYPO3\CMS\Extbase\Validation\ValidatorResolver|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
41 $validatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
42 $validatorResolver->_set('objectManager', $mockObjectManager);
43 $this->assertFalse($validatorResolver->_call('resolveValidatorObjectName', 'Foo'));
44 }
45
46 /**
47 * @test
48 */
49 public function resolveValidatorObjectNameReturnsTheGivenArgumentIfAnObjectOfThatNameIsRegistered() {
50 $validatorName = uniqid('FooValidator_') . 'Validator';
51 eval('class ' . $validatorName . ' {}');
52 $validatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
53 $this->assertSame($validatorName, $validatorResolver->_call('resolveValidatorObjectName', $validatorName));
54 }
55
56 /**
57 * @test
58 */
59 public function resolveValidatorObjectNameReturnsTheGivenArgumentIfANamespacedObjectOfThatNameIsRegistered() {
60 $namespace = 'Acme\\Bar';
61 $className = uniqid('FooValidator') . 'Validator';
62 $validatorName = $namespace . '\\' . $className;
63 eval('namespace ' . $namespace . '; ' . LF . 'class ' . $className . ' {}');
64 $validatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
65 $this->assertSame($validatorName, $validatorResolver->_call('resolveValidatorObjectName', $validatorName));
66 }
67
68 /**
69 * @test
70 */
71 public function resolveValidatorObjectNameCanResolveShorthandNotNamespacedValidatorNames() {
72 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
73 eval('class Tx_Mypkg_Validation_Validator_MyFirstValidator {}');
74 $validatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
75 $validatorResolver->_set('objectManager', $mockObjectManager);
76 $this->assertSame('Tx_Mypkg_Validation_Validator_MyFirstValidator', $validatorResolver->_call('resolveValidatorObjectName', 'Mypkg:MyFirst'));
77 }
78
79 /**
80 * @return array
81 */
82 public function namespacedShorthandValidatornames() {
83 return array(
84 array('TYPO3\\CMS\\Mypkg\\Validation\\Validator', 'MySecondValidator', 'TYPO3.CMS.Mypkg:MySecond'),
85 array('Acme\\Mypkg\\Validation\\Validator', 'MyThirdValidator', 'Acme.Mypkg:MyThird')
86 );
87 }
88
89 /**
90 * @test
91 * @dataProvider namespacedShorthandValidatornames
92 */
93 public function resolveValidatorObjectNameCanResolveNamespacedShorthandValidatornames($namespace, $className, $shorthandValidatorname) {
94 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
95 eval('namespace ' . $namespace . '; class ' . $className . ' {}');
96 $validatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
97 $validatorResolver->_set('objectManager', $mockObjectManager);
98 $this->assertSame($namespace . '\\' . $className, $validatorResolver->_call('resolveValidatorObjectName', $shorthandValidatorname));
99 }
100
101 /**
102 * @test
103 */
104 public function resolveValidatorObjectNameCanResolveShortNamesOfBuiltInValidators() {
105 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
106 eval('namespace TYPO3\\CMS\\Extbase\\Validation\\Validator; class FooValidator {}');
107 $validatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
108 $validatorResolver->_set('objectManager', $mockObjectManager);
109 $this->assertSame('TYPO3\\CMS\\Extbase\\Validation\\Validator\\FooValidator', $validatorResolver->_call('resolveValidatorObjectName', 'Foo'));
110 }
111
112 /**
113 * @test
114 */
115 public function createValidatorResolvesAndReturnsAValidatorAndPassesTheGivenOptions() {
116 $className = uniqid('Test');
117 $mockValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ObjectValidatorInterface', array('setOptions', 'canValidate', 'isPropertyValid'), array(), $className);
118 $mockValidator->expects($this->once())->method('setOptions')->with(array('foo' => 'bar'));
119 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
120 $mockObjectManager->expects($this->any())->method('get')->with($className)->will($this->returnValue($mockValidator));
121 $validatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('resolveValidatorObjectName'));
122 $validatorResolver->_set('objectManager', $mockObjectManager);
123 $validatorResolver->expects($this->once())->method('resolveValidatorObjectName')->with($className)->will($this->returnValue($className));
124 $validator = $validatorResolver->createValidator($className, array('foo' => 'bar'));
125 $this->assertSame($mockValidator, $validator);
126 }
127
128 /**
129 * @test
130 */
131 public function createValidatorReturnsNullIfAValidatorCouldNotBeResolved() {
132 $validatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('resolveValidatorObjectName'), array(), '', FALSE);
133 $validatorResolver->expects($this->once())->method('resolveValidatorObjectName')->with('Foo')->will($this->returnValue(FALSE));
134 $validator = $validatorResolver->createValidator('Foo', array('foo' => 'bar'));
135 $this->assertNull($validator);
136 }
137
138 /**
139 * @test
140 */
141 public function getBaseValidatorCachesTheResultOfTheBuildBaseValidatorChainCalls() {
142 $mockConjunctionValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
143 $validatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('buildBaseValidatorConjunction'), array(), '', FALSE);
144 $validatorResolver->expects($this->once())->method('buildBaseValidatorConjunction')->with('Tx_Virtual_Foo')->will($this->returnValue($mockConjunctionValidator));
145 $result = $validatorResolver->getBaseValidatorConjunction('Tx_Virtual_Foo');
146 $this->assertSame($mockConjunctionValidator, $result, '#1');
147 $result = $validatorResolver->getBaseValidatorConjunction('Tx_Virtual_Foo');
148 $this->assertSame($mockConjunctionValidator, $result, '#2');
149 }
150
151 /**
152 * @test
153 * @author Sebastian Kurfürst <sbastian@typo3.org>
154 */
155 public function buildMethodArgumentsValidatorConjunctionsReturnsEmptyArrayIfMethodHasNoArguments() {
156 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction'), array(), '', FALSE);
157 $methodTagsValues = array();
158 $methodParameters = array();
159 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
160 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
161 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
162 $validatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('createValidator'));
163 $validatorResolver->injectReflectionService($mockReflectionService);
164 $result = $validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($mockController), 'fooAction');
165 $this->assertSame(array(), $result);
166 }
167
168 /**
169 * @test
170 * @author Robert Lemke <robert@typo3.org>
171 * @author Bastian Waidelich <bastian@typo3.org>
172 */
173 public function buildMethodArgumentsValidatorConjunctionsBuildsAConjunctionFromValidateAnnotationsOfTheSpecifiedMethod() {
174 $mockObject = $this->getMock('stdClass', array('fooMethod'), array(), '', FALSE);
175 $methodParameters = array(
176 'arg1' => array(
177 'type' => 'string'
178 ),
179 'arg2' => array(
180 'type' => 'array'
181 )
182 );
183 $methodTagsValues = array(
184 'param' => array(
185 'string $arg1',
186 'array $arg2'
187 ),
188 'validate' => array(
189 '$arg1 Foo(bar = baz), Bar',
190 '$arg2 F3_TestPackage_Quux'
191 )
192 );
193 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
194 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockObject), 'fooAction')->will($this->returnValue($methodTagsValues));
195 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockObject), 'fooAction')->will($this->returnValue($methodParameters));
196 $mockStringValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
197 $mockArrayValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
198 $mockFooValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
199 $mockBarValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
200 $mockQuuxValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
201 $conjunction1 = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
202 $conjunction1->expects($this->at(0))->method('addValidator')->with($mockStringValidator);
203 $conjunction1->expects($this->at(1))->method('addValidator')->with($mockFooValidator);
204 $conjunction1->expects($this->at(2))->method('addValidator')->with($mockBarValidator);
205 $conjunction2 = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
206 $conjunction2->expects($this->at(0))->method('addValidator')->with($mockArrayValidator);
207 $conjunction2->expects($this->at(1))->method('addValidator')->with($mockQuuxValidator);
208 $mockObjectFactory = $this->getMock('Tx_Extbase_Object_FactoryInterface');
209 $mockArguments = new \TYPO3\CMS\Extbase\Mvc\Controller\Arguments();
210 $mockArguments->addArgument(new \TYPO3\CMS\Extbase\Mvc\Controller\Argument('arg1', 'dummyValue'));
211 $mockArguments->addArgument(new \TYPO3\CMS\Extbase\Mvc\Controller\Argument('arg2', 'dummyValue'));
212 $validatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('createValidator'));
213 $validatorResolver->expects($this->at(0))->method('createValidator')->with('Conjunction')->will($this->returnValue($conjunction1));
214 $validatorResolver->expects($this->at(1))->method('createValidator')->with('string')->will($this->returnValue($mockStringValidator));
215 $validatorResolver->expects($this->at(2))->method('createValidator')->with('Conjunction')->will($this->returnValue($conjunction2));
216 $validatorResolver->expects($this->at(3))->method('createValidator')->with('array')->will($this->returnValue($mockArrayValidator));
217 $validatorResolver->expects($this->at(4))->method('createValidator')->with('Foo', array('bar' => 'baz'))->will($this->returnValue($mockFooValidator));
218 $validatorResolver->expects($this->at(5))->method('createValidator')->with('Bar')->will($this->returnValue($mockBarValidator));
219 $validatorResolver->expects($this->at(6))->method('createValidator')->with('F3_TestPackage_Quux')->will($this->returnValue($mockQuuxValidator));
220 $validatorResolver->injectReflectionService($mockReflectionService);
221 $result = $validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($mockObject), 'fooAction');
222 $this->assertEquals(array('arg1' => $conjunction1, 'arg2' => $conjunction2), $result);
223 }
224
225 /**
226 * @test
227 * @author Sebastian Kurfürst <sbastian@typo3.org>
228 * @expectedException \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationConfigurationException
229 */
230 public function buildMethodArgumentsValidatorConjunctionsThrowsExceptionIfValidationAnnotationForNonExistingArgumentExists() {
231 $mockObject = $this->getMock('stdClass', array('fooMethod'), array(), '', FALSE);
232 $methodParameters = array(
233 'arg1' => array(
234 'type' => 'string'
235 )
236 );
237 $methodTagsValues = array(
238 'param' => array(
239 'string $arg1'
240 ),
241 'validate' => array(
242 '$arg2 F3_TestPackage_Quux'
243 )
244 );
245 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
246 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockObject), 'fooAction')->will($this->returnValue($methodTagsValues));
247 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockObject), 'fooAction')->will($this->returnValue($methodParameters));
248 $mockStringValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
249 $mockQuuxValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
250 $conjunction1 = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
251 $conjunction1->expects($this->at(0))->method('addValidator')->with($mockStringValidator);
252 $validatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('createValidator'));
253 $validatorResolver->expects($this->at(0))->method('createValidator')->with('Conjunction')->will($this->returnValue($conjunction1));
254 $validatorResolver->expects($this->at(1))->method('createValidator')->with('string')->will($this->returnValue($mockStringValidator));
255 $validatorResolver->expects($this->at(2))->method('createValidator')->with('F3_TestPackage_Quux')->will($this->returnValue($mockQuuxValidator));
256 $validatorResolver->injectReflectionService($mockReflectionService);
257 $validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($mockObject), 'fooAction');
258 }
259
260 /**
261 * @test
262 * @author Robert Lemke <robert@typo3.org>
263 * @author Christopher Hlubek <hlubek@networkteam.com>
264 */
265 public function buildBaseValidatorConjunctionAddsValidatorsDefinedByAnnotationsInTheClassToTheReturnedConjunction() {
266 $mockObject = $this->getMock('stdClass');
267 $className = get_class($mockObject);
268 $propertyTagsValues = array(
269 'foo' => array(
270 'var' => array('string'),
271 'validate' => array(
272 'Foo(bar = baz), Bar',
273 'Baz'
274 )
275 ),
276 'bar' => array(
277 'var' => array('integer'),
278 'validate' => array(
279 'F3_TestPackage_Quux'
280 )
281 )
282 );
283 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array(), array(), '', FALSE);
284 $mockReflectionService->expects($this->at(0))->method('getClassPropertyNames')->with($className)->will($this->returnValue(array('foo', 'bar')));
285 $mockReflectionService->expects($this->at(1))->method('getPropertyTagsValues')->with($className, 'foo')->will($this->returnValue($propertyTagsValues['foo']));
286 $mockReflectionService->expects($this->at(2))->method('getPropertyTagsValues')->with($className, 'bar')->will($this->returnValue($propertyTagsValues['bar']));
287 $mockObjectValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\GenericObjectValidator', array(), array(), '', FALSE);
288 $mockConjunctionValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
289 $mockConjunctionValidator->expects($this->once())->method('addValidator')->with($mockObjectValidator);
290 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
291 $mockObjectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator')->will($this->returnValue($mockConjunctionValidator));
292 $validatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('resolveValidatorObjectName', 'createValidator'));
293 $validatorResolver->injectReflectionService($mockReflectionService);
294 $validatorResolver->injectObjectManager($mockObjectManager);
295 $validatorResolver->expects($this->at(0))->method('createValidator')->with('GenericObject')->will($this->returnValue($mockObjectValidator));
296 $validatorResolver->expects($this->at(1))->method('createValidator')->with('Foo', array('bar' => 'baz'))->will($this->returnValue($mockObjectValidator));
297 $validatorResolver->expects($this->at(2))->method('createValidator')->with('Bar')->will($this->returnValue($mockObjectValidator));
298 $validatorResolver->expects($this->at(3))->method('createValidator')->with('Baz')->will($this->returnValue($mockObjectValidator));
299 $validatorResolver->expects($this->at(4))->method('createValidator')->with('F3_TestPackage_Quux')->will($this->returnValue($mockObjectValidator));
300 $validatorResolver->expects($this->at(5))->method('createValidator')->with($className . 'Validator')->will($this->returnValue(NULL));
301 $result = $validatorResolver->_call('buildBaseValidatorConjunction', $className);
302 $this->assertSame($mockConjunctionValidator, $result);
303 }
304
305 /**
306 * @test
307 * @author Bastian Waidelich <bastian@typo3.org>
308 */
309 public function resolveValidatorObjectNameCallsUnifyDataType() {
310 $mockValidatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('unifyDataType'));
311 $mockValidatorResolver->expects($this->any())->method('unifyDataType')->with('someDataType');
312 $mockValidatorResolver->_call('resolveValidatorObjectName', 'someDataType');
313 }
314
315 /**
316 * @test
317 * @author Bastian Waidelich <bastian@typo3.org>
318 */
319 public function unifyDataTypeCorrectlyRenamesPhpDataTypes() {
320 $mockValidatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
321 $this->assertEquals('Integer', $mockValidatorResolver->_call('unifyDataType', 'integer'));
322 $this->assertEquals('Integer', $mockValidatorResolver->_call('unifyDataType', 'int'));
323 $this->assertEquals('String', $mockValidatorResolver->_call('unifyDataType', 'string'));
324 $this->assertEquals('Array', $mockValidatorResolver->_call('unifyDataType', 'array'));
325 $this->assertEquals('Float', $mockValidatorResolver->_call('unifyDataType', 'float'));
326 $this->assertEquals('Float', $mockValidatorResolver->_call('unifyDataType', 'double'));
327 $this->assertEquals('Boolean', $mockValidatorResolver->_call('unifyDataType', 'boolean'));
328 $this->assertEquals('Boolean', $mockValidatorResolver->_call('unifyDataType', 'bool'));
329 $this->assertEquals('Boolean', $mockValidatorResolver->_call('unifyDataType', 'bool'));
330 $this->assertEquals('Number', $mockValidatorResolver->_call('unifyDataType', 'number'));
331 $this->assertEquals('Number', $mockValidatorResolver->_call('unifyDataType', 'numeric'));
332 }
333
334 /**
335 * @test
336 * @author Bastian Waidelich <bastian@typo3.org>
337 */
338 public function unifyDataTypeRenamesMixedToRaw() {
339 $mockValidator = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
340 $this->assertEquals('Raw', $mockValidator->_call('unifyDataType', 'mixed'));
341 }
342
343 /**
344 * dataProvider for parseValidatorAnnotationCanParseAnnotations
345 *
346 * @author Karsten Dambekalns <karsten@typo3.org>
347 * @author Christopher Hlubek <hlubek@networkteam.com>
348 * @return array
349 */
350 public function validatorAnnotations() {
351 return array(
352 array(
353 '$var Bar',
354 array(
355 'argumentName' => 'var',
356 'validators' => array(
357 array('validatorName' => 'Bar', 'validatorOptions' => array())
358 )
359 )
360 ),
361 array(
362 '$var Bar, Foo',
363 array(
364 'argumentName' => 'var',
365 'validators' => array(
366 array('validatorName' => 'Bar', 'validatorOptions' => array()),
367 array('validatorName' => 'Foo', 'validatorOptions' => array())
368 )
369 )
370 ),
371 array(
372 '$var Baz (Foo=Bar)',
373 array(
374 'argumentName' => 'var',
375 'validators' => array(
376 array('validatorName' => 'Baz', 'validatorOptions' => array('Foo' => 'Bar'))
377 )
378 )
379 ),
380 array(
381 '$var Buzz (Foo="B=a, r", Baz=1)',
382 array(
383 'argumentName' => 'var',
384 'validators' => array(
385 array('validatorName' => 'Buzz', 'validatorOptions' => array('Foo' => 'B=a, r', 'Baz' => '1'))
386 )
387 )
388 ),
389 array(
390 '$var Foo(Baz=1, Bar=Quux)',
391 array(
392 'argumentName' => 'var',
393 'validators' => array(
394 array('validatorName' => 'Foo', 'validatorOptions' => array('Baz' => '1', 'Bar' => 'Quux'))
395 )
396 )
397 ),
398 array(
399 '$var Pax, Foo(Baz = \'1\', Bar = Quux)',
400 array(
401 'argumentName' => 'var',
402 'validators' => array(
403 array('validatorName' => 'Pax', 'validatorOptions' => array()),
404 array('validatorName' => 'Foo', 'validatorOptions' => array('Baz' => '1', 'Bar' => 'Quux'))
405 )
406 )
407 ),
408 array(
409 '$var Reg (P="[at]*(h|g)"), Quux',
410 array(
411 'argumentName' => 'var',
412 'validators' => array(
413 array('validatorName' => 'Reg', 'validatorOptions' => array('P' => '[at]*(h|g)')),
414 array('validatorName' => 'Quux', 'validatorOptions' => array())
415 )
416 )
417 ),
418 array(
419 '$var Baz (Foo="B\\"ar")',
420 array(
421 'argumentName' => 'var',
422 'validators' => array(
423 array('validatorName' => 'Baz', 'validatorOptions' => array('Foo' => 'B"ar'))
424 )
425 )
426 ),
427 array(
428 '$var F3_TestPackage_Quux',
429 array(
430 'argumentName' => 'var',
431 'validators' => array(
432 array('validatorName' => 'F3_TestPackage_Quux', 'validatorOptions' => array())
433 )
434 )
435 ),
436 array(
437 '$var Baz(Foo="5"), Bar(Quux="123")',
438 array(
439 'argumentName' => 'var',
440 'validators' => array(
441 array('validatorName' => 'Baz', 'validatorOptions' => array('Foo' => '5')),
442 array('validatorName' => 'Bar', 'validatorOptions' => array('Quux' => '123'))
443 )
444 )
445 ),
446 array(
447 '$var Baz(Foo="2"), Bar(Quux=123, Pax="a weird \\"string\\" with *freaky* \\stuff")',
448 array(
449 'argumentName' => 'var',
450 'validators' => array(
451 array('validatorName' => 'Baz', 'validatorOptions' => array('Foo' => '2')),
452 array('validatorName' => 'Bar', 'validatorOptions' => array('Quux' => '123', 'Pax' => 'a weird "string" with *freaky* \\stuff'))
453 )
454 )
455 )
456 );
457 }
458
459 /**
460 * @test
461 * @dataProvider validatorAnnotations
462 * @author Karsten Dambekalns <karsten@typo3.org>
463 * @param mixed $annotation
464 * @param mixed $expectedResult
465 */
466 public function parseValidatorAnnotationCanParseAnnotations($annotation, $expectedResult) {
467 $mockValidatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
468 $result = $mockValidatorResolver->_call('parseValidatorAnnotation', $annotation);
469 $this->assertEquals($result, $expectedResult);
470 }
471
472 }
473
474
475 ?>