ChildrenTest.php 6.9 KB

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