‪TYPO3CMS  10.4
SessionTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use Psr\Container\ContainerInterface;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
26 class ‪SessionTest extends UnitTestCase
27 {
28  protected function ‪createContainer(): ‪Container
29  {
30  $psrContainer = $this->getMockBuilder(ContainerInterface::class)->setMethods(['has', 'get'])->getMock();
31  $psrContainer->expects(self::any())->method('has')->willReturn(false);
32  return new ‪Container($psrContainer);
33  }
34 
39  {
40  $someObject = new \ArrayObject([]);
41  $session = new ‪Session($this->‪createContainer());
42  $session->registerReconstitutedEntity($someObject);
43 
44  $ReconstitutedEntities = $session->getReconstitutedEntities();
45  self::assertTrue($ReconstitutedEntities->contains($someObject));
46  }
47 
52  {
53  $someObject = new \ArrayObject([]);
54  $session = new ‪Session($this->‪createContainer());
55  $session->registerObject($someObject, 'fakeUuid');
56  $session->registerReconstitutedEntity($someObject);
57  $session->unregisterReconstitutedEntity($someObject);
58 
59  $ReconstitutedEntities = $session->getReconstitutedEntities();
60  self::assertFalse($ReconstitutedEntities->contains($someObject));
61  }
62 
67  {
68  $object1 = new \stdClass();
69  $object2 = new \stdClass();
70  $session = new ‪Session($this->‪createContainer());
71  $session->registerObject($object1, 12345);
72 
73  self::assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
74  self::assertFalse($session->hasObject($object2), 'Session claims it does have unregistered object.');
75  }
76 
81  {
82  $session = new ‪Session($this->‪createContainer());
83  $session->registerObject(new \stdClass(), 12345);
84 
85  self::assertTrue($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
86  self::assertFalse($session->hasIdentifier('67890', 'stdClass'), 'Session claims it does have unregistered object.');
87  }
88 
93  {
94  $object = new \stdClass();
95  $session = new ‪Session($this->‪createContainer());
96  $session->registerObject($object, 12345);
97 
98  self::assertEquals($session->getIdentifierByObject($object), 12345, 'Did not get UUID registered for object.');
99  }
100 
105  {
106  $object = new \stdClass();
107  $session = new ‪Session($this->‪createContainer());
108  $session->registerObject($object, 12345);
109 
110  self::assertSame($session->getObjectByIdentifier('12345', 'stdClass'), $object, 'Did not get object registered for UUID.');
111  }
112 
117  {
118  $object1 = new \stdClass();
119  $object2 = new \stdClass();
120  $session = new ‪Session($this->‪createContainer());
121  $session->registerObject($object1, 12345);
122  $session->registerObject($object2, 67890);
123 
124  self::assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
125  self::assertTrue($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
126  self::assertTrue($session->hasObject($object1), 'Session claims it does not have registered object.');
127  self::assertTrue($session->hasIdentifier('67890', 'stdClass'), 'Session claims it does not have registered object.');
128 
129  $session->unregisterObject($object1);
130 
131  self::assertFalse($session->hasObject($object1), 'Session claims it does have unregistered object.');
132  self::assertFalse($session->hasIdentifier('12345', 'stdClass'), 'Session claims it does not have registered object.');
133  self::assertTrue($session->hasObject($object2), 'Session claims it does not have registered object.');
134  self::assertTrue($session->hasIdentifier('67890', 'stdClass'), 'Session claims it does not have registered object.');
135  }
136 
140  public function ‪newSessionIsEmpty()
141  {
142  $persistenceSession = new ‪Session($this->‪createContainer());
143  $reconstitutedObjects = $persistenceSession->getReconstitutedEntities();
144  self::assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
145  }
146 
151  {
152  $persistenceSession = new ‪Session($this->‪createContainer());
153  $entity = $this->createMock(AbstractEntity::class);
154  $persistenceSession->registerReconstitutedEntity($entity);
155  $reconstitutedObjects = $persistenceSession->getReconstitutedEntities();
156  self::assertTrue($reconstitutedObjects->contains($entity), 'The object was not registered as reconstituted.');
157  }
158 
163  {
164  $persistenceSession = new ‪Session($this->‪createContainer());
165  $entity = $this->createMock(AbstractEntity::class);
166  $persistenceSession->registerReconstitutedEntity($entity);
167  $persistenceSession->unregisterReconstitutedEntity($entity);
168  $reconstitutedObjects = $persistenceSession->getReconstitutedEntities();
169  self::assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
170  }
171 }
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\objectRegisteredWithRegisterReconstitutedEntityCanBeRetrievedWithGetReconstitutedEntities
‪objectRegisteredWithRegisterReconstitutedEntityCanBeRetrievedWithGetReconstitutedEntities()
Definition: SessionTest.php:38
‪TYPO3\CMS\Extbase\Object\Container\Container
Definition: Container.php:39
‪TYPO3\CMS\Extbase\DomainObject\AbstractEntity
Definition: AbstractEntity.php:23
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\getIdentifierByObjectReturnsRegisteredUUIDForObject
‪getIdentifierByObjectReturnsRegisteredUUIDForObject()
Definition: SessionTest.php:92
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\hasIdentifierReturnsTrueForRegisteredObject
‪hasIdentifierReturnsTrueForRegisteredObject()
Definition: SessionTest.php:80
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\getObjectByIdentifierReturnsRegisteredObjectForUUID
‪getObjectByIdentifierReturnsRegisteredObjectForUUID()
Definition: SessionTest.php:104
‪TYPO3\CMS\Extbase\Persistence\Generic\Session
Definition: Session.php:27
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic
Definition: BackendTest.php:18
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\unregisterObjectRemovesRegisteredObject
‪unregisterObjectRemovesRegisteredObject()
Definition: SessionTest.php:116
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\objectCanBeUnregisteredAsReconstituted
‪objectCanBeUnregisteredAsReconstituted()
Definition: SessionTest.php:162
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\newSessionIsEmpty
‪newSessionIsEmpty()
Definition: SessionTest.php:140
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\createContainer
‪createContainer()
Definition: SessionTest.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\objectCanBeRegisteredAsReconstituted
‪objectCanBeRegisteredAsReconstituted()
Definition: SessionTest.php:150
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\unregisterReconstitutedEntityRemovesObjectFromSession
‪unregisterReconstitutedEntityRemovesObjectFromSession()
Definition: SessionTest.php:51
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest\hasObjectReturnsTrueForRegisteredObject
‪hasObjectReturnsTrueForRegisteredObject()
Definition: SessionTest.php:66
‪TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\SessionTest
Definition: SessionTest.php:27