bfcbf4ce77b1dbdf26c5e8b73f73a5baaf7a99b0
[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', $objectManager);
42 $this->assertSame(FALSE, $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 resolveValidatorObjectNameCanResolveShorthandValidatornames() {
59 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
60 eval('class Tx_Mypkg_Validation_Validator_MyValidator {}');
61 $validatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
62 $validatorResolver->_set('objectManager', $mockObjectManager);
63 $this->assertSame('Tx_Mypkg_Validation_Validator_MyValidator', $validatorResolver->_call('resolveValidatorObjectName', 'Mypkg:My'));
64 }
65
66 /**
67 * @test
68 */
69 public function resolveValidatorObjectNameCanResolveShortNamesOfBuiltInValidators() {
70 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
71 eval('class Tx_Extbase_Validation_Validator_FooValidator {}');
72 $validatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
73 $validatorResolver->_set('objectManager', $mockObjectManager);
74 $this->assertSame('Tx_Extbase_Validation_Validator_FooValidator', $validatorResolver->_call('resolveValidatorObjectName', 'Foo'));
75 }
76
77 /**
78 * @test
79 */
80 public function createValidatorResolvesAndReturnsAValidatorAndPassesTheGivenOptions() {
81 $className = uniqid('Test');
82 $mockValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ObjectValidatorInterface', array('setOptions', 'canValidate', 'isPropertyValid'), array(), $className);
83 $mockValidator->expects($this->once())->method('setOptions')->with(array('foo' => 'bar'));
84 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
85 $mockObjectManager->expects($this->any())->method('get')->with($className)->will($this->returnValue($mockValidator));
86 $validatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('resolveValidatorObjectName'));
87 $validatorResolver->_set('objectManager', $mockObjectManager);
88 $validatorResolver->expects($this->once())->method('resolveValidatorObjectName')->with($className)->will($this->returnValue($className));
89 $validator = $validatorResolver->createValidator($className, array('foo' => 'bar'));
90 $this->assertSame($mockValidator, $validator);
91 }
92
93 /**
94 * @test
95 */
96 public function createValidatorReturnsNullIfAValidatorCouldNotBeResolved() {
97 $validatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('resolveValidatorObjectName'), array(), '', FALSE);
98 $validatorResolver->expects($this->once())->method('resolveValidatorObjectName')->with('Foo')->will($this->returnValue(FALSE));
99 $validator = $validatorResolver->createValidator('Foo', array('foo' => 'bar'));
100 $this->assertNull($validator);
101 }
102
103 /**
104 * @test
105 */
106 public function getBaseValidatorCachesTheResultOfTheBuildBaseValidatorChainCalls() {
107 $mockConjunctionValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
108 $validatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('buildBaseValidatorConjunction'), array(), '', FALSE);
109 $validatorResolver->expects($this->once())->method('buildBaseValidatorConjunction')->with('Tx_Virtual_Foo')->will($this->returnValue($mockConjunctionValidator));
110 $result = $validatorResolver->getBaseValidatorConjunction('Tx_Virtual_Foo');
111 $this->assertSame($mockConjunctionValidator, $result, '#1');
112 $result = $validatorResolver->getBaseValidatorConjunction('Tx_Virtual_Foo');
113 $this->assertSame($mockConjunctionValidator, $result, '#2');
114 }
115
116 /**
117 * @test
118 * @author Sebastian Kurfürst <sbastian@typo3.org>
119 */
120 public function buildMethodArgumentsValidatorConjunctionsReturnsEmptyArrayIfMethodHasNoArguments() {
121 $mockController = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ActionController', array('fooAction'), array(), '', FALSE);
122 $methodTagsValues = array();
123 $methodParameters = array();
124 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\Service', array(), array(), '', FALSE);
125 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodTagsValues));
126 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockController), 'fooAction')->will($this->returnValue($methodParameters));
127 $validatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('createValidator'));
128 $validatorResolver->injectReflectionService($mockReflectionService);
129 $result = $validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($mockController), 'fooAction');
130 $this->assertSame(array(), $result);
131 }
132
133 /**
134 * @test
135 * @author Robert Lemke <robert@typo3.org>
136 * @author Bastian Waidelich <bastian@typo3.org>
137 */
138 public function buildMethodArgumentsValidatorConjunctionsBuildsAConjunctionFromValidateAnnotationsOfTheSpecifiedMethod() {
139 $mockObject = $this->getMock('stdClass', array('fooMethod'), array(), '', FALSE);
140 $methodParameters = array(
141 'arg1' => array(
142 'type' => 'string'
143 ),
144 'arg2' => array(
145 'type' => 'array'
146 )
147 );
148 $methodTagsValues = array(
149 'param' => array(
150 'string $arg1',
151 'array $arg2'
152 ),
153 'validate' => array(
154 '$arg1 Foo(bar = baz), Bar',
155 '$arg2 F3_TestPackage_Quux'
156 )
157 );
158 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\Service', array(), array(), '', FALSE);
159 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockObject), 'fooAction')->will($this->returnValue($methodTagsValues));
160 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockObject), 'fooAction')->will($this->returnValue($methodParameters));
161 $mockStringValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
162 $mockArrayValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
163 $mockFooValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
164 $mockBarValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
165 $mockQuuxValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
166 $conjunction1 = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
167 $conjunction1->expects($this->at(0))->method('addValidator')->with($mockStringValidator);
168 $conjunction1->expects($this->at(1))->method('addValidator')->with($mockFooValidator);
169 $conjunction1->expects($this->at(2))->method('addValidator')->with($mockBarValidator);
170 $conjunction2 = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
171 $conjunction2->expects($this->at(0))->method('addValidator')->with($mockArrayValidator);
172 $conjunction2->expects($this->at(1))->method('addValidator')->with($mockQuuxValidator);
173 $mockObjectFactory = $this->getMock('Tx_Extbase_Object_FactoryInterface');
174 $mockArguments = new \TYPO3\CMS\Extbase\Mvc\Controller\Arguments();
175 $mockArguments->addArgument(new \TYPO3\CMS\Extbase\Mvc\Controller\Argument('arg1', 'dummyValue'));
176 $mockArguments->addArgument(new \TYPO3\CMS\Extbase\Mvc\Controller\Argument('arg2', 'dummyValue'));
177 $validatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('createValidator'));
178 $validatorResolver->expects($this->at(0))->method('createValidator')->with('Conjunction')->will($this->returnValue($conjunction1));
179 $validatorResolver->expects($this->at(1))->method('createValidator')->with('string')->will($this->returnValue($mockStringValidator));
180 $validatorResolver->expects($this->at(2))->method('createValidator')->with('Conjunction')->will($this->returnValue($conjunction2));
181 $validatorResolver->expects($this->at(3))->method('createValidator')->with('array')->will($this->returnValue($mockArrayValidator));
182 $validatorResolver->expects($this->at(4))->method('createValidator')->with('Foo', array('bar' => 'baz'))->will($this->returnValue($mockFooValidator));
183 $validatorResolver->expects($this->at(5))->method('createValidator')->with('Bar')->will($this->returnValue($mockBarValidator));
184 $validatorResolver->expects($this->at(6))->method('createValidator')->with('F3_TestPackage_Quux')->will($this->returnValue($mockQuuxValidator));
185 $validatorResolver->injectReflectionService($mockReflectionService);
186 $result = $validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($mockObject), 'fooAction');
187 $this->assertEquals(array('arg1' => $conjunction1, 'arg2' => $conjunction2), $result);
188 }
189
190 /**
191 * @test
192 * @author Sebastian Kurfürst <sbastian@typo3.org>
193 * @expectedException \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationConfigurationException
194 */
195 public function buildMethodArgumentsValidatorConjunctionsThrowsExceptionIfValidationAnnotationForNonExistingArgumentExists() {
196 $mockObject = $this->getMock('stdClass', array('fooMethod'), array(), '', FALSE);
197 $methodParameters = array(
198 'arg1' => array(
199 'type' => 'string'
200 )
201 );
202 $methodTagsValues = array(
203 'param' => array(
204 'string $arg1'
205 ),
206 'validate' => array(
207 '$arg2 F3_TestPackage_Quux'
208 )
209 );
210 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\Service', array(), array(), '', FALSE);
211 $mockReflectionService->expects($this->once())->method('getMethodTagsValues')->with(get_class($mockObject), 'fooAction')->will($this->returnValue($methodTagsValues));
212 $mockReflectionService->expects($this->once())->method('getMethodParameters')->with(get_class($mockObject), 'fooAction')->will($this->returnValue($methodParameters));
213 $mockStringValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
214 $mockQuuxValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ValidatorInterface', array(), array(), '', FALSE);
215 $conjunction1 = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
216 $conjunction1->expects($this->at(0))->method('addValidator')->with($mockStringValidator);
217 $validatorResolver = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('createValidator'));
218 $validatorResolver->expects($this->at(0))->method('createValidator')->with('Conjunction')->will($this->returnValue($conjunction1));
219 $validatorResolver->expects($this->at(1))->method('createValidator')->with('string')->will($this->returnValue($mockStringValidator));
220 $validatorResolver->expects($this->at(2))->method('createValidator')->with('F3_TestPackage_Quux')->will($this->returnValue($mockQuuxValidator));
221 $validatorResolver->injectReflectionService($mockReflectionService);
222 $validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($mockObject), 'fooAction');
223 }
224
225 /**
226 * @test
227 * @author Robert Lemke <robert@typo3.org>
228 * @author Christopher Hlubek <hlubek@networkteam.com>
229 */
230 public function buildBaseValidatorConjunctionAddsValidatorsDefinedByAnnotationsInTheClassToTheReturnedConjunction() {
231 $mockObject = $this->getMock('stdClass');
232 $className = get_class($mockObject);
233 $propertyTagsValues = array(
234 'foo' => array(
235 'var' => array('string'),
236 'validate' => array(
237 'Foo(bar = baz), Bar',
238 'Baz'
239 )
240 ),
241 'bar' => array(
242 'var' => array('integer'),
243 'validate' => array(
244 'F3_TestPackage_Quux'
245 )
246 )
247 );
248 $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\Service', array(), array(), '', FALSE);
249 $mockReflectionService->expects($this->at(0))->method('getClassPropertyNames')->with($className)->will($this->returnValue(array('foo', 'bar')));
250 $mockReflectionService->expects($this->at(1))->method('getPropertyTagsValues')->with($className, 'foo')->will($this->returnValue($propertyTagsValues['foo']));
251 $mockReflectionService->expects($this->at(2))->method('getPropertyTagsValues')->with($className, 'bar')->will($this->returnValue($propertyTagsValues['bar']));
252 $mockObjectValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\GenericObjectValidator', array(), array(), '', FALSE);
253 $mockConjunctionValidator = $this->getMock('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator', array(), array(), '', FALSE);
254 $mockConjunctionValidator->expects($this->once())->method('addValidator')->with($mockObjectValidator);
255 $mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface', array(), array(), '', FALSE);
256 $mockObjectManager->expects($this->at(0))->method('get')->with('TYPO3\\CMS\\Extbase\\Validation\\Validator\\ConjunctionValidator')->will($this->returnValue($mockConjunctionValidator));
257 $validatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('resolveValidatorObjectName', 'createValidator'));
258 $validatorResolver->injectReflectionService($mockReflectionService);
259 $validatorResolver->injectObjectManager($mockObjectManager);
260 $validatorResolver->expects($this->at(0))->method('createValidator')->with('GenericObject')->will($this->returnValue($mockObjectValidator));
261 $validatorResolver->expects($this->at(1))->method('createValidator')->with('Foo', array('bar' => 'baz'))->will($this->returnValue($mockObjectValidator));
262 $validatorResolver->expects($this->at(2))->method('createValidator')->with('Bar')->will($this->returnValue($mockObjectValidator));
263 $validatorResolver->expects($this->at(3))->method('createValidator')->with('Baz')->will($this->returnValue($mockObjectValidator));
264 $validatorResolver->expects($this->at(4))->method('createValidator')->with('F3_TestPackage_Quux')->will($this->returnValue($mockObjectValidator));
265 $validatorResolver->expects($this->at(5))->method('createValidator')->with($className . 'Validator')->will($this->returnValue(NULL));
266 $result = $validatorResolver->_call('buildBaseValidatorConjunction', $className);
267 $this->assertSame($mockConjunctionValidator, $result);
268 }
269
270 /**
271 * @test
272 * @author Bastian Waidelich <bastian@typo3.org>
273 */
274 public function resolveValidatorObjectNameCallsUnifyDataType() {
275 $mockValidatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('unifyDataType'));
276 $mockValidatorResolver->expects($this->once())->method('unifyDataType')->with('someDataType');
277 $mockValidatorResolver->_call('resolveValidatorObjectName', 'someDataType');
278 }
279
280 /**
281 * @test
282 * @author Bastian Waidelich <bastian@typo3.org>
283 */
284 public function unifyDataTypeCorrectlyRenamesPhpDataTypes() {
285 $mockValidatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
286 $this->assertEquals('Integer', $mockValidatorResolver->_call('unifyDataType', 'integer'));
287 $this->assertEquals('Integer', $mockValidatorResolver->_call('unifyDataType', 'int'));
288 $this->assertEquals('String', $mockValidatorResolver->_call('unifyDataType', 'string'));
289 $this->assertEquals('Array', $mockValidatorResolver->_call('unifyDataType', 'array'));
290 $this->assertEquals('Float', $mockValidatorResolver->_call('unifyDataType', 'float'));
291 $this->assertEquals('Float', $mockValidatorResolver->_call('unifyDataType', 'double'));
292 $this->assertEquals('Boolean', $mockValidatorResolver->_call('unifyDataType', 'boolean'));
293 $this->assertEquals('Boolean', $mockValidatorResolver->_call('unifyDataType', 'bool'));
294 $this->assertEquals('Boolean', $mockValidatorResolver->_call('unifyDataType', 'bool'));
295 $this->assertEquals('Number', $mockValidatorResolver->_call('unifyDataType', 'number'));
296 $this->assertEquals('Number', $mockValidatorResolver->_call('unifyDataType', 'numeric'));
297 }
298
299 /**
300 * @test
301 * @author Bastian Waidelich <bastian@typo3.org>
302 */
303 public function unifyDataTypeRenamesMixedToRaw() {
304 $mockValidator = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
305 $this->assertEquals('Raw', $mockValidator->_call('unifyDataType', 'mixed'));
306 }
307
308 /**
309 * dataProvider for parseValidatorAnnotationCanParseAnnotations
310 *
311 * @author Karsten Dambekalns <karsten@typo3.org>
312 * @author Christopher Hlubek <hlubek@networkteam.com>
313 * @return array
314 */
315 public function validatorAnnotations() {
316 return array(
317 array(
318 '$var Bar',
319 array(
320 'argumentName' => 'var',
321 'validators' => array(
322 array('validatorName' => 'Bar', 'validatorOptions' => array())
323 )
324 )
325 ),
326 array(
327 '$var Bar, Foo',
328 array(
329 'argumentName' => 'var',
330 'validators' => array(
331 array('validatorName' => 'Bar', 'validatorOptions' => array()),
332 array('validatorName' => 'Foo', 'validatorOptions' => array())
333 )
334 )
335 ),
336 array(
337 '$var Baz (Foo=Bar)',
338 array(
339 'argumentName' => 'var',
340 'validators' => array(
341 array('validatorName' => 'Baz', 'validatorOptions' => array('Foo' => 'Bar'))
342 )
343 )
344 ),
345 array(
346 '$var Buzz (Foo="B=a, r", Baz=1)',
347 array(
348 'argumentName' => 'var',
349 'validators' => array(
350 array('validatorName' => 'Buzz', 'validatorOptions' => array('Foo' => 'B=a, r', 'Baz' => '1'))
351 )
352 )
353 ),
354 array(
355 '$var Foo(Baz=1, Bar=Quux)',
356 array(
357 'argumentName' => 'var',
358 'validators' => array(
359 array('validatorName' => 'Foo', 'validatorOptions' => array('Baz' => '1', 'Bar' => 'Quux'))
360 )
361 )
362 ),
363 array(
364 '$var Pax, Foo(Baz = \'1\', Bar = Quux)',
365 array(
366 'argumentName' => 'var',
367 'validators' => array(
368 array('validatorName' => 'Pax', 'validatorOptions' => array()),
369 array('validatorName' => 'Foo', 'validatorOptions' => array('Baz' => '1', 'Bar' => 'Quux'))
370 )
371 )
372 ),
373 array(
374 '$var Reg (P="[at]*(h|g)"), Quux',
375 array(
376 'argumentName' => 'var',
377 'validators' => array(
378 array('validatorName' => 'Reg', 'validatorOptions' => array('P' => '[at]*(h|g)')),
379 array('validatorName' => 'Quux', 'validatorOptions' => array())
380 )
381 )
382 ),
383 array(
384 '$var Baz (Foo="B\\"ar")',
385 array(
386 'argumentName' => 'var',
387 'validators' => array(
388 array('validatorName' => 'Baz', 'validatorOptions' => array('Foo' => 'B"ar'))
389 )
390 )
391 ),
392 array(
393 '$var F3_TestPackage_Quux',
394 array(
395 'argumentName' => 'var',
396 'validators' => array(
397 array('validatorName' => 'F3_TestPackage_Quux', 'validatorOptions' => array())
398 )
399 )
400 ),
401 array(
402 '$var Baz(Foo="5"), Bar(Quux="123")',
403 array(
404 'argumentName' => 'var',
405 'validators' => array(
406 array('validatorName' => 'Baz', 'validatorOptions' => array('Foo' => '5')),
407 array('validatorName' => 'Bar', 'validatorOptions' => array('Quux' => '123'))
408 )
409 )
410 ),
411 array(
412 '$var Baz(Foo="2"), Bar(Quux=123, Pax="a weird \\"string\\" with *freaky* \\stuff")',
413 array(
414 'argumentName' => 'var',
415 'validators' => array(
416 array('validatorName' => 'Baz', 'validatorOptions' => array('Foo' => '2')),
417 array('validatorName' => 'Bar', 'validatorOptions' => array('Quux' => '123', 'Pax' => 'a weird "string" with *freaky* \\stuff'))
418 )
419 )
420 )
421 );
422 }
423
424 /**
425 * @test
426 * @dataProvider validatorAnnotations
427 * @author Karsten Dambekalns <karsten@typo3.org>
428 * @param mixed $annotation
429 * @param mixed $expectedResult
430 */
431 public function parseValidatorAnnotationCanParseAnnotations($annotation, $expectedResult) {
432 $mockValidatorResolver = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Validation\\ValidatorResolver', array('dummy'));
433 $result = $mockValidatorResolver->_call('parseValidatorAnnotation', $annotation);
434 $this->assertEquals($result, $expectedResult);
435 }
436
437 }
438
439
440 ?>