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