‪TYPO3CMS  ‪main
DataMapperTest.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 Doctrine\Instantiator\InstantiatorInterface;
21 use PHPUnit\Framework\Attributes\Test;
22 use Psr\EventDispatcher\EventDispatcherInterface;
35 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
36 
37 final class ‪DataMapperTest extends UnitTestCase
38 {
39  protected bool ‪$resetSingletonInstances = true;
40 
44 
45  protected function ‪setUp(): void
46  {
47  parent::setUp();
48 
49  $this->columnMap = new ‪ColumnMap('foo');
50 
51  $this->columnMapFactory = new ‪ColumnMapFactory(
52  $this->createMock(ReflectionService::class)
53  );
54 
55  $dataMapFactory = new ‪DataMapFactory(
56  $this->createMock(ReflectionService::class),
57  $this->createMock(ConfigurationManager::class),
58  $this->createMock(CacheManager::class),
59  $this->createMock(ClassesConfiguration::class),
60  $this->columnMapFactory,
61  'foo'
62  );
63 
64  $this->dataMapper = new ‪DataMapper(
65  $this->createMock(ReflectionService::class),
66  $this->createMock(QueryObjectModelFactory::class),
67  $this->createMock(Session::class),
68  $dataMapFactory,
69  $this->createMock(QueryFactory::class),
70  $this->createMock(EventDispatcherInterface::class),
71  $this->createMock(InstantiatorInterface::class),
72  );
73  }
74 
75  #[Test]
77  {
78  // Arrange
79  $this->columnMapFactory->setOneToManyRelation(
80  $this->columnMap,
81  [
82  'foreign_table' => 'tx_myextension_bar',
83  ]
84  );
85 
86  // Act
87  $orderings = $this->dataMapper->getOrderingsForColumnMap($this->columnMap);
88 
89  // Assert
90  self::assertNull($orderings);
91  }
92 
93  #[Test]
95  {
96  // Arrange
97  $this->columnMapFactory->setOneToManyRelation(
98  $this->columnMap,
99  [
100  'foreign_table' => 'tx_myextension_bar',
101  'foreign_default_sortby' => '',
102  ]
103  );
104 
105  // Act
106  $orderings = $this->dataMapper->getOrderingsForColumnMap($this->columnMap);
107 
108  // Assert
109  self::assertNull($orderings);
110  }
111 
112  #[Test]
114  {
115  // Arrange
116  $this->columnMapFactory->setOneToManyRelation(
117  $this->columnMap,
118  [
119  'foreign_table' => 'tx_myextension_bar',
120  'foreign_default_sortby' => 'pid invalid',
121  ]
122  );
123 
124  // Act
125  $orderings = $this->dataMapper->getOrderingsForColumnMap($this->columnMap);
126 
127  // Assert
128  self::assertSame(
130  $orderings
131  );
132  }
133 
134  #[Test]
136  {
137  // Arrange
138  $this->columnMapFactory->setOneToManyRelation(
139  $this->columnMap,
140  [
141  'foreign_table' => 'tx_myextension_bar',
142  'foreign_sortby' => 'uid',
143  ]
144  );
145 
146  // Act
147  $orderings = $this->dataMapper->getOrderingsForColumnMap($this->columnMap);
148 
149  // Assert
150  self::assertSame(
152  $orderings
153  );
154  }
155 
156  #[Test]
158  {
159  // Arrange
160  $this->columnMapFactory->setOneToManyRelation(
161  $this->columnMap,
162  [
163  'foreign_table' => 'tx_myextension_bar',
164  'foreign_sortby' => 'uid',
165  'foreign_default_sortby' => 'pid',
166  ]
167  );
168 
169  // Act
170  $orderings = $this->dataMapper->getOrderingsForColumnMap($this->columnMap);
171 
172  // Assert
173  self::assertSame(
175  $orderings
176  );
177  }
178 
179  #[Test]
181  {
182  // Arrange
183  $this->columnMapFactory->setOneToManyRelation(
184  $this->columnMap,
185  [
186  'foreign_table' => 'tx_myextension_bar',
187  'foreign_default_sortby' => 'pid',
188  ]
189  );
190 
191  // Act
192  $orderings = $this->dataMapper->getOrderingsForColumnMap($this->columnMap);
193 
194  // Assert
195  self::assertSame(
197  $orderings
198  );
199  }
200 
201  #[Test]
203  {
204  // Arrange
205  $this->columnMapFactory->setOneToManyRelation(
206  $this->columnMap,
207  [
208  'foreign_table' => 'tx_myextension_bar',
209  'foreign_default_sortby' => 'pid desc',
210  ]
211  );
212 
213  // Act
214  $orderings = $this->dataMapper->getOrderingsForColumnMap($this->columnMap);
215 
216  // Assert
217  self::assertSame(
219  $orderings
220  );
221  }
222 
223  #[Test]
225  {
226  // Arrange
227  $this->columnMapFactory->setOneToManyRelation(
228  $this->columnMap,
229  [
230  'foreign_table' => 'tx_myextension_bar',
231  'foreign_default_sortby' => 'pid desc, title, uid asc',
232  ]
233  );
234 
235  // Act
236  $orderings = $this->dataMapper->getOrderingsForColumnMap($this->columnMap);
237 
238  // Assert
239  self::assertSame(
241  $orderings
242  );
243  }
244 }
‪TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
Definition: QueryFactory.php:32
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMapFactory
Definition: ColumnMapFactory.php:33
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest\getOrderingsForColumnMapReturnsNullIfForeignDefaultSortByIsEmpty
‪getOrderingsForColumnMapReturnsNullIfForeignDefaultSortByIsEmpty()
Definition: DataMapperTest.php:94
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest\$columnMap
‪ColumnMap $columnMap
Definition: DataMapperTest.php:41
‪TYPO3\CMS\Extbase\Persistence\QueryInterface
Definition: QueryInterface.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest\setOneToManyRelationDetectsForeignDefaultSortByWithDirection
‪setOneToManyRelationDetectsForeignDefaultSortByWithDirection()
Definition: DataMapperTest.php:202
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap
Definition: ColumnMap.php:27
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest\$dataMapper
‪DataMapper $dataMapper
Definition: DataMapperTest.php:43
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\ORDER_DESCENDING
‪const ORDER_DESCENDING
Definition: QueryInterface.php:100
‪TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory
Definition: QueryObjectModelFactory.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest\setUp
‪setUp()
Definition: DataMapperTest.php:45
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
Definition: DataMapper.php:58
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper
Definition: DataMapFactoryTest.php:18
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest\getOrderingsForColumnMapReturnsNullIfNeitherForeignSortByNorForeignDefaultSortByAreSet
‪getOrderingsForColumnMapReturnsNullIfNeitherForeignSortByNorForeignDefaultSortByAreSet()
Definition: DataMapperTest.php:76
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
Definition: DataMapFactory.php:34
‪TYPO3\CMS\Extbase\Reflection\ReflectionService
Definition: ReflectionService.php:28
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager
Definition: ConfigurationManager.php:32
‪TYPO3\CMS\Extbase\Persistence\QueryInterface\ORDER_ASCENDING
‪const ORDER_ASCENDING
Definition: QueryInterface.php:99
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest\getOrderingsForColumnMapFallBackToAscendingOrdering
‪getOrderingsForColumnMapFallBackToAscendingOrdering()
Definition: DataMapperTest.php:113
‪TYPO3\CMS\Extbase\Persistence\Generic\Session
Definition: Session.php:27
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest\setOneToManyRelationDetectsForeignDefaultSortByWithoutDirection
‪setOneToManyRelationDetectsForeignDefaultSortByWithoutDirection()
Definition: DataMapperTest.php:180
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest
Definition: DataMapperTest.php:38
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest\$columnMapFactory
‪ColumnMapFactory $columnMapFactory
Definition: DataMapperTest.php:42
‪TYPO3\CMS\Extbase\Persistence\ClassesConfiguration
Definition: ClassesConfiguration.php:21
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest\setOneToManyRelationDetectsForeignSortBy
‪setOneToManyRelationDetectsForeignSortBy()
Definition: DataMapperTest.php:135
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest\setOneToManyRelationDetectsMultipleForeignDefaultSortByWithAndWithoutDirection
‪setOneToManyRelationDetectsMultipleForeignDefaultSortByWithAndWithoutDirection()
Definition: DataMapperTest.php:224
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap
Definition: Relation.php:18
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest\setOneToManyRelationDetectsForeignSortByWithForeignDefaultSortBy
‪setOneToManyRelationDetectsForeignSortByWithForeignDefaultSortBy()
Definition: DataMapperTest.php:157
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper\DataMapperTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: DataMapperTest.php:39