40 $this->mockConfigurationBuilder = $this->getMock(
'TYPO3\\CMS\\Extbase\\Property\\PropertyMappingConfigurationBuilder');
41 $this->mockConfiguration = $this->getMock(
'TYPO3\\CMS\\Extbase\\Property\\PropertyMappingConfigurationInterface');
49 array(
'someString',
'string'),
52 array(TRUE,
'boolean'),
53 array(array(),
'array')
64 public function sourceTypeCanBeCorrectlyDetermined($source, $sourceType) {
66 $propertyMapper = $this->
getAccessibleMock(
'TYPO3\\CMS\\Extbase\\Property\\PropertyMapper', array(
'dummy'));
67 $this->assertEquals($sourceType, $propertyMapper->_call(
'determineSourceType', $source));
76 array(
new \stdClass()),
77 array(
new \ArrayObject())
88 public function sourceWhichIsNoSimpleTypeThrowsException($source) {
90 $propertyMapper = $this->
getAccessibleMock(
'TYPO3\\CMS\\Extbase\\Property\\PropertyMapper', array(
'dummy'));
91 $propertyMapper->_call(
'determineSourceType', $source);
101 protected function getMockTypeConverter($name =
'', $canConvertFrom = TRUE, $properties = array(), $typeOfSubObject =
'') {
102 $mockTypeConverter = $this->getMock(
'TYPO3\\CMS\\Extbase\\Property\\TypeConverterInterface');
103 $mockTypeConverter->_name = $name;
104 $mockTypeConverter->expects($this->any())->method(
'canConvertFrom')->will($this->returnValue($canConvertFrom));
105 $mockTypeConverter->expects($this->any())->method(
'convertFrom')->will($this->returnValue($name));
106 $mockTypeConverter->expects($this->any())->method(
'getSourceChildPropertiesToBeConverted')->will($this->returnValue($properties));
107 $mockTypeConverter->expects($this->any())->method(
'getTypeOfChildProperty')->will($this->returnValue($typeOfSubObject));
108 return $mockTypeConverter;
115 public function findTypeConverterShouldReturnTypeConverterFromConfigurationIfItIsSet() {
117 $this->mockConfiguration->expects($this->any())->method(
'getTypeConverter')->will($this->returnValue($mockTypeConverter));
119 $propertyMapper = $this->
getAccessibleMock(
'TYPO3\\CMS\\Extbase\\Property\\PropertyMapper', array(
'dummy'));
120 $this->assertSame($mockTypeConverter, $propertyMapper->_call(
'findTypeConverter',
'someSource',
'someTargetType', $this->mockConfiguration));
129 array(
'someStringSource',
'string', array(
135 )),
'string2string,prio10' 137 array(array(
'some' =>
'array'),
'string', array(
143 )),
'array2string,prio10' 145 array(
'someStringSource',
'bool', array(
151 )),
'string2boolean,prio10' 153 array(
'someStringSource',
'int', array(
159 )),
'string2integer,prio10' 174 $propertyMapper = $this->
getAccessibleMock(
'TYPO3\CMS\Extbase\Property\PropertyMapper', array(
'dummy'));
175 $propertyMapper->_set(
'typeConverters', $typeConverters);
176 $actualTypeConverter = $propertyMapper->_call(
'findTypeConverter', $source, $targetType, $this->mockConfiguration);
177 $this->assertSame($expectedTypeConverter, $actualTypeConverter->_name);
186 $className1 = $this->
getUniqueId(
'TYPO3_Flow_Testclass1_', FALSE);
187 $className2 = $this->
getUniqueId(
'TYPO3_Flow_Testclass2_', FALSE);
188 $className3 = $this->
getUniqueId(
'TYPO3_Flow_Testclass3_', FALSE);
190 $interfaceName1 = $this->
getUniqueId(
'TYPO3_Flow_TestInterface1_', FALSE);
191 $interfaceName2 = $this->
getUniqueId(
'TYPO3_Flow_TestInterface2_', FALSE);
192 $interfaceName3 = $this->
getUniqueId(
'TYPO3_Flow_TestInterface3_', FALSE);
195 interface $interfaceName2 {} 196 interface $interfaceName1 {} 198 interface $interfaceName3 extends $interfaceName2 {} 200 class $className1 implements $interfaceName1 {} 201 class $className2 extends $className1 {} 202 class $className3 extends $className2 implements $interfaceName3 {} 207 'target' => $className3,
208 'expectedConverter' =>
'Class3Converter',
209 'typeConverters' => array(
221 'target' => $className3,
222 'expectedConverter' =>
'Class2Converter',
223 'typeConverters' => array(
235 'target' => $className3,
236 'expectedConverter' =>
'Class2Converter-HighPriority',
237 'typeConverters' => array(
244 'target' => $className3,
245 'expectedConverter' =>
'Interface1Converter',
246 'typeConverters' => array(
257 'target' => $className3,
258 'expectedConverter' =>
'Interface1Converter',
259 'typeConverters' => array(
266 'shouldFailWithException' =>
'TYPO3\\CMS\\Extbase\\Property\\Exception\\DuplicateTypeConverterException' 271 'target' => $className3,
272 'expectedConverter' =>
'GenericObjectConverter-HighPriority',
273 'typeConverters' => array(
285 'target' =>
'SomeNotExistingClassName',
286 'expectedConverter' =>
'GenericObjectConverter-HighPriority',
287 'typeConverters' => array(),
288 'shouldFailWithException' =>
'TYPO3\\CMS\\Extbase\\Property\\Exception\\InvalidTargetException' 293 'target' => $className3,
294 'expectedConverter' =>
'Class3Converter',
295 'typeConverters' => array(),
296 'shouldFailWithException' =>
'TYPO3\\CMS\\Extbase\\Property\\Exception\\TypeConverterException' 301 'target' =>
new \stdClass(),
302 'expectedConverter' =>
'',
303 'typeConverters' => array(),
304 'shouldFailWithException' =>
'TYPO3\\CMS\\Extbase\\Property\\Exception\\InvalidTargetException' 321 $propertyMapper = $this->
getAccessibleMock(
'TYPO3\CMS\Extbase\Property\PropertyMapper', array(
'dummy'));
322 $propertyMapper->_set(
'typeConverters', array(
'string' => $typeConverters));
324 $actualTypeConverter = $propertyMapper->_call(
'findTypeConverter',
'someSourceString', $targetClass, $this->mockConfiguration);
325 if ($shouldFailWithException) {
326 $this->fail(
'Expected exception ' . $shouldFailWithException .
' which was not thrown.');
328 $this->assertSame($expectedTypeConverter, $actualTypeConverter->_name);
330 if ($shouldFailWithException === FALSE) {
333 $this->assertInstanceOf($shouldFailWithException, $e);
341 $propertyMapper = $this->
getAccessibleMock(
'TYPO3\CMS\Extbase\Property\PropertyMapper', array(
'dummy'));
342 $this->
inject($propertyMapper,
'configurationBuilder', $this->mockConfigurationBuilder);
344 $this->mockConfigurationBuilder->expects($this->once())->method(
'build')->will($this->returnValue($this->mockConfiguration));
347 $typeConverters = array(
349 'string' => array(10 => $converter)
353 $propertyMapper->_set(
'typeConverters', $typeConverters);
354 $this->assertEquals(
'string2string', $propertyMapper->convert(
'source',
'string'));
360 public function findFirstEligibleTypeConverterInObjectHierarchyShouldReturnNullIfSourceTypeIsUnknown() {
362 $propertyMapper = $this->
getAccessibleMock(
'TYPO3\\CMS\\Extbase\\Property\\PropertyMapper', array(
'dummy'));
363 $this->assertNull($propertyMapper->_call(
'findFirstEligibleTypeConverterInObjectHierarchy',
'source',
'unknownSourceType',
'TYPO3\\CMS\\Extbase\\Core\\Bootstrap'));
370 $source = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
371 $targetType =
'TYPO3\CMS\Extbase\Persistence\ObjectStorage';
373 $propertyMapper = $this->
getAccessibleMock(
'TYPO3\CMS\Extbase\Property\PropertyMapper', array(
'dummy'));
374 $this->assertSame($source, $propertyMapper->_callRef(
'doMapping', $source, $targetType, $this->mockConfiguration, $propertyPath));
381 $source = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
382 $targetType =
'TYPO3\CMS\Extbase\Persistence\ObjectStorage<SomeEntity>';
384 $propertyMapper = $this->
getAccessibleMock(
'TYPO3\CMS\Extbase\Property\PropertyMapper', array(
'dummy'));
385 $this->assertSame($source, $propertyMapper->_callRef(
'doMapping', $source, $targetType, $this->mockConfiguration, $propertyPath));
392 $source = array(
'firstProperty' => 1,
'secondProperty' => 2);
393 $typeConverters = array(
395 'stdClass' => array(10 => $this->
getMockTypeConverter(
'array2object', TRUE, $source,
'integer'))
401 $configuration = new \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration();
403 $propertyMapper = $this->
getAccessibleMock(
'TYPO3\CMS\Extbase\Property\PropertyMapper', array(
'dummy'));
404 $propertyMapper->_set(
'typeConverters', $typeConverters);
406 $propertyMapper->convert($source,
'stdClass', $configuration->allowProperties(
'firstProperty')->skipProperties(
'secondProperty'));
413 $source = array(
'firstProperty' => 1,
'secondProperty' => 2);
414 $typeConverters = array(
416 'stdClass' => array(10 => $this->
getMockTypeConverter(
'array2object', TRUE, $source,
'integer'))
422 $configuration = new \TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration();
424 $propertyMapper = $this->
getAccessibleMock(
'TYPO3\CMS\Extbase\Property\PropertyMapper', array(
'dummy'));
425 $propertyMapper->_set(
'typeConverters', $typeConverters);
427 $propertyMapper->convert($source,
'stdClass', $configuration->allowProperties(
'firstProperty')->skipUnknownProperties());
convertSkipsPropertiesIfConfiguredTo()
inject($target, $name, $dependency)
findTypeConverterShouldReturnHighestPriorityTypeConverterForSimpleType($source, $targetType, $typeConverters, $expectedTypeConverter)
dataProviderForObjectTypeConverters()
getMockTypeConverter($name='', $canConvertFrom=TRUE, $properties=array(), $typeOfSubObject='')
$mockConfigurationBuilder
convertSkipsUnknownPropertiesIfConfiguredTo()
doMappingReturnsSourceUnchangedIfAlreadyConverted()
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
convertShouldAskConfigurationBuilderForDefaultConfiguration()
doMappingReturnsSourceUnchangedIfAlreadyConvertedToCompositeType()
dataProviderForFindTypeConverter()
findTypeConverterShouldReturnConverterForTargetObjectIfItExists($targetClass, $expectedTypeConverter, $typeConverters, $shouldFailWithException=FALSE)