FileBackendTest.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /*
  3. ==New BSD License==
  4. Copyright (c) 2012, Colin Mollenhour
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright
  9. notice, this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in the
  12. documentation and/or other materials provided with the distribution.
  13. * The name of Colin Mollenhour may not be used to endorse or promote products
  14. derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
  19. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. require_once 'app/Mage.php'; // Just for autoloading
  27. require_once 'CommonExtendedBackendTest.php';
  28. /**
  29. * @copyright Copyright (c) 2012 Colin Mollenhour (http://colin.mollenhour.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Cm_Cache_FileBackendTest extends Zend_Cache_CommonExtendedBackendTest {
  33. protected $_instance;
  34. protected $_cache_dir;
  35. public function __construct($name = null, array $data = array(), $dataName = '')
  36. {
  37. parent::__construct('Cm_Cache_Backend_File', $data, $dataName);
  38. }
  39. public function setUp($notag = false)
  40. {
  41. $this->mkdir();
  42. $this->_instance = new Cm_Cache_Backend_File(array(
  43. 'cache_dir' => $this->getTmpDir() . DIRECTORY_SEPARATOR,
  44. ));
  45. parent::setUp($notag);
  46. }
  47. public function tearDown()
  48. {
  49. parent::tearDown();
  50. unset($this->_instance);
  51. }
  52. public function testConstructorBadOption() { }
  53. public function testConstructorCorrectCall() { }
  54. public function testGetWithANonExistingCacheIdAndANullLifeTime()
  55. {
  56. $this->_instance->setDirectives(array('lifetime' => null));
  57. $this->assertFalse($this->_instance->load('barbar'));
  58. }
  59. public function testSaveCorrectCallWithHashedDirectoryStructure()
  60. {
  61. $this->_instance->setOption('hashed_directory_level', 2);
  62. $res = $this->_instance->save('data to cache', 'foo', array('tag1', 'tag2'));
  63. $this->assertTrue($res);
  64. }
  65. public function testCleanModeAllWithHashedDirectoryStructure()
  66. {
  67. $this->_instance->setOption('hashed_directory_level', 2);
  68. $this->assertTrue($this->_instance->clean('all'));
  69. $this->assertFalse($this->_instance->test('bar'));
  70. $this->assertFalse($this->_instance->test('bar2'));
  71. }
  72. public function testSaveWithABadCacheDir()
  73. {
  74. $this->_instance->setOption('cache_dir', '/foo/bar/lfjlqsdjfklsqd/');
  75. $res = $this->_instance->save('data to cache', 'foo', array('tag1', 'tag2'));
  76. $this->assertFalse($res);
  77. }
  78. }