PageRenderTime 61ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zend/Cache/FileBackendTest.php

https://bitbucket.org/ksekar/campus
PHP | 126 lines | 70 code | 19 blank | 37 comment | 0 complexity | b01c4d617659471a22bd95ea197153e1 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: FileBackendTest.php 24594 2012-01-05 21:27:01Z matthew $
  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. * @category Zend
  38. * @package Zend_Cache
  39. * @subpackage UnitTests
  40. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. * @group Zend_Cache
  43. */
  44. class Zend_Cache_FileBackendTest extends Zend_Cache_CommonExtendedBackendTest {
  45. protected $_instance;
  46. protected $_instance2;
  47. protected $_cache_dir;
  48. public function __construct($name = null, array $data = array(), $dataName = '')
  49. {
  50. parent::__construct('Zend_Cache_Backend_File', $data, $dataName);
  51. }
  52. public function setUp($notag = false)
  53. {
  54. $this->mkdir();
  55. $this->_cache_dir = $this->getTmpDir() . DIRECTORY_SEPARATOR;
  56. $this->_instance = new Zend_Cache_Backend_File(array(
  57. 'cache_dir' => $this->_cache_dir,
  58. ));
  59. $logger = new Zend_Log(new Zend_Log_Writer_Null());
  60. $this->_instance->setDirectives(array('logger' => $logger));
  61. parent::setUp($notag);
  62. }
  63. public function tearDown()
  64. {
  65. parent::tearDown();
  66. unset($this->_instance);
  67. }
  68. public function testConstructorCorrectCall()
  69. {
  70. $test = new Zend_Cache_Backend_File(array());
  71. }
  72. public function testConstructorWithABadFileNamePrefix()
  73. {
  74. try {
  75. $class = new Zend_Cache_Backend_File(array(
  76. 'file_name_prefix' => 'foo bar'
  77. ));
  78. } catch (Zend_Cache_Exception $e) {
  79. return;
  80. }
  81. $this->fail('Zend_Cache_Exception was expected but not thrown');
  82. }
  83. public function testGetWithANonExistingCacheIdAndANullLifeTime()
  84. {
  85. $this->_instance->setDirectives(array('lifetime' => null));
  86. $this->assertFalse($this->_instance->load('barbar'));
  87. }
  88. public function testSaveCorrectCallWithHashedDirectoryStructure()
  89. {
  90. $this->_instance->setOption('hashed_directory_level', 2);
  91. $res = $this->_instance->save('data to cache', 'foo', array('tag1', 'tag2'));
  92. $this->assertTrue($res);
  93. }
  94. public function testCleanModeAllWithHashedDirectoryStructure()
  95. {
  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'));
  100. }
  101. public function testSaveWithABadCacheDir()
  102. {
  103. $this->_instance->setOption('cache_dir', '/foo/bar/lfjlqsdjfklsqd/');
  104. $res = $this->_instance->save('data to cache', 'foo', array('tag1', 'tag2'));
  105. $this->assertFalse($res);
  106. }
  107. }