TYPO3 CMS  TYPO3_6-2
TransientMemoryBackendTest.php
Go to the documentation of this file.
1 <?php
3 
25 
31  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
32  $data = 'Some data';
33  $identifier = 'MyIdentifier';
34  $backend->set($identifier, $data);
35  }
36 
41  $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
42  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
43  $backend->setCache($cache);
44  $data = 'Some data';
45  $identifier = 'MyIdentifier';
46  $backend->set($identifier, $data);
47  $inCache = $backend->has($identifier);
48  $this->assertTrue($inCache);
49  }
50 
54  public function itIsPossibleToSetAndGetEntry() {
55  $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
56  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
57  $backend->setCache($cache);
58  $data = 'Some data';
59  $identifier = 'MyIdentifier';
60  $backend->set($identifier, $data);
61  $fetchedData = $backend->get($identifier);
62  $this->assertEquals($data, $fetchedData);
63  }
64 
69  $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
70  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
71  $backend->setCache($cache);
72  $data = 'Some data';
73  $identifier = 'MyIdentifier';
74  $backend->set($identifier, $data);
75  $backend->remove($identifier);
76  $inCache = $backend->has($identifier);
77  $this->assertFalse($inCache);
78  }
79 
84  $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
85  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
86  $backend->setCache($cache);
87  $data = 'Some data';
88  $identifier = 'MyIdentifier';
89  $backend->set($identifier, $data);
90  $otherData = 'some other data';
91  $backend->set($identifier, $otherData);
92  $fetchedData = $backend->get($identifier);
93  $this->assertEquals($otherData, $fetchedData);
94  }
95 
100  $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
101  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
102  $backend->setCache($cache);
103  $data = 'Some data';
104  $entryIdentifier = 'MyIdentifier';
105  $backend->set($entryIdentifier, $data, array('UnitTestTag%tag1', 'UnitTestTag%tag2'));
106  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag1');
107  $this->assertEquals($entryIdentifier, $retrieved[0]);
108  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag2');
109  $this->assertEquals($entryIdentifier, $retrieved[0]);
110  }
111 
116  $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
117  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
118  $backend->setCache($cache);
119  $identifier = 'NonExistingIdentifier';
120  $inCache = $backend->has($identifier);
121  $this->assertFalse($inCache);
122  }
123 
128  $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
129  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
130  $backend->setCache($cache);
131  $identifier = 'NonExistingIdentifier';
132  $inCache = $backend->remove($identifier);
133  $this->assertFalse($inCache);
134  }
135 
140  $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
141  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
142  $backend->setCache($cache);
143  $data = 'some data' . microtime();
144  $backend->set('TransientMemoryBackendTest1', $data, array('UnitTestTag%test', 'UnitTestTag%boring'));
145  $backend->set('TransientMemoryBackendTest2', $data, array('UnitTestTag%test', 'UnitTestTag%special'));
146  $backend->set('TransientMemoryBackendTest3', $data, array('UnitTestTag%test'));
147  $backend->flushByTag('UnitTestTag%special');
148  $this->assertTrue($backend->has('TransientMemoryBackendTest1'), 'TransientMemoryBackendTest1');
149  $this->assertFalse($backend->has('TransientMemoryBackendTest2'), 'TransientMemoryBackendTest2');
150  $this->assertTrue($backend->has('TransientMemoryBackendTest3'), 'TransientMemoryBackendTest3');
151  }
152 
156  public function flushRemovesAllCacheEntries() {
157  $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\FrontendInterface', array(), array(), '', FALSE);
158  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
159  $backend->setCache($cache);
160  $data = 'some data' . microtime();
161  $backend->set('TransientMemoryBackendTest1', $data);
162  $backend->set('TransientMemoryBackendTest2', $data);
163  $backend->set('TransientMemoryBackendTest3', $data);
164  $backend->flush();
165  $this->assertFalse($backend->has('TransientMemoryBackendTest1'), 'TransientMemoryBackendTest1');
166  $this->assertFalse($backend->has('TransientMemoryBackendTest2'), 'TransientMemoryBackendTest2');
167  $this->assertFalse($backend->has('TransientMemoryBackendTest3'), 'TransientMemoryBackendTest3');
168  }
169 
170 }