‪TYPO3CMS  11.5
QueryFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Prophecy\PhpUnit\ProphecyTrait;
21 use Psr\Container\ContainerInterface;
32 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
33 
37 class ‪QueryFactoryTest extends UnitTestCase
38 {
39  use ProphecyTrait;
40 
41  protected string ‪$className = 'Vendor\\Ext\\Domain\\Model\\ClubMate';
43 
47  protected ‪$container;
48 
52  protected ‪$dataMapFactory;
53 
57  protected ‪$dataMap;
58 
59  protected function ‪setUp(): void
60  {
61  parent::setUp();
62 
63  $this->container = $this->createMock(ContainerInterface::class);
64 
65  $this->dataMap = $this->getMockBuilder(DataMap::class)
66  ->onlyMethods(['getIsStatic', 'getRootLevel'])
67  ->setConstructorArgs(['Vendor\\Ext\\Domain\\Model\\ClubMate', 'tx_ext_domain_model_clubmate'])
68  ->getMock();
69 
70  $this->dataMapFactory = $this->getMockBuilder(DataMapFactory::class)
71  ->disableOriginalConstructor()
72  ->onlyMethods(['buildDataMap'])
73  ->addMethods(['convertClassNameToTableName'])
74  ->getMock();
75  $this->dataMapFactory->method('buildDataMap')->willReturn($this->dataMap);
76 
77  $this->queryFactory = new ‪QueryFactory(
78  $this->createMock(ConfigurationManagerInterface::class),
79  $this->dataMapFactory,
80  $this->container
81  );
82  }
83 
84  public function ‪getStaticAndRootLevelAndExpectedResult(): array
85  {
86  return [
87  'Respect storage page is set when entity is neither marked as static nor as rootLevel.' => [false, false, true],
88  'Respect storage page is set when entity is marked as static and rootLevel.' => [true, true, false],
89  'Respect storage page is set when entity is marked as static but not rootLevel.' => [true, false, false],
90  'Respect storage page is set when entity is not marked as static but as rootLevel.' => [false, true, false],
91  ];
92  }
93 
102  public function ‪createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult): void
103  {
104  $this->dataMap->method('getIsStatic')->willReturn($static);
105  $this->dataMap->method('getRootLevel')->willReturn($rootLevel);
106 
107  $query = $this->createMock(ForwardCompatibleQueryInterface::class);
108  $querySettings = new Typo3QuerySettings(
109  new Context(),
110  $this->prophesize(ConfigurationManagerInterface::class)->reveal()
111  );
112  GeneralUtility::addInstance(QuerySettingsInterface::class, $querySettings);
113  $this->container->method('has')->willReturn(true);
114  $this->container->expects(self::once())->method('get')->with(QueryInterface::class)->willReturn($query);
115 
116  $query->expects(self::once())->method('setQuerySettings')->with($querySettings);
117  $this->queryFactory->create($this->className);
118 
119  self::assertSame(
120  $expectedResult,
121  $querySettings->getRespectStoragePage()
122  );
123  }
124 }
‪TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
Definition: QueryFactory.php:32
‪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\setUp
‪setUp()
Definition: QueryFactoryTest.php:55
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\getStaticAndRootLevelAndExpectedResult
‪getStaticAndRootLevelAndExpectedResult()
Definition: QueryFactoryTest.php:80
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
Definition: DataMapFactory.php:39
‪TYPO3\CMS\Extbase\Persistence\ForwardCompatibleQueryInterface
Definition: ForwardCompatibleQueryInterface.php:25
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue
‪createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult)
Definition: QueryFactoryTest.php:98
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\$className
‪string $className
Definition: QueryFactoryTest.php:40
‪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\$container
‪Psr Container ContainerInterface $container
Definition: QueryFactoryTest.php:45
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest
Definition: QueryFactoryTest.php:38
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\$dataMap
‪TYPO3 CMS Extbase Persistence Generic Mapper DataMap PHPUnit Framework MockObject MockObject $dataMap
Definition: QueryFactoryTest.php:53
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\$queryFactory
‪QueryFactory $queryFactory
Definition: QueryFactoryTest.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\QueryFactoryTest\$dataMapFactory
‪TYPO3 CMS Extbase Persistence Generic Mapper DataMapFactory PHPUnit Framework MockObject MockObject $dataMapFactory
Definition: QueryFactoryTest.php:49
‪TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings
Definition: Typo3QuerySettings.php:29