‪TYPO3CMS  10.4
CacheServiceTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪CacheServiceTest extends UnitTestCase
26 {
30  protected ‪$cacheService;
31 
36 
37  protected function ‪setUp(): void
38  {
39  parent::setUp();
40  $this->cacheService = new ‪CacheService();
41  $this->cacheManagerMock = $this->createMock(CacheManager::class);
42  $this->cacheService->injectCacheManager($this->cacheManagerMock);
43  }
44 
49  {
50  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_123']);
51  $this->cacheService->clearPageCache(123);
52  }
53 
58  {
59  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_0']);
60  $this->cacheService->clearPageCache('Foo');
61  }
62 
67  {
68  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroup')->with('pages');
69  $this->cacheService->clearPageCache();
70  }
71 
76  {
77  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_1', 'pageId_2', 'pageId_3']);
78  $this->cacheService->clearPageCache([1, 2, 3]);
79  }
80 
84  public function ‪clearsCachesOfRegisteredPageIds()
85  {
86  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_2', 'pageId_15', 'pageId_8']);
87 
88  $this->cacheService->getPageIdStack()->push(8);
89  $this->cacheService->getPageIdStack()->push(15);
90  $this->cacheService->getPageIdStack()->push(2);
91 
92  $this->cacheService->clearCachesOfRegisteredPageIds();
93  }
94 
99  {
100  $this->cacheManagerMock->expects(self::once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_2', 'pageId_15', 'pageId_8']);
101 
102  $this->cacheService->getPageIdStack()->push(8);
103  $this->cacheService->getPageIdStack()->push(15);
104  $this->cacheService->getPageIdStack()->push(15);
105  $this->cacheService->getPageIdStack()->push(2);
106  $this->cacheService->getPageIdStack()->push(2);
107 
108  $this->cacheService->clearCachesOfRegisteredPageIds();
109  }
110 }
‪TYPO3\CMS\Extbase\Tests\Unit\Service
Definition: CacheServiceTest.php:16
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheConvertsPageIdsToArray
‪clearPageCacheConvertsPageIdsToArray()
Definition: CacheServiceTest.php:46
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified
‪clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified()
Definition: CacheServiceTest.php:64
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest
Definition: CacheServiceTest.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPages
‪clearPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPages()
Definition: CacheServiceTest.php:73
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\$cacheService
‪TYPO3 CMS Extbase Service CacheService $cacheService
Definition: CacheServiceTest.php:29
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\$cacheManagerMock
‪TYPO3 CMS Core Cache CacheManager PHPUnit_Framework_MockObject_MockObject $cacheManagerMock
Definition: CacheServiceTest.php:33
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearsCachesOfDuplicateRegisteredPageIdsOnlyOnce
‪clearsCachesOfDuplicateRegisteredPageIdsOnlyOnce()
Definition: CacheServiceTest.php:96
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\setUp
‪setUp()
Definition: CacheServiceTest.php:35
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheConvertsPageIdsToNumericArray
‪clearPageCacheConvertsPageIdsToNumericArray()
Definition: CacheServiceTest.php:55
‪TYPO3\CMS\Extbase\Service\CacheService
Definition: CacheService.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearsCachesOfRegisteredPageIds
‪clearsCachesOfRegisteredPageIds()
Definition: CacheServiceTest.php:82