‪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 
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 
29 class ‪DataMapperTest extends FunctionalTestCase
30 {
34  protected ‪$persistenceManager;
35 
36  protected ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
37 
41  protected function ‪setUp(): void
42  {
43  parent::setUp();
44  $this->persistenceManager = $this->get(PersistenceManager::class);
45  ‪$GLOBALS['BE_USER'] = new ‪BackendUserAuthentication();
46  }
47 
52  {
53  $example = new ‪DateExample();
54  $date = new \DateTime('2016-03-06T12:40:00+01:00');
55  $example->setDatetimeInt($date);
56 
57  $this->persistenceManager->add($example);
58  $this->persistenceManager->persistAll();
59  $uid = $this->persistenceManager->getIdentifierByObject($example);
60  $this->persistenceManager->clearState();
61 
63  $example = $this->persistenceManager->getObjectByIdentifier($uid, DateExample::class);
64 
65  self::assertEquals($example->getDatetimeInt()->getTimestamp(), $date->getTimestamp());
66  }
67 
72  {
73  $example = new DateExample();
74  $date = new \DateTime('2016-03-06T12:40:00+01:00');
75  $example->setDatetimeText($date);
76 
77  $this->persistenceManager->add($example);
78  $this->persistenceManager->persistAll();
79  $uid = $this->persistenceManager->getIdentifierByObject($example);
80  $this->persistenceManager->clearState();
81 
83  $example = $this->persistenceManager->getObjectByIdentifier($uid, DateExample::class);
84 
85  self::assertEquals($example->getDatetimeText()->getTimestamp(), $date->getTimestamp());
86  }
87 
92  {
93  $example = new DateExample();
94  $date = new \DateTime('2016-03-06T12:40:00');
95  $example->setDatetimeDatetime($date);
96 
97  $this->persistenceManager->add($example);
98  $this->persistenceManager->persistAll();
99  $uid = $this->persistenceManager->getIdentifierByObject($example);
100  $this->persistenceManager->clearState();
101 
103  $example = $this->persistenceManager->getObjectByIdentifier($uid, DateExample::class);
104 
105  self::assertEquals($example->getDatetimeDatetime()->getTimestamp(), $date->getTimestamp());
106  }
107 
111  public function ‪dateTimeImmutableIntIsHandledAsDateTime(): void
112  {
113  $subject = new DateTimeImmutableExample();
114  $date = new \DateTimeImmutable('2018-07-24T20:40:00');
115  $subject->setDatetimeImmutableInt($date);
116 
117  $this->persistenceManager->add($subject);
118  $this->persistenceManager->persistAll();
119  $uid = $this->persistenceManager->getIdentifierByObject($subject);
120  $this->persistenceManager->clearState();
121 
123  $subject = $this->persistenceManager->getObjectByIdentifier($uid, DateTimeImmutableExample::class);
124 
125  self::assertEquals($date, $subject->getDatetimeImmutableInt());
126  }
127 
131  public function ‪dateTimeImmutableTextIsHandledAsDateTime(): void
132  {
133  $subject = new DateTimeImmutableExample();
134  $date = new \DateTimeImmutable('2018-07-24T20:40:00');
135  $subject->setDatetimeImmutableText($date);
136 
137  $this->persistenceManager->add($subject);
138  $this->persistenceManager->persistAll();
139  $uid = $this->persistenceManager->getIdentifierByObject($subject);
140  $this->persistenceManager->clearState();
141 
143  $subject = $this->persistenceManager->getObjectByIdentifier($uid, DateTimeImmutableExample::class);
144 
145  self::assertEquals($date, $subject->getDatetimeImmutableText());
146  }
147 
152  {
153  $subject = new DateTimeImmutableExample();
154  $date = new \DateTimeImmutable('2018-07-24T20:40:00');
155  $subject->setDatetimeImmutableDatetime($date);
156 
157  $this->persistenceManager->add($subject);
158  $this->persistenceManager->persistAll();
159  $uid = $this->persistenceManager->getIdentifierByObject($subject);
160  $this->persistenceManager->clearState();
161 
163  $subject = $this->persistenceManager->getObjectByIdentifier($uid, DateTimeImmutableExample::class);
164 
165  self::assertSame($date->getTimestamp(), $subject->getDatetimeImmutableDatetime()->getTimestamp());
166  }
167 
172  {
173  // Arrange
174  $this->importCSVDataSet('typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.csv');
175  $this->importCSVDataSet('typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/comments.csv');
176 
177  $dataMapper = $this->get(DataMapper::class);
178 
179  $post = new Post();
180  $post->_setProperty('uid', 1);
181 
182  // Act
183  $comments = $dataMapper->fetchRelated($post, 'comments', '5', false)->toArray();
184 
185  // Assert
186  self::assertSame(
187  [5, 4, 3, 2, 1], // foreign_default_sortby is set to uid desc, see
188  array_map(fn(Comment $comment) => $comment->getUid(), $comments)
189  );
190  }
191 }
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper\DataMapperTest\dateValuesAreStoredInLocalTimeInDatetimeDatabaseFields
‪dateValuesAreStoredInLocalTimeInDatetimeDatabaseFields()
Definition: DataMapperTest.php:90
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper\DataMapperTest\fetchRelatedRespectsForeignDefaultSortByTCAConfiguration
‪fetchRelatedRespectsForeignDefaultSortByTCAConfiguration()
Definition: DataMapperTest.php:170
‪TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject\getUid
‪int null getUid()
Definition: AbstractDomainObject.php:67
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper\DataMapperTest
Definition: DataMapperTest.php:30
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper\DataMapperTest\dateTimeImmutableTextIsHandledAsDateTime
‪dateTimeImmutableTextIsHandledAsDateTime()
Definition: DataMapperTest.php:130
‪ExtbaseTeam\BlogExample\Domain\Model\DateExample
Definition: DateExample.php:23
‪TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
Definition: DataMapper.php:51
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper
Definition: DataMapFactoryTest.php:18
‪TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
Definition: PersistenceManager.php:28
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper\DataMapperTest\dateTimeImmutableIntIsHandledAsDateTime
‪dateTimeImmutableIntIsHandledAsDateTime()
Definition: DataMapperTest.php:110
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper\DataMapperTest\$testExtensionsToLoad
‪$testExtensionsToLoad
Definition: DataMapperTest.php:35
‪ExtbaseTeam\BlogExample\Domain\Model\Post
Definition: Post.php:28
‪ExtbaseTeam\BlogExample\Domain\Model\Comment
Definition: Comment.php:27
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper\DataMapperTest\dateTimeImmutableDateTimeIsHandledAsDateTime
‪dateTimeImmutableDateTimeIsHandledAsDateTime()
Definition: DataMapperTest.php:150
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper\DataMapperTest\dateValuesAreStoredInUtcInIntegerDatabaseFields
‪dateValuesAreStoredInUtcInIntegerDatabaseFields()
Definition: DataMapperTest.php:50
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper\DataMapperTest\dateValuesAreStoredInUtcInTextDatabaseFields
‪dateValuesAreStoredInUtcInTextDatabaseFields()
Definition: DataMapperTest.php:70
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper\DataMapperTest\$persistenceManager
‪PersistenceManager $persistenceManager
Definition: DataMapperTest.php:33
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper\DataMapperTest\setUp
‪setUp()
Definition: DataMapperTest.php:40
‪ExtbaseTeam\BlogExample\Domain\Model\DateTimeImmutableExample
Definition: DateTimeImmutableExample.php:23