4
* @subpackage UnitTests
10
require_once 'Zend/Cache.php';
11
require_once 'Zend/Cache/Backend/File.php';
16
require_once 'Zend/Log.php';
17
require_once 'Zend/Log/Writer/Null.php';
20
* Common tests for backends
22
require_once 'CommonExtendedBackendTest.php';
27
require_once 'PHPUnit/Framework/TestCase.php';
31
* @subpackage UnitTests
33
class Zend_Cache_FileBackendTest extends Zend_Cache_CommonExtendedBackendTest {
36
protected $_instance2;
37
protected $_cache_dir;
39
public function __construct($name = null, array $data = array(), $dataName = '')
41
parent::__construct('Zend_Cache_Backend_File', $data, $dataName);
44
public function setUp($notag = false)
47
$this->_cache_dir = $this->getTmpDir() . DIRECTORY_SEPARATOR;
48
$this->_instance = new Zend_Cache_Backend_File(array(
49
'cache_dir' => $this->_cache_dir,
52
$logger = new Zend_Log(new Zend_Log_Writer_Null());
53
$this->_instance->setDirectives(array('logger' => $logger));
55
parent::setUp($notag);
58
public function tearDown()
61
unset($this->_instance);
64
public function testConstructorCorrectCall()
66
$test = new Zend_Cache_Backend_File(array());
69
public function testConstructorWithABadFileNamePrefix()
72
$class = new Zend_Cache_Backend_File(array(
73
'file_name_prefix' => 'foo bar'
75
} catch (Zend_Cache_Exception $e) {
78
$this->fail('Zend_Cache_Exception was expected but not thrown');
81
public function testGetWithANonExistingCacheIdAndANullLifeTime()
83
$this->_instance->setDirectives(array('lifetime' => null));
84
$this->assertFalse($this->_instance->load('barbar'));
87
public function testSaveCorrectCallWithHashedDirectoryStructure()
89
$this->_instance->setOption('hashed_directory_level', 2);
90
$res = $this->_instance->save('data to cache', 'foo', array('tag1', 'tag2'));
91
$this->assertTrue($res);
94
public function testCleanModeAllWithHashedDirectoryStructure()
96
$this->_instance->setOption('hashed_directory_level', 2);
97
$this->assertTrue($this->_instance->clean('all'));
98
$this->assertFalse($this->_instance->test('bar'));
99
$this->assertFalse($this->_instance->test('bar2'));
102
public function testSaveWithABadCacheDir()
104
$this->_instance->setOption('cache_dir', '/foo/bar/lfjlqsdjfklsqd/');
105
$res = $this->_instance->save('data to cache', 'foo', array('tag1', 'tag2'));
106
$this->assertFalse($res);