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