[TASK] Merge submodule workspaces into core
[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 * Copyright notice
6 *
7 * (c) 2012 Alexander Schnitzler <alex.schnitzler@typovision.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Testcase for \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
29 *
30 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
31 * @author Oliver Klee <typo3-coding@oliverklee.de>
32 */
33 class QueryFactoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
34
35 /**
36 * @var string
37 */
38 protected $className = 'Vendor\\Ext\\Domain\\Model\\ClubMate';
39
40 /**
41 * @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
42 */
43 protected $queryFactory = NULL;
44
45 /**
46 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
47 */
48 protected $objectManager = NULL;
49
50 /**
51 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper|\PHPUnit_Framework_MockObject_MockObject
52 */
53 protected $dataMapper = NULL;
54
55 /**
56 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap|\PHPUnit_Framework_MockObject_MockObject
57 */
58 protected $dataMap;
59
60 protected function setUp() {
61 $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'));
62
63 $this->queryFactory = new \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory();
64 $this->queryFactory->injectConfigurationManager(
65 $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface')
66 );
67
68 $this->objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
69 $this->queryFactory->injectObjectManager($this->objectManager);
70
71 $this->dataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap', 'convertClassNameToTableName'));
72 $this->dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($this->dataMap));
73 $this->queryFactory->injectDataMapper($this->dataMapper);
74 }
75
76 protected function tearDown() {
77 unset($this->objectManager, $this->dataMapper, $this->queryFactory);
78 }
79
80 public function getStaticAndRootLevelAndExpectedResult() {
81 return array(
82 'Respect storage page is set when entity is neither marked as static nor as rootLevel.' => array(FALSE, FALSE, TRUE),
83 'Respect storage page is set when entity is marked as static and rootLevel.' => array(TRUE, TRUE, FALSE),
84 'Respect storage page is set when entity is marked as static but not rootLevel.' => array(TRUE, FALSE, FALSE),
85 'Respect storage page is set when entity is not marked as static but as rootLevel.' => array(FALSE, TRUE, FALSE),
86 );
87 }
88
89 /**
90 * @param boolean $static
91 * @param boolean $rootLevel
92 * @param boolean $expectedResult
93 *
94 * @dataProvider getStaticAndRootLevelAndExpectedResult
95 * @test
96 */
97 public function createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult) {
98 $this->dataMap->expects($this->any())->method('getIsStatic')->will($this->returnValue($static));
99 $this->dataMap->expects($this->any())->method('getRootLevel')->will($this->returnValue($rootLevel));
100
101 $query = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
102 $this->objectManager->expects($this->at(0))->method('get')
103 ->with('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface')
104 ->will($this->returnValue($query));
105
106 $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
107 $this->objectManager->expects($this->at(1))->method('get')
108 ->with('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface')
109 ->will($this->returnValue($querySettings));
110 $query->expects($this->once())->method('setQuerySettings')->with($querySettings);
111 $this->queryFactory->create($this->className);
112
113 $this->assertSame(
114 $expectedResult,
115 $querySettings->getRespectStoragePage()
116 );
117 }
118 }
119
120 ?>