TYPO3 CMS  TYPO3_7-6
TransientMemoryBackendTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 {
29  {
30  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
31  $data = 'Some data';
32  $identifier = 'MyIdentifier';
33  $backend->set($identifier, $data);
34  }
35 
40  {
41  $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class, [], [], '', 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  {
56  $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class, [], [], '', false);
57  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
58  $backend->setCache($cache);
59  $data = 'Some data';
60  $identifier = 'MyIdentifier';
61  $backend->set($identifier, $data);
62  $fetchedData = $backend->get($identifier);
63  $this->assertEquals($data, $fetchedData);
64  }
65 
70  {
71  $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class, [], [], '', false);
72  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
73  $backend->setCache($cache);
74  $data = 'Some data';
75  $identifier = 'MyIdentifier';
76  $backend->set($identifier, $data);
77  $backend->remove($identifier);
78  $inCache = $backend->has($identifier);
79  $this->assertFalse($inCache);
80  }
81 
86  {
87  $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class, [], [], '', false);
88  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
89  $backend->setCache($cache);
90  $data = 'Some data';
91  $identifier = 'MyIdentifier';
92  $backend->set($identifier, $data);
93  $otherData = 'some other data';
94  $backend->set($identifier, $otherData);
95  $fetchedData = $backend->get($identifier);
96  $this->assertEquals($otherData, $fetchedData);
97  }
98 
103  {
104  $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class, [], [], '', false);
105  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
106  $backend->setCache($cache);
107  $data = 'Some data';
108  $entryIdentifier = 'MyIdentifier';
109  $backend->set($entryIdentifier, $data, ['UnitTestTag%tag1', 'UnitTestTag%tag2']);
110  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag1');
111  $this->assertEquals($entryIdentifier, $retrieved[0]);
112  $retrieved = $backend->findIdentifiersByTag('UnitTestTag%tag2');
113  $this->assertEquals($entryIdentifier, $retrieved[0]);
114  }
115 
120  {
121  $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class, [], [], '', false);
122  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
123  $backend->setCache($cache);
124  $identifier = 'NonExistingIdentifier';
125  $inCache = $backend->has($identifier);
126  $this->assertFalse($inCache);
127  }
128 
133  {
134  $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class, [], [], '', false);
135  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
136  $backend->setCache($cache);
137  $identifier = 'NonExistingIdentifier';
138  $inCache = $backend->remove($identifier);
139  $this->assertFalse($inCache);
140  }
141 
146  {
147  $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class, [], [], '', false);
148  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
149  $backend->setCache($cache);
150  $data = 'some data' . microtime();
151  $backend->set('TransientMemoryBackendTest1', $data, ['UnitTestTag%test', 'UnitTestTag%boring']);
152  $backend->set('TransientMemoryBackendTest2', $data, ['UnitTestTag%test', 'UnitTestTag%special']);
153  $backend->set('TransientMemoryBackendTest3', $data, ['UnitTestTag%test']);
154  $backend->flushByTag('UnitTestTag%special');
155  $this->assertTrue($backend->has('TransientMemoryBackendTest1'), 'TransientMemoryBackendTest1');
156  $this->assertFalse($backend->has('TransientMemoryBackendTest2'), 'TransientMemoryBackendTest2');
157  $this->assertTrue($backend->has('TransientMemoryBackendTest3'), 'TransientMemoryBackendTest3');
158  }
159 
163  public function flushRemovesAllCacheEntries()
164  {
165  $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface::class, [], [], '', false);
166  $backend = new \TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend('Testing');
167  $backend->setCache($cache);
168  $data = 'some data' . microtime();
169  $backend->set('TransientMemoryBackendTest1', $data);
170  $backend->set('TransientMemoryBackendTest2', $data);
171  $backend->set('TransientMemoryBackendTest3', $data);
172  $backend->flush();
173  $this->assertFalse($backend->has('TransientMemoryBackendTest1'), 'TransientMemoryBackendTest1');
174  $this->assertFalse($backend->has('TransientMemoryBackendTest2'), 'TransientMemoryBackendTest2');
175  $this->assertFalse($backend->has('TransientMemoryBackendTest3'), 'TransientMemoryBackendTest3');
176  }
177 }