[BUGFIX] Add missing namespace parts
[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\Components\TestingFramework\Core\Unit\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 protected function setUp()
33 {
34 $this->cacheService = new \TYPO3\CMS\Extbase\Service\CacheService();
35 $this->cacheManagerMock = $this->createMock(\TYPO3\CMS\Core\Cache\CacheManager::class);
36 $this->cacheService->injectCacheManager($this->cacheManagerMock);
37 }
38
39 /**
40 * @test
41 */
42 public function clearPageCacheConvertsPageIdsToArray()
43 {
44 $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_123']);
45 $this->cacheService->clearPageCache(123);
46 }
47
48 /**
49 * @test
50 */
51 public function clearPageCacheConvertsPageIdsToNumericArray()
52 {
53 $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_0']);
54 $this->cacheService->clearPageCache('Foo');
55 }
56
57 /**
58 * @test
59 */
60 public function clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified()
61 {
62 $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroup')->with('pages');
63 $this->cacheService->clearPageCache();
64 }
65
66 /**
67 * @test
68 */
69 public function clearPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPages()
70 {
71 $this->cacheManagerMock->expects($this->at(0))->method('flushCachesInGroupByTags')->with('pages', ['pageId_1', 'pageId_2', 'pageId_3']);
72 $this->cacheService->clearPageCache([1, 2, 3]);
73 }
74
75 /**
76 * @test
77 */
78 public function clearsCachesOfRegisteredPageIds()
79 {
80 $this->cacheManagerMock->expects($this->at(0))->method('flushCachesInGroupByTags')->with('pages', ['pageId_2', 'pageId_15', 'pageId_8']);
81
82 $this->cacheService->getPageIdStack()->push(8);
83 $this->cacheService->getPageIdStack()->push(15);
84 $this->cacheService->getPageIdStack()->push(2);
85
86 $this->cacheService->clearCachesOfRegisteredPageIds();
87 }
88
89 /**
90 * @test
91 */
92 public function clearsCachesOfDuplicateRegisteredPageIdsOnlyOnce()
93 {
94 $this->cacheManagerMock->expects($this->at(0))->method('flushCachesInGroupByTags')->with('pages', ['pageId_2', 'pageId_15', 'pageId_8']);
95
96 $this->cacheService->getPageIdStack()->push(8);
97 $this->cacheService->getPageIdStack()->push(15);
98 $this->cacheService->getPageIdStack()->push(15);
99 $this->cacheService->getPageIdStack()->push(2);
100 $this->cacheService->getPageIdStack()->push(2);
101
102 $this->cacheService->clearCachesOfRegisteredPageIds();
103 }
104 }