|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de> 00006 * All rights reserved 00007 * 00008 * This class is a backport of the corresponding class of FLOW3. 00009 * All credits go to the v5 team. 00010 * 00011 * This script is part of the TYPO3 project. The TYPO3 project is 00012 * free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2 of the License, or 00015 * (at your option) any later version. 00016 * 00017 * The GNU General Public License can be found at 00018 * http://www.gnu.org/copyleft/gpl.html. 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 00028 class Tx_Extbase_Tests_Unit_Persistence_ObjectStorageTest extends Tx_Extbase_Tests_Unit_BaseTestCase { 00029 00030 /** 00031 * @test 00032 */ 00033 public function anObjectCanBeAttached() { 00034 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage(); 00035 $object1 = new StdClass; 00036 $object2 = new StdClass; 00037 $objectStorage->attach($object1); 00038 $objectStorage->attach($object2, 'foo'); 00039 $this->assertEquals($objectStorage[$object1], NULL); 00040 $this->assertEquals($objectStorage[$object2], 'foo'); 00041 } 00042 00043 /** 00044 * @test 00045 */ 00046 public function anObjectCanBeDetached() { 00047 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage(); 00048 $object1 = new StdClass; 00049 $object2 = new StdClass; 00050 $objectStorage->attach($object1); 00051 $objectStorage->attach($object2, 'foo'); 00052 $this->assertEquals(count($objectStorage), 2); 00053 $objectStorage->detach($object1); 00054 $this->assertEquals(count($objectStorage), 1); 00055 $objectStorage->detach($object2); 00056 $this->assertEquals(count($objectStorage), 0); 00057 } 00058 00059 /** 00060 * @test 00061 */ 00062 public function offsetSetAssociatesDataToAnObjectInTheStorage() { 00063 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage(); 00064 $object1 = new StdClass; 00065 $object2 = new StdClass; 00066 $objectStorage->offsetSet($object1, 'foo'); 00067 $this->assertEquals(count($objectStorage), 1); 00068 $objectStorage[$object2] = 'bar'; 00069 $this->assertEquals(count($objectStorage), 2); 00070 } 00071 00072 /** 00073 * @test 00074 */ 00075 public function offsetUnsetRemovesAnObjectFromTheStorage() { 00076 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage(); 00077 $object1 = new StdClass; 00078 $object2 = new StdClass; 00079 $objectStorage->attach($object1); 00080 $objectStorage->attach($object2, 'foo'); 00081 $this->assertEquals(count($objectStorage), 2); 00082 $objectStorage->offsetUnset($object2); 00083 $this->assertEquals(count($objectStorage), 1); 00084 $objectStorage->offsetUnset($object1); 00085 $this->assertEquals(count($objectStorage), 0); 00086 } 00087 00088 /** 00089 * @test 00090 */ 00091 public function offsetGetReturnsTheDataAssociatedWithAnObject() { 00092 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage(); 00093 $object1 = new StdClass; 00094 $object2 = new StdClass; 00095 $objectStorage[$object1] = 'foo'; 00096 $objectStorage->attach($object2); 00097 $this->assertEquals($objectStorage->offsetGet($object1), 'foo'); 00098 $this->assertEquals($objectStorage->offsetGet($object2), NULL); 00099 } 00100 00101 /** 00102 * @test 00103 */ 00104 public function offsetExistsChecksWhetherAnObjectExistsInTheStorage() { 00105 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage(); 00106 $object1 = new StdClass; 00107 $object2 = new StdClass; 00108 $objectStorage->attach($object1); 00109 $this->assertEquals($objectStorage->offsetExists($object1), TRUE); 00110 $this->assertEquals($objectStorage->offsetExists($object2), FALSE); 00111 } 00112 00113 /** 00114 * @test 00115 */ 00116 public function getInfoReturnsTheDataAssociatedWithTheCurrentIteratorEntry() { 00117 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage(); 00118 $object1 = new StdClass; 00119 $object2 = new StdClass; 00120 $object3 = new StdClass; 00121 $objectStorage->attach($object1, 42); 00122 $objectStorage->attach($object2, 'foo'); 00123 $objectStorage->attach($object3, array('bar', 'baz')); 00124 $objectStorage->rewind(); 00125 $this->assertEquals($objectStorage->getInfo(), 42); 00126 $objectStorage->next(); 00127 $this->assertEquals($objectStorage->getInfo(), 'foo'); 00128 $objectStorage->next(); 00129 $this->assertEquals($objectStorage->getInfo(), array('bar', 'baz')); 00130 } 00131 00132 /** 00133 * @test 00134 */ 00135 public function setInfoSetsTheDataAssociatedWithTheCurrentIteratorEntry() { 00136 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage(); 00137 $object1 = new StdClass; 00138 $object2 = new StdClass; 00139 $objectStorage->attach($object1); 00140 $objectStorage->attach($object2, 'foo'); 00141 $objectStorage->rewind(); 00142 $objectStorage->setInfo(42); 00143 $objectStorage->next(); 00144 $objectStorage->setInfo('bar'); 00145 $this->assertEquals($objectStorage[$object1], 42); 00146 $this->assertEquals($objectStorage[$object2], 'bar'); 00147 } 00148 00149 /** 00150 * @test 00151 */ 00152 public function removeAllRemovesObjectsContainedInAnotherStorageFromTheCurrentStorage() { 00153 $object1 = new StdClass; 00154 $object2 = new StdClass; 00155 $objectStorageA = new Tx_Extbase_Persistence_ObjectStorage(); 00156 $objectStorageA->attach($object1, 'foo'); 00157 $objectStorageB = new Tx_Extbase_Persistence_ObjectStorage(); 00158 $objectStorageB->attach($object1, 'bar'); 00159 $objectStorageB->attach($object2, 'baz'); 00160 $this->assertEquals(count($objectStorageB), 2); 00161 $objectStorageB->removeAll($objectStorageA); 00162 $this->assertEquals(count($objectStorageB), 1); 00163 } 00164 00165 /** 00166 * @test 00167 */ 00168 public function addAllAddsAllObjectsFromAnotherStorage() { 00169 $object1 = new StdClass; 00170 $object2 = new StdClass; 00171 $objectStorageA = new Tx_Extbase_Persistence_ObjectStorage(); // It might be better to mock this 00172 $objectStorageA->attach($object1, 'foo'); 00173 $objectStorageB = new Tx_Extbase_Persistence_ObjectStorage(); 00174 $objectStorageB->attach($object2, 'baz'); 00175 $this->assertEquals($objectStorageB->offsetExists($object1), FALSE); 00176 $objectStorageB->addAll($objectStorageA); 00177 $this->assertEquals($objectStorageB[$object1], 'foo'); 00178 $this->assertEquals($objectStorageB[$object2], 'baz'); 00179 } 00180 00181 00182 /** 00183 * @test 00184 */ 00185 public function theStorageCanBeRetrievedAsArray() { 00186 $objectStorage = new Tx_Extbase_Persistence_ObjectStorage(); 00187 $object1 = new StdClass; 00188 $object2 = new StdClass; 00189 $objectStorage->attach($object1, 'foo'); 00190 $objectStorage->attach($object2, 'bar'); 00191 $this->assertEquals($objectStorage->toArray(), array($object1, $object2)); 00192 } 00193 00194 } 00195 ?>
1.8.0