2 declare(strict_types = 1);
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
33 protected function setUp()
35 $this->validatorResolver = $this->getAccessibleMock(\
TYPO3\CMS\
Extbase\Validation\ValidatorResolver::class, [
'dummy']);
43 $mockController = $this->getAccessibleMock(\
TYPO3\CMS\
Extbase\Mvc\Controller\ActionController::class, [
'fooAction'], [],
'',
false);
44 $className = get_class($mockController);
45 $methodName =
'fooAction';
47 $classSchemaMock = $this->createMock(ClassSchema::class);
48 $classSchemaMock->expects($this->any())->method(
'getMethod')->with($methodName)->willReturn([
52 $mockReflectionService = $this->createMock(\
TYPO3\CMS\
Extbase\Reflection\ReflectionService::class);
53 $mockReflectionService->expects($this->any())->method(
'getClassSchema')->with($className)->willReturn($classSchemaMock);
60 $this->assertSame([], $result);
68 $mockObject = $this->getMockBuilder(
'stdClass')
69 ->setMethods([
'fooMethod'])
70 ->disableOriginalConstructor()
73 $className = get_class($mockObject);
74 $methodName =
'fooAction';
90 '$arg1 Foo(bar = baz), Bar',
91 '$arg2 VENDOR\\ModelCollection\\Domain\\Model\\Model'
95 $classSchemaMock = $this->createMock(ClassSchema::class);
96 $classSchemaMock->expects($this->any())->method(
'getMethod')->with($methodName)->willReturn([
97 'params' => $methodParameters,
98 'tags' => $methodTagsValues
101 $mockReflectionService = $this->createMock(\
TYPO3\CMS\
Extbase\Reflection\ReflectionService::class);
102 $mockReflectionService->expects($this->any())->method(
'getClassSchema')->with($className)->willReturn($classSchemaMock);
104 $mockStringValidator = $this->createMock(\
TYPO3\CMS\
Extbase\Validation\Validator\ValidatorInterface::class);
105 $mockArrayValidator = $this->createMock(\
TYPO3\CMS\
Extbase\Validation\Validator\ValidatorInterface::class);
106 $mockFooValidator = $this->createMock(\
TYPO3\CMS\
Extbase\Validation\Validator\ValidatorInterface::class);
107 $mockBarValidator = $this->createMock(\
TYPO3\CMS\
Extbase\Validation\Validator\ValidatorInterface::class);
108 $mockQuuxValidator = $this->createMock(\
TYPO3\CMS\
Extbase\Validation\Validator\ValidatorInterface::class);
109 $conjunction1 = $this->createMock(\
TYPO3\CMS\
Extbase\Validation\Validator\ConjunctionValidator::class);
110 $conjunction1->expects($this->at(0))->method(
'addValidator')->with($mockStringValidator);
111 $conjunction1->expects($this->at(1))->method(
'addValidator')->with($mockFooValidator);
112 $conjunction1->expects($this->at(2))->method(
'addValidator')->with($mockBarValidator);
113 $conjunction2 = $this->createMock(\
TYPO3\CMS\
Extbase\Validation\Validator\ConjunctionValidator::class);
114 $conjunction2->expects($this->at(0))->method(
'addValidator')->with($mockArrayValidator);
115 $conjunction2->expects($this->at(1))->method(
'addValidator')->with($mockQuuxValidator);
116 $mockArguments = new \TYPO3\CMS\Extbase\Mvc\Controller\Arguments();
117 $mockArguments->addArgument(
new \
TYPO3\CMS\
Extbase\Mvc\Controller\Argument(
'arg1',
'dummyValue'));
118 $mockArguments->addArgument(
new \
TYPO3\CMS\
Extbase\Mvc\Controller\Argument(
'arg2',
'dummyValue'));
122 $validatorResolver->expects($this->at(0))->method(
'createValidator')->with(\
TYPO3\CMS\
Extbase\Validation\Validator\ConjunctionValidator::class)->will($this->returnValue($conjunction1));
123 $validatorResolver->expects($this->at(1))->method(
'createValidator')->with(
'string')->will($this->returnValue($mockStringValidator));
124 $validatorResolver->expects($this->at(2))->method(
'createValidator')->with(\
TYPO3\CMS\
Extbase\Validation\Validator\ConjunctionValidator::class)->will($this->returnValue($conjunction2));
125 $validatorResolver->expects($this->at(3))->method(
'createValidator')->with(
'array')->will($this->returnValue($mockArrayValidator));
126 $validatorResolver->expects($this->at(4))->method(
'createValidator')->with(
'Foo', [
'bar' =>
'baz'])->will($this->returnValue($mockFooValidator));
127 $validatorResolver->expects($this->at(5))->method(
'createValidator')->with(
'Bar')->will($this->returnValue($mockBarValidator));
128 $validatorResolver->expects($this->at(6))->method(
'createValidator')->with(
'VENDOR\\ModelCollection\\Domain\\Model\\Model')->will($this->returnValue($mockQuuxValidator));
132 $this->assertEquals([
'arg1' => $conjunction1,
'arg2' => $conjunction2], $result);
140 $this->expectException(InvalidValidationConfigurationException::class);
141 $this->expectExceptionCode(1253172726);
142 $mockObject = $this->getMockBuilder(
'stdClass')
143 ->setMethods([
'fooMethod'])
144 ->disableOriginalConstructor()
147 $className = get_class($mockObject);
148 $methodName =
'fooAction';
150 $methodParameters = [
155 $methodTagsValues = [
160 '$arg2 VENDOR\\ModelCollection\\Domain\\Model\\Model'
164 $classSchemaMock = $this->createMock(ClassSchema::class);
165 $classSchemaMock->expects($this->any())->method(
'getMethod')->with($methodName)->willReturn([
166 'params' => $methodParameters,
167 'tags' => $methodTagsValues
170 $mockReflectionService = $this->createMock(\
TYPO3\CMS\
Extbase\Reflection\ReflectionService::class);
171 $mockReflectionService->expects($this->any())->method(
'getClassSchema')->with($className)->willReturn($classSchemaMock);
173 $mockStringValidator = $this->createMock(\
TYPO3\CMS\
Extbase\Validation\Validator\ValidatorInterface::class);
174 $mockQuuxValidator = $this->createMock(\
TYPO3\CMS\
Extbase\Validation\Validator\ValidatorInterface::class);
175 $conjunction1 = $this->createMock(\
TYPO3\CMS\
Extbase\Validation\Validator\ConjunctionValidator::class);
176 $conjunction1->expects($this->at(0))->method(
'addValidator')->with($mockStringValidator);
180 $validatorResolver->expects($this->at(0))->method(
'createValidator')->with(\
TYPO3\CMS\
Extbase\Validation\Validator\ConjunctionValidator::class)->will($this->returnValue($conjunction1));
181 $validatorResolver->expects($this->at(1))->method(
'createValidator')->with(
'string')->will($this->returnValue($mockStringValidator));
182 $validatorResolver->expects($this->at(2))->method(
'createValidator')->with(
'VENDOR\\ModelCollection\\Domain\\Model\\Model')->will($this->returnValue($mockQuuxValidator));
197 'argumentName' =>
'var',
199 [
'validatorName' =>
'Bar',
'validatorOptions' => []]
206 'argumentName' =>
'var',
208 [
'validatorName' =>
'Bar',
'validatorOptions' => []],
209 [
'validatorName' =>
'Foo',
'validatorOptions' => []]
214 '$var Baz (Foo=Bar)',
216 'argumentName' =>
'var',
218 [
'validatorName' =>
'Baz',
'validatorOptions' => [
'Foo' =>
'Bar']]
223 '$var Buzz (Foo="B=a, r", Baz=1)',
225 'argumentName' =>
'var',
227 [
'validatorName' =>
'Buzz',
'validatorOptions' => [
'Foo' =>
'B=a, r',
'Baz' =>
'1']]
232 '$var Foo(Baz=1, Bar=Quux)',
234 'argumentName' =>
'var',
236 [
'validatorName' =>
'Foo',
'validatorOptions' => [
'Baz' =>
'1',
'Bar' =>
'Quux']]
241 '$var Pax, Foo(Baz = \'1\', Bar = Quux)',
243 'argumentName' =>
'var',
245 [
'validatorName' =>
'Pax',
'validatorOptions' => []],
246 [
'validatorName' =>
'Foo',
'validatorOptions' => [
'Baz' =>
'1',
'Bar' =>
'Quux']]
251 '$var Reg (P="[at]*(h|g)"), Quux',
253 'argumentName' =>
'var',
255 [
'validatorName' =>
'Reg',
'validatorOptions' => [
'P' =>
'[at]*(h|g)']],
256 [
'validatorName' =>
'Quux',
'validatorOptions' => []]
261 '$var Baz (Foo="B\\"ar")',
263 'argumentName' =>
'var',
265 [
'validatorName' =>
'Baz',
'validatorOptions' => [
'Foo' =>
'B"ar']]
270 '$var Baz(Foo="5"), Bar(Quux="123")',
272 'argumentName' =>
'var',
274 [
'validatorName' =>
'Baz',
'validatorOptions' => [
'Foo' =>
'5']],
275 [
'validatorName' =>
'Bar',
'validatorOptions' => [
'Quux' =>
'123']]
280 '$var Baz(Foo="2"), Bar(Quux=123, Pax="a weird \\"string\\" with *freaky* \\stuff")',
282 'argumentName' =>
'var',
284 [
'validatorName' =>
'Baz',
'validatorOptions' => [
'Foo' =>
'2']],
285 [
'validatorName' =>
'Bar',
'validatorOptions' => [
'Quux' =>
'123',
'Pax' =>
'a weird "string" with *freaky* \\stuff']]
289 'namespaced validator class name' => [
290 'annotation' =>
'$var F3\TestPackage\Quux',
292 'argumentName' =>
'var',
294 [
'validatorName' =>
'F3\TestPackage\Quux',
'validatorOptions' => []]
298 'shorthand notation for system validator' => [
299 'annotation' =>
'$var TYPO3.CMS.Mypkg:MySecond',
301 'argumentName' =>
'var',
303 [
'validatorName' =>
'TYPO3.CMS.Mypkg:MySecond',
'validatorOptions' => []]
307 'shorthand notation for custom validator with parameter' => [
308 'annotation' =>
'$var Acme.Mypkg:MyThird(Foo="2")',
310 'argumentName' =>
'var',
312 [
'validatorName' =>
'Acme.Mypkg:MyThird',
'validatorOptions' => [
'Foo' =>
'2']]
328 $result = $this->validatorResolver->_call(
'parseValidatorAnnotation', $annotation);
329 static::assertEquals($result, $expectedResult);