TYPO3 CMS  TYPO3_8-7
QueryFactoryTest.php
Go to the documentation of this file.
1 <?php
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 
20 class QueryFactoryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
25  protected $className = 'Vendor\\Ext\\Domain\\Model\\ClubMate';
26 
30  protected $queryFactory = null;
31 
35  protected $dataMapper = null;
36 
40  protected $dataMap;
41 
42  protected function setUp()
43  {
44  $this->dataMap = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap::class)
45  ->setMethods(['getIsStatic', 'getRootLevel'])
46  ->setConstructorArgs(['Vendor\\Ext\\Domain\\Model\\ClubMate', 'tx_ext_domain_model_clubmate'])
47  ->getMock();
48 
49  $this->queryFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory::class, ['dummy']);
50  $this->queryFactory->_set(
51  'configurationManager',
52  $this->createMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class)
53  );
54 
55  $this->dataMapper = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class)
56  ->setMethods(['getDataMap', 'convertClassNameToTableName'])
57  ->getMock();
58  $this->dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($this->dataMap));
59  $this->queryFactory->_set('dataMapper', $this->dataMapper);
60  }
61 
63  {
64  return [
65  'Respect storage page is set when entity is neither marked as static nor as rootLevel.' => [false, false, true],
66  'Respect storage page is set when entity is marked as static and rootLevel.' => [true, true, false],
67  'Respect storage page is set when entity is marked as static but not rootLevel.' => [true, false, false],
68  'Respect storage page is set when entity is not marked as static but as rootLevel.' => [false, true, false],
69  ];
70  }
71 
80  public function createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult)
81  {
83  $objectManager = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
84  $this->queryFactory->_set('objectManager', $objectManager);
85 
86  $this->dataMap->expects($this->any())->method('getIsStatic')->will($this->returnValue($static));
87  $this->dataMap->expects($this->any())->method('getRootLevel')->will($this->returnValue($rootLevel));
88 
89  $query = $this->createMock(\TYPO3\CMS\Extbase\Persistence\QueryInterface::class);
90  $objectManager->expects($this->at(0))->method('get')
91  ->with(\TYPO3\CMS\Extbase\Persistence\QueryInterface::class)
92  ->will($this->returnValue($query));
93 
94  $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
95  $objectManager->expects($this->at(1))->method('get')
96  ->with(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class)
97  ->will($this->returnValue($querySettings));
98  $query->expects($this->once())->method('setQuerySettings')->with($querySettings);
99  $this->queryFactory->create($this->className);
100 
101  $this->assertSame(
102  $expectedResult,
103  $querySettings->getRespectStoragePage()
104  );
105  }
106 }