[TASK] Use name-resolution instead of strings where possible: 3
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Persistence / Generic / Mapper / DataMapFactoryTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper;
3 /**
4 * This file is part of the TYPO3 CMS project.
5 *
6 * It is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License, either version 2
8 * of the License, or any later version.
9 *
10 * For the full copyright and license information, please read the
11 * LICENSE.txt file that was distributed with this source code.
12 *
13 * The TYPO3 project - inspiring people to share!
14 */
15
16 use TYPO3\CMS\Core\Tests\AccessibleObjectInterface;
17 use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap;
18 use TYPO3\CMS\Core\DataHandling\TableColumnType;
19 use TYPO3\CMS\Core\DataHandling\TableColumnSubType;
20
21 /**
22 * Test case
23 */
24 class DataMapFactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
25
26 /**
27 * @return array
28 */
29 public function oneToOneRelation() {
30 return array(
31 array('Tx_Myext_Domain_Model_Foo'),
32 array(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser::class)
33 );
34 }
35
36 /**
37 * @test
38 * @dataProvider oneToOneRelation
39 */
40 public function setRelationsDetectsOneToOneRelation($className) {
41 $mockColumnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array(), array(), '', FALSE);
42 $columnConfiguration = array(
43 'type' => 'select',
44 'foreign_table' => 'tx_myextension_bar',
45 'foreign_field' => 'parentid'
46 );
47 $propertyMetaData = array(
48 'type' => $className,
49 'elementType' => NULL
50 );
51 $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
52 $mockDataMapFactory->expects($this->once())->method('setOneToOneRelation')->will($this->returnValue($mockColumnMap));
53 $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
54 $mockDataMapFactory->expects($this->never())->method('setManyToManyRelation');
55 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
56 }
57
58 /**
59 * @test
60 */
61 public function settingOneToOneRelationSetsRelationTableMatchFields() {
62 $mockColumnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array(), array(), '', FALSE);
63 $matchFields = array(
64 'fieldname' => 'foo_model'
65 );
66 $columnConfiguration = array(
67 'type' => 'select',
68 'foreign_table' => 'tx_myextension_bar',
69 'foreign_field' => 'parentid',
70 'foreign_match_fields' => $matchFields
71 );
72
73 $mockColumnMap->expects($this->once())
74 ->method('setRelationTableMatchFields')
75 ->with($matchFields);
76 $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('dummy'), array(), '', FALSE);
77 $mockDataMapFactory->_call('setOneToOneRelation', $mockColumnMap, $columnConfiguration);
78 }
79
80 /**
81 * @test
82 */
83 public function settingOneToManyRelationSetsRelationTableMatchFields() {
84 $mockColumnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array(), array(), '', FALSE);
85 $matchFields = array(
86 'fieldname' => 'foo_model'
87 );
88 $columnConfiguration = array(
89 'type' => 'select',
90 'foreign_table' => 'tx_myextension_bar',
91 'foreign_field' => 'parentid',
92 'foreign_match_fields' => $matchFields
93 );
94
95 $mockColumnMap->expects($this->once())
96 ->method('setRelationTableMatchFields')
97 ->with($matchFields);
98 $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('dummy'), array(), '', FALSE);
99 $mockDataMapFactory->_call('setOneToManyRelation', $mockColumnMap, $columnConfiguration);
100 }
101
102 /**
103 * @test
104 */
105 public function setRelationsDetectsOneToOneRelationWithIntermediateTable() {
106 $mockColumnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array(), array(), '', FALSE);
107 $columnConfiguration = array(
108 'type' => 'select',
109 'foreign_table' => 'tx_myextension_bar',
110 'MM' => 'tx_myextension_mm'
111 );
112 $propertyMetaData = array(
113 'type' => 'Tx_Myext_Domain_Model_Foo',
114 'elementType' => NULL
115 );
116 $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
117 $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
118 $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
119 $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation')->will($this->returnValue($mockColumnMap));
120 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
121 }
122
123 /**
124 * @test
125 */
126 public function setRelationsDetectsOneToManyRelation() {
127 $mockColumnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array(), array(), '', FALSE);
128 $columnConfiguration = array(
129 'type' => 'select',
130 'foreign_table' => 'tx_myextension_bar',
131 'foreign_field' => 'parentid',
132 'foreign_table_field' => 'parenttable'
133 );
134 $propertyMetaData = array(
135 'type' => \TYPO3\CMS\Extbase\Persistence\ObjectStorage::class,
136 'elementType' => 'Tx_Myext_Domain_Model_Foo'
137 );
138 $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
139 $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
140 $mockDataMapFactory->expects($this->once())->method('setOneToManyRelation')->will($this->returnValue($mockColumnMap));
141 $mockDataMapFactory->expects($this->never())->method('setManyToManyRelation');
142 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
143 }
144
145 /**
146 * @test
147 */
148 public function setRelationsDetectsManyToManyRelationOfTypeSelect() {
149 $mockColumnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array(), array(), '', FALSE);
150 $columnConfiguration = array(
151 'type' => 'select',
152 'foreign_table' => 'tx_myextension_bar',
153 'MM' => 'tx_myextension_mm'
154 );
155 $propertyMetaData = array(
156 'type' => \TYPO3\CMS\Extbase\Persistence\ObjectStorage::class,
157 'elementType' => 'Tx_Myext_Domain_Model_Foo'
158 );
159 $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
160 $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
161 $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
162 $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation')->will($this->returnValue($mockColumnMap));
163 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
164 }
165
166 /**
167 * @test
168 */
169 public function setRelationsDetectsManyToManyRelationOfTypeInlineWithIntermediateTable() {
170 $mockColumnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array(), array(), '', FALSE);
171 $columnConfiguration = array(
172 'type' => 'inline',
173 'foreign_table' => 'tx_myextension_righttable',
174 'MM' => 'tx_myextension_mm'
175 );
176 $propertyMetaData = array(
177 'type' => \TYPO3\CMS\Extbase\Persistence\ObjectStorage::class,
178 'elementType' => 'Tx_Myext_Domain_Model_Foo'
179 );
180 $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
181 $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
182 $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
183 $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation')->will($this->returnValue($mockColumnMap));
184 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
185 }
186
187 /**
188 * @test
189 */
190 public function columnMapIsInitializedWithManyToManyRelationOfTypeSelect() {
191 $leftColumnsDefinition = array(
192 'rights' => array(
193 'type' => 'select',
194 'foreign_table' => 'tx_myextension_righttable',
195 'foreign_table_where' => 'WHERE 1=1',
196 'MM' => 'tx_myextension_mm',
197 'MM_table_where' => 'WHERE 2=2'
198 )
199 );
200 $mockColumnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array(), array(), '', FALSE);
201 $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
202 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
203 $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
204 $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with($this->equalTo('WHERE 1=1'));
205 $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting'));
206 $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
207 $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
208 $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
209 $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
210 $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('dummy'), array(), '', FALSE);
211 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
212 }
213
214 /**
215 * @test
216 */
217 public function columnMapIsInitializedWithOppositeManyToManyRelationOfTypeSelect() {
218 $rightColumnsDefinition = array(
219 'lefts' => array(
220 'type' => 'select',
221 'foreign_table' => 'tx_myextension_lefttable',
222 'MM' => 'tx_myextension_mm',
223 'MM_opposite_field' => 'rights'
224 )
225 );
226 $leftColumnsDefinition['rights']['MM_opposite_field'] = 'opposite_field';
227 $mockColumnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array(), array(), '', FALSE);
228 $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
229 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
230 $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_lefttable'));
231 $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with(NULL);
232 $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting_foreign'));
233 $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_foreign'));
234 $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
235 $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
236 $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
237 $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('dummy'), array(), '', FALSE);
238 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $rightColumnsDefinition['lefts']);
239 }
240
241 /**
242 * @test
243 */
244 public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndIntermediateTable() {
245 $leftColumnsDefinition = array(
246 'rights' => array(
247 'type' => 'inline',
248 'foreign_table' => 'tx_myextension_righttable',
249 'MM' => 'tx_myextension_mm',
250 'foreign_sortby' => 'sorting'
251 )
252 );
253 $mockColumnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array(), array(), '', FALSE);
254 $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
255 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
256 $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
257 $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement');
258 $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting'));
259 $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
260 $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
261 $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
262 $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
263 $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('getColumnsDefinition'), array(), '', FALSE);
264 $mockDataMapFactory->expects($this->never())->method('getColumnsDefinition');
265 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
266 }
267
268 /**
269 * @test
270 */
271 public function columnMapIsInitializedWithManyToManyRelationWithoutPidColumn() {
272 $leftColumnsDefinition = array(
273 'rights' => array(
274 'type' => 'select',
275 'foreign_table' => 'tx_myextension_righttable',
276 'foreign_table_where' => 'WHERE 1=1',
277 'MM' => 'tx_myextension_mm'
278 )
279 );
280 $mockColumnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array(), array(), '', FALSE);
281 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
282 $mockColumnMap->expects($this->once())->method('getRelationTableName')->will($this->returnValue('tx_myextension_mm'));
283 $mockColumnMap->expects($this->never())->method('setrelationTablePageIdColumnName');
284 $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('getControlSection'), array(), '', FALSE);
285 $mockDataMapFactory->expects($this->once())->method('getControlSection')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue(NULL));
286 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
287 }
288
289 /**
290 * @test
291 */
292 public function columnMapIsInitializedWithManyToManyRelationWithPidColumn() {
293 $leftColumnsDefinition = array(
294 'rights' => array(
295 'type' => 'select',
296 'foreign_table' => 'tx_myextension_righttable',
297 'foreign_table_where' => 'WHERE 1=1',
298 'MM' => 'tx_myextension_mm'
299 )
300 );
301 $mockColumnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array(), array(), '', FALSE);
302 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
303 $mockColumnMap->expects($this->once())->method('getRelationTableName')->will($this->returnValue('tx_myextension_mm'));
304 $mockColumnMap->expects($this->once())->method('setrelationTablePageIdColumnName')->with($this->equalTo('pid'));
305 $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('getControlSection'), array(), '', FALSE);
306 $mockDataMapFactory->expects($this->once())->method('getControlSection')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue(array('ctrl' => array('foo' => 'bar'))));
307 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
308 }
309
310 /**
311 * @return array
312 */
313 public function columnMapIsInitializedWithFieldEvaluationsForDateTimeFieldsDataProvider() {
314 return array(
315 'date field' => array('date', 'date'),
316 'datetime field' => array('datetime', 'datetime'),
317 'no date/datetime field' => array('', NULL),
318 );
319 }
320
321 /**
322 * @param string $type
323 * @param NULL|string $expectedValue
324 * @test
325 * @dataProvider columnMapIsInitializedWithFieldEvaluationsForDateTimeFieldsDataProvider
326 */
327 public function columnMapIsInitializedWithFieldEvaluationsForDateTimeFields($type, $expectedValue) {
328 $columnDefinition = array(
329 'type' => 'input',
330 'dbType' => $type,
331 'eval' => $type,
332 );
333
334 $mockColumnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array('setDateTimeStorageFormat'), array(), '', FALSE);
335
336 if ($expectedValue !== NULL) {
337 $mockColumnMap->expects($this->once())->method('setDateTimeStorageFormat')->with($this->equalTo($type));
338 } else {
339 $mockColumnMap->expects($this->never())->method('setDateTimeStorageFormat');
340 }
341
342 $accessibleClassName = $this->buildAccessibleProxy(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class);
343 $accessibleDataMapFactory = new $accessibleClassName();
344 $accessibleDataMapFactory->_callRef('setFieldEvaluations', $mockColumnMap, $columnDefinition);
345 }
346
347 /**
348 * @test
349 * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidClassException
350 */
351 public function buildDataMapThrowsExceptionIfClassNameIsNotKnown() {
352 $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('getControlSection'), array(), '', FALSE);
353 $cacheMock = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, array('get'), array(), '', FALSE);
354 $cacheMock->expects($this->any())->method('get')->will($this->returnValue(FALSE));
355 $mockDataMapFactory->_set('dataMapCache', $cacheMock);
356 $mockDataMapFactory->buildDataMap('UnknownObject');
357 }
358
359 /**
360 * @test
361 */
362 public function buildDataMapFetchesSubclassesRecursively() {
363 $this->markTestSkipped('Incomplete mocking in a complex scenario. This should be a functional test');
364 $configuration = array(
365 'persistence' => array(
366 'classes' => array(
367 \TYPO3\CMS\Extbase\Domain\Model\FrontendUser::class => array(
368 'subclasses' => array(
369 'Tx_SampleExt_Domain_Model_LevelOne1' => 'Tx_SampleExt_Domain_Model_LevelOne1',
370 'Tx_SampleExt_Domain_Model_LevelOne2' => 'Tx_SampleExt_Domain_Model_LevelOne2'
371 )
372 ),
373 'Tx_SampleExt_Domain_Model_LevelOne1' => array(
374 'subclasses' => array(
375 'Tx_SampleExt_Domain_Model_LevelTwo1' => 'Tx_SampleExt_Domain_Model_LevelTwo1',
376 'Tx_SampleExt_Domain_Model_LevelTwo2' => 'Tx_SampleExt_Domain_Model_LevelTwo2'
377 )
378 ),
379 'Tx_SampleExt_Domain_Model_LevelOne2' => array(
380 'subclasses' => array()
381 )
382 )
383 )
384 );
385 $expectedSubclasses = array(
386 'Tx_SampleExt_Domain_Model_LevelOne1',
387 'Tx_SampleExt_Domain_Model_LevelTwo1',
388 'Tx_SampleExt_Domain_Model_LevelTwo2',
389 'Tx_SampleExt_Domain_Model_LevelOne2'
390 );
391
392 /** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */
393 $objectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class, array('dummy'), array(), '', FALSE);
394
395 /** @var $configurationManager \TYPO3\CMS\Extbase\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject */
396 $configurationManager = $this->getMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class);
397 $configurationManager->expects($this->once())->method('getConfiguration')->with('Framework')->will($this->returnValue($configuration));
398 /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory $dataMapFactory */
399 $dataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('test'));
400 $dataMapFactory->_set('reflectionService', new \TYPO3\CMS\Extbase\Reflection\ReflectionService());
401 $dataMapFactory->_set('objectManager', $objectManager);
402 $dataMapFactory->_set('configurationManager', $configurationManager);
403 $cacheMock = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\VariableFrontend::class, array(), array(), '', FALSE);
404 $cacheMock->expects($this->any())->method('get')->will($this->returnValue(FALSE));
405 $dataMapFactory->_set('dataMapCache', $cacheMock);
406 $dataMap = $dataMapFactory->buildDataMap(\TYPO3\CMS\Extbase\Domain\Model\FrontendUser::class);
407 $this->assertSame($expectedSubclasses, $dataMap->getSubclasses());
408 }
409
410 /**
411 * @return array
412 */
413 public function classNameTableNameMappings() {
414 return array(
415 'Core classes' => array(\TYPO3\CMS\Belog\Domain\Model\LogEntry::class, 'tx_belog_domain_model_logentry'),
416 'Core classes with namespaces and leading backslash' => array('\\TYPO3\\CMS\\Belog\\Domain\\Model\\LogEntry', 'tx_belog_domain_model_logentry'),
417 'Extension classes' => array('ExtbaseTeam\\BlogExample\\Domain\\Model\\Blog', 'tx_blogexample_domain_model_blog'),
418 'Extension classes with namespaces and leading backslash' => array('\\ExtbaseTeam\\BlogExample\\Domain\\Model\\Blog', 'tx_blogexample_domain_model_blog'),
419 'Extension classes without namespace' => array('Tx_News_Domain_Model_News', 'tx_news_domain_model_news'),
420 'Extension classes without namespace but leading slash' => array('\\Tx_News_Domain_Model_News', 'tx_news_domain_model_news'),
421 );
422 }
423
424 /**
425 * @test
426 * @dataProvider classNameTableNameMappings
427 */
428 public function resolveTableNameReturnsExpectedTablenames($className, $expected) {
429 $dataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('dummy'));
430 $this->assertSame($expected, $dataMapFactory->_call('resolveTableName', $className));
431 }
432
433 /**
434 * @test
435 */
436 public function createColumnMapReturnsAValidColumnMap() {
437 /** @var $dataMapFactory \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory */
438 $dataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('dummy'));
439
440 /** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */
441 $objectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
442 $columnMap = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array(), array('column', 'property'));
443 $objectManager->expects($this->once())->method('get')->will($this->returnValue($columnMap));
444
445 $dataMapFactory->_set('objectManager', $objectManager);
446
447 $this->assertEquals(
448 $columnMap,
449 $dataMapFactory->_call('createColumnMap', 'column', 'property')
450 );
451 }
452
453 /**
454 * @return array
455 */
456 public function tcaConfigurationsContainingTypeAndInternalType() {
457 return array(
458 array(array('type' => 'input'), TableColumnType::INPUT, NULL),
459 array(array('type' => 'text'), TableColumnType::TEXT, NULL),
460 array(array('type' => 'check'), TableColumnType::CHECK, NULL),
461 array(array('type' => 'radio'), TableColumnType::RADIO, NULL),
462 array(array('type' => 'select'), TableColumnType::SELECT, NULL),
463 array(array('type' => 'group', 'internal_type' => 'db'), TableColumnType::GROUP, TableColumnSubType::DB),
464 array(array('type' => 'group', 'internal_type' => 'file'), TableColumnType::GROUP, TableColumnSubType::FILE),
465 array(array('type' => 'group', 'internal_type' => 'file_reference'), TableColumnType::GROUP, TableColumnSubType::FILE_REFERENCE),
466 array(array('type' => 'group', 'internal_type' => 'folder'), TableColumnType::GROUP, TableColumnSubType::FOLDER),
467 array(array('type' => 'none'), TableColumnType::NONE, NULL),
468 array(array('type' => 'passthrough'), TableColumnType::PASSTHROUGH, NULL),
469 array(array('type' => 'user'), TableColumnType::USER, NULL),
470 array(array('type' => 'flex'), TableColumnType::FLEX, NULL),
471 array(array('type' => 'inline'), TableColumnType::INLINE, NULL),
472 );
473 }
474
475 /**
476 * @test
477 * @dataProvider tcaConfigurationsContainingTypeAndInternalType
478 *
479 * @param array $columnConfiguration
480 * @param string $type
481 * @param string $internalType
482 */
483 public function setTypeDetectsTypeAndInternalTypeProperly(array $columnConfiguration, $type, $internalType) {
484 /** @var $dataMapFactory \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory | AccessibleObjectInterface */
485 $dataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, array('dummy'));
486
487 /** @var ColumnMap $columnMap */
488 $columnMap = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, array('dummy'), array(), '', FALSE);
489
490 $dataMapFactory->_call('setType', $columnMap, $columnConfiguration);
491
492 $this->assertEquals($type, (string)$columnMap->getType());
493 $this->assertEquals($internalType, (string)$columnMap->getInternalType());
494 }
495 }