TYPO3 CMS  TYPO3_8-7
CacheServiceTest.php
Go to the documentation of this file.
1 <?php
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 
20 class CacheServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
25  protected $cacheService;
26 
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 
43  {
44  $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_123']);
45  $this->cacheService->clearPageCache(123);
46  }
47 
52  {
53  $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_0']);
54  $this->cacheService->clearPageCache('Foo');
55  }
56 
61  {
62  $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroup')->with('pages');
63  $this->cacheService->clearPageCache();
64  }
65 
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 
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 
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 }