2
0

FileBackendTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @category Zend
  16. * @package Zend_Cache
  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
  20. * @version $Id$
  21. */
  22. /**
  23. * Zend_Cache
  24. */
  25. require_once 'Zend/Cache.php';
  26. require_once 'Zend/Cache/Backend/File.php';
  27. /**
  28. * Zend_Log
  29. */
  30. require_once 'Zend/Log.php';
  31. require_once 'Zend/Log/Writer/Null.php';
  32. /**
  33. * Common tests for backends
  34. */
  35. require_once 'CommonExtendedBackendTest.php';
  36. /**
  37. * PHPUnit test case
  38. */
  39. require_once 'PHPUnit/Framework/TestCase.php';
  40. /**
  41. * @category Zend
  42. * @package Zend_Cache
  43. * @subpackage UnitTests
  44. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  45. * @license http://framework.zend.com/license/new-bsd New BSD License
  46. * @group Zend_Cache
  47. */
  48. class Zend_Cache_FileBackendTest extends Zend_Cache_CommonExtendedBackendTest {
  49. protected $_instance;
  50. protected $_instance2;
  51. protected $_cache_dir;
  52. public function __construct($name = null, array $data = array(), $dataName = '')
  53. {
  54. parent::__construct('Zend_Cache_Backend_File', $data, $dataName);
  55. }
  56. public function setUp($notag = false)
  57. {
  58. $this->mkdir();
  59. $this->_cache_dir = $this->getTmpDir() . DIRECTORY_SEPARATOR;
  60. $this->_instance = new Zend_Cache_Backend_File(array(
  61. 'cache_dir' => $this->_cache_dir,
  62. ));
  63. $logger = new Zend_Log(new Zend_Log_Writer_Null());
  64. $this->_instance->setDirectives(array('logger' => $logger));
  65. parent::setUp($notag);
  66. }
  67. public function tearDown()
  68. {
  69. parent::tearDown();
  70. unset($this->_instance);
  71. }
  72. public function testConstructorCorrectCall()
  73. {
  74. $test = new Zend_Cache_Backend_File(array());
  75. }
  76. public function testConstructorWithABadFileNamePrefix()
  77. {
  78. try {
  79. $class = new Zend_Cache_Backend_File(array(
  80. 'file_name_prefix' => 'foo bar'
  81. ));
  82. } catch (Zend_Cache_Exception $e) {
  83. return;
  84. }
  85. $this->fail('Zend_Cache_Exception was expected but not thrown');
  86. }
  87. public function testGetWithANonExistingCacheIdAndANullLifeTime()
  88. {
  89. $this->_instance->setDirectives(array('lifetime' => null));
  90. $this->assertFalse($this->_instance->load('barbar'));
  91. }
  92. public function testSaveCorrectCallWithHashedDirectoryStructure()
  93. {
  94. $this->_instance->setOption('hashed_directory_level', 2);
  95. $res = $this->_instance->save('data to cache', 'foo', array('tag1', 'tag2'));
  96. $this->assertTrue($res);
  97. }
  98. public function testCleanModeAllWithHashedDirectoryStructure()
  99. {
  100. $this->_instance->setOption('hashed_directory_level', 2);
  101. $this->assertTrue($this->_instance->clean('all'));
  102. $this->assertFalse($this->_instance->test('bar'));
  103. $this->assertFalse($this->_instance->test('bar2'));
  104. }
  105. public function testSaveWithABadCacheDir()
  106. {
  107. $this->_instance->setOption('cache_dir', '/foo/bar/lfjlqsdjfklsqd/');
  108. $res = $this->_instance->save('data to cache', 'foo', array('tag1', 'tag2'));
  109. $this->assertFalse($res);
  110. }
  111. }