TYPO3 API  SVNRelease
t3lib_cache_factoryTest.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009-2011 Ingo Renner <ingo@typo3.org>
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 
00025 require_once 'backend/class.t3lib_cache_backend_mockbackend.php';
00026 
00027 /**
00028  * Testcase for the Cache Factory
00029  *
00030  * This file is a backport from FLOW3
00031  *
00032  * @author  Ingo Renner <ingo@typo3.org>
00033  * @package TYPO3
00034  * @subpackage tests
00035  * @version $Id: t3lib_cache_factoryTest.php 10121 2011-01-18 20:15:30Z ohader $
00036  */
00037 class t3lib_cache_FactoryTest extends tx_phpunit_testcase {
00038 
00039     /**
00040      * Sets up this testcase
00041      *
00042      * @return void
00043      * @author Ingo Renner <ingo@typo3.org>
00044      */
00045     public function setUp() {
00046         $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheBackends']['t3lib_cache_backend_MockBackend'] = 't3lib_cache_backend_MockBackend';
00047     }
00048 
00049     /**
00050      * @test
00051      * @author Robert Lemke <robert@typo3.org>
00052      * @author Karsten Dambekalns <karsten@typo3.org>
00053      * @author Ingo Renner <ingo@typo3.org>
00054      */
00055     public function createReturnsInstanceOfTheSpecifiedCacheFrontend() {
00056         $backend = $this->getMock('t3lib_cache_backend_NullBackend', array(), array(), '', FALSE);
00057         $cache = $this->getMock('t3lib_cache_frontend_VariableFrontend', array(), array(), '', FALSE);
00058 
00059         $mockCacheManager = $this->getMock('t3lib_cache_Manager', array('registerCache'), array(), '', FALSE);
00060         $factory = new t3lib_cache_Factory();
00061         $factory->setCacheManager($mockCacheManager);
00062 
00063         $cache = $factory->create('TYPO3_Cache_FactoryTest_Cache', 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_NullBackend');
00064         $this->assertType('t3lib_cache_frontend_VariableFrontend', $cache);
00065     }
00066 
00067     /**
00068      * @test
00069      * @author Robert Lemke <robert@typo3.org>
00070      * @author Karsten Dambekalns <karsten@typo3.org>
00071      * @author Ingo Renner <ingo@typo3.org>
00072      */
00073     public function createInjectsAnInstanceOfTheSpecifiedBackendIntoTheCacheFrontend() {
00074         $backend = $this->getMock('t3lib_cache_backend_FileBackend', array(), array(), '', FALSE);
00075         $cache = $this->getMock('t3lib_cache_frontend_VariableFrontend', array(), array(), '', FALSE);
00076 
00077         $mockCacheManager = $this->getMock('t3lib_cache_Manager', array('registerCache'), array(), '', FALSE);
00078         $factory = new t3lib_cache_Factory();
00079         $factory->setCacheManager($mockCacheManager);
00080 
00081         $factory->create('TYPO3_Cache_FactoryTest_Cache', 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_FileBackend');
00082     }
00083 
00084     /**
00085      * @test
00086      * @author Robert Lemke <robert@typo3.org>
00087      * @author Karsten Dambekalns <karsten@typo3.org>
00088      * @author Ingo Renner <ingo@typo3.org>
00089      */
00090     public function createPassesBackendOptionsToTheCreatedBackend() {
00091         $someValue = microtime();
00092         $backendOptions = array('someOption' => $someValue);
00093 
00094         $cache = $this->getMock('t3lib_cache_frontend_VariableFrontend', array(), array(), '', FALSE);
00095 
00096         $mockCacheManager = $this->getMock('t3lib_cache_Manager', array('registerCache'), array(), '', FALSE);
00097         $factory = new t3lib_cache_Factory();
00098         $factory->setCacheManager($mockCacheManager);
00099 
00100         $cache = $factory->create('TYPO3_Cache_FactoryTest_Cache', 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_MockBackend', $backendOptions);
00101 
00102         $this->assertEquals($someValue, $cache->getBackend()->getSomeOption(), 'create() did not pass the backend options to the backend.');
00103     }
00104 
00105     /**
00106      * @test
00107      * @author Robert Lemke <robert@typo3.org>
00108      * @author Karsten Dambekalns <karsten@typo3.org>
00109      * @author Ingo Renner <ingo@typo3.org>
00110      */
00111 /*
00112     Not working yet
00113 
00114     public function createRegistersTheCacheAtTheCacheManager() {
00115         $cacheIdentifier = 'TYPO3_Cache_FactoryTest_Cache';
00116         $backend = $this->getMock('t3lib_cache_backend_NullBackend', array(), array(), '', FALSE);
00117         $cache = $this->getMock('t3lib_cache_frontend_VariableFrontend', array('getCache'), array($cacheIdentifier, $backend), '', true);
00118         $cache->getBackend()->setCache($cache);
00119 
00120         $mockCacheManager = $this->getMock('t3lib_cache_Manager', array('registerCache'), array(), '', FALSE);
00121         $mockCacheManager->expects($this->once())->method('registerCache')->with($cache);
00122 #       $mockCacheManager->expects($this->once())->method('registerCache')->with('t3lib_cache_frontend_VariableFrontend');
00123         $factory = new t3lib_cache_Factory();
00124         $factory->setCacheManager($mockCacheManager);
00125 
00126         $factory->create($cacheIdentifier, 't3lib_cache_frontend_VariableFrontend', 't3lib_cache_backend_NullBackend');
00127     }
00128 */
00129 }
00130 
00131 ?>