TYPO3 CMS  TYPO3_6-2
CacheManagerTest.php
Go to the documentation of this file.
1 <?php
3 
25 
31  $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
32  $cache1 = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE);
33  $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('test'));
34  $cache2 = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE);
35  $cache2->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('test'));
36  $manager->registerCache($cache1);
37  $manager->registerCache($cache2);
38  }
39 
44  $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
45  $cache1 = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE);
46  $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1'));
47  $cache2 = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE);
48  $cache2->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache2'));
49  $manager->registerCache($cache1);
50  $manager->registerCache($cache2);
51  $this->assertSame($cache2, $manager->getCache('cache2'), 'The cache returned by getCache() was not the same I registered.');
52  }
53 
59  $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
60  $cache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE);
61  $cache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('someidentifier'));
62  $manager->registerCache($cache);
63  $manager->getCache('someidentifier');
64  $manager->getCache('doesnotexist');
65  }
66 
70  public function hasCacheReturnsCorrectResult() {
71  $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
72  $cache1 = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE);
73  $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1'));
74  $manager->registerCache($cache1);
75  $this->assertTrue($manager->hasCache('cache1'), 'hasCache() did not return TRUE.');
76  $this->assertFalse($manager->hasCache('cache2'), 'hasCache() did not return FALSE.');
77  }
78 
83  $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
84  $cache1 = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE);
85  $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1'));
86  $cache1->expects($this->once())->method('flushByTag')->with($this->equalTo('theTag'));
87  $manager->registerCache($cache1);
88  $cache2 = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE);
89  $cache2->expects($this->once())->method('flushByTag')->with($this->equalTo('theTag'));
90  $manager->registerCache($cache2);
91  $manager->flushCachesByTag('theTag');
92  }
93 
98  $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
99  $cache1 = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE);
100  $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1'));
101  $cache1->expects($this->once())->method('flush');
102  $manager->registerCache($cache1);
103  $cache2 = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE);
104  $cache2->expects($this->once())->method('flush');
105  $manager->registerCache($cache2);
106  $manager->flushCaches();
107  }
108 
114  $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
115  $manager->flushCachesInGroup('nonExistingGroup');
116  }
117 
123  $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
124  $manager->flushCachesInGroup('nonExistingGroup', 'someTag');
125  }
126 
131  $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
132  $cacheIdentifier = $this->getUniqueId('Test');
133  $cacheObjectName = 'testCache';
134  $backendObjectName = 'testBackend';
135  $backendOptions = array('foo');
136  $configuration = array(
137  $cacheIdentifier => array(
138  'frontend' => $cacheObjectName,
139  'backend' => $backendObjectName,
140  'options' => $backendOptions
141  )
142  );
143  $factory = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheFactory', array('create'), array(), '', FALSE);
144  $factory->expects($this->once())->method('create')->with($cacheIdentifier, $cacheObjectName, $backendObjectName, $backendOptions);
145  $manager->injectCacheFactory($factory);
146  $manager->setCacheConfigurations($configuration);
147  $manager->getCache($cacheIdentifier);
148  }
149 
154  $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
155  $cacheIdentifier = $this->getUniqueId('Test');
156  $backendObjectName = 'testBackend';
157  $backendOptions = array('foo');
158  $configuration = array(
159  $cacheIdentifier => array(
160  'backend' => $backendObjectName,
161  'options' => $backendOptions
162  )
163  );
164  $factory = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheFactory', array('create'), array(), '', FALSE);
165  $factory->expects($this->once())->method('create')->with($cacheIdentifier, 'TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', $backendObjectName, $backendOptions);
166  $manager->injectCacheFactory($factory);
167  $manager->setCacheConfigurations($configuration);
168  $manager->getCache($cacheIdentifier);
169  }
170 
175  $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
176  $cacheIdentifier = $this->getUniqueId('Test');
177  $cacheObjectName = 'testCache';
178  $backendOptions = array('foo');
179  $configuration = array(
180  $cacheIdentifier => array(
181  'frontend' => $cacheObjectName,
182  'options' => $backendOptions
183  )
184  );
185  $factory = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheFactory', array('create'), array(), '', FALSE);
186  $factory->expects($this->once())->method('create')->with($cacheIdentifier, $cacheObjectName, 'TYPO3\\CMS\\Core\\Cache\\Backend\\Typo3DatabaseBackend', $backendOptions);
187  $manager->injectCacheFactory($factory);
188  $manager->setCacheConfigurations($configuration);
189  $manager->getCache($cacheIdentifier);
190  }
191 
196  $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
197  $cacheIdentifier = $this->getUniqueId('Test');
198  $cacheObjectName = 'testCache';
199  $backendObjectName = 'testBackend';
200  $configuration = array(
201  $cacheIdentifier => array(
202  'frontend' => $cacheObjectName,
203  'backend' => $backendObjectName
204  )
205  );
206  $factory = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheFactory', array('create'), array(), '', FALSE);
207  $factory->expects($this->once())->method('create')->with($cacheIdentifier, $cacheObjectName, $backendObjectName, array());
208  $manager->injectCacheFactory($factory);
209  $manager->setCacheConfigurations($configuration);
210  $manager->getCache($cacheIdentifier);
211  }
212 
213 }