TYPO3 CMS  TYPO3_8-7
CachingFrameworkGarbageCollectionTest.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 
18 
22 class CachingFrameworkGarbageCollectionTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
27  protected $singletonInstances = [];
28 
32  protected function setUp()
33  {
35  }
36 
40  protected function tearDown()
41  {
43  parent::tearDown();
44  }
45 
49  public function executeCallsCollectGarbageOfConfiguredBackend()
50  {
51  $cache = $this->createMock(\TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class);
52  $cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
53  $cache->expects($this->atLeastOnce())->method('collectGarbage');
54  $mockCacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
55  $mockCacheManager->registerCache($cache);
56  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $mockCacheManager);
57  $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = [
58  'cache' => [
59  'frontend' => \TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class,
60  'backend' => \TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class,
61  ]
62  ];
64  $subject = $this->getMockBuilder(\TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask::class)
65  ->setMethods(['dummy'])
66  ->disableOriginalConstructor()
67  ->getMock();
68  $subject->selectedBackends = [\TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class];
69  $subject->execute();
70  }
71 
75  public function executeDoesNotCallCollectGarbageOfNotConfiguredBackend()
76  {
77  $cache = $this->createMock(\TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class);
78  $cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
79  $cache->expects($this->never())->method('collectGarbage');
80  $mockCacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
81  $mockCacheManager->registerCache($cache);
82  GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $mockCacheManager);
83  $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = [
84  'cache' => [
85  'frontend' => \TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class,
86  'backend' => \TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class,
87  ]
88  ];
90  $subject = $this->getMockBuilder(\TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask::class)
91  ->setMethods(['dummy'])
92  ->disableOriginalConstructor()
93  ->getMock();
94  $subject->selectedBackends = [\TYPO3\CMS\Core\Cache\Backend\NullBackend::class];
95  $subject->execute();
96  }
97 }
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']