7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
17 * @subpackage UnitTests
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
26 require_once 'Zend/Cache.php';
27 require_once 'Zend/Cache/Backend/File.php';
32 require_once 'Zend/Log.php';
33 require_once 'Zend/Log/Writer/Null.php';
36 * Common tests for backends
38 require_once 'CommonExtendedBackendTest.php';
43 require_once 'PHPUnit/Framework/TestCase.php';
48 * @subpackage UnitTests
49 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
50 * @license http://framework.zend.com/license/new-bsd New BSD License
53 class Zend_Cache_FileBackendTest
extends Zend_Cache_CommonExtendedBackendTest
{
56 protected $_instance2;
57 protected $_cache_dir;
59 public function __construct($name = null, array $data = array(), $dataName = '')
61 parent
::__construct('Zend_Cache_Backend_File', $data, $dataName);
64 public function setUp($notag = false)
67 $this->_cache_dir
= $this->getTmpDir() . DIRECTORY_SEPARATOR
;
68 $this->_instance
= new Zend_Cache_Backend_File(array(
69 'cache_dir' => $this->_cache_dir
,
72 $logger = new Zend_Log(new Zend_Log_Writer_Null());
73 $this->_instance
->setDirectives(array('logger' => $logger));
75 parent
::setUp($notag);
78 public function tearDown()
81 unset($this->_instance
);
84 public function testConstructorCorrectCall()
86 $test = new Zend_Cache_Backend_File(array());
89 public function testConstructorWithABadFileNamePrefix()
92 $class = new Zend_Cache_Backend_File(array(
93 'file_name_prefix' => 'foo bar'
95 } catch (Zend_Cache_Exception
$e) {
98 $this->fail('Zend_Cache_Exception was expected but not thrown');
101 public function testGetWithANonExistingCacheIdAndANullLifeTime()
103 $this->_instance
->setDirectives(array('lifetime' => null));
104 $this->assertFalse($this->_instance
->load('barbar'));
107 public function testSaveCorrectCallWithHashedDirectoryStructure()
109 $this->_instance
->setOption('hashed_directory_level', 2);
110 $res = $this->_instance
->save('data to cache', 'foo', array('tag1', 'tag2'));
111 $this->assertTrue($res);
114 public function testCleanModeAllWithHashedDirectoryStructure()
116 $this->_instance
->setOption('hashed_directory_level', 2);
117 $this->assertTrue($this->_instance
->clean('all'));
118 $this->assertFalse($this->_instance
->test('bar'));
119 $this->assertFalse($this->_instance
->test('bar2'));
122 public function testSaveWithABadCacheDir()
124 $this->_instance
->setOption('cache_dir', '/foo/bar/lfjlqsdjfklsqd/');
125 $res = $this->_instance
->save('data to cache', 'foo', array('tag1', 'tag2'));
126 $this->assertFalse($res);