Fixed #11206: Cleaned up test "t3lib_extmgm_testcase" (Thanks to Oliver Klee)
[Packages/TYPO3.CMS.git] / tests / t3lib / cache / t3lib_cache_factorytestcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Ingo Renner <ingo@typo3.org>
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 require_once(PATH_t3lib . 'cache/backend/class.t3lib_cache_backend_nullbackend.php');
27 require_once('backend/class.t3lib_cache_backend_mockbackend.php');
28
29 /**
30 * Testcase for the Cache Factory
31 *
32 * This file is a backport from FLOW3
33 *
34 * @author Ingo Renner <ingo@typo3.org>
35 * @package TYPO3
36 * @subpackage tests
37 * @version $Id$
38 */
39 class t3lib_cache_FactoryTestCase extends tx_phpunit_testcase {
40
41 /**
42 * Sets up this testcase
43 *
44 * @return void
45 * @author Ingo Renner <ingo@typo3.org>
46 */
47 public function setUp() {
48 $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheBackends']['t3lib_cache_backend_MockBackend'] = 'typo3_src/tests/t3lib/cache/backend/class.t3lib_cache_backend_mockbackend.php:t3lib_cache_backend_MockBackend';
49 }
50
51 /**
52 * @test
53 * @author Robert Lemke <robert@typo3.org>
54 * @author Karsten Dambekalns <karsten@typo3.org>
55 * @author Ingo Renner <ingo@typo3.org>
56 */
57 public function createReturnsInstanceOfTheSpecifiedCacheFrontend() {
58 $backend = $this->getMock('t3lib_cache_backend_NullBackend', array(), array(), '', FALSE);
59 $cache = $this->getMock('t3lib_cache_frontend_VariableFrontend', array(), array(), '', FALSE);
60
61 $mockCacheManager = $this->getMock('t3lib_cache_Manager', array('registerCache'), array(), '', FALSE);
62 $factory = new t3lib_cache_Factory();
63 $factory->setCacheManager($mockCacheManager);
64
65 $cache = $factory->create('TYPO3_Cache_FactoryTest_Cache', 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_NullBackend');
66 $this->assertType('t3lib_cache_frontend_VariableFrontend', $cache);
67 }
68
69 /**
70 * @test
71 * @author Robert Lemke <robert@typo3.org>
72 * @author Karsten Dambekalns <karsten@typo3.org>
73 * @author Ingo Renner <ingo@typo3.org>
74 */
75 public function createInjectsAnInstanceOfTheSpecifiedBackendIntoTheCacheFrontend() {
76 $backend = $this->getMock('t3lib_cache_backend_FileBackend', array(), array(), '', FALSE);
77 $cache = $this->getMock('t3lib_cache_frontend_VariableFrontend', array(), array(), '', FALSE);
78
79 $mockCacheManager = $this->getMock('t3lib_cache_Manager', array('registerCache'), array(), '', FALSE);
80 $factory = new t3lib_cache_Factory();
81 $factory->setCacheManager($mockCacheManager);
82
83 $factory->create('TYPO3_Cache_FactoryTest_Cache', 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_FileBackend');
84 }
85
86 /**
87 * @test
88 * @author Robert Lemke <robert@typo3.org>
89 * @author Karsten Dambekalns <karsten@typo3.org>
90 * @author Ingo Renner <ingo@typo3.org>
91 */
92 public function createPassesBackendOptionsToTheCreatedBackend() {
93 $someValue = microtime();
94 $backendOptions = array('someOption' => $someValue);
95
96 $cache = $this->getMock('t3lib_cache_frontend_VariableFrontend', array(), array(), '', FALSE);
97
98 $mockCacheManager = $this->getMock('t3lib_cache_Manager', array('registerCache'), array(), '', FALSE);
99 $factory = new t3lib_cache_Factory();
100 $factory->setCacheManager($mockCacheManager);
101
102 $cache = $factory->create('TYPO3_Cache_FactoryTest_Cache', 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_MockBackend', $backendOptions);
103
104 $this->assertEquals($someValue, $cache->getBackend()->getSomeOption(), 'create() did not pass the backend options to the backend.');
105 }
106
107 /**
108 * @test
109 * @author Robert Lemke <robert@typo3.org>
110 * @author Karsten Dambekalns <karsten@typo3.org>
111 * @author Ingo Renner <ingo@typo3.org>
112 */
113 /*
114 Not working yet
115
116 public function createRegistersTheCacheAtTheCacheManager() {
117 $cacheIdentifier = 'TYPO3_Cache_FactoryTest_Cache';
118 $backend = $this->getMock('t3lib_cache_backend_NullBackend', array(), array(), '', FALSE);
119 $cache = $this->getMock('t3lib_cache_frontend_VariableFrontend', array('getCache'), array($cacheIdentifier, $backend), '', true);
120 $cache->getBackend()->setCache($cache);
121
122 $mockCacheManager = $this->getMock('t3lib_cache_Manager', array('registerCache'), array(), '', FALSE);
123 $mockCacheManager->expects($this->once())->method('registerCache')->with($cache);
124 # $mockCacheManager->expects($this->once())->method('registerCache')->with('t3lib_cache_frontend_VariableFrontend');
125 $factory = new t3lib_cache_Factory();
126 $factory->setCacheManager($mockCacheManager);
127
128 $factory->create($cacheIdentifier, 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_NullBackend');
129 }
130 */
131 }
132
133 ?>