17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
42 protected function setUp()
44 $this->simpleValueArgument = $this->getAccessibleMock(\
TYPO3\CMS\
Extbase\Mvc\Controller\Argument::class, [
'dummy'], [
'someName',
'string']);
45 $this->objectArgument = $this->getAccessibleMock(\
TYPO3\CMS\
Extbase\Mvc\Controller\Argument::class, [
'dummy'], [
'someName',
'DateTime']);
46 $this->mockPropertyMapper = $this->createMock(\
TYPO3\CMS\
Extbase\Property\PropertyMapper::class);
47 $this->simpleValueArgument->_set(
'propertyMapper', $this->mockPropertyMapper);
48 $this->objectArgument->_set(
'propertyMapper', $this->mockPropertyMapper);
49 $this->mockConfiguration = new \TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfiguration();
50 $propertyMappingConfiguranion = new \TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfiguration();
51 $this->simpleValueArgument->_set(
'propertyMappingConfiguration', $propertyMappingConfiguranion);
52 $this->objectArgument->_set(
'propertyMappingConfiguration', $propertyMappingConfiguranion);
60 $this->expectException(\InvalidArgumentException::class);
61 $this->expectExceptionCode(1232551853);
62 new \TYPO3\CMS\Extbase\Mvc\Controller\Argument(
'',
'Text');
70 $this->expectException(\InvalidArgumentException::class);
71 $this->expectExceptionCode(1187951688);
72 new \TYPO3\CMS\Extbase\Mvc\Controller\Argument(
new \ArrayObject(),
'Text');
80 $this->assertEquals(
'string', $this->simpleValueArgument->getDataType(),
'The specified data type has not been set correctly.');
81 $this->assertEquals(
'someName', $this->simpleValueArgument->getName(),
'The specified name has not been set correctly.');
89 $returnedArgument = $this->simpleValueArgument->setShortName(
'x');
90 $this->assertSame($this->simpleValueArgument, $returnedArgument,
'The returned argument is not the original argument.');
112 $this->expectException(\InvalidArgumentException::class);
113 $this->expectExceptionCode(1195824959);
114 $this->simpleValueArgument->setShortName($invalidShortName);
122 $this->simpleValueArgument->setShortName(
'x');
123 $this->assertEquals(
'x', $this->simpleValueArgument->getShortName());
131 $returnedArgument = $this->simpleValueArgument->setRequired(
true);
132 $this->assertSame($this->simpleValueArgument, $returnedArgument,
'The returned argument is not the original argument.');
133 $this->assertTrue($this->simpleValueArgument->isRequired());
141 $returnedArgument = $this->simpleValueArgument->setDefaultValue(
'default');
142 $this->assertSame($this->simpleValueArgument, $returnedArgument,
'The returned argument is not the original argument.');
143 $this->assertSame(
'default', $this->simpleValueArgument->getDefaultValue());
151 $mockValidator = $this->createMock(\
TYPO3\CMS\
Extbase\Validation\Validator\ValidatorInterface::class);
152 $returnedArgument = $this->simpleValueArgument->setValidator($mockValidator);
153 $this->assertSame($this->simpleValueArgument, $returnedArgument,
'The returned argument is not the original argument.');
154 $this->assertSame($mockValidator, $this->simpleValueArgument->getValidator());
162 $returnedArgument = $this->simpleValueArgument->setValue(
null);
163 $this->assertSame($this->simpleValueArgument, $returnedArgument,
'The returned argument is not the original argument.');
171 $this->simpleValueArgument = new \TYPO3\CMS\Extbase\Mvc\Controller\Argument(
'dummy',
'string');
172 $this->simpleValueArgument = $this->getAccessibleMock(\
TYPO3\CMS\
Extbase\Mvc\Controller\Argument::class, [
'dummy'], [
'dummy',
'string']);
173 $this->simpleValueArgument->setValue(
null);
174 $this->assertNull($this->simpleValueArgument->getValue());
182 $this->mockPropertyMapper->expects($this->never())->method(
'convert');
183 $this->objectArgument->setValue(
new \DateTime());
191 $this->mockPropertyMapper->expects($this->once())->method(
'convert')->with(
'someRawValue',
'string', $this->mockConfiguration)->will($this->returnValue(
'convertedValue'));
192 $this->mockPropertyMapper->expects($this->once())->method(
'getMessages')->will($this->returnValue(
new \
TYPO3\CMS\
Extbase\Error\Result()));
193 return $this->simpleValueArgument->setValue(
'someRawValue');
202 $this->assertSame(
'convertedValue', $this->simpleValueArgument->getValue());
203 $this->assertTrue($this->simpleValueArgument->isValid());
219 $error = new \TYPO3\CMS\Extbase\Error\Error(
'Some Error', 1234);
220 $mockValidator = $this->getMockBuilder(\
TYPO3\CMS\
Extbase\Validation\Validator\ValidatorInterface::class)
221 ->setMethods([
'validate',
'getOptions'])
223 $validationMessages = new \TYPO3\CMS\Extbase\Error\Result();
224 $validationMessages->addError($error);
225 $mockValidator->expects($this->once())->method(
'validate')->with(
'convertedValue')->will($this->returnValue($validationMessages));
226 $this->simpleValueArgument->setValidator($mockValidator);
228 $this->assertFalse($this->simpleValueArgument->isValid());
229 $this->assertEquals([$error], $this->simpleValueArgument->validate()->getErrors());
237 $this->assertNull($this->simpleValueArgument->getPropertyMappingConfiguration()->getConfigurationValue(\
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::class, \
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED));
238 $this->assertNull($this->simpleValueArgument->getPropertyMappingConfiguration()->getConfigurationValue(\
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::class, \
TYPO3\CMS\
Extbase\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED));