| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Ldap
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- /**
- * Zend_Ldap_OnlineTestCase
- */
- require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'OnlineTestCase.php';
- /**
- * @see Zend_Ldap_Node
- */
- require_once 'Zend/Ldap/Node.php';
- /**
- * @category Zend
- * @package Zend_Ldap
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @group Zend_Ldap
- * @group Zend_Ldap_Node
- */
- class Zend_Ldap_Node_ChildrenTest extends Zend_Ldap_OnlineTestCase
- {
- protected function setUp()
- {
- parent::setUp();
- $this->_prepareLdapServer();
- }
- protected function tearDown()
- {
- $this->_cleanupLdapServer();
- parent::tearDown();
- }
- public function testGetChildrenOnAttachedNode()
- {
- $node=$this->_getLdap()->getBaseNode();
- $children=$node->getChildren();
- $this->assertTrue($children instanceof Zend_Ldap_Node_ChildrenIterator);
- $this->assertEquals(6, count($children));
- $this->assertTrue($children['ou=Node'] instanceof Zend_Ldap_Node);
- }
- public function testGetChildrenOnDetachedNode()
- {
- $node=$this->_getLdap()->getBaseNode();
- $node->detachLdap();
- $children=$node->getChildren();
- $this->assertTrue($children instanceof Zend_Ldap_Node_ChildrenIterator);
- $this->assertEquals(0, count($children));
- $node->attachLdap($this->_getLdap());
- $node->reload();
- $children=$node->getChildren();
- $this->assertTrue($children instanceof Zend_Ldap_Node_ChildrenIterator);
- $this->assertEquals(6, count($children));
- $this->assertTrue($children['ou=Node'] instanceof Zend_Ldap_Node);
- }
- public function testHasChildrenOnAttachedNode()
- {
- $node=$this->_getLdap()->getNode(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE);
- $this->assertTrue($node->hasChildren());
- $this->assertTrue($node->hasChildren());
- $node=$this->_getLdap()->getNode($this->_createDn('ou=Node,'));
- $this->assertTrue($node->hasChildren());
- $this->assertTrue($node->hasChildren());
- $node=$this->_getLdap()->getNode($this->_createDn('ou=Test1,'));
- $this->assertFalse($node->hasChildren());
- $this->assertFalse($node->hasChildren());
- $node=$this->_getLdap()->getNode($this->_createDn('ou=Test1,ou=Node,'));
- $this->assertFalse($node->hasChildren());
- $this->assertFalse($node->hasChildren());
- }
- public function testHasChildrenOnDetachedNodeWithoutPriorGetChildren()
- {
- $node=$this->_getLdap()->getNode(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE);
- $node->detachLdap();
- $this->assertFalse($node->hasChildren());
- $node=$this->_getLdap()->getNode($this->_createDn('ou=Node,'));
- $node->detachLdap();
- $this->assertFalse($node->hasChildren());
- $node=$this->_getLdap()->getNode($this->_createDn('ou=Test1,'));
- $node->detachLdap();
- $this->assertFalse($node->hasChildren());
- $node=$this->_getLdap()->getNode($this->_createDn('ou=Test1,ou=Node,'));
- $node->detachLdap();
- $this->assertFalse($node->hasChildren());
- }
- public function testHasChildrenOnDetachedNodeWithPriorGetChildren()
- {
- $node=$this->_getLdap()->getNode(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE);
- $node->getChildren();
- $node->detachLdap();
- $this->assertTrue($node->hasChildren());
- $node=$this->_getLdap()->getNode($this->_createDn('ou=Node,'));
- $node->getChildren();
- $node->detachLdap();
- $this->assertTrue($node->hasChildren());
- $node=$this->_getLdap()->getNode($this->_createDn('ou=Test1,'));
- $node->getChildren();
- $node->detachLdap();
- $this->assertFalse($node->hasChildren());
- $node=$this->_getLdap()->getNode($this->_createDn('ou=Test1,ou=Node,'));
- $node->getChildren();
- $node->detachLdap();
- $this->assertFalse($node->hasChildren());
- }
- public function testChildrenCollectionSerialization()
- {
- $node=$this->_getLdap()->getNode($this->_createDn('ou=Node,'));
- $children=$node->getChildren();
- $this->assertTrue($node->hasChildren());
- $this->assertEquals(2, count($children));
- $string=serialize($node);
- $node2=unserialize($string);
- $children2=$node2->getChildren();
- $this->assertTrue($node2->hasChildren());
- $this->assertEquals(2, count($children2));
- $node2->attachLdap($this->_getLdap());
- $children2=$node2->getChildren();
- $this->assertTrue($node2->hasChildren());
- $this->assertEquals(2, count($children2));
- $node=$this->_getLdap()->getNode($this->_createDn('ou=Node,'));
- $this->assertTrue($node->hasChildren());
- $string=serialize($node);
- $node2=unserialize($string);
- $this->assertFalse($node2->hasChildren());
- $node2->attachLdap($this->_getLdap());
- $this->assertTrue($node2->hasChildren());
- }
- public function testCascadingAttachAndDetach()
- {
- $node=$this->_getLdap()->getBaseNode();
- $baseChildren=$node->getChildren();
- $nodeChildren=$baseChildren['ou=Node']->getChildren();
- $this->assertTrue($node->isAttached());
- foreach ($baseChildren as $bc) {
- $this->assertTrue($bc->isAttached());
- }
- foreach ($nodeChildren as $nc) {
- $this->assertTrue($nc->isAttached());
- }
- $node->detachLdap();
- $this->assertFalse($node->isAttached());
- foreach ($baseChildren as $bc) {
- $this->assertFalse($bc->isAttached());
- }
- foreach ($nodeChildren as $nc) {
- $this->assertFalse($nc->isAttached());
- }
- $node->attachLdap($this->_getLdap());
- $this->assertTrue($node->isAttached());
- $this->assertSame($this->_getLdap(), $node->getLdap());
- foreach ($baseChildren as $bc) {
- $this->assertTrue($bc->isAttached());
- $this->assertSame($this->_getLdap(), $bc->getLdap());
- }
- foreach ($nodeChildren as $nc) {
- $this->assertTrue($nc->isAttached());
- $this->assertSame($this->_getLdap(), $nc->getLdap());
- }
- }
- }
|