Added feature #15306: [Caching framework] Add scheduler task to execute garbage colle...
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / tests / tx_scheduler_cachingframeworkgarbagecollectionTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Christian Kuhn <lolli@schwarzbu.ch>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for class "tx_scheduler_CachingFrameworkGarbageCollection"
27 *
28 * @package TYPO3
29 * @subpackage tx_scheduler
30 *
31 * @author Christian Kuhn <lolli@schwarzbu.ch>
32 */
33 class tx_scheduler_CachingFrameworkGarbageCollectionTest extends tx_phpunit_testcase {
34 protected $backupGlobals = TRUE;
35
36 /**
37 * @test
38 */
39 public function executeCallsCollectGarbageOfConfiguredBackend() {
40 $cache = $this->getMock('t3lib_cache_frontend_StringFrontend', array(), array(), '', FALSE);
41 $cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
42
43 $cache->expects($this->atLeastOnce())->method('collectGarbage');
44
45 $GLOBALS['typo3CacheManager'] = new t3lib_cache_Manager();
46 $GLOBALS['typo3CacheManager']->registerCache($cache);
47 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = array(
48 'cache' => array(
49 'frontend' => 't3lib_cache_frontend_StringFrontend',
50 'backend' => 't3lib_cache_backend_AbstractBackend',
51 ),
52 );
53
54 $task = new tx_scheduler_CachingFrameworkGarbageCollection();
55 $task->selectedBackends = array('t3lib_cache_backend_AbstractBackend');
56 $task->execute();
57 }
58
59 /**
60 * @test
61 */
62 public function executeDoesNotCallCollectGarbageOfConfiguredBackend() {
63 $cache = $this->getMock('t3lib_cache_frontend_StringFrontend', array(), array(), '', FALSE);
64 $cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
65
66 $cache->expects($this->never())->method('collectGarbage');
67
68 $GLOBALS['typo3CacheManager'] = new t3lib_cache_Manager();
69 $GLOBALS['typo3CacheManager']->registerCache($cache);
70 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = array(
71 'cache' => array(
72 'frontend' => 't3lib_cache_frontend_StringFrontend',
73 'backend' => 't3lib_cache_backend_AbstractBackend',
74 ),
75 );
76
77 $task = new tx_scheduler_CachingFrameworkGarbageCollection();
78 $task->selectedBackends = array('t3lib_cache_backend_NullBackend');
79 $task->execute();
80 }
81 }
82 ?>