ChildrenTest.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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_Ldap
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * Zend_Ldap_OnlineTestCase
  23. */
  24. require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'OnlineTestCase.php';
  25. /**
  26. * @see Zend_Ldap_Node
  27. */
  28. require_once 'Zend/Ldap/Node.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Ldap
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Ldap_Node_ChildrenTest extends Zend_Ldap_OnlineTestCase
  37. {
  38. protected function setUp()
  39. {
  40. parent::setUp();
  41. $this->_prepareLdapServer();
  42. }
  43. protected function tearDown()
  44. {
  45. $this->_cleanupLdapServer();
  46. parent::tearDown();
  47. }
  48. public function testGetChildrenOnAttachedNode()
  49. {
  50. $node=$this->_getLdap()->getBaseNode();
  51. $children=$node->getChildren();
  52. $this->assertType('Zend_Ldap_Node_ChildrenIterator', $children);
  53. $this->assertEquals(6, count($children));
  54. $this->assertType('Zend_Ldap_Node', $children['ou=Node']);
  55. }
  56. public function testGetChildrenOnDetachedNode()
  57. {
  58. $node=$this->_getLdap()->getBaseNode();
  59. $node->detachLdap();
  60. $children=$node->getChildren();
  61. $this->assertType('Zend_Ldap_Node_ChildrenIterator', $children);
  62. $this->assertEquals(0, count($children));
  63. $node->attachLdap($this->_getLdap());
  64. $node->reload();
  65. $children=$node->getChildren();
  66. $this->assertType('Zend_Ldap_Node_ChildrenIterator', $children);
  67. $this->assertEquals(6, count($children));
  68. $this->assertType('Zend_Ldap_Node', $children['ou=Node']);
  69. }
  70. public function testHasChildrenOnAttachedNode()
  71. {
  72. $node=$this->_getLdap()->getNode(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE);
  73. $this->assertTrue($node->hasChildren());
  74. $this->assertTrue($node->hasChildren());
  75. $node=$this->_getLdap()->getNode($this->_createDn('ou=Node,'));
  76. $this->assertTrue($node->hasChildren());
  77. $this->assertTrue($node->hasChildren());
  78. $node=$this->_getLdap()->getNode($this->_createDn('ou=Test1,'));
  79. $this->assertFalse($node->hasChildren());
  80. $this->assertFalse($node->hasChildren());
  81. $node=$this->_getLdap()->getNode($this->_createDn('ou=Test1,ou=Node,'));
  82. $this->assertFalse($node->hasChildren());
  83. $this->assertFalse($node->hasChildren());
  84. }
  85. public function testHasChildrenOnDetachedNodeWithoutPriorGetChildren()
  86. {
  87. $node=$this->_getLdap()->getNode(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE);
  88. $node->detachLdap();
  89. $this->assertFalse($node->hasChildren());
  90. $node=$this->_getLdap()->getNode($this->_createDn('ou=Node,'));
  91. $node->detachLdap();
  92. $this->assertFalse($node->hasChildren());
  93. $node=$this->_getLdap()->getNode($this->_createDn('ou=Test1,'));
  94. $node->detachLdap();
  95. $this->assertFalse($node->hasChildren());
  96. $node=$this->_getLdap()->getNode($this->_createDn('ou=Test1,ou=Node,'));
  97. $node->detachLdap();
  98. $this->assertFalse($node->hasChildren());
  99. }
  100. public function testHasChildrenOnDetachedNodeWithPriorGetChildren()
  101. {
  102. $node=$this->_getLdap()->getNode(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE);
  103. $node->getChildren();
  104. $node->detachLdap();
  105. $this->assertTrue($node->hasChildren());
  106. $node=$this->_getLdap()->getNode($this->_createDn('ou=Node,'));
  107. $node->getChildren();
  108. $node->detachLdap();
  109. $this->assertTrue($node->hasChildren());
  110. $node=$this->_getLdap()->getNode($this->_createDn('ou=Test1,'));
  111. $node->getChildren();
  112. $node->detachLdap();
  113. $this->assertFalse($node->hasChildren());
  114. $node=$this->_getLdap()->getNode($this->_createDn('ou=Test1,ou=Node,'));
  115. $node->getChildren();
  116. $node->detachLdap();
  117. $this->assertFalse($node->hasChildren());
  118. }
  119. public function testChildrenCollectionSerialization()
  120. {
  121. $node=$this->_getLdap()->getNode($this->_createDn('ou=Node,'));
  122. $children=$node->getChildren();
  123. $this->assertTrue($node->hasChildren());
  124. $this->assertEquals(2, count($children));
  125. $string=serialize($node);
  126. $node2=unserialize($string);
  127. $children2=$node2->getChildren();
  128. $this->assertTrue($node2->hasChildren());
  129. $this->assertEquals(2, count($children2));
  130. $node2->attachLdap($this->_getLdap());
  131. $children2=$node2->getChildren();
  132. $this->assertTrue($node2->hasChildren());
  133. $this->assertEquals(2, count($children2));
  134. $node=$this->_getLdap()->getNode($this->_createDn('ou=Node,'));
  135. $this->assertTrue($node->hasChildren());
  136. $string=serialize($node);
  137. $node2=unserialize($string);
  138. $this->assertFalse($node2->hasChildren());
  139. $node2->attachLdap($this->_getLdap());
  140. $this->assertTrue($node2->hasChildren());
  141. }
  142. public function testCascadingAttachAndDetach()
  143. {
  144. $node=$this->_getLdap()->getBaseNode();
  145. $baseChildren=$node->getChildren();
  146. $nodeChildren=$baseChildren['ou=Node']->getChildren();
  147. $this->assertTrue($node->isAttached());
  148. foreach ($baseChildren as $bc) {
  149. $this->assertTrue($bc->isAttached());
  150. }
  151. foreach ($nodeChildren as $nc) {
  152. $this->assertTrue($nc->isAttached());
  153. }
  154. $node->detachLdap();
  155. $this->assertFalse($node->isAttached());
  156. foreach ($baseChildren as $bc) {
  157. $this->assertFalse($bc->isAttached());
  158. }
  159. foreach ($nodeChildren as $nc) {
  160. $this->assertFalse($nc->isAttached());
  161. }
  162. $node->attachLdap($this->_getLdap());
  163. $this->assertTrue($node->isAttached());
  164. $this->assertSame($this->_getLdap(), $node->getLdap());
  165. foreach ($baseChildren as $bc) {
  166. $this->assertTrue($bc->isAttached());
  167. $this->assertSame($this->_getLdap(), $bc->getLdap());
  168. }
  169. foreach ($nodeChildren as $nc) {
  170. $this->assertTrue($nc->isAttached());
  171. $this->assertSame($this->_getLdap(), $nc->getLdap());
  172. }
  173. }
  174. }