[TASK] Remove access to constant TYPO3_UseCachingFramework
[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 public function tearDown() {
61 $GLOBALS['TYPO3_DB'] = $this->typo3DbBackup;
62 $GLOBALS['typo3CacheManager'] = $this->cacheManagerBackup;
63 }
64
65 /**
66 * @test
67 */
68 public function clearPageCacheConvertsPageIdsToArray() {
69 $cacheService = $this->getMock('Tx_Extbase_Service_CacheService', array('flushPageCache', 'flushPageSectionCache'));
70 $cacheService->expects($this->once())->method('flushPageCache')->with(array(123));
71 $cacheService->expects($this->once())->method('flushPageSectionCache')->with(array(123));
72 $cacheService->clearPageCache(123);
73 }
74
75 /**
76 * @test
77 */
78 public function clearPageCacheConvertsPageIdsToNumericArray() {
79 $cacheService = $this->getMock('Tx_Extbase_Service_CacheService', array('flushPageCache', 'flushPageSectionCache'));
80 $cacheService->expects($this->once())->method('flushPageCache')->with(array(0));
81 $cacheService->expects($this->once())->method('flushPageSectionCache')->with(array(0));
82 $cacheService->clearPageCache('Foo');
83 }
84
85 /**
86 * @test
87 */
88 public function clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified() {
89 $cacheService = $this->getMock('Tx_Extbase_Service_CacheService', array('flushPageCache', 'flushPageSectionCache'));
90 $cacheService->expects($this->once())->method('flushPageCache')->with(NULL);
91 $cacheService->expects($this->once())->method('flushPageSectionCache')->with(NULL);
92 $cacheService->clearPageCache();
93 }
94
95 /**
96 * @test
97 */
98 public function flushPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPages() {
99 $mockCacheFrontend = $this->getMock('t3lib_cache_frontend_Frontend');
100 $mockCacheFrontend->expects($this->at(0))->method('flushByTag')->with('pageId_1');
101 $mockCacheFrontend->expects($this->at(1))->method('flushByTag')->with('pageId_2');
102 $mockCacheFrontend->expects($this->at(2))->method('flushByTag')->with('pageId_3');
103
104 $GLOBALS['typo3CacheManager']->expects($this->once())->method('getCache')->with('cache_pages')->will($this->returnValue($mockCacheFrontend));
105
106 $this->cacheService->_call('flushPageCache', array(1,2,3));
107 }
108
109 /**
110 * @test
111 */
112 public function flushPageCacheUsesCacheManagerToFlushCacheOfAllPagesIfPageIdsIsNull() {
113 $mockCacheFrontend = $this->getMock('t3lib_cache_frontend_Frontend');
114 $mockCacheFrontend->expects($this->once())->method('flush');
115
116 $GLOBALS['typo3CacheManager']->expects($this->once())->method('getCache')->with('cache_pages')->will($this->returnValue($mockCacheFrontend));
117
118 $this->cacheService->_call('flushPageCache');
119 }
120
121 /**
122 * @test
123 */
124 public function flushPageSectionCacheUsesCacheManagerToFlushCacheOfSpecifiedPageSections() {
125 $mockCacheFrontend = $this->getMock('t3lib_cache_frontend_Frontend');
126 $mockCacheFrontend->expects($this->at(0))->method('flushByTag')->with('pageId_1');
127 $mockCacheFrontend->expects($this->at(1))->method('flushByTag')->with('pageId_2');
128 $mockCacheFrontend->expects($this->at(2))->method('flushByTag')->with('pageId_3');
129
130 $GLOBALS['typo3CacheManager']->expects($this->once())->method('getCache')->with('cache_pagesection')->will($this->returnValue($mockCacheFrontend));
131
132 $this->cacheService->_call('flushPageSectionCache', array(1,2,3));
133 }
134
135 /**
136 * @test
137 */
138 public function flushPageSectionCacheUsesCacheManagerToFlushCacheOfAllPageSectionsIfPageIdsIsNull() {
139 $mockCacheFrontend = $this->getMock('t3lib_cache_frontend_Frontend');
140 $mockCacheFrontend->expects($this->once())->method('flush');
141
142 $GLOBALS['typo3CacheManager']->expects($this->once())->method('getCache')->with('cache_pagesection')->will($this->returnValue($mockCacheFrontend));
143
144 $this->cacheService->_call('flushPageSectionCache');
145 }
146
147 }
148 ?>