[BUGFIX] Tests: Replace objectManager with mock in ext:extbase
[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\Persistence\Generic\Mapper\DataMapper|\PHPUnit_Framework_MockObject_MockObject
47 */
48 protected $dataMapper = NULL;
49
50 /**
51 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap|\PHPUnit_Framework_MockObject_MockObject
52 */
53 protected $dataMap;
54
55 protected function setUp() {
56 $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'));
57
58 $this->queryFactory = $this->getAccessibleMock('TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory', array('dummy'));
59 $this->queryFactory->_set('configurationManager',
60 $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface')
61 );
62
63 $this->dataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap', 'convertClassNameToTableName'));
64 $this->dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($this->dataMap));
65 $this->queryFactory->_set('dataMapper', $this->dataMapper);
66 }
67
68 public function getStaticAndRootLevelAndExpectedResult() {
69 return array(
70 'Respect storage page is set when entity is neither marked as static nor as rootLevel.' => array(FALSE, FALSE, TRUE),
71 'Respect storage page is set when entity is marked as static and rootLevel.' => array(TRUE, TRUE, FALSE),
72 'Respect storage page is set when entity is marked as static but not rootLevel.' => array(TRUE, FALSE, FALSE),
73 'Respect storage page is set when entity is not marked as static but as rootLevel.' => array(FALSE, TRUE, FALSE),
74 );
75 }
76
77 /**
78 * @param boolean $static
79 * @param boolean $rootLevel
80 * @param boolean $expectedResult
81 *
82 * @dataProvider getStaticAndRootLevelAndExpectedResult
83 * @test
84 */
85 public function createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult) {
86 /** @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject $objectManager */
87 $objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
88 $this->queryFactory->_set('objectManager', $objectManager);
89
90 $this->dataMap->expects($this->any())->method('getIsStatic')->will($this->returnValue($static));
91 $this->dataMap->expects($this->any())->method('getRootLevel')->will($this->returnValue($rootLevel));
92
93 $query = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
94 $objectManager->expects($this->at(0))->method('get')
95 ->with('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface')
96 ->will($this->returnValue($query));
97
98 $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
99 $objectManager->expects($this->at(1))->method('get')
100 ->with('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface')
101 ->will($this->returnValue($querySettings));
102 $query->expects($this->once())->method('setQuerySettings')->with($querySettings);
103 $this->queryFactory->create($this->className);
104
105 $this->assertSame(
106 $expectedResult,
107 $querySettings->getRespectStoragePage()
108 );
109 }
110 }