‪TYPO3CMS  9.5
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 
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪QueryFactoryTest extends UnitTestCase
23 {
27  protected ‪$className = 'Vendor\\Ext\\Domain\\Model\\ClubMate';
28 
32  protected ‪$queryFactory;
33 
37  protected ‪$dataMapFactory;
38 
42  protected ‪$dataMap;
43 
44  protected function ‪setUp()
45  {
46  $this->dataMap = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\Mapper\DataMap::class)
47  ->setMethods(['getIsStatic', 'getRootLevel'])
48  ->setConstructorArgs(['Vendor\\Ext\\Domain\\Model\\ClubMate', 'tx_ext_domain_model_clubmate'])
49  ->getMock();
50 
51  $this->queryFactory = $this->getAccessibleMock(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\QueryFactory::class, ['dummy']);
52  $this->queryFactory->_set(
53  'configurationManager',
54  $this->createMock(\‪TYPO3\CMS\‪Extbase\Configuration\ConfigurationManagerInterface::class)
55  );
56 
57  $this->dataMapFactory = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\Mapper\DataMapFactory::class)
58  ->setMethods(['buildDataMap', 'convertClassNameToTableName'])
59  ->getMock();
60  $this->dataMapFactory->expects($this->any())->method('buildDataMap')->will($this->returnValue($this->dataMap));
61  $this->queryFactory->_set('dataMapFactory', $this->dataMapFactory);
62  }
63 
65  {
66  return [
67  'Respect storage page is set when entity is neither marked as static nor as rootLevel.' => [false, false, true],
68  'Respect storage page is set when entity is marked as static and rootLevel.' => [true, true, false],
69  'Respect storage page is set when entity is marked as static but not rootLevel.' => [true, false, false],
70  'Respect storage page is set when entity is not marked as static but as rootLevel.' => [false, true, false],
71  ];
72  }
73 
82  public function ‪createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult)
83  {
85  $objectManager = $this->createMock(\‪TYPO3\CMS\‪Extbase\Object\ObjectManager::class);
86  $this->queryFactory->_set('objectManager', $objectManager);
87 
88  $this->dataMap->expects($this->any())->method('getIsStatic')->will($this->returnValue($static));
89  $this->dataMap->expects($this->any())->method('getRootLevel')->will($this->returnValue($rootLevel));
90 
91  $query = $this->createMock(\‪TYPO3\CMS\‪Extbase\Persistence\QueryInterface::class);
92  $objectManager->expects($this->at(0))->method('get')
93  ->with(\‪TYPO3\CMS\‪Extbase\Persistence\QueryInterface::class)
94  ->will($this->returnValue($query));
95 
96  $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
97  $objectManager->expects($this->at(1))->method('get')
98  ->with(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\QuerySettingsInterface::class)
99  ->will($this->returnValue($querySettings));
100  $query->expects($this->once())->method('setQuerySettings')->with($querySettings);
101  $this->queryFactory->create($this->className);
102 
103  $this->assertSame(
104  $expectedResult,
105  $querySettings->getRespectStoragePage()
106  );
107  }
108 }
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\setUp
‪setUp()
Definition: QueryFactoryTest.php:40
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\$dataMap
‪TYPO3 CMS Extbase Persistence Generic Mapper DataMap PHPUnit_Framework_MockObject_MockObject $dataMap
Definition: QueryFactoryTest.php:38
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\getStaticAndRootLevelAndExpectedResult
‪getStaticAndRootLevelAndExpectedResult()
Definition: QueryFactoryTest.php:60
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue
‪createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult)
Definition: QueryFactoryTest.php:78
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\$queryFactory
‪TYPO3 CMS Extbase Persistence Generic QueryFactory $queryFactory
Definition: QueryFactoryTest.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\$className
‪string $className
Definition: QueryFactoryTest.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic
Definition: BackendTest.php:3
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest
Definition: QueryFactoryTest.php:23
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\$dataMapFactory
‪TYPO3 CMS Extbase Persistence Generic Mapper DataMapFactory PHPUnit_Framework_MockObject_MockObject $dataMapFactory
Definition: QueryFactoryTest.php:34