TYPO3 CMS  TYPO3_6-2
SessionTest.php
Go to the documentation of this file.
1 <?php
3 
17 
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 
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 
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 
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 
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 
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 
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 
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 
126  $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
127  $entity = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity');
128  $persistenceSession->registerReconstitutedEntity($entity);
129  $reconstitutedObjects = $persistenceSession->getReconstitutedEntities();
130  $this->assertTrue($reconstitutedObjects->contains($entity), 'The object was not registered as reconstituted.');
131  }
132 
137  $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
138  $entity = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity');
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 }