[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Service / CacheServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Service;
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
17 /**
18 * Test case
19 */
20 class CacheServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @var \TYPO3\CMS\Extbase\Service\CacheService
24 */
25 protected $cacheService;
26
27 /**
28 * @var \TYPO3\CMS\Core\Cache\CacheManager|PHPUnit_Framework_MockObject_MockObject
29 */
30 protected $cacheManagerMock;
31
32 public function setUp() {
33 $this->cacheService = new \TYPO3\CMS\Extbase\Service\CacheService();
34 $this->cacheManagerMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager');
35 $this->cacheService->injectCacheManager($this->cacheManagerMock);
36 }
37
38 /**
39 * @test
40 */
41 public function clearPageCacheConvertsPageIdsToArray() {
42 $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroupByTag')->with('pages', 'pageId_123');
43 $this->cacheService->clearPageCache(123);
44 }
45
46 /**
47 * @test
48 */
49 public function clearPageCacheConvertsPageIdsToNumericArray() {
50 $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroupByTag')->with('pages', 'pageId_0');
51 $this->cacheService->clearPageCache('Foo');
52 }
53
54 /**
55 * @test
56 */
57 public function clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified() {
58 $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroup')->with('pages');
59 $this->cacheService->clearPageCache();
60 }
61
62 /**
63 * @test
64 */
65 public function clearPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPages() {
66 $this->cacheManagerMock->expects($this->at(0))->method('flushCachesInGroupByTag')->with('pages', 'pageId_1');
67 $this->cacheManagerMock->expects($this->at(1))->method('flushCachesInGroupByTag')->with('pages', 'pageId_2');
68 $this->cacheManagerMock->expects($this->at(2))->method('flushCachesInGroupByTag')->with('pages', 'pageId_3');
69 $this->cacheService->clearPageCache(array(1, 2, 3));
70 }
71
72 /**
73 * @test
74 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
75 */
76 public function clearsCachesOfRegisteredPageIds() {
77 $this->cacheManagerMock->expects($this->at(0))->method('flushCachesInGroupByTag')->with('pages', 'pageId_2');
78 $this->cacheManagerMock->expects($this->at(1))->method('flushCachesInGroupByTag')->with('pages', 'pageId_15');
79 $this->cacheManagerMock->expects($this->at(2))->method('flushCachesInGroupByTag')->with('pages', 'pageId_8');
80
81 $this->cacheService->getPageIdStack()->push(8);
82 $this->cacheService->getPageIdStack()->push(15);
83 $this->cacheService->getPageIdStack()->push(2);
84
85 $this->cacheService->clearCachesOfRegisteredPageIds();
86 }
87
88 /**
89 * @test
90 * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
91 */
92 public function clearsCachesOfDuplicateRegisteredPageIdsOnlyOnce() {
93 $this->cacheManagerMock->expects($this->at(0))->method('flushCachesInGroupByTag')->with('pages', 'pageId_2');
94 $this->cacheManagerMock->expects($this->at(1))->method('flushCachesInGroupByTag')->with('pages', 'pageId_15');
95 $this->cacheManagerMock->expects($this->at(2))->method('flushCachesInGroupByTag')->with('pages', 'pageId_8');
96 $this->cacheManagerMock->expects($this->exactly(3))->method('flushCachesInGroupByTag');
97
98 $this->cacheService->getPageIdStack()->push(8);
99 $this->cacheService->getPageIdStack()->push(15);
100 $this->cacheService->getPageIdStack()->push(15);
101 $this->cacheService->getPageIdStack()->push(2);
102 $this->cacheService->getPageIdStack()->push(2);
103
104 $this->cacheService->clearCachesOfRegisteredPageIds();
105 }
106 }