bfdfeb2cb34f5173e0c4b2bd98b863c340a4bf8f
[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 * Copyright notice
6 *
7 * This class is a backport of the corresponding class of TYPO3 Flow.
8 * All credits go to the TYPO3 Flow team.
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30 class DataMapFactoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
31
32 /**
33 * @return array
34 */
35 public function oneToOneRelation() {
36 return array(
37 array('Tx_Myext_Domain_Model_Foo'),
38 array('TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser')
39 );
40 }
41
42 /**
43 * @test
44 * @dataProvider oneToOneRelation
45 */
46 public function setRelationsDetectsOneToOneRelation($className) {
47 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
48 $columnConfiguration = array(
49 'type' => 'select',
50 'foreign_table' => 'tx_myextension_bar',
51 'foreign_field' => 'parentid'
52 );
53 $propertyMetaData = array(
54 'type' => $className,
55 'elementType' => NULL
56 );
57 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
58 $mockDataMapFactory->expects($this->once())->method('setOneToOneRelation');
59 $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
60 $mockDataMapFactory->expects($this->never())->method('setManyToManyRelation');
61 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
62 }
63
64 /**
65 * @test
66 */
67 public function settingOneToOneRelationSetsRelationTableMatchFields() {
68 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
69 $matchFields = array(
70 'fieldname' => 'foo_model'
71 );
72 $columnConfiguration = array(
73 'type' => 'select',
74 'foreign_table' => 'tx_myextension_bar',
75 'foreign_field' => 'parentid',
76 'foreign_match_fields' => $matchFields
77 );
78
79 $mockColumnMap->expects($this->once())
80 ->method('setRelationTableMatchFields')
81 ->with($matchFields);
82 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'), array(), '', FALSE);
83 $mockDataMapFactory->_call('setOneToOneRelation', $mockColumnMap, $columnConfiguration);
84 }
85
86 /**
87 * @test
88 */
89 public function settingOneToManyRelationSetsRelationTableMatchFields() {
90 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
91 $matchFields = array(
92 'fieldname' => 'foo_model'
93 );
94 $columnConfiguration = array(
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', array('dummy'), array(), '', FALSE);
105 $mockDataMapFactory->_call('setOneToManyRelation', $mockColumnMap, $columnConfiguration);
106 }
107
108 /**
109 * @test
110 */
111 public function setRelationsDetectsOneToOneRelationWithIntermediateTable() {
112 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
113 $columnConfiguration = array(
114 'type' => 'select',
115 'foreign_table' => 'tx_myextension_bar',
116 'MM' => 'tx_myextension_mm'
117 );
118 $propertyMetaData = array(
119 'type' => 'Tx_Myext_Domain_Model_Foo',
120 'elementType' => NULL
121 );
122 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
123 $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
124 $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
125 $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
126 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
127 }
128
129 /**
130 * @test
131 */
132 public function setRelationsDetectsOneToManyRelation() {
133 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
134 $columnConfiguration = array(
135 'type' => 'select',
136 'foreign_table' => 'tx_myextension_bar',
137 'foreign_field' => 'parentid',
138 'foreign_table_field' => 'parenttable'
139 );
140 $propertyMetaData = array(
141 'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
142 'elementType' => 'Tx_Myext_Domain_Model_Foo'
143 );
144 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
145 $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
146 $mockDataMapFactory->expects($this->once())->method('setOneToManyRelation');
147 $mockDataMapFactory->expects($this->never())->method('setManyToManyRelation');
148 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
149 }
150
151 /**
152 * @test
153 */
154 public function setRelationsDetectsManyToManyRelationOfTypeSelect() {
155 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
156 $columnConfiguration = array(
157 'type' => 'select',
158 'foreign_table' => 'tx_myextension_bar',
159 'MM' => 'tx_myextension_mm'
160 );
161 $propertyMetaData = array(
162 'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
163 'elementType' => 'Tx_Myext_Domain_Model_Foo'
164 );
165 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
166 $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
167 $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
168 $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
169 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
170 }
171
172 /**
173 * @test
174 */
175 public function setRelationsDetectsManyToManyRelationOfTypeInlineWithIntermediateTable() {
176 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
177 $columnConfiguration = array(
178 'type' => 'inline',
179 'foreign_table' => 'tx_myextension_righttable',
180 'MM' => 'tx_myextension_mm'
181 );
182 $propertyMetaData = array(
183 'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
184 'elementType' => 'Tx_Myext_Domain_Model_Foo'
185 );
186 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
187 $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
188 $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
189 $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
190 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
191 }
192
193 /**
194 * @test
195 */
196 public function columnMapIsInitializedWithManyToManyRelationOfTypeSelect() {
197 $leftColumnsDefinition = array(
198 'rights' => array(
199 'type' => 'select',
200 'foreign_table' => 'tx_myextension_righttable',
201 'foreign_table_where' => 'WHERE 1=1',
202 'MM' => 'tx_myextension_mm',
203 'MM_table_where' => 'WHERE 2=2'
204 )
205 );
206 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
207 $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
208 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
209 $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
210 $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with($this->equalTo('WHERE 1=1'));
211 $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting'));
212 $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
213 $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
214 $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
215 $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
216 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'), array(), '', FALSE);
217 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
218 }
219
220 /**
221 * @test
222 */
223 public function columnMapIsInitializedWithOppositeManyToManyRelationOfTypeSelect() {
224 $rightColumnsDefinition = array(
225 'lefts' => array(
226 'type' => 'select',
227 'foreign_table' => 'tx_myextension_lefttable',
228 'MM' => 'tx_myextension_mm',
229 'MM_opposite_field' => 'rights'
230 )
231 );
232 $leftColumnsDefinition['rights']['MM_opposite_field'] = 'opposite_field';
233 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
234 $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
235 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
236 $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_lefttable'));
237 $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with(NULL);
238 $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting_foreign'));
239 $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_foreign'));
240 $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
241 $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
242 $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
243 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'), array(), '', FALSE);
244 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $rightColumnsDefinition['lefts']);
245 }
246
247 /**
248 * @test
249 */
250 public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndIntermediateTable() {
251 $leftColumnsDefinition = array(
252 'rights' => array(
253 'type' => 'inline',
254 'foreign_table' => 'tx_myextension_righttable',
255 'MM' => 'tx_myextension_mm',
256 'foreign_sortby' => 'sorting'
257 )
258 );
259 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
260 $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
261 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
262 $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
263 $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement');
264 $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting'));
265 $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
266 $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
267 $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
268 $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
269 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getColumnsDefinition'), array(), '', FALSE);
270 $mockDataMapFactory->expects($this->never())->method('getColumnsDefinition');
271 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
272 }
273
274 /**
275 * @test
276 */
277 public function columnMapIsInitializedWithManyToManyRelationWithoutPidColumn() {
278 $leftColumnsDefinition = array(
279 'rights' => array(
280 'type' => 'select',
281 'foreign_table' => 'tx_myextension_righttable',
282 'foreign_table_where' => 'WHERE 1=1',
283 'MM' => 'tx_myextension_mm'
284 )
285 );
286 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
287 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
288 $mockColumnMap->expects($this->once())->method('getRelationTableName')->will($this->returnValue('tx_myextension_mm'));
289 $mockColumnMap->expects($this->never())->method('setrelationTablePageIdColumnName');
290 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getControlSection'), array(), '', FALSE);
291 $mockDataMapFactory->expects($this->once())->method('getControlSection')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue(NULL));
292 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
293 }
294
295 /**
296 * @test
297 */
298 public function columnMapIsInitializedWithManyToManyRelationWithPidColumn() {
299 $leftColumnsDefinition = array(
300 'rights' => array(
301 'type' => 'select',
302 'foreign_table' => 'tx_myextension_righttable',
303 'foreign_table_where' => 'WHERE 1=1',
304 'MM' => 'tx_myextension_mm'
305 )
306 );
307 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
308 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
309 $mockColumnMap->expects($this->once())->method('getRelationTableName')->will($this->returnValue('tx_myextension_mm'));
310 $mockColumnMap->expects($this->once())->method('setrelationTablePageIdColumnName')->with($this->equalTo('pid'));
311 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getControlSection'), array(), '', FALSE);
312 $mockDataMapFactory->expects($this->once())->method('getControlSection')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue(array('ctrl' => array('foo' => 'bar'))));
313 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
314 }
315
316 /**
317 * @return array
318 */
319 public function columnMapIsInitializedWithFieldEvaluationsForDateTimeFieldsDataProvider() {
320 return array(
321 'date field' => array('date', 'date'),
322 'datetime field' => array('datetime', 'datetime'),
323 'no date/datetime field' => array('', NULL),
324 );
325 }
326
327 /**
328 * @param string $type
329 * @param NULL|string $expectedValue
330 * @test
331 * @dataProvider columnMapIsInitializedWithFieldEvaluationsForDateTimeFieldsDataProvider
332 */
333 public function columnMapIsInitializedWithFieldEvaluationsForDateTimeFields($type, $expectedValue) {
334 $columnDefinition = array(
335 'type' => 'input',
336 'dbType' => $type,
337 'eval' => $type,
338 );
339
340 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array('setDateTimeStorageFormat'), array(), '', FALSE);
341
342 if ($expectedValue !== NULL) {
343 $mockColumnMap->expects($this->once())->method('setDateTimeStorageFormat')->with($this->equalTo($type));
344 } else {
345 $mockColumnMap->expects($this->never())->method('setDateTimeStorageFormat');
346 }
347
348 $accessibleClassName = $this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory');
349 $accessibleDataMapFactory = new $accessibleClassName();
350 $accessibleDataMapFactory->_callRef('setFieldEvaluations', $mockColumnMap, $columnDefinition);
351 }
352
353 /**
354 * @test
355 * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidClassException
356 */
357 public function buildDataMapThrowsExceptionIfClassNameIsNotKnown() {
358 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getControlSection'), array(), '', FALSE);
359 $cacheMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', array('get'), array(), '', FALSE);
360 $cacheMock->expects($this->any())->method('get')->will($this->returnValue(FALSE));
361 $mockDataMapFactory->_set('dataMapCache', $cacheMock);
362 $mockDataMapFactory->buildDataMap('UnknownObject');
363 }
364
365 /**
366 * @test
367 */
368 public function buildDataMapFetchesSubclassesRecursively() {
369 $configuration = array(
370 'persistence' => array(
371 'classes' => array(
372 'TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser' => array(
373 'subclasses' => array(
374 'Tx_SampleExt_Domain_Model_LevelOne1' => 'Tx_SampleExt_Domain_Model_LevelOne1',
375 'Tx_SampleExt_Domain_Model_LevelOne2' => 'Tx_SampleExt_Domain_Model_LevelOne2'
376 )
377 ),
378 'Tx_SampleExt_Domain_Model_LevelOne1' => array(
379 'subclasses' => array(
380 'Tx_SampleExt_Domain_Model_LevelTwo1' => 'Tx_SampleExt_Domain_Model_LevelTwo1',
381 'Tx_SampleExt_Domain_Model_LevelTwo2' => 'Tx_SampleExt_Domain_Model_LevelTwo2'
382 )
383 ),
384 'Tx_SampleExt_Domain_Model_LevelOne2' => array(
385 'subclasses' => array()
386 )
387 )
388 )
389 );
390 $expectedSubclasses = array(
391 'Tx_SampleExt_Domain_Model_LevelOne1',
392 'Tx_SampleExt_Domain_Model_LevelTwo1',
393 'Tx_SampleExt_Domain_Model_LevelTwo2',
394 'Tx_SampleExt_Domain_Model_LevelOne2'
395 );
396 /** @var $configurationManager \TYPO3\CMS\Extbase\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject */
397 $configurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
398 $configurationManager->expects($this->once())->method('getConfiguration')->with('Framework')->will($this->returnValue($configuration));
399 $dataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('test'));
400 $dataMapFactory->injectReflectionService(new \TYPO3\CMS\Extbase\Reflection\ReflectionService());
401 $dataMapFactory->injectObjectManager(new \TYPO3\CMS\Extbase\Object\ObjectManager());
402 $dataMapFactory->injectConfigurationManager($configurationManager);
403 $cacheMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', 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');
407 $this->assertSame($dataMap->getSubclasses(), $expectedSubclasses);
408 }
409
410 /**
411 * @return array
412 */
413 public function classNameTableNameMappings() {
414 return array(
415 'Core classes' => array('TYPO3\\CMS\\Belog\\Domain\\Model\\LogEntry', 'tx_belog_domain_model_logentry'),
416 'Extension classes' => array('ExtbaseTeam\\BlogExample\\Domain\\Model\\Blog', 'tx_blogexample_domain_model_blog'),
417 'Extension classes without namespace' => array('Tx_News_Domain_Model_News', 'tx_news_domain_model_news'),
418 );
419 }
420
421 /**
422 * @test
423 * @dataProvider classNameTableNameMappings
424 */
425 public function resolveTableNameReturnsExpectedTablenames($className, $expected) {
426 $dataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'));
427 $this->assertSame($expected, $dataMapFactory->_call('resolveTableName', $className));
428 }
429
430 /**
431 * @test
432 */
433 public function createColumnMapReturnsAValidColumnMap() {
434 /** @var $dataMapFactory \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory */
435 $dataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'));
436 $dataMapFactory->injectObjectManager($this->objectManager);
437
438 $this->assertEquals(
439 new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('column', 'property'),
440 $dataMapFactory->_call('createColumnMap', 'column', 'property')
441 );
442 }
443
444 }
445
446 ?>