[TASK] Shorten the extend class in all unit tests
[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 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18
19 /**
20 * Test case
21 */
22 class CacheServiceTest extends UnitTestCase
23 {
24 /**
25 * @var \TYPO3\CMS\Extbase\Service\CacheService
26 */
27 protected $cacheService;
28
29 /**
30 * @var \TYPO3\CMS\Core\Cache\CacheManager|PHPUnit_Framework_MockObject_MockObject
31 */
32 protected $cacheManagerMock;
33
34 protected function setUp()
35 {
36 $this->cacheService = new \TYPO3\CMS\Extbase\Service\CacheService();
37 $this->cacheManagerMock = $this->createMock(\TYPO3\CMS\Core\Cache\CacheManager::class);
38 $this->cacheService->injectCacheManager($this->cacheManagerMock);
39 }
40
41 /**
42 * @test
43 */
44 public function clearPageCacheConvertsPageIdsToArray()
45 {
46 $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_123']);
47 $this->cacheService->clearPageCache(123);
48 }
49
50 /**
51 * @test
52 */
53 public function clearPageCacheConvertsPageIdsToNumericArray()
54 {
55 $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_0']);
56 $this->cacheService->clearPageCache('Foo');
57 }
58
59 /**
60 * @test
61 */
62 public function clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified()
63 {
64 $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroup')->with('pages');
65 $this->cacheService->clearPageCache();
66 }
67
68 /**
69 * @test
70 */
71 public function clearPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPages()
72 {
73 $this->cacheManagerMock->expects($this->at(0))->method('flushCachesInGroupByTags')->with('pages', ['pageId_1', 'pageId_2', 'pageId_3']);
74 $this->cacheService->clearPageCache([1, 2, 3]);
75 }
76
77 /**
78 * @test
79 */
80 public function clearsCachesOfRegisteredPageIds()
81 {
82 $this->cacheManagerMock->expects($this->at(0))->method('flushCachesInGroupByTags')->with('pages', ['pageId_2', 'pageId_15', 'pageId_8']);
83
84 $this->cacheService->getPageIdStack()->push(8);
85 $this->cacheService->getPageIdStack()->push(15);
86 $this->cacheService->getPageIdStack()->push(2);
87
88 $this->cacheService->clearCachesOfRegisteredPageIds();
89 }
90
91 /**
92 * @test
93 */
94 public function clearsCachesOfDuplicateRegisteredPageIdsOnlyOnce()
95 {
96 $this->cacheManagerMock->expects($this->at(0))->method('flushCachesInGroupByTags')->with('pages', ['pageId_2', 'pageId_15', 'pageId_8']);
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 }