TYPO3 CMS  TYPO3_7-6
SessionTest.php
Go to the documentation of this file.
1 <?php
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  */
17 {
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 
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 
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 
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 
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 
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 
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 
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 
134  {
135  $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
136  $entity = $this->getMock(\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 
146  {
147  $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
148  $entity = $this->getMock(\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 }