TYPO3 CMS  TYPO3_7-6
DataMapperTest.php
Go to the documentation of this file.
1 <?php
3 
8 
10 {
11 
16 
20  protected $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
21 
25  protected $coreExtensionsToLoad = ['extbase', 'fluid'];
26 
30  protected $objectManager;
31 
35  protected function setUp()
36  {
37  parent::setUp();
38 
39  $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
40  $this->persistenceManager = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class);
41  }
42 
46  public function datetimeObjectsCanBePersistedToDatetimeDatabaseFields()
47  {
48  $date = new \DateTime('2016-03-06T12:40:00+01:00');
49  $comment = new Comment();
50  $comment->setDate($date);
51 
52  $this->persistenceManager->add($comment);
53  $this->persistenceManager->persistAll();
54  $uid = $this->persistenceManager->getIdentifierByObject($comment);
55  $this->persistenceManager->clearState();
56 
58  $existingComment = $this->persistenceManager->getObjectByIdentifier($uid, Comment::class);
59 
60  $this->assertEquals($date->getTimestamp(), $existingComment->getDate()->getTimestamp());
61  }
65  public function dateValuesAreStoredInUtcInIntegerDatabaseFields()
66  {
67  $example = new DateExample();
68  $date = new \DateTime('2016-03-06T12:40:00+01:00');
69  $example->setDatetimeInt($date);
70 
71  $this->persistenceManager->add($example);
72  $this->persistenceManager->persistAll();
73  $uid = $this->persistenceManager->getIdentifierByObject($example);
74  $this->persistenceManager->clearState();
75 
77  $example = $this->persistenceManager->getObjectByIdentifier($uid, DateExample::class);
78 
79  $this->assertEquals($example->getDatetimeInt()->getTimestamp(), $date->getTimestamp());
80  }
81 
85  public function dateValuesAreStoredInUtcInTextDatabaseFields()
86  {
87  $example = new DateExample();
88  $date = new \DateTime('2016-03-06T12:40:00+01:00');
89  $example->setDatetimeText($date);
90 
91  $this->persistenceManager->add($example);
92  $this->persistenceManager->persistAll();
93  $uid = $this->persistenceManager->getIdentifierByObject($example);
94  $this->persistenceManager->clearState();
95 
97  $example = $this->persistenceManager->getObjectByIdentifier($uid, DateExample::class);
98 
99  $this->assertEquals($example->getDatetimeText()->getTimestamp(), $date->getTimestamp());
100  }
101 
105  public function dateValuesAreStoredInUtcInDatetimeDatabaseFields()
106  {
107  $example = new DateExample();
108  $date = new \DateTime('2016-03-06T12:40:00+01:00');
109  $example->setDatetimeDatetime($date);
110 
111  $this->persistenceManager->add($example);
112  $this->persistenceManager->persistAll();
113  $uid = $this->persistenceManager->getIdentifierByObject($example);
114  $this->persistenceManager->clearState();
115 
117  $example = $this->persistenceManager->getObjectByIdentifier($uid, DateExample::class);
118 
119  $this->assertEquals($example->getDatetimeDatetime()->getTimestamp(), $date->getTimestamp());
120  }
121 }
$uid
Definition: server.php:38