e89e5e6451d98cbae259477010839ad0ebd38ca1
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Persistence / Generic / QueryFactoryTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic;
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 /**
18 * Test case
19 */
20 class QueryFactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @var string
24 */
25 protected $className = 'Vendor\\Ext\\Domain\\Model\\ClubMate';
26
27 /**
28 * @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
29 */
30 protected $queryFactory = NULL;
31
32 /**
33 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper|\PHPUnit_Framework_MockObject_MockObject
34 */
35 protected $dataMapper = NULL;
36
37 /**
38 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap|\PHPUnit_Framework_MockObject_MockObject
39 */
40 protected $dataMap;
41
42 protected function setUp() {
43 $this->dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getIsStatic', 'getRootLevel'), array('Vendor\\Ext\\Domain\\Model\\ClubMate', 'tx_ext_domain_model_clubmate'));
44
45 $this->queryFactory = $this->getAccessibleMock('TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory', array('dummy'));
46 $this->queryFactory->_set('configurationManager',
47 $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface')
48 );
49
50 $this->dataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap', 'convertClassNameToTableName'));
51 $this->dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($this->dataMap));
52 $this->queryFactory->_set('dataMapper', $this->dataMapper);
53 }
54
55 public function getStaticAndRootLevelAndExpectedResult() {
56 return array(
57 'Respect storage page is set when entity is neither marked as static nor as rootLevel.' => array(FALSE, FALSE, TRUE),
58 'Respect storage page is set when entity is marked as static and rootLevel.' => array(TRUE, TRUE, FALSE),
59 'Respect storage page is set when entity is marked as static but not rootLevel.' => array(TRUE, FALSE, FALSE),
60 'Respect storage page is set when entity is not marked as static but as rootLevel.' => array(FALSE, TRUE, FALSE),
61 );
62 }
63
64 /**
65 * @param bool $static
66 * @param bool $rootLevel
67 * @param bool $expectedResult
68 *
69 * @dataProvider getStaticAndRootLevelAndExpectedResult
70 * @test
71 */
72 public function createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult) {
73 /** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */
74 $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
75 $this->queryFactory->_set('objectManager', $objectManager);
76
77 $this->dataMap->expects($this->any())->method('getIsStatic')->will($this->returnValue($static));
78 $this->dataMap->expects($this->any())->method('getRootLevel')->will($this->returnValue($rootLevel));
79
80 $query = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
81 $objectManager->expects($this->at(0))->method('get')
82 ->with('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface')
83 ->will($this->returnValue($query));
84
85 $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
86 $objectManager->expects($this->at(1))->method('get')
87 ->with('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface')
88 ->will($this->returnValue($querySettings));
89 $query->expects($this->once())->method('setQuerySettings')->with($querySettings);
90 $this->queryFactory->create($this->className);
91
92 $this->assertSame(
93 $expectedResult,
94 $querySettings->getRespectStoragePage()
95 );
96 }
97 }