569ffad1ff4b5889adbf0fb5ff1549141a010eb4
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Persistence / Generic / Mapper / DataMapperTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper;
3
4 use ExtbaseTeam\BlogExample\Domain\Model\Comment;
5 use ExtbaseTeam\BlogExample\Domain\Model\DateExample;
6 use TYPO3\CMS\Core\Utility\GeneralUtility;
7
8 class DataMapperTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
9 {
10 /**
11 * @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
12 */
13 protected $persistenceManager;
14
15 /**
16 * @var array
17 */
18 protected $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
19
20 /**
21 * @var array
22 */
23 protected $coreExtensionsToLoad = ['extbase', 'fluid'];
24
25 /**
26 * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface The object manager
27 */
28 protected $objectManager;
29
30 /**
31 * Sets up this test suite.
32 */
33 protected function setUp()
34 {
35 parent::setUp();
36
37 $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
38 $this->persistenceManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
39 }
40
41 /**
42 * @test
43 */
44 public function datetimeObjectsCanBePersistedToDatetimeDatabaseFields()
45 {
46 $date = new \DateTime('2016-03-06T12:40:00+01:00');
47 $comment = new Comment();
48 $comment->setDate($date);
49
50 $this->persistenceManager->add($comment);
51 $this->persistenceManager->persistAll();
52 $uid = $this->persistenceManager->getIdentifierByObject($comment);
53 $this->persistenceManager->clearState();
54
55 /** @var Comment $existingComment */
56 $existingComment = $this->persistenceManager->getObjectByIdentifier($uid, Comment::class);
57
58 $this->assertEquals($date->getTimestamp(), $existingComment->getDate()->getTimestamp());
59 }
60 /**
61 * @test
62 */
63 public function dateValuesAreStoredInUtcInIntegerDatabaseFields()
64 {
65 $example = new DateExample();
66 $date = new \DateTime('2016-03-06T12:40:00+01:00');
67 $example->setDatetimeInt($date);
68
69 $this->persistenceManager->add($example);
70 $this->persistenceManager->persistAll();
71 $uid = $this->persistenceManager->getIdentifierByObject($example);
72 $this->persistenceManager->clearState();
73
74 /** @var DateExample $example */
75 $example = $this->persistenceManager->getObjectByIdentifier($uid, DateExample::class);
76
77 $this->assertEquals($example->getDatetimeInt()->getTimestamp(), $date->getTimestamp());
78 }
79
80 /**
81 * @test
82 */
83 public function dateValuesAreStoredInUtcInTextDatabaseFields()
84 {
85 $example = new DateExample();
86 $date = new \DateTime('2016-03-06T12:40:00+01:00');
87 $example->setDatetimeText($date);
88
89 $this->persistenceManager->add($example);
90 $this->persistenceManager->persistAll();
91 $uid = $this->persistenceManager->getIdentifierByObject($example);
92 $this->persistenceManager->clearState();
93
94 /** @var DateExample $example */
95 $example = $this->persistenceManager->getObjectByIdentifier($uid, DateExample::class);
96
97 $this->assertEquals($example->getDatetimeText()->getTimestamp(), $date->getTimestamp());
98 }
99
100 /**
101 * @test
102 */
103 public function dateValuesAreStoredInUtcInDatetimeDatabaseFields()
104 {
105 $example = new DateExample();
106 $date = new \DateTime('2016-03-06T12:40:00+01:00');
107 $example->setDatetimeDatetime($date);
108
109 $this->persistenceManager->add($example);
110 $this->persistenceManager->persistAll();
111 $uid = $this->persistenceManager->getIdentifierByObject($example);
112 $this->persistenceManager->clearState();
113
114 /** @var DateExample $example */
115 $example = $this->persistenceManager->getObjectByIdentifier($uid, DateExample::class);
116
117 $this->assertEquals($example->getDatetimeDatetime()->getTimestamp(), $date->getTimestamp());
118 }
119 }