[BUGFIX] create ClassSchema with ObjectManager::create()
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Service / CacheServiceTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Extbase Team
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 /**
27 * Testcase for class Tx_Extbase_Service_CacheService
28 *
29 * @package Extbase
30 * @subpackage extbase
31 */
32
33 class Tx_Extbase_Tests_Unit_Service_CacheServiceTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
34
35 /**
36 * @var Tx_Extbase_Service_CacheService
37 */
38 protected $cacheService;
39
40 /**
41 * @var t3lib_DB
42 */
43 protected $typo3DbBackup;
44
45 /**
46 * @var t3lib_cache_Manager
47 */
48 protected $cacheManagerBackup;
49
50 public function setUp() {
51 $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
52 $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB');
53
54 $this->cacheManagerBackup = $GLOBALS['typo3CacheManager'];
55 $GLOBALS['typo3CacheManager'] = $this->getMock('t3lib_cache_Manager');
56
57 $this->cacheService = $this->getAccessibleMock('Tx_Extbase_Service_CacheService', array('dummy'));
58 }
59
60 /**
61 * @test
62 */
63 public function clearPageCacheConvertsPageIdsToArray() {
64 $cacheService = $this->getMock('Tx_Extbase_Service_CacheService', array('flushPageCache', 'flushPageSectionCache'));
65 $cacheService->expects($this->once())->method('flushPageCache')->with(array(123));
66 $cacheService->expects($this->once())->method('flushPageSectionCache')->with(array(123));
67 $cacheService->clearPageCache(123);
68 }
69
70 /**
71 * @test
72 */
73 public function clearPageCacheConvertsPageIdsToNumericArray() {
74 $cacheService = $this->getMock('Tx_Extbase_Service_CacheService', array('flushPageCache', 'flushPageSectionCache'));
75 $cacheService->expects($this->once())->method('flushPageCache')->with(array(0));
76 $cacheService->expects($this->once())->method('flushPageSectionCache')->with(array(0));
77 $cacheService->clearPageCache('Foo');
78 }
79
80 /**
81 * @test
82 */
83 public function clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified() {
84 $cacheService = $this->getMock('Tx_Extbase_Service_CacheService', array('flushPageCache', 'flushPageSectionCache'));
85 $cacheService->expects($this->once())->method('flushPageCache')->with(NULL);
86 $cacheService->expects($this->once())->method('flushPageSectionCache')->with(NULL);
87 $cacheService->clearPageCache();
88 }
89
90 /**
91 * @test
92 */
93 public function flushPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPagesIfCachingFrameworkIsEnabled() {
94 $mockCacheFrontend = $this->getMock('t3lib_cache_frontend_Frontend');
95 $mockCacheFrontend->expects($this->at(0))->method('flushByTag')->with('pageId_1');
96 $mockCacheFrontend->expects($this->at(1))->method('flushByTag')->with('pageId_2');
97 $mockCacheFrontend->expects($this->at(2))->method('flushByTag')->with('pageId_3');
98
99 $GLOBALS['typo3CacheManager']->expects($this->once())->method('getCache')->with('cache_pages')->will($this->returnValue($mockCacheFrontend));
100
101 $this->cacheService->_set('useCachingFramework', TRUE);
102 $this->cacheService->_call('flushPageCache', array(1,2,3));
103 }
104
105 /**
106 * @test
107 */
108 public function flushPageCacheUsesCacheManagerToFlushCacheOfAllPagesIfCachingFrameworkIsEnabledAndPageIdsIsNull() {
109 $mockCacheFrontend = $this->getMock('t3lib_cache_frontend_Frontend');
110 $mockCacheFrontend->expects($this->once())->method('flush');
111
112 $GLOBALS['typo3CacheManager']->expects($this->once())->method('getCache')->with('cache_pages')->will($this->returnValue($mockCacheFrontend));
113
114 $this->cacheService->_set('useCachingFramework', TRUE);
115 $this->cacheService->_call('flushPageCache');
116 }
117
118 /**
119 * @test
120 */
121 public function flushPageCacheFlushesCacheOfSpecifiedPagesDirectlyIfCachingFrameworkIsDisabled() {
122 $GLOBALS['TYPO3_DB']->expects($this->once())->method('cleanIntArray')->with(array(1,2,3))->will($this->returnValue(array(3,2,1)));
123 $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_DELETEquery')->with(
124 'cache_pages',
125 'page_id IN (3,2,1)'
126 );
127
128 $this->cacheService->_set('useCachingFramework', FALSE);
129 $this->cacheService->_call('flushPageCache', array(1,2,3));
130 }
131
132 /**
133 * test
134 */
135 public function flushPageCacheFlushesCacheOfAllPagesDirectlyIfCachingFrameworkIsDisabled() {
136 $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_TRUNCATEquery')->with('cache_pages');
137
138 $this->cacheService->_set('useCachingFramework', FALSE);
139 $this->cacheService->_call('flushPageCache');
140 }
141
142 /**
143 * @test
144 */
145 public function flushPageSectionCacheUsesCacheManagerToFlushCacheOfSpecifiedPageSectionsIfCachingFrameworkIsEnabled() {
146 $mockCacheFrontend = $this->getMock('t3lib_cache_frontend_Frontend');
147 $mockCacheFrontend->expects($this->at(0))->method('flushByTag')->with('pageId_1');
148 $mockCacheFrontend->expects($this->at(1))->method('flushByTag')->with('pageId_2');
149 $mockCacheFrontend->expects($this->at(2))->method('flushByTag')->with('pageId_3');
150
151 $GLOBALS['typo3CacheManager']->expects($this->once())->method('getCache')->with('cache_pagesection')->will($this->returnValue($mockCacheFrontend));
152
153 $this->cacheService->_set('useCachingFramework', TRUE);
154 $this->cacheService->_call('flushPageSectionCache', array(1,2,3));
155 }
156
157 /**
158 * @test
159 */
160 public function flushPageSectionCacheUsesCacheManagerToFlushCacheOfAllPageSectionsIfCachingFrameworkIsEnabledAndPageIdsIsNull() {
161 $mockCacheFrontend = $this->getMock('t3lib_cache_frontend_Frontend');
162 $mockCacheFrontend->expects($this->once())->method('flush');
163
164 $GLOBALS['typo3CacheManager']->expects($this->once())->method('getCache')->with('cache_pagesection')->will($this->returnValue($mockCacheFrontend));
165
166 $this->cacheService->_set('useCachingFramework', TRUE);
167 $this->cacheService->_call('flushPageSectionCache');
168 }
169
170 /**
171 * @test
172 */
173 public function flushPageSectionCacheFlushesCacheOfSpecifiedPageSectionsDirectlyIfCachingFrameworkIsDisabled() {
174 $GLOBALS['TYPO3_DB']->expects($this->once())->method('cleanIntArray')->with(array(1,2,3))->will($this->returnValue(array(3,2,1)));
175 $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_DELETEquery')->with(
176 'cache_pagesection',
177 'page_id IN (3,2,1)'
178 );
179
180 $this->cacheService->_set('useCachingFramework', FALSE);
181 $this->cacheService->_call('flushPageSectionCache', array(1,2,3));
182 }
183
184 /**
185 * test
186 */
187 public function flushPageSectionCacheCacheFlushesCacheOfAllPageSectionsDirectlyIfCachingFrameworkIsDisabled() {
188 $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_TRUNCATEquery')->with('cache_pagesection');
189
190 $this->cacheService->_set('useCachingFramework', FALSE);
191 $this->cacheService->_call('flushPageSectionCache');
192 }
193
194 }
195 ?>