[BUGFIX] Add missing namespace parts
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Persistence / Generic / SessionTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 class SessionTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
17 {
18 /**
19 * @test
20 */
21 public function objectRegisteredWithRegisterReconstitutedEntityCanBeRetrievedWithGetReconstitutedEntities()
22 {
23 $someObject = new \ArrayObject([]);
24 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
25 $session->registerReconstitutedEntity($someObject, ['identifier' => 'fakeUuid']);
26
27 $ReconstitutedEntities = $session->getReconstitutedEntities();
28 $this->assertTrue($ReconstitutedEntities->contains($someObject));
29 }
30
31 /**
32 * @test
33 */
34 public function unregisterReconstitutedEntityRemovesObjectFromSession()
35 {
36 $someObject = new \ArrayObject([]);
37 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
38 $session->registerObject($someObject, 'fakeUuid');
39 $session->registerReconstitutedEntity($someObject, ['identifier' => 'fakeUuid']);
40 $session->unregisterReconstitutedEntity($someObject);
41
42 $ReconstitutedEntities = $session->getReconstitutedEntities();
43 $this->assertFalse($ReconstitutedEntities->contains($someObject));
44 }
45
46 /**
47 * @test
48 */
49 public function hasObjectReturnsTrueForRegisteredObject()
50 {
51 $object1 = new \stdClass();
52 $object2 = new \stdClass();
53 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
54 $session->registerObject($object1, 12345);
55
56 $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
57 $this->assertFalse($session->hasObject($object2), 'Session claims it does have unregistered object.');
58 }
59
60 /**
61 * @test
62 */
63 public function hasIdentifierReturnsTrueForRegisteredObject()
64 {
65 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
66 $session->registerObject(new \stdClass(), 12345);
67
68 $this->assertTrue($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
69 $this->assertFalse($session->hasIdentifier('67890', 'stdClass'), 'Session claims it does have unregistered object.');
70 }
71
72 /**
73 * @test
74 */
75 public function getIdentifierByObjectReturnsRegisteredUUIDForObject()
76 {
77 $object = new \stdClass();
78 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
79 $session->registerObject($object, 12345);
80
81 $this->assertEquals($session->getIdentifierByObject($object), 12345, 'Did not get UUID registered for object.');
82 }
83
84 /**
85 * @test
86 */
87 public function getObjectByIdentifierReturnsRegisteredObjectForUUID()
88 {
89 $object = new \stdClass();
90 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
91 $session->registerObject($object, 12345);
92
93 $this->assertSame($session->getObjectByIdentifier('12345', 'stdClass'), $object, 'Did not get object registered for UUID.');
94 }
95
96 /**
97 * @test
98 */
99 public function unregisterObjectRemovesRegisteredObject()
100 {
101 $object1 = new \stdClass();
102 $object2 = new \stdClass();
103 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
104 $session->registerObject($object1, 12345);
105 $session->registerObject($object2, 67890);
106
107 $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
108 $this->assertTrue($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
109 $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
110 $this->assertTrue($session->hasIdentifier('67890', 'stdClass'), 'Session claims it does not have registered object.');
111
112 $session->unregisterObject($object1);
113
114 $this->assertFalse($session->hasObject($object1), 'Session claims it does have unregistered object.');
115 $this->assertFalse($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
116 $this->assertTrue($session->hasObject($object2), 'Session claims it does not have registered object.');
117 $this->assertTrue($session->hasIdentifier('67890', 'stdClass'), 'Session claims it does not have registered object.');
118 }
119
120 /**
121 * @test
122 */
123 public function newSessionIsEmpty()
124 {
125 $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
126 $reconstitutedObjects = $persistenceSession->getReconstitutedEntities();
127 $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
128 }
129
130 /**
131 * @test
132 */
133 public function objectCanBeRegisteredAsReconstituted()
134 {
135 $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
136 $entity = $this->createMock(\TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class);
137 $persistenceSession->registerReconstitutedEntity($entity);
138 $reconstitutedObjects = $persistenceSession->getReconstitutedEntities();
139 $this->assertTrue($reconstitutedObjects->contains($entity), 'The object was not registered as reconstituted.');
140 }
141
142 /**
143 * @test
144 */
145 public function objectCanBeUnregisteredAsReconstituted()
146 {
147 $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
148 $entity = $this->createMock(\TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class);
149 $persistenceSession->registerReconstitutedEntity($entity);
150 $persistenceSession->unregisterReconstitutedEntity($entity);
151 $reconstitutedObjects = $persistenceSession->getReconstitutedEntities();
152 $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
153 }
154 }