/sbw/ZendFramework-1.11.4/tests/Zend/Memory/AccessControllerTest.php

https://github.com/nbcutech/o3drupal · PHP · 161 lines · 82 code · 29 blank · 50 comment · 12 complexity · 8e4f64856e124701c0d1492672f31b6c MD5 · raw file

  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_Memory
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: AccessControllerTest.php 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. if (!defined('PHPUnit_MAIN_METHOD')) {
  23. define('PHPUnit_MAIN_METHOD', 'Zend_Memory_AccessControllerTest::main');
  24. }
  25. /** Zend_Memory */
  26. require_once 'Zend/Memory.php';
  27. /**
  28. * @category Zend
  29. * @package Zend_Memory
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @group Zend_Memory
  34. */
  35. class Zend_Memory_Container_AccessControllerTest extends PHPUnit_Framework_TestCase
  36. {
  37. /**
  38. * Memory manager, used for tests
  39. *
  40. * @var Zend_Memory_Manager
  41. */
  42. private $_memoryManager = null;
  43. public static function main()
  44. {
  45. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  46. $result = PHPUnit_TextUI_TestRunner::run($suite);
  47. }
  48. public function setUp()
  49. {
  50. $tmpDir = sys_get_temp_dir() . '/zend_memory';
  51. $this->_removeCacheDir($tmpDir);
  52. mkdir($tmpDir);
  53. $this->cacheDir = $tmpDir;
  54. }
  55. protected function _removeCacheDir($dir)
  56. {
  57. if (!file_exists($dir)) {
  58. return true;
  59. }
  60. if (!is_dir($dir) || is_link($dir)) {
  61. return unlink($dir);
  62. }
  63. foreach (scandir($dir) as $item) {
  64. if ($item == '.' || $item == '..') {
  65. continue;
  66. }
  67. $this->_removeCacheDir($dir . '/' . $item);
  68. }
  69. return rmdir($dir);
  70. }
  71. /**
  72. * Retrieve memory manager
  73. *
  74. */
  75. private function _getMemoryManager()
  76. {
  77. if ($this->_memoryManager === null) {
  78. $backendOptions = array('cache_dir' => $this->cacheDir); // Directory where to put the cache files
  79. $this->_memoryManager = Zend_Memory::factory('File', $backendOptions);
  80. }
  81. return $this->_memoryManager;
  82. }
  83. /**
  84. * tests the Movable memory container object creation
  85. */
  86. public function testCreation()
  87. {
  88. $memoryManager = $this->_getMemoryManager();
  89. $memObject = $memoryManager->create('012345678');
  90. $this->assertTrue($memObject instanceof Zend_Memory_AccessController);
  91. }
  92. /**
  93. * tests the value access methods
  94. */
  95. public function testValueAccess()
  96. {
  97. $memoryManager = $this->_getMemoryManager();
  98. $memObject = $memoryManager->create('0123456789');
  99. // getRef() method
  100. $this->assertEquals($memObject->getRef(), '0123456789');
  101. $valueRef = &$memObject->getRef();
  102. $valueRef[3] = '_';
  103. $this->assertEquals($memObject->getRef(), '012_456789');
  104. if (version_compare(PHP_VERSION, '5.2') < 0) {
  105. // Skip next tests for PHP versions before 5.2
  106. return;
  107. }
  108. // value property
  109. $this->assertEquals((string)$memObject->value, '012_456789');
  110. $memObject->value[7] = '_';
  111. $this->assertEquals((string)$memObject->value, '012_456_89');
  112. $memObject->value = 'another value';
  113. $this->assertTrue($memObject->value instanceof Zend_Memory_Value);
  114. $this->assertEquals((string)$memObject->value, 'another value');
  115. }
  116. /**
  117. * tests lock()/unlock()/isLocked() functions
  118. */
  119. public function testLock()
  120. {
  121. $memoryManager = $this->_getMemoryManager();
  122. $memObject = $memoryManager->create('012345678');
  123. $this->assertFalse((boolean)$memObject->isLocked());
  124. $memObject->lock();
  125. $this->assertTrue((boolean)$memObject->isLocked());
  126. $memObject->unlock();
  127. $this->assertFalse((boolean)$memObject->isLocked());
  128. }
  129. }
  130. if (PHPUnit_MAIN_METHOD == 'Zend_Memory_AccessControllerTest::main') {
  131. Zend_Memory_AccessControllerTest::main();
  132. }