‪TYPO3CMS  9.5
SessionTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
23 class ‪SessionTest extends UnitTestCase
24 {
29  {
30  $someObject = new \ArrayObject([]);
31  $session = new ‪Session(new ‪Container());
32  $session->registerReconstitutedEntity($someObject);
33 
34  $ReconstitutedEntities = $session->getReconstitutedEntities();
35  $this->assertTrue($ReconstitutedEntities->contains($someObject));
36  }
37 
42  {
43  $someObject = new \ArrayObject([]);
44  $session = new ‪Session(new ‪Container());
45  $session->registerObject($someObject, 'fakeUuid');
46  $session->registerReconstitutedEntity($someObject);
47  $session->unregisterReconstitutedEntity($someObject);
48 
49  $ReconstitutedEntities = $session->getReconstitutedEntities();
50  $this->assertFalse($ReconstitutedEntities->contains($someObject));
51  }
52 
57  {
58  $object1 = new \stdClass();
59  $object2 = new \stdClass();
60  $session = new ‪Session(new ‪Container());
61  $session->registerObject($object1, 12345);
62 
63  $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
64  $this->assertFalse($session->hasObject($object2), 'Session claims it does have unregistered object.');
65  }
66 
71  {
72  $session = new ‪Session(new ‪Container());
73  $session->registerObject(new \stdClass(), 12345);
74 
75  $this->assertTrue($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
76  $this->assertFalse($session->hasIdentifier('67890', 'stdClass'), 'Session claims it does have unregistered object.');
77  }
78 
83  {
84  $object = new \stdClass();
85  $session = new ‪Session(new ‪Container());
86  $session->registerObject($object, 12345);
87 
88  $this->assertEquals($session->getIdentifierByObject($object), 12345, 'Did not get UUID registered for object.');
89  }
90 
95  {
96  $object = new \stdClass();
97  $session = new ‪Session(new ‪Container());
98  $session->registerObject($object, 12345);
99 
100  $this->assertSame($session->getObjectByIdentifier('12345', 'stdClass'), $object, 'Did not get object registered for UUID.');
101  }
102 
107  {
108  $object1 = new \stdClass();
109  $object2 = new \stdClass();
110  $session = new ‪Session(new ‪Container());
111  $session->registerObject($object1, 12345);
112  $session->registerObject($object2, 67890);
113 
114  $this->assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
115  $this->assertTrue($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
116  $this->assertTrue($session->hasObject($object1), '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  $session->unregisterObject($object1);
120 
121  $this->assertFalse($session->hasObject($object1), 'Session claims it does have unregistered object.');
122  $this->assertFalse($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
123  $this->assertTrue($session->hasObject($object2), 'Session claims it does not have registered object.');
124  $this->assertTrue($session->hasIdentifier('67890', 'stdClass'), 'Session claims it does not have registered object.');
125  }
126 
130  public function ‪newSessionIsEmpty()
131  {
132  $persistenceSession = new ‪Session(new ‪Container());
133  $reconstitutedObjects = $persistenceSession->getReconstitutedEntities();
134  $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
135  }
136 
141  {
142  $persistenceSession = new ‪Session(new ‪Container());
143  $entity = $this->createMock(AbstractEntity::class);
144  $persistenceSession->registerReconstitutedEntity($entity);
145  $reconstitutedObjects = $persistenceSession->getReconstitutedEntities();
146  $this->assertTrue($reconstitutedObjects->contains($entity), 'The object was not registered as reconstituted.');
147  }
148 
153  {
154  $persistenceSession = new ‪Session(new ‪Container());
155  $entity = $this->createMock(AbstractEntity::class);
156  $persistenceSession->registerReconstitutedEntity($entity);
157  $persistenceSession->unregisterReconstitutedEntity($entity);
158  $reconstitutedObjects = $persistenceSession->getReconstitutedEntities();
159  $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
160  }
161 }
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\objectRegisteredWithRegisterReconstitutedEntityCanBeRetrievedWithGetReconstitutedEntities
‪objectRegisteredWithRegisterReconstitutedEntityCanBeRetrievedWithGetReconstitutedEntities()
Definition: SessionTest.php:28
‪TYPO3\CMS\Extbase\Object\Container\Container
Definition: Container.php:30
‪TYPO3\CMS\Extbase\DomainObject\AbstractEntity
Definition: AbstractEntity.php:22
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\getIdentifierByObjectReturnsRegisteredUUIDForObject
‪getIdentifierByObjectReturnsRegisteredUUIDForObject()
Definition: SessionTest.php:82
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\hasIdentifierReturnsTrueForRegisteredObject
‪hasIdentifierReturnsTrueForRegisteredObject()
Definition: SessionTest.php:70
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\getObjectByIdentifierReturnsRegisteredObjectForUUID
‪getObjectByIdentifierReturnsRegisteredObjectForUUID()
Definition: SessionTest.php:94
‪TYPO3\CMS\Extbase\Persistence\Generic\Session
Definition: Session.php:24
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic
Definition: BackendTest.php:3
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\unregisterObjectRemovesRegisteredObject
‪unregisterObjectRemovesRegisteredObject()
Definition: SessionTest.php:106
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\objectCanBeUnregisteredAsReconstituted
‪objectCanBeUnregisteredAsReconstituted()
Definition: SessionTest.php:152
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\newSessionIsEmpty
‪newSessionIsEmpty()
Definition: SessionTest.php:130
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\objectCanBeRegisteredAsReconstituted
‪objectCanBeRegisteredAsReconstituted()
Definition: SessionTest.php:140
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\unregisterReconstitutedEntityRemovesObjectFromSession
‪unregisterReconstitutedEntityRemovesObjectFromSession()
Definition: SessionTest.php:41
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\hasObjectReturnsTrueForRegisteredObject
‪hasObjectReturnsTrueForRegisteredObject()
Definition: SessionTest.php:56
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest
Definition: SessionTest.php:24