TYPO3 CMS  TYPO3_6-2
RegistryTest.php
Go to the documentation of this file.
1 <?php
3 
23 
27  protected $registry;
28 
32  public function setUp() {
33  $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array());
34  $GLOBALS['TYPO3_DB']->expects($this->any())->method('fullQuoteStr')->will($this->onConsecutiveCalls('\'tx_phpunit\'', '\'someKey\'', '\'tx_phpunit\'', '\'someKey\''));
35  $this->registry = new \TYPO3\CMS\Core\Registry();
36  }
37 
43  $this->registry->get('', 'someKey');
44  }
45 
51  $this->registry->get('t', 'someKey');
52  }
53 
57  public function getRetrievesTheCorrectEntry() {
58  $testKey = 'TYPO3\\CMS\\Core\\Registry_testcase.testData.getRetrievesTheCorrectEntry';
59  $testValue = 'getRetrievesTheCorrectEntry';
60  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->with('*', 'sys_registry', 'entry_namespace = \'tx_phpunit\'')->will($this->returnValue(array(
61  array('entry_key' => $testKey, 'entry_value' => serialize($testValue))
62  )));
63  $this->assertEquals($this->registry->get('tx_phpunit', $testKey), $testValue, 'The actual data did not match the expected data.');
64  }
65 
70  $testKey1 = 'TYPO3\\CMS\\Core\\Registry_testcase.testData.getLazyLoadsEntriesOfOneNamespace1';
71  $testValue1 = 'getLazyLoadsEntriesOfOneNamespace1';
72  $testKey2 = 'TYPO3\\CMS\\Core\\Registry_testcase.testData.getLazyLoadsEntriesOfOneNamespace2';
73  $testValue2 = 'getLazyLoadsEntriesOfOneNamespace2';
74  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->with('*', 'sys_registry', 'entry_namespace = \'tx_phpunit\'')->will($this->returnValue(array(
75  array('entry_key' => $testKey1, 'entry_value' => serialize($testValue1)),
76  array('entry_key' => $testKey2, 'entry_value' => serialize($testValue2))
77  )));
78  $this->assertEquals($this->registry->get('tx_phpunit', $testKey1), $testValue1, 'The actual data did not match the expected data.');
79  $this->assertEquals($this->registry->get('tx_phpunit', $testKey2), $testValue2, 'The actual data did not match the expected data.');
80  }
81 
86  $defaultValue = 'getReturnsTheDefaultValueIfTheRequestedKeyWasNotFound';
87  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTgetRows')->with('*', 'sys_registry', 'entry_namespace = \'tx_phpunit\'')->will($this->returnValue(array(
88  array('entry_key' => 'foo', 'entry_value' => 'bar')
89  )));
90  $this->assertEquals($defaultValue, $this->registry->get('tx_phpunit', 'someNonExistingKey', $defaultValue), 'A value other than the default value was returned.');
91  }
92 
98  $this->registry->set('', 'someKey', 'someValue');
99  }
100 
106  $this->registry->set('t', 'someKey', 'someValue');
107  }
108 
112  public function setAllowsValidNamespaces() {
113  $registry = $this->getMock('TYPO3\\CMS\\Core\\Registry', array('loadEntriesByNamespace'));
114  $registry->set('tx_thisIsValid', 'someKey', 'someValue');
115  $registry->set('thisIsValid', 'someKey', 'someValue');
116  $registry->set('user_soIsThis', 'someKey', 'someValue');
117  $registry->set('core', 'someKey', 'someValue');
118  }
119 
124  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_INSERTquery')->with('sys_registry', array(
125  'entry_namespace' => 'tx_phpunit',
126  'entry_key' => 'someKey',
127  'entry_value' => serialize('someValue')
128  ));
129  $registry = $this->getMock('TYPO3\\CMS\\Core\\Registry', array('loadEntriesByNamespace'));
130  $registry->set('tx_phpunit', 'someKey', 'someValue');
131  }
132 
136  public function setUpdatesExistingKeys() {
137  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_SELECTquery')->with('uid', 'sys_registry', 'entry_namespace = \'tx_phpunit\' AND entry_key = \'someKey\'')->will($this->returnValue('DBResource'));
138  $GLOBALS['TYPO3_DB']->expects($this->once())->method('sql_num_rows')->with('DBResource')->will($this->returnValue(1));
139  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_UPDATEquery')->with('sys_registry', 'entry_namespace = \'tx_phpunit\' AND entry_key = \'someKey\'', array(
140  'entry_value' => serialize('someValue')
141  ));
142  $GLOBALS['TYPO3_DB']->expects($this->never())->method('exec_INSERTquery');
143  $registry = $this->getMock('TYPO3\\CMS\\Core\\Registry', array('loadEntriesByNamespace'));
144  $registry->set('tx_phpunit', 'someKey', 'someValue');
145  }
146 
152  $this->registry->remove('t', 'someKey');
153  }
154 
159  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_DELETEquery')->with('sys_registry', 'entry_namespace = \'tx_phpunit\' AND entry_key = \'someKey\'');
160  $this->registry->remove('tx_phpunit', 'someKey');
161  }
162 
167  $registry = $this->getMock('TYPO3\\CMS\\Core\\Registry', array('loadEntriesByNamespace'));
168  $registry->set('tx_phpunit', 'someKey', 'someValue');
169  $registry->set('tx_phpunit', 'someOtherKey', 'someOtherValue');
170  $registry->set('tx_otherNamespace', 'someKey', 'someValueInOtherNamespace');
171  $registry->remove('tx_phpunit', 'someKey');
172  $this->assertEquals('defaultValue', $registry->get('tx_phpunit', 'someKey', 'defaultValue'), 'A value other than the default value was returned, thus the entry was still present.');
173  $this->assertEquals('someOtherValue', $registry->get('tx_phpunit', 'someOtherKey', 'defaultValue'), 'A value other than the stored value was returned, thus the entry was removed.');
174  $this->assertEquals('someValueInOtherNamespace', $registry->get('tx_otherNamespace', 'someKey', 'defaultValue'), 'A value other than the stored value was returned, thus the entry was removed.');
175  }
176 
182  $this->registry->removeAllByNamespace('');
183  }
184 
189  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_DELETEquery')->with('sys_registry', 'entry_namespace = \'tx_phpunit\'');
190  $this->registry->removeAllByNamespace('tx_phpunit');
191  }
192 
197  $registry = $this->getMock('TYPO3\\CMS\\Core\\Registry', array('loadEntriesByNamespace'));
198  $registry->set('tx_phpunit', 'someKey', 'someValue');
199  $registry->set('tx_phpunit', 'someOtherKey', 'someOtherValue');
200  $registry->set('tx_otherNamespace', 'someKey', 'someValueInOtherNamespace');
201  $registry->removeAllByNamespace('tx_phpunit');
202  $this->assertEquals('defaultValue', $registry->get('tx_phpunit', 'someKey', 'defaultValue'), 'A value other than the default value was returned, thus the entry was still present.');
203  $this->assertEquals('defaultValue', $registry->get('tx_phpunit', 'someOtherKey', 'defaultValue'), 'A value other than the default value was returned, thus the entry was still present.');
204  $this->assertEquals('someValueInOtherNamespace', $registry->get('tx_otherNamespace', 'someKey', 'defaultValue'), 'A value other than the stored value was returned, thus the entry was removed.');
205  }
206 
207 }
removeAllByNamespaceUnsetsValuesOfTheSpecifiedNamespaceFromTheInternalEntriesCache()
removeAllByNamespaceReallyRemovesAllEntriesOfTheSpecifiedNamespaceFromTheDatabase()
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]