TYPO3 CMS  TYPO3_7-6
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 
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->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap::class, ['getIsStatic', 'getRootLevel'], ['Vendor\\Ext\\Domain\\Model\\ClubMate', 'tx_ext_domain_model_clubmate']);
45 
46  $this->queryFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory::class, ['dummy']);
47  $this->queryFactory->_set('configurationManager',
48  $this->getMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class)
49  );
50 
51  $this->dataMapper = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class, ['getDataMap', 'convertClassNameToTableName']);
52  $this->dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($this->dataMap));
53  $this->queryFactory->_set('dataMapper', $this->dataMapper);
54  }
55 
57  {
58  return [
59  'Respect storage page is set when entity is neither marked as static nor as rootLevel.' => [false, false, true],
60  'Respect storage page is set when entity is marked as static and rootLevel.' => [true, true, false],
61  'Respect storage page is set when entity is marked as static but not rootLevel.' => [true, false, false],
62  'Respect storage page is set when entity is not marked as static but as rootLevel.' => [false, true, false],
63  ];
64  }
65 
74  public function createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult)
75  {
77  $objectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
78  $this->queryFactory->_set('objectManager', $objectManager);
79 
80  $this->dataMap->expects($this->any())->method('getIsStatic')->will($this->returnValue($static));
81  $this->dataMap->expects($this->any())->method('getRootLevel')->will($this->returnValue($rootLevel));
82 
83  $query = $this->getMock(\TYPO3\CMS\Extbase\Persistence\QueryInterface::class);
84  $objectManager->expects($this->at(0))->method('get')
85  ->with(\TYPO3\CMS\Extbase\Persistence\QueryInterface::class)
86  ->will($this->returnValue($query));
87 
88  $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
89  $objectManager->expects($this->at(1))->method('get')
90  ->with(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class)
91  ->will($this->returnValue($querySettings));
92  $query->expects($this->once())->method('setQuerySettings')->with($querySettings);
93  $this->queryFactory->create($this->className);
94 
95  $this->assertSame(
96  $expectedResult,
97  $querySettings->getRespectStoragePage()
98  );
99  }
100 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)