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