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