‪TYPO3CMS  9.5
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 
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪CacheServiceTest extends UnitTestCase
23 {
27  protected ‪$cacheService;
28 
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 
45  {
46  $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_123']);
47  $this->cacheService->clearPageCache(123);
48  }
49 
54  {
55  $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroupByTags')->with('pages', ['pageId_0']);
56  $this->cacheService->clearPageCache('Foo');
57  }
58 
63  {
64  $this->cacheManagerMock->expects($this->once())->method('flushCachesInGroup')->with('pages');
65  $this->cacheService->clearPageCache();
66  }
67 
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 
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 
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 }
‪TYPO3\CMS\Extbase\Tests\Unit\Service
Definition: CacheServiceTest.php:2
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheConvertsPageIdsToArray
‪clearPageCacheConvertsPageIdsToArray()
Definition: CacheServiceTest.php:42
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified
‪clearPageCacheDoesNotConvertPageIdsIfNoneAreSpecified()
Definition: CacheServiceTest.php:60
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest
Definition: CacheServiceTest.php:23
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPages
‪clearPageCacheUsesCacheManagerToFlushCacheOfSpecifiedPages()
Definition: CacheServiceTest.php:69
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\$cacheService
‪TYPO3 CMS Extbase Service CacheService $cacheService
Definition: CacheServiceTest.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\$cacheManagerMock
‪TYPO3 CMS Core Cache CacheManager PHPUnit_Framework_MockObject_MockObject $cacheManagerMock
Definition: CacheServiceTest.php:30
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearsCachesOfDuplicateRegisteredPageIdsOnlyOnce
‪clearsCachesOfDuplicateRegisteredPageIdsOnlyOnce()
Definition: CacheServiceTest.php:92
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\setUp
‪setUp()
Definition: CacheServiceTest.php:32
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearPageCacheConvertsPageIdsToNumericArray
‪clearPageCacheConvertsPageIdsToNumericArray()
Definition: CacheServiceTest.php:51
‪TYPO3\CMS\Extbase\Tests\Unit\Service\CacheServiceTest\clearsCachesOfRegisteredPageIds
‪clearsCachesOfRegisteredPageIds()
Definition: CacheServiceTest.php:78