* wrote some unit tests for the Persistence Session (using a patched version of tx_ph...
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / TX_EXTMVC_Persistence_Session_testcase.php
1 <?php
2 declare(ENCODING = 'utf-8');
3
4 /* *
5 * This script belongs to the FLOW3 framework. *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License as published by the *
9 * Free Software Foundation, either version 3 of the License, or (at your *
10 * option) any later version. *
11 * *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
20 * *
21 * The TYPO3 project - inspiring people to share! *
22 * */
23
24 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Persistence/TX_EXTMVC_Persistence_Session.php');
25 require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/DomainObject/TX_EXTMVC_DomainObject_Entity.php');
26
27 class TX_EXTMVC_Persistence_Session_testcase extends tx_phpunit_testcase {
28
29 public function test_NewSessionIsEmpty() {
30 $session = new TX_EXTMVC_Persistence_Session;
31 $addedObjects = $session->getAddedObjects();
32 $removedObjects = $session->getRemovedObjects();
33 $reconstitutedObjects = $session->getReconstitutedObjects();
34 $this->assertEquals(0, count($addedObjects), 'The added objects storage was not empty.');
35 $this->assertEquals(0, count($removedObjects), 'The removed objects storage was not empty.');
36 $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
37 }
38
39 public function test_ObjectCanBeRegisteredAsAdded() {
40 $session = new TX_EXTMVC_Persistence_Session;
41 $entity = $this->getMock('TX_EXTMVC_DomainObject_Entity');
42 $session->registerAddedObject($entity);
43 $addedObjects = $session->getAddedObjects();
44 $removedObjects = $session->getRemovedObjects();
45 $reconstitutedObjects = $session->getReconstitutedObjects();
46
47 $this->assertEquals(1, count($addedObjects), 'The added objects storage holds 0 or more than 1 objects.');
48 $this->assertSame($entity, $addedObjects[0], 'The returned object was not the same as the registered one.');
49 $this->assertEquals(0, count($removedObjects), 'The removed objects storage was not empty.');
50 $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
51 }
52
53 public function test_ObjectCanBeRegisteredAsRemoved() {
54 $session = new TX_EXTMVC_Persistence_Session;
55 $entity = $this->getMock('TX_EXTMVC_DomainObject_Entity');
56 $session->registerRemovedObject($entity);
57 $addedObjects = $session->getAddedObjects();
58 $removedObjects = $session->getRemovedObjects();
59 $reconstitutedObjects = $session->getReconstitutedObjects();
60
61 $this->assertEquals(0, count($addedObjects), 'The added objects storage was not empty.');
62 $this->assertEquals(1, count($removedObjects), 'The removed objects storage holds 0 or more than 1 objects.');
63 $this->assertSame($entity, $removedObjects[0], 'The returned object was not the same as the registered one.');
64 $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
65 }
66
67 public function test_ObjectCanBeRegisteredAsReconstituted() {
68 $session = new TX_EXTMVC_Persistence_Session;
69 $entity = $this->getMock('TX_EXTMVC_DomainObject_Entity');
70 $session->registerReconstitutedObject($entity);
71 $addedObjects = $session->getAddedObjects();
72 $removedObjects = $session->getRemovedObjects();
73 $reconstitutedObjects = $session->getReconstitutedObjects();
74
75 $this->assertEquals(0, count($addedObjects), 'The added objects storage was not empty.');
76 $this->assertEquals(0, count($removedObjects), 'The removed objects storage was not empty.');
77 $this->assertEquals(1, count($reconstitutedObjects), 'The reconstituted objects storage holds 0 or more than 1 objects.');
78 $this->assertSame($entity, $reconstitutedObjects[0], 'The returned object was not the same as the registered one.');
79 }
80
81 public function test_ObjectCanBeRemovedAfterBeingAdded() {
82 $session = new TX_EXTMVC_Persistence_Session;
83 $entity = $this->getMock('TX_EXTMVC_DomainObject_Entity');
84 $session->registerAddedObject($entity);
85 $session->registerRemovedObject($entity);
86 $addedObjects = $session->getAddedObjects();
87 $removedObjects = $session->getRemovedObjects();
88 $reconstitutedObjects = $session->getReconstitutedObjects();
89
90 $this->assertEquals(0, count($addedObjects), 'The added objects storage was not empty.');
91 $this->assertEquals(0, count($removedObjects), 'The removed objects storage was not empty.');
92 $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
93 }
94
95 public function test_AnObjectCanBeRemovedAfterBeingAdded() {
96 $session = new TX_EXTMVC_Persistence_Session;
97 $entity = $this->getMock('TX_EXTMVC_DomainObject_Entity');
98 $session->registerAddedObject($entity);
99 $session->registerRemovedObject($entity);
100 $addedObjects = $session->getAddedObjects();
101 $removedObjects = $session->getRemovedObjects();
102 $reconstitutedObjects = $session->getReconstitutedObjects();
103
104 $this->assertEquals(0, count($addedObjects), 'The added objects storage was not empty.');
105 $this->assertEquals(0, count($removedObjects), 'The removed objects storage was not empty.');
106 $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
107 }
108
109 public function test_TryingToRegisterReconstitutedObjectsAsAddedResultsInAnException() {
110 $this->setExpectedException('InvalidArgumentException');
111 $session = new TX_EXTMVC_Persistence_Session;
112 $entity = $this->getMock('TX_EXTMVC_DomainObject_Entity');
113 $session->registerReconstitutedObject($entity);
114 $session->registerAddedObject($entity);
115 }
116
117 public function test_TryingToRegisterAddedObjectsAsReconstitutedResultsInAnException() {
118 $this->setExpectedException('InvalidArgumentException');
119 $session = new TX_EXTMVC_Persistence_Session;
120 $entity1 = $this->getMock('TX_EXTMVC_DomainObject_Entity');
121 $entity2 = $this->getMock('TX_EXTMVC_DomainObject_Entity');
122 $session->registerAddedObject($entity1);
123 $session->registerReconstitutedObject($entity1);
124 }
125
126
127 }
128 ?>