TYPO3 CMS  TYPO3_6-2
ObjectConverterTest.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script belongs to the Extbase framework. *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License as published by the *
9  * Free Software Foundation, either version 3 of the License, or (at your *
10  * option) any later version. *
11  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with the script. *
19  * If not, see http://www.gnu.org/licenses/lgpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
26 
31 
35  protected $converter;
36 
41 
45  protected $mockObjectManager;
46 
50  protected $mockContainer;
51 
56  public function setUp() {
57  $this->mockReflectionService = $this->getMock('TYPO3\CMS\Extbase\Reflection\ReflectionService');
58  $this->mockObjectManager = $this->getMock('TYPO3\CMS\Extbase\Object\ObjectManagerInterface');
59  $this->mockContainer = $this->getMock('\TYPO3\CMS\Extbase\Object\Container\Container');
60 
61  $this->converter = new ObjectConverter();
62  $this->inject($this->converter, 'reflectionService', $this->mockReflectionService);
63  $this->inject($this->converter, 'objectManager', $this->mockObjectManager);
64  $this->inject($this->converter, 'objectContainer', $this->mockContainer);
65  }
66 
70  public function checkMetadata() {
71  $this->assertEquals(array('array'), $this->converter->getSupportedSourceTypes(), 'Source types do not match');
72  $this->assertEquals('object', $this->converter->getSupportedTargetType(), 'Target type does not match');
73  $this->assertEquals(0, $this->converter->getPriority(), 'Priority does not match');
74  }
75 
79  public function dataProviderForCanConvert() {
80  return array(
81  // Is entity => cannot convert
82  array('TYPO3\\CMS\\Extbase\\Tests\\Fixture\\Entity', FALSE),
83  // Is valueobject => cannot convert
84  array('TYPO3\\CMS\\Extbase\\Tests\\Fixture\\ValueObject', FALSE),
85  // Is no entity and no value object => can convert
86  array('stdClass', TRUE)
87  );
88  }
89 
96  public function canConvertFromReturnsTrueIfClassIsTaggedWithEntityOrValueObject($className, $expected) {
97  $this->assertEquals($expected, $this->converter->canConvertFrom('myInputData', $className));
98  }
99 
104  $this->mockReflectionService->expects($this->any())->method('hasMethod')->with('TheTargetType', 'setThePropertyName')->will($this->returnValue(FALSE));
105  $this->mockReflectionService->expects($this->any())->method('getMethodParameters')->with('TheTargetType', '__construct')->will($this->returnValue(array(
106  'thePropertyName' => array(
107  'type' => 'TheTypeOfSubObject',
108  'elementType' => NULL
109  )
110  )));
111  $this->mockContainer->expects($this->any())->method('getImplementationClassName')->will($this->returnValue('TheTargetType'));
112 
113  $configuration = new PropertyMappingConfiguration();
114  $configuration->setTypeConverterOptions('TYPO3\CMS\Extbase\Property\TypeConverter\ObjectConverter', array());
115  $this->assertEquals('TheTypeOfSubObject', $this->converter->getTypeOfChildProperty('TheTargetType', 'thePropertyName', $configuration));
116  }
117 
118 }
inject($target, $name, $dependency)