[TASK] Use name-resolution instead of strings where possible: 3
[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\CMS\Core\Tests\UnitTestCase {
17
18 /**
19 * @test
20 */
21 public function objectRegisteredWithRegisterReconstitutedEntityCanBeRetrievedWithGetReconstitutedEntities() {
22 $someObject = new \ArrayObject(array());
23 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
24 $session->registerReconstitutedEntity($someObject, array('identifier' => 'fakeUuid'));
25
26 $ReconstitutedEntities = $session->getReconstitutedEntities();
27 $this->assertTrue($ReconstitutedEntities->contains($someObject));
28 }
29
30 /**
31 * @test
32 */
33 public function unregisterReconstitutedEntityRemovesObjectFromSession() {
34 $someObject = new \ArrayObject(array());
35 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
36 $session->registerObject($someObject, 'fakeUuid');
37 $session->registerReconstitutedEntity($someObject, array('identifier' => 'fakeUuid'));
38 $session->unregisterReconstitutedEntity($someObject);
39
40 $ReconstitutedEntities = $session->getReconstitutedEntities();
41 $this->assertFalse($ReconstitutedEntities->contains($someObject));
42 }
43
44 /**
45 * @test
46 */
47 public function hasObjectReturnsTrueForRegisteredObject() {
48 $object1 = new \stdClass();
49 $object2 = new \stdClass();
50 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
51 $session->registerObject($object1, 12345);
52
53 $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
54 $this->assertFalse($session->hasObject($object2), 'Session claims it does have unregistered object.');
55 }
56
57 /**
58 * @test
59 */
60 public function hasIdentifierReturnsTrueForRegisteredObject() {
61 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
62 $session->registerObject(new \stdClass(), 12345);
63
64 $this->assertTrue($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
65 $this->assertFalse($session->hasIdentifier('67890', 'stdClass'), 'Session claims it does have unregistered object.');
66 }
67
68 /**
69 * @test
70 */
71 public function getIdentifierByObjectReturnsRegisteredUUIDForObject() {
72 $object = new \stdClass();
73 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
74 $session->registerObject($object, 12345);
75
76 $this->assertEquals($session->getIdentifierByObject($object), 12345, 'Did not get UUID registered for object.');
77 }
78
79 /**
80 * @test
81 */
82 public function getObjectByIdentifierReturnsRegisteredObjectForUUID() {
83 $object = new \stdClass();
84 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
85 $session->registerObject($object, 12345);
86
87 $this->assertSame($session->getObjectByIdentifier('12345', 'stdClass'), $object, 'Did not get object registered for UUID.');
88 }
89
90 /**
91 * @test
92 */
93 public function unregisterObjectRemovesRegisteredObject() {
94 $object1 = new \stdClass();
95 $object2 = new \stdClass();
96 $session = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
97 $session->registerObject($object1, 12345);
98 $session->registerObject($object2, 67890);
99
100 $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
101 $this->assertTrue($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
102 $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
103 $this->assertTrue($session->hasIdentifier('67890', 'stdClass'), 'Session claims it does not have registered object.');
104
105 $session->unregisterObject($object1);
106
107 $this->assertFalse($session->hasObject($object1), 'Session claims it does have unregistered object.');
108 $this->assertFalse($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
109 $this->assertTrue($session->hasObject($object2), '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
113 /**
114 * @test
115 */
116 public function newSessionIsEmpty() {
117 $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
118 $reconstitutedObjects = $persistenceSession->getReconstitutedEntities();
119 $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
120 }
121
122 /**
123 * @test
124 */
125 public function objectCanBeRegisteredAsReconstituted() {
126 $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
127 $entity = $this->getMock(\TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class);
128 $persistenceSession->registerReconstitutedEntity($entity);
129 $reconstitutedObjects = $persistenceSession->getReconstitutedEntities();
130 $this->assertTrue($reconstitutedObjects->contains($entity), 'The object was not registered as reconstituted.');
131 }
132
133 /**
134 * @test
135 */
136 public function objectCanBeUnregisteredAsReconstituted() {
137 $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
138 $entity = $this->getMock(\TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class);
139 $persistenceSession->registerReconstitutedEntity($entity);
140 $persistenceSession->unregisterReconstitutedEntity($entity);
141 $reconstitutedObjects = $persistenceSession->getReconstitutedEntities();
142 $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
143 }
144 }