TYPO3 CMS  TYPO3_8-7
DataMapperTest.php
Go to the documentation of this file.
1 <?php
3 
7 
8 class DataMapperTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
9 {
14 
18  protected $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
19 
23  protected $coreExtensionsToLoad = ['extbase', 'fluid'];
24 
28  protected $objectManager;
29 
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 
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 
56  $existingComment = $this->persistenceManager->getObjectByIdentifier($uid, Comment::class);
57 
58  $this->assertEquals($date->getTimestamp(), $existingComment->getDate()->getTimestamp());
59  }
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 
75  $example = $this->persistenceManager->getObjectByIdentifier($uid, DateExample::class);
76 
77  $this->assertEquals($example->getDatetimeInt()->getTimestamp(), $date->getTimestamp());
78  }
79 
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 
95  $example = $this->persistenceManager->getObjectByIdentifier($uid, DateExample::class);
96 
97  $this->assertEquals($example->getDatetimeText()->getTimestamp(), $date->getTimestamp());
98  }
99 
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 
115  $example = $this->persistenceManager->getObjectByIdentifier($uid, DateExample::class);
116 
117  $this->assertEquals($example->getDatetimeDatetime()->getTimestamp(), $date->getTimestamp());
118  }
119 }
static makeInstance($className,... $constructorArguments)