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(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
         $rdn = Zend_Ldap_Dn::implodeRdn($n->getRdnArray(), Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
         if ($i == 0) {
             $this->assertEquals(Zend_Ldap_Dn::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE)->toString(Zend_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 = Zend_Ldap_Dn::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE)->toString(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
                 }
                 $this->assertEquals('ou=Test' . $j, $rdn);
                 $this->assertEquals('ou=Test' . $j . ',' . $base, $dn);
             }
         }
         $i++;
     }
     $this->assertEquals(9, $i);
 }
Beispiel #2
0
 /**
  * Renames a LDAP entry from one DN to another DN.
  *
  * This method implicitely moves the entry to another location within the tree.
  *
  * @param  string|Zend_Ldap_Dn $from
  * @param  string|Zend_Ldap_Dn $to
  * @param  boolean             $recursively
  * @param  boolean             $alwaysEmulate
  * @return Zend_Ldap Provides a fluid interface
  * @throws Zend_Ldap_Exception
  */
 public function rename($from, $to, $recursively = false, $alwaysEmulate = false)
 {
     $emulate = (bool) $alwaysEmulate;
     if (!function_exists('ldap_rename')) {
         $emulate = true;
     } else {
         if ($recursively) {
             $emulate = true;
         }
     }
     if ($emulate === false) {
         if ($from instanceof Zend_Ldap_Dn) {
             $from = $from->toString();
         }
         if ($to instanceof Zend_Ldap_Dn) {
             $newDnParts = $to->toArray();
         } else {
             $newDnParts = Zend_Ldap_Dn::explodeDn($to);
         }
         $newRdn = Zend_Ldap_Dn::implodeRdn(array_shift($newDnParts));
         $newParent = Zend_Ldap_Dn::implodeDn($newDnParts);
         $isOK = @ldap_rename($this->getResource(), $from, $newRdn, $newParent, true);
         if ($isOK === false) {
             /**
              * @see Zend_Ldap_Exception
              */
             #require_once 'Zend/Ldap/Exception.php';
             throw new Zend_Ldap_Exception($this, 'renaming ' . $from . ' to ' . $to);
         } else {
             if (!$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');
     Zend_Ldap_Dn::implodeRdn($a);
 }