38 if (!extension_loaded(
'apc') || ini_get(
'apc.enabled') == 0 || ini_get(
'apc.enable_cli') == 0) {
39 $this->markTestSkipped(
'APC/APCu extension was not available, or it was disabled for CLI.');
41 if (ini_get(
'apc.slam_defense') == 1) {
42 $this->markTestSkipped(
'This testcase can only be executed with apc.slam_defense = Off');
65 $inCache =
$backend->has($identifier);
66 $this->assertTrue($inCache,
'APC backend failed to set and check entry');
77 $fetchedData =
$backend->get($identifier);
78 $this->assertEquals($data, $fetchedData,
'APC backend failed to set and retrieve data');
90 $inCache =
$backend->has($identifier);
91 $this->assertFalse($inCache,
'Failed to set and remove data from APC backend');
102 $otherData =
'some other data';
103 $backend->set($identifier, $otherData);
104 $fetchedData =
$backend->get($identifier);
105 $this->assertEquals($otherData, $fetchedData,
'APC backend failed to overwrite and retrieve data');
115 $backend->set($identifier, $data, array(
'UnitTestTag%tag1',
'UnitTestTag%tag2'));
116 $retrieved =
$backend->findIdentifiersByTag(
'UnitTestTag%tag1');
117 $this->assertEquals($identifier, $retrieved[0],
'Could not retrieve expected entry by tag.');
118 $retrieved =
$backend->findIdentifiersByTag(
'UnitTestTag%tag2');
119 $this->assertEquals($identifier, $retrieved[0],
'Could not retrieve expected entry by tag.');
129 $backend->set($identifier, $data, array(
'UnitTestTag%tag1',
'UnitTestTag%tagX'));
130 $backend->set($identifier, $data, array(
'UnitTestTag%tag3'));
131 $retrieved =
$backend->findIdentifiersByTag(
'UnitTestTag%tagX');
132 $this->assertEquals(array(), $retrieved,
'Found entry which should no longer exist.');
138 public function setCacheIsSettingIdentifierPrefixWithCacheIdentifier() {
140 $cacheMock = $this->getMock(
'TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(),
'', FALSE);
141 $cacheMock->expects($this->any())->method(
'getIdentifier')->will($this->returnValue(
146 $backendMock = $this->getMock(
147 'TYPO3\\CMS\\Core\\Cache\\Backend\\ApcBackend',
148 array(
'setIdentifierPrefix',
'getCurrentUserData',
'getPathSite'),
152 $backendMock->expects($this->once())->method(
'getCurrentUserData')->will(
153 $this->returnValue(array(
'name' =>
'testname'))
156 $backendMock->expects($this->once())->method(
'getPathSite')->will(
157 $this->returnValue(
'testpath')
161 $backendMock->expects($this->once())->method(
'setIdentifierPrefix')->with($expectedIdentifier);
162 $backendMock->setCache($cacheMock);
170 $identifier = $this->
getUniqueId(
'NonExistingIdentifier');
171 $inCache =
$backend->has($identifier);
172 $this->assertFalse($inCache,
'"has" did not return FALSE when checking on non existing identifier');
180 $identifier = $this->
getUniqueId(
'NonExistingIdentifier');
181 $inCache =
$backend->remove($identifier);
182 $this->assertFalse($inCache,
'"remove" did not return FALSE when checking on non existing identifier');
189 if (version_compare(phpversion(),
'5.4.0',
'<')) {
190 $this->markTestSkipped(
'This test is not reliable with PHP version below 5.4.0');
193 $data =
'some data' . microtime();
194 $backend->set(
'BackendAPCTest1', $data, array(
'UnitTestTag%test',
'UnitTestTag%boring'));
195 $backend->set(
'BackendAPCTest2', $data, array(
'UnitTestTag%test',
'UnitTestTag%special'));
196 $backend->set(
'BackendAPCTest3', $data, array(
'UnitTestTag%test'));
197 $backend->flushByTag(
'UnitTestTag%special');
198 $this->assertTrue(
$backend->has(
'BackendAPCTest1'),
'BackendAPCTest1');
199 $this->assertFalse(
$backend->has(
'BackendAPCTest2'),
'BackendAPCTest2');
200 $this->assertTrue(
$backend->has(
'BackendAPCTest3'),
'BackendAPCTest3');
208 $data =
'some data' . microtime();
209 $backend->set(
'BackendAPCTest1', $data);
210 $backend->set(
'BackendAPCTest2', $data);
211 $backend->set(
'BackendAPCTest3', $data);
213 $this->assertFalse(
$backend->has(
'BackendAPCTest1'),
'BackendAPCTest1');
214 $this->assertFalse(
$backend->has(
'BackendAPCTest2'),
'BackendAPCTest2');
215 $this->assertFalse(
$backend->has(
'BackendAPCTest3'),
'BackendAPCTest3');
221 public function flushRemovesOnlyOwnEntries() {
223 $thisCache = $this->getMock(
'TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(),
'', FALSE);
224 $thisCache->expects($this->any())->method(
'getIdentifier')->will($this->returnValue(
'thisCache'));
226 $thisBackend->setCache($thisCache);
229 $thatCache = $this->getMock(
'TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(),
'', FALSE);
230 $thatCache->expects($this->any())->method(
'getIdentifier')->will($this->returnValue(
'thatCache'));
232 $thatBackend->setCache($thatCache);
233 $thisBackend->set(
'thisEntry',
'Hello');
234 $thatBackend->set(
'thatEntry',
'World!');
235 $thatBackend->flush();
236 $this->assertEquals(
'Hello', $thisBackend->get(
'thisEntry'));
237 $this->assertFalse($thatBackend->has(
'thatEntry'));
247 $data = str_repeat(
'abcde', 1024 * 1024);
250 $this->assertTrue(
$backend->has($identifier));
251 $this->assertEquals(
$backend->get($identifier), $data);
259 $tags = array(
'UnitTestTag%test',
'UnitTestTag%boring');
261 $backend = $this->setUpBackend(TRUE);
262 $backend->_call(
'addIdentifierToTags', $identifier, $tags);
265 $backend->_call(
'findTagsByIdentifier', $identifier)
268 $backend->_call(
'addIdentifierToTags', $identifier, $tags);
271 $backend->_call(
'findTagsByIdentifier', $identifier)
281 protected function setUpBackend($accessible = FALSE) {
283 $cache = $this->getMock(
'TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(),
'', FALSE);
285 $accessibleClassName = $this->
buildAccessibleProxy(
'\\TYPO3\\CMS\\Core\\Cache\\Backend\\ApcBackend');
286 $backend =
new $accessibleClassName(
'Testing');
setRemovesTagsFromPreviousSet()
itIsPossibleToRemoveEntryFromCache()
itIsPossibleToOverwriteAnEntryInTheCache()
setTagsOnlyOnceToIdentifier()
flushByTagRemovesCacheEntriesWithSpecifiedTag()
static shortMD5($input, $len=10)
hasReturnsFalseIfTheEntryDoesNotExist()
itIsPossibleToSetAndGetEntry()
setThrowsExceptionIfNoFrontEndHasBeenSet()
removeReturnsFalseIfTheEntryDoesntExist()
buildAccessibleProxy($className)
flushRemovesAllCacheEntries()
itIsPossibleToSetAndCheckExistenceInCache()
findIdentifiersByTagFindsSetEntries()