[CLEANUP] Adjust code to coding guidelines
[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 * 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 setRelationsDetectsOneToOneRelationWithIntermediateTable() {
68 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
69 $columnConfiguration = array(
70 'type' => 'select',
71 'foreign_table' => 'tx_myextension_bar',
72 'MM' => 'tx_myextension_mm'
73 );
74 $propertyMetaData = array(
75 'type' => 'Tx_Myext_Domain_Model_Foo',
76 'elementType' => NULL
77 );
78 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
79 $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
80 $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
81 $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
82 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
83 }
84
85 /**
86 * @test
87 */
88 public function setRelationsDetectsOneToManyRelation() {
89 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
90 $columnConfiguration = array(
91 'type' => 'select',
92 'foreign_table' => 'tx_myextension_bar',
93 'foreign_field' => 'parentid',
94 'foreign_table_field' => 'parenttable'
95 );
96 $propertyMetaData = array(
97 'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
98 'elementType' => 'Tx_Myext_Domain_Model_Foo'
99 );
100 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
101 $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
102 $mockDataMapFactory->expects($this->once())->method('setOneToManyRelation');
103 $mockDataMapFactory->expects($this->never())->method('setManyToManyRelation');
104 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
105 }
106
107 /**
108 * @test
109 */
110 public function setRelationsDetectsManyToManyRelationOfTypeSelect() {
111 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
112 $columnConfiguration = array(
113 'type' => 'select',
114 'foreign_table' => 'tx_myextension_bar',
115 'MM' => 'tx_myextension_mm'
116 );
117 $propertyMetaData = array(
118 'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
119 'elementType' => 'Tx_Myext_Domain_Model_Foo'
120 );
121 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
122 $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
123 $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
124 $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
125 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
126 }
127
128 /**
129 * @test
130 */
131 public function setRelationsDetectsManyToManyRelationOfTypeInlineWithIntermediateTable() {
132 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
133 $columnConfiguration = array(
134 'type' => 'inline',
135 'foreign_table' => 'tx_myextension_righttable',
136 'MM' => 'tx_myextension_mm'
137 );
138 $propertyMetaData = array(
139 'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
140 'elementType' => 'Tx_Myext_Domain_Model_Foo'
141 );
142 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
143 $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
144 $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
145 $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
146 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
147 }
148
149 /**
150 * @test
151 */
152 public function setRelationsDetectsManyToManyRelationOfTypeInlineWithForeignSelector() {
153 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
154 $columnConfiguration = array(
155 'type' => 'inline',
156 'foreign_table' => 'tx_myextension_mm',
157 'foreign_field' => 'uid_local',
158 'foreign_selector' => 'uid_foreign'
159 );
160 $propertyMetaData = array(
161 'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
162 'elementType' => 'Tx_Myext_Domain_Model_Foo'
163 );
164 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
165 $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
166 $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
167 $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
168 $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
169 }
170
171 /**
172 * @test
173 */
174 public function columnMapIsInitializedWithManyToManyRelationOfTypeSelect() {
175 $leftColumnsDefinition = array(
176 'rights' => array(
177 'type' => 'select',
178 'foreign_table' => 'tx_myextension_righttable',
179 'foreign_table_where' => 'WHERE 1=1',
180 'MM' => 'tx_myextension_mm',
181 'MM_table_where' => 'WHERE 2=2'
182 )
183 );
184 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
185 $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
186 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
187 $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
188 $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with($this->equalTo('WHERE 1=1'));
189 $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting'));
190 $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
191 $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
192 $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
193 $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
194 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'), array(), '', FALSE);
195 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
196 }
197
198 /**
199 * @test
200 */
201 public function columnMapIsInitializedWithOppositeManyToManyRelationOfTypeSelect() {
202 $rightColumnsDefinition = array(
203 'lefts' => array(
204 'type' => 'select',
205 'foreign_table' => 'tx_myextension_lefttable',
206 'MM' => 'tx_myextension_mm',
207 'MM_opposite_field' => 'rights'
208 )
209 );
210 $leftColumnsDefinition['rights']['MM_opposite_field'] = 'opposite_field';
211 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
212 $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\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_lefttable'));
215 $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with(NULL);
216 $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting_foreign'));
217 $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_foreign'));
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', array('dummy'), array(), '', FALSE);
222 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $rightColumnsDefinition['lefts']);
223 }
224
225 /**
226 * @test
227 */
228 public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndIntermediateTable() {
229 $leftColumnsDefinition = array(
230 'rights' => array(
231 'type' => 'inline',
232 'foreign_table' => 'tx_myextension_righttable',
233 'MM' => 'tx_myextension_mm',
234 'foreign_sortby' => 'sorting'
235 )
236 );
237 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
238 $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
239 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
240 $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
241 $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement');
242 $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting'));
243 $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
244 $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
245 $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
246 $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
247 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getColumnsDefinition'), array(), '', FALSE);
248 $mockDataMapFactory->expects($this->never())->method('getColumnsDefinition');
249 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
250 }
251
252 /**
253 * @test
254 */
255 public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndForeignSelector() {
256 $leftColumnsDefinition = array(
257 'rights' => array(
258 'type' => 'inline',
259 'foreign_table' => 'tx_myextension_mm',
260 'foreign_field' => 'uid_local',
261 'foreign_selector' => 'uid_foreign',
262 'foreign_sortby' => 'sorting'
263 )
264 );
265 $relationTableColumnsDefiniton = array(
266 'uid_local' => array(
267 'config' => array('foreign_table' => 'tx_myextension_localtable')
268 ),
269 'uid_foreign' => array(
270 'config' => array('foreign_table' => 'tx_myextension_righttable')
271 )
272 );
273 $rightColumnsDefinition = array(
274 'lefts' => array(
275 'type' => 'inline',
276 'foreign_table' => 'tx_myextension_mm',
277 'foreign_field' => 'uid_foreign',
278 'foreign_selector' => 'uid_local',
279 'foreign_sortby' => 'sorting_foreign'
280 )
281 );
282 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
283 $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
284 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
285 $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
286 $mockColumnMap->expects($this->never())->method('setChildTableWhereStatement');
287 $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting'));
288 $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
289 $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
290 $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
291 $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
292 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getColumnsDefinition'), array(), '', FALSE);
293 $mockDataMapFactory->expects($this->once())->method('getColumnsDefinition')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue($relationTableColumnsDefiniton));
294 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
295 }
296
297 /**
298 * @test
299 */
300 public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndForeignSelectorWithForeignTableField() {
301 $leftColumnsDefinition = array(
302 'rights' => array(
303 'type' => 'inline',
304 'foreign_table' => 'tx_myextension_mm',
305 'foreign_field' => 'uid_local',
306 'foreign_selector' => 'uid_foreign',
307 'foreign_table_field' => 'tx_myextension_localtable',
308 'foreign_sortby' => 'sorting'
309 )
310 );
311 $relationTableColumnsDefinition = array(
312 'uid_local' => array(
313 'config' => array('foreign_table' => 'tx_myextension_localtable')
314 ),
315 'uid_foreign' => array(
316 'config' => array('foreign_table' => 'tx_myextension_righttable')
317 )
318 );
319 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
320 $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
321 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
322 $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
323 $mockColumnMap->expects($this->never())->method('setChildTableWhereStatement');
324 $mockColumnMap->expects($this->once())->method('setChildSortbyFieldName')->with($this->equalTo('sorting'));
325 $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
326 $mockColumnMap->expects($this->once())->method('setParentTableFieldName')->with($this->equalTo('tx_myextension_localtable'));
327 $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
328 $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
329
330 $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory'), array('getColumnsDefinition'), array(), '', FALSE);
331 $mockDataMapFactory->expects($this->once())->method('getColumnsDefinition')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue($relationTableColumnsDefinition));
332 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
333 }
334
335 /**
336 * @test
337 */
338 public function columnMapIsInitializedWithManyToManyRelationWithoutPidColumn() {
339 $leftColumnsDefinition = array(
340 'rights' => array(
341 'type' => 'select',
342 'foreign_table' => 'tx_myextension_righttable',
343 'foreign_table_where' => 'WHERE 1=1',
344 'MM' => 'tx_myextension_mm'
345 )
346 );
347 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
348 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
349 $mockColumnMap->expects($this->once())->method('getRelationTableName')->will($this->returnValue('tx_myextension_mm'));
350 $mockColumnMap->expects($this->never())->method('setrelationTablePageIdColumnName');
351 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getControlSection'), array(), '', FALSE);
352 $mockDataMapFactory->expects($this->once())->method('getControlSection')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue(NULL));
353 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
354 }
355
356 /**
357 * @test
358 */
359 public function columnMapIsInitializedWithManyToManyRelationWithPidColumn() {
360 $leftColumnsDefinition = array(
361 'rights' => array(
362 'type' => 'select',
363 'foreign_table' => 'tx_myextension_righttable',
364 'foreign_table_where' => 'WHERE 1=1',
365 'MM' => 'tx_myextension_mm'
366 )
367 );
368 $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
369 $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
370 $mockColumnMap->expects($this->once())->method('getRelationTableName')->will($this->returnValue('tx_myextension_mm'));
371 $mockColumnMap->expects($this->once())->method('setrelationTablePageIdColumnName')->with($this->equalTo('pid'));
372 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getControlSection'), array(), '', FALSE);
373 $mockDataMapFactory->expects($this->once())->method('getControlSection')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue(array('ctrl' => array('foo' => 'bar'))));
374 $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
375 }
376
377 /**
378 * @test
379 * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidClassException
380 */
381 public function buildDataMapThrowsExceptionIfClassNameIsNotKnown() {
382 $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getControlSection'), array(), '', FALSE);
383 $cacheMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', array('get'), array(), '', FALSE);
384 $cacheMock->expects($this->any())->method('get')->will($this->returnValue(FALSE));
385 $mockDataMapFactory->_set('dataMapCache', $cacheMock);
386 $mockDataMapFactory->buildDataMap('UnknownObject');
387 }
388
389 /**
390 * @test
391 */
392 public function buildDataMapFetchesSubclassesRecursively() {
393 $configuration = array(
394 'persistence' => array(
395 'classes' => array(
396 'TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser' => array(
397 'subclasses' => array(
398 'Tx_SampleExt_Domain_Model_LevelOne1' => 'Tx_SampleExt_Domain_Model_LevelOne1',
399 'Tx_SampleExt_Domain_Model_LevelOne2' => 'Tx_SampleExt_Domain_Model_LevelOne2'
400 )
401 ),
402 'Tx_SampleExt_Domain_Model_LevelOne1' => array(
403 'subclasses' => array(
404 'Tx_SampleExt_Domain_Model_LevelTwo1' => 'Tx_SampleExt_Domain_Model_LevelTwo1',
405 'Tx_SampleExt_Domain_Model_LevelTwo2' => 'Tx_SampleExt_Domain_Model_LevelTwo2'
406 )
407 ),
408 'Tx_SampleExt_Domain_Model_LevelOne2' => array(
409 'subclasses' => array()
410 )
411 )
412 )
413 );
414 $expectedSubclasses = array(
415 'Tx_SampleExt_Domain_Model_LevelOne1',
416 'Tx_SampleExt_Domain_Model_LevelTwo1',
417 'Tx_SampleExt_Domain_Model_LevelTwo2',
418 'Tx_SampleExt_Domain_Model_LevelOne2'
419 );
420 /** @var $configurationManager \TYPO3\CMS\Extbase\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject */
421 $configurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
422 $configurationManager->expects($this->once())->method('getConfiguration')->with('Framework')->will($this->returnValue($configuration));
423 $dataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('test'));
424 $dataMapFactory->injectReflectionService(new \TYPO3\CMS\Extbase\Reflection\ReflectionService());
425 $dataMapFactory->injectObjectManager(new \TYPO3\CMS\Extbase\Object\ObjectManager());
426 $dataMapFactory->injectConfigurationManager($configurationManager);
427 $cacheMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', array(), array(), '', FALSE);
428 $cacheMock->expects($this->any())->method('get')->will($this->returnValue(FALSE));
429 $dataMapFactory->_set('dataMapCache', $cacheMock);
430 $dataMap = $dataMapFactory->buildDataMap('TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser');
431 $this->assertSame($dataMap->getSubclasses(), $expectedSubclasses);
432 }
433
434 /**
435 * @return array
436 */
437 public function classNameTableNameMappings() {
438 return array(
439 'Core classes' => array('TYPO3\\CMS\\Belog\\Domain\\Model\\LogEntry', 'tx_belog_domain_model_logentry'),
440 'Extension classes' => array('ExtbaseTeam\\BlogExample\\Domain\\Model\\Blog', 'tx_blogexample_domain_model_blog'),
441 'Extension classes without namespace' => array('Tx_News_Domain_Model_News', 'tx_news_domain_model_news'),
442 );
443 }
444
445 /**
446 * @test
447 * @dataProvider classNameTableNameMappings
448 */
449 public function resolveTableNameReturnsExpectedTablenames($className, $expected) {
450 $dataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'));
451 $this->assertSame($expected, $dataMapFactory->_call('resolveTableName', $className));
452 }
453 }
454
455 ?>