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