‪TYPO3CMS  10.4
QueryFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪QueryFactoryTest extends UnitTestCase
32 {
36  protected ‪$className = 'Vendor\\Ext\\Domain\\Model\\ClubMate';
37 
41  protected ‪$queryFactory;
42 
46  protected ‪$objectManager;
47 
51  protected ‪$dataMapFactory;
52 
56  protected ‪$dataMap;
57 
58  protected function ‪setUp(): void
59  {
60  parent::setUp();
62  $this->objectManager = $this->createMock(ObjectManager::class);
63 
64  $this->dataMap = $this->getMockBuilder(DataMap::class)
65  ->setMethods(['getIsStatic', 'getRootLevel'])
66  ->setConstructorArgs(['Vendor\\Ext\\Domain\\Model\\ClubMate', 'tx_ext_domain_model_clubmate'])
67  ->getMock();
68 
69  $this->dataMapFactory = $this->getMockBuilder(DataMapFactory::class)
70  ->disableOriginalConstructor()
71  ->setMethods(['buildDataMap', 'convertClassNameToTableName'])
72  ->getMock();
73  $this->dataMapFactory->expects(self::any())->method('buildDataMap')->willReturn($this->dataMap);
74 
75  $this->queryFactory = new ‪QueryFactory(
76  $this->objectManager,
77  $this->createMock(ConfigurationManagerInterface::class),
78  $this->dataMapFactory
79  );
80  }
81 
83  {
84  return [
85  'Respect storage page is set when entity is neither marked as static nor as rootLevel.' => [false, false, true],
86  'Respect storage page is set when entity is marked as static and rootLevel.' => [true, true, false],
87  'Respect storage page is set when entity is marked as static but not rootLevel.' => [true, false, false],
88  'Respect storage page is set when entity is not marked as static but as rootLevel.' => [false, true, false],
89  ];
90  }
91 
100  public function ‪createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult)
101  {
102  $this->dataMap->expects(self::any())->method('getIsStatic')->willReturn($static);
103  $this->dataMap->expects(self::any())->method('getRootLevel')->willReturn($rootLevel);
104 
105  $query = $this->createMock(QueryInterface::class);
106  $querySettings = new Typo3QuerySettings();
107  $this->objectManager->expects(self::exactly(2))->method('get')
108  ->withConsecutive([QueryInterface::class], [QuerySettingsInterface::class])
109  ->willReturnOnConsecutiveCalls($query, $querySettings);
110 
111  $query->expects(self::once())->method('setQuerySettings')->with($querySettings);
112  $this->queryFactory->create($this->className);
113 
114  self::assertSame(
115  $expectedResult,
116  $querySettings->getRespectStoragePage()
117  );
118  }
119 }
‪TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
Definition: QueryFactory.php:30
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap
Definition: DataMap.php:23
‪TYPO3\CMS\Extbase\Persistence\QueryInterface
Definition: QueryInterface.php:29
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\$objectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface PHPUnit Framework MockObject MockObject $objectManager
Definition: QueryFactoryTest.php:43
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\setUp
‪setUp()
Definition: QueryFactoryTest.php:53
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\getStaticAndRootLevelAndExpectedResult
‪getStaticAndRootLevelAndExpectedResult()
Definition: QueryFactoryTest.php:77
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
Definition: DataMapFactory.php:42
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue
‪createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult)
Definition: QueryFactoryTest.php:95
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\$queryFactory
‪TYPO3 CMS Extbase Persistence Generic QueryFactory $queryFactory
Definition: QueryFactoryTest.php:39
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\$className
‪string $className
Definition: QueryFactoryTest.php:35
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic
Definition: BackendTest.php:18
‪TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
Definition: QuerySettingsInterface.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest
Definition: QueryFactoryTest.php:32
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\$dataMap
‪TYPO3 CMS Extbase Persistence Generic Mapper DataMap PHPUnit Framework MockObject MockObject $dataMap
Definition: QueryFactoryTest.php:51
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\$dataMapFactory
‪TYPO3 CMS Extbase Persistence Generic Mapper DataMapFactory PHPUnit Framework MockObject MockObject $dataMapFactory
Definition: QueryFactoryTest.php:47
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings
Definition: Typo3QuerySettings.php:29