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