[~CONFIGURATION] Extbase: Set lockType to empty string instead of 'system'.
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Persistence / ObjectStorage_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 class Tx_Extbase_Persistence_ObjectStorage_testcase extends Tx_Extbase_BaseTestCase {
29
30 /**
31 * @test
32 */
33 public function anObjectCanBeAttached() {
34 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
35 $object = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
36 $objectStorage->attach($object);
37 $result = $objectStorage->offsetGet($object);
38
39 $this->assertEquals($result, $object, 'The retrieved object differs from the attached object.');
40 }
41
42 /**
43 * @test
44 * @expectedException Tx_Extbase_MVC_Exception_InvalidArgumentType
45 */
46 public function attachingSomethingElseThanAnObjectThrowsAnException() {
47 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
48 $objectStorage->attach('foo');
49 }
50
51 /**
52 * @test
53 */
54 public function anObjectCanBeDetached() {
55 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
56 $object = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
57 $objectStorage->offsetSet($object, $object);
58 $resultBeforeDetaching = $objectStorage->offsetGet($object);
59
60 $this->assertEquals($resultBeforeDetaching, $object, 'The object could not be set via offsetSet().');
61
62 $objectStorage->detach($object);
63 $resultAfterDetaching = $objectStorage->offsetGet($object);
64
65 $this->assertEquals($resultAfterDetaching, NULL, 'The object could not be detached.');
66 }
67
68 /**
69 * @test
70 * @expectedException Tx_Extbase_MVC_Exception_InvalidArgumentType
71 */
72 public function detachingSomethingElseThanAnObjectThrowsAnException() {
73 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
74 $objectStorage->detach('foo');
75 }
76
77 /**
78 * @test
79 * @expectedException Tx_Extbase_MVC_Exception_InvalidArgumentType
80 */
81 public function addingAnObjectWithoutAnObjectAsOffsetThrowsAnException() {
82 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
83 $object = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
84 $objectStorage[] = $object;
85 }
86
87 /**
88 * @test
89 */
90 public function anObjectCouldBeSetViaAnOffset() {
91 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
92 $object = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
93 $objectStorage[$object] = $object;
94 $result = $objectStorage->offsetGet($object);
95
96 $this->assertEquals($result, $object, 'The retrieved object differs from the attached object.');
97 }
98
99 /**
100 * @test
101 */
102 public function itCanBeTestedIfTheStorageContainsAnObject() {
103 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
104 $object = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
105 $objectStorage->attach($object);
106 $result = $objectStorage->contains($object);
107
108 $this->assertEquals($result, TRUE, 'The method object differs from the attached object.');
109 }
110
111 /**
112 * @test
113 * @expectedException Tx_Extbase_MVC_Exception_InvalidArgumentType
114 */
115 public function unsettingSomethingElseThanAnObjectThrowsAnException() {
116 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
117 // $object = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
118 // $objectStorage->offsetSet($object, $object);
119 $objectStorage->offsetUnset('foo');
120 }
121
122 /**
123 * @test
124 */
125 public function anObjectCanBeUnset() {
126 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
127 $object = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
128 $objectStorage->offsetSet($object, $object);
129 $resultBeforeDetaching = $objectStorage->offsetGet($object);
130
131 $this->assertEquals($resultBeforeDetaching, $object, 'The object could not be set via offsetSet().');
132
133 $objectStorage->offsetUnset($object);
134 $resultAfterDetaching = $objectStorage->offsetGet($object);
135
136 $this->assertEquals($resultAfterDetaching, NULL, 'The object could not be unsetted.');
137 }
138
139 /**
140 * @test
141 */
142 public function theStorageCanBeRetrievedAsArray() {
143 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage();
144 $object1 = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
145 $objectStorage->offsetSet($object1, $object1);
146 $object2 = $this->getMock('Tx_Extbase_DomainObject_AbstractEntity');
147 $objectStorage->offsetSet($object2, $object2);
148 $result = $objectStorage->toArray();
149
150 $this->assertEquals(is_array($result), TRUE, 'The result was not an array as expected.');
151 $this->assertEquals(count($result), 2, 'The retrieved array did not contain two elements.');
152 }
153
154 }
155 ?>