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