32 if (!extension_loaded(
'xcache')) {
33 $this->markTestSkipped(
'xcache extension was not available');
35 if (php_sapi_name() ===
'cli') {
36 $this->markTestSkipped(
'XCache is not supported in CLI mode.');
59 $inCache =
$backend->has($identifier);
60 $this->assertTrue($inCache,
'xcache backend failed to set and check entry');
71 $fetchedData =
$backend->get($identifier);
72 $this->assertEquals($data, $fetchedData,
'xcache backend failed to set and retrieve data');
84 $inCache =
$backend->has($identifier);
85 $this->assertFalse($inCache,
'Failed to set and remove data from xcache backend');
96 $otherData =
'some other data';
97 $backend->set($identifier, $otherData);
98 $fetchedData =
$backend->get($identifier);
99 $this->assertEquals($otherData, $fetchedData,
'xcache backend failed to overwrite and retrieve data');
109 $backend->set($identifier, $data, array(
'UnitTestTag%tag1',
'UnitTestTag%tag2'));
110 $retrieved =
$backend->findIdentifiersByTag(
'UnitTestTag%tag1');
111 $this->assertEquals($identifier, $retrieved[0],
'Could not retrieve expected entry by tag.');
112 $retrieved =
$backend->findIdentifiersByTag(
'UnitTestTag%tag2');
113 $this->assertEquals($identifier, $retrieved[0],
'Could not retrieve expected entry by tag.');
123 $backend->set($identifier, $data, array(
'UnitTestTag%tag1',
'UnitTestTag%tagX'));
124 $backend->set($identifier, $data, array(
'UnitTestTag%tag3'));
125 $retrieved =
$backend->findIdentifiersByTag(
'UnitTestTag%tagX');
126 $this->assertEquals(array(), $retrieved,
'Found entry which should no longer exist.');
134 $identifier = $this->
getUniqueId(
'NonExistingIdentifier');
135 $inCache =
$backend->has($identifier);
136 $this->assertFalse($inCache,
'"has" did not return FALSE when checking on non existing identifier');
144 $identifier = $this->
getUniqueId(
'NonExistingIdentifier');
145 $inCache =
$backend->remove($identifier);
146 $this->assertFalse($inCache,
'"remove" did not return FALSE when checking on non existing identifier');
154 $data =
'some data' . microtime();
155 $backend->set(
'BackendXcacheTest1', $data, array(
'UnitTestTag%test',
'UnitTestTag%boring'));
156 $backend->set(
'BackendXcacheTest2', $data, array(
'UnitTestTag%test',
'UnitTestTag%special'));
157 $backend->set(
'BackendXcacheTest3', $data, array(
'UnitTestTag%test'));
158 $backend->flushByTag(
'UnitTestTag%special');
159 $this->assertTrue(
$backend->has(
'BackendXcacheTest1'),
'BackendXcacheTest1');
160 $this->assertFalse(
$backend->has(
'BackendXcacheTest2'),
'BackendXcacheTest2');
161 $this->assertTrue(
$backend->has(
'BackendXcacheTest3'),
'BackendXcacheTest3');
169 $data =
'some data' . microtime();
170 $backend->set(
'BackendXcacheTest1', $data);
171 $backend->set(
'BackendXcacheTest2', $data);
172 $backend->set(
'BackendXcacheTest3', $data);
174 $this->assertFalse(
$backend->has(
'BackendXcacheTest1'),
'BackendXcacheTest1');
175 $this->assertFalse(
$backend->has(
'BackendXcacheTest2'),
'BackendXcacheTest2');
176 $this->assertFalse(
$backend->has(
'BackendXcacheTest3'),
'BackendXcacheTest3');
182 public function flushRemovesOnlyOwnEntries() {
184 $thisCache = $this->getMock(
'TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(),
'', FALSE);
185 $thisCache->expects($this->any())->method(
'getIdentifier')->will($this->returnValue(
'thisCache'));
187 $thisBackend->setCache($thisCache);
190 $thatCache = $this->getMock(
'TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(),
'', FALSE);
191 $thatCache->expects($this->any())->method(
'getIdentifier')->will($this->returnValue(
'thatCache'));
193 $thatBackend->setCache($thatCache);
194 $thisBackend->set(
'thisEntry',
'Hello');
195 $thatBackend->set(
'thatEntry',
'World!');
196 $thatBackend->flush();
197 $this->assertEquals(
'Hello', $thisBackend->get(
'thisEntry'));
198 $this->assertFalse($thatBackend->has(
'thatEntry'));
208 $data = str_repeat(
'abcde', 1024 * 1024);
211 $this->assertTrue(
$backend->has($identifier));
212 $this->assertEquals(
$backend->get($identifier), $data);
220 $tags = array(
'UnitTestTag%test',
'UnitTestTag%boring');
222 $backend = $this->setUpBackend(TRUE);
223 $backend->_call(
'addIdentifierToTags', $identifier, $tags);
226 $backend->_call(
'findTagsByIdentifier', $identifier)
229 $backend->_call(
'addIdentifierToTags', $identifier, $tags);
232 $backend->_call(
'findTagsByIdentifier', $identifier)
242 protected function setUpBackend($accessible = FALSE) {
244 $cache = $this->getMock(
'TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(),
'', FALSE);
246 $accessibleClassName = $this->
buildAccessibleProxy(
'\\TYPO3\\CMS\\Core\\Cache\\Backend\\XcacheBackend');
247 $backend =
new $accessibleClassName(
'Testing');
itIsPossibleToOverwriteAnEntryInTheCache()
setRemovesTagsFromPreviousSet()
removeReturnsFalseIfTheEntryDoesntExist()
itIsPossibleToSetAndCheckExistenceInCache()
findIdentifiersByTagFindsSetEntries()
flushRemovesAllCacheEntries()
hasReturnsFalseIfTheEntryDoesntExist()
setThrowsExceptionIfNoFrontEndHasBeenSet()
itIsPossibleToRemoveEntryFromCache()
buildAccessibleProxy($className)
flushByTagRemovesCacheEntriesWithSpecifiedTag()
itIsPossibleToSetAndGetEntry()
setTagsOnlyOnceToIdentifier()