public function testSimpleRecursiveIteration() { $node = $this->_getLDAP()->getBaseNode(); $ri = new \RecursiveIteratorIterator($node, \RecursiveIteratorIterator::SELF_FIRST); $i = 0; foreach ($ri as $rdn => $n) { $dn = $n->getDn()->toString(Ldap\Dn::ATTR_CASEFOLD_LOWER); $rdn = Ldap\Dn::implodeRdn($n->getRdnArray(), Ldap\Dn::ATTR_CASEFOLD_LOWER); if ($i == 0) { $this->assertEquals(Ldap\Dn::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE)->toString(Ldap\Dn::ATTR_CASEFOLD_LOWER), $dn); } else { if ($i == 1) { $this->assertEquals('ou=Node', $rdn); $this->assertEquals($this->_createDn('ou=Node,'), $dn); } else { if ($i < 4) { $j = $i - 1; $base = $this->_createDn('ou=Node,'); } else { $j = $i - 3; $base = Ldap\Dn::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE)->toString(Ldap\Dn::ATTR_CASEFOLD_LOWER); } $this->assertEquals('ou=Test' . $j, $rdn); $this->assertEquals('ou=Test' . $j . ',' . $base, $dn); } } $i++; } $this->assertEquals(9, $i); }
/** * Renames a LDAP entry from one DN to another DN. * * This method implicitly moves the entry to another location within the tree. * * @param string|Dn $from * @param string|Dn $to * @param boolean $recursively * @param boolean $alwaysEmulate * @return Ldap Provides a fluid interface * @throws Exception\LdapException */ public function rename($from, $to, $recursively = false, $alwaysEmulate = false) { $emulate = (bool) $alwaysEmulate; if (!function_exists('ldap_rename')) { $emulate = true; } elseif ($recursively) { $emulate = true; } if ($emulate === false) { if ($from instanceof Dn) { $from = $from->toString(); } if ($to instanceof Dn) { $newDnParts = $to->toArray(); } else { $newDnParts = Dn::explodeDn($to); } $newRdn = Dn::implodeRdn(array_shift($newDnParts)); $newParent = Dn::implodeDn($newDnParts); ErrorHandler::start(E_WARNING); $isOK = ldap_rename($this->getResource(), $from, $newRdn, $newParent, true); ErrorHandler::stop(); if ($isOK === false) { throw new Exception\LdapException($this, 'renaming ' . $from . ' to ' . $to); } elseif (!$this->exists($to)) { $emulate = true; } } if ($emulate) { $this->copy($from, $to, $recursively); $this->delete($from, $recursively); } return $this; }
/** * @expectedException Zend\Ldap\Exception */ public function testImplodeRdnInvalidThree() { $a = array('cn' => 'value', 'ou'); Ldap\Dn::implodeRdn($a); }