AccessControllerTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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-2009 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. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../TestHelper.php';
  26. /** Zend_Memory */
  27. require_once 'Zend/Memory.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_Memory
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  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. /**
  44. * Retrieve memory manager
  45. *
  46. */
  47. private function _getMemoryManager()
  48. {
  49. if ($this->_memoryManager === null) {
  50. $backendOptions = array('cache_dir' => dirname(__FILE__) . '/_files/'); // Directory where to put the cache files
  51. $this->_memoryManager = Zend_Memory::factory('File', $backendOptions);
  52. }
  53. return $this->_memoryManager;
  54. }
  55. /**
  56. * tests the Movable memory container object creation
  57. */
  58. public function testCreation()
  59. {
  60. $memoryManager = $this->_getMemoryManager();
  61. $memObject = $memoryManager->create('012345678');
  62. $this->assertTrue($memObject instanceof Zend_Memory_AccessController);
  63. }
  64. /**
  65. * tests the value access methods
  66. */
  67. public function testValueAccess()
  68. {
  69. $memoryManager = $this->_getMemoryManager();
  70. $memObject = $memoryManager->create('0123456789');
  71. // getRef() method
  72. $this->assertEquals($memObject->getRef(), '0123456789');
  73. $valueRef = &$memObject->getRef();
  74. $valueRef[3] = '_';
  75. $this->assertEquals($memObject->getRef(), '012_456789');
  76. if (version_compare(PHP_VERSION, '5.2') < 0) {
  77. // Skip next tests for PHP versions before 5.2
  78. return;
  79. }
  80. // value property
  81. $this->assertEquals((string)$memObject->value, '012_456789');
  82. $memObject->value[7] = '_';
  83. $this->assertEquals((string)$memObject->value, '012_456_89');
  84. $memObject->value = 'another value';
  85. $this->assertTrue($memObject->value instanceof Zend_Memory_Value);
  86. $this->assertEquals((string)$memObject->value, 'another value');
  87. }
  88. /**
  89. * tests lock()/unlock()/isLocked() functions
  90. */
  91. public function testLock()
  92. {
  93. $memoryManager = $this->_getMemoryManager();
  94. $memObject = $memoryManager->create('012345678');
  95. $this->assertFalse((boolean)$memObject->isLocked());
  96. $memObject->lock();
  97. $this->assertTrue((boolean)$memObject->isLocked());
  98. $memObject->unlock();
  99. $this->assertFalse((boolean)$memObject->isLocked());
  100. }
  101. }