Example #1
0
 /**
  * Returns the schema DN
  *
  * @return \Zend\LDAP\DN
  */
 public function getSchemaDn()
 {
     $schemaDn = $this->getSubschemaSubentry();
     return LDAP\DN::fromString($schemaDn);
 }
 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);
 }
Example #3
0
 /**
  * Returns the schema DN
  *
  * @return \Zend\LDAP\DN
  */
 public function getSchemaDn()
 {
     $schemaDn = $this->getSchemaNamingContext();
     return \Zend\LDAP\DN::fromString($schemaDn);
 }
Example #4
0
 public function testIsChildOfWithDnObjects()
 {
     $dn1 = LDAP\DN::fromString('cb=name1,cn=name2,dc=example,dc=org');
     $dn2 = LDAP\DN::fromString('dc=example,dc=org');
     $this->assertTrue(LDAP\DN::isChildOf($dn1, $dn2));
 }
Example #5
0
 public function testSaveWithDnObject()
 {
     $dn = LDAP\DN::fromString($this->_createDn('ou=TestCreated,'));
     $data = array('ou' => 'TestCreated', 'objectclass' => 'organizationalUnit');
     try {
         $this->_getLDAP()->save($dn, $data);
         $this->assertTrue($this->_getLDAP()->exists($dn));
         $data['l'] = 'mylocation1';
         $this->_getLDAP()->save($dn, $data);
         $this->assertTrue($this->_getLDAP()->exists($dn));
         $entry = $this->_getLDAP()->getEntry($dn);
         $this->_getLDAP()->delete($dn);
         $this->assertEquals('mylocation1', $entry['l'][0]);
     } catch (LDAP\Exception $e) {
         if ($this->_getLDAP()->exists($dn)) {
             $this->_getLDAP()->delete($dn);
         }
         $this->fail($e->getMessage());
     }
 }
Example #6
0
 public function testRecursiveCopyWithDnObjects()
 {
     $orgSubTreeDn = LDAP\DN::fromString($this->_orgSubTreeDn);
     $newSubTreeDn = LDAP\DN::fromString($this->_newSubTreeDn);
     $this->_getLDAP()->copy($orgSubTreeDn, $newSubTreeDn, true);
     $this->assertTrue($this->_getLDAP()->exists($orgSubTreeDn));
     $this->assertTrue($this->_getLDAP()->exists($newSubTreeDn));
     $this->assertEquals(3, $this->_getLDAP()->countChildren($orgSubTreeDn));
     $this->assertEquals(3, $this->_getLDAP()->countChildren('ou=Subtree1,' . $orgSubTreeDn->toString()));
     $this->assertEquals(3, $this->_getLDAP()->countChildren($newSubTreeDn));
     $this->assertEquals(3, $this->_getLDAP()->countChildren('ou=Subtree1,' . $newSubTreeDn->toString()));
 }
Example #7
0
 protected function _createDn($dn)
 {
     if (substr($dn, -1) !== ',') {
         $dn .= ',';
     }
     $dn = $dn . TESTS_ZEND_LDAP_WRITEABLE_SUBTREE;
     return LDAP\DN::fromString($dn)->toString(LDAP\DN::ATTR_CASEFOLD_LOWER);
 }
Example #8
0
 public function testGetSingleEntryWithDnObject()
 {
     $dn = LDAP\DN::fromString($this->_createDn('ou=Test1,'));
     $entry = $this->_getLDAP()->getEntry($dn);
     $this->assertEquals($dn->toString(), $entry["dn"]);
 }
Example #9
0
 public function testDnObjectCloning()
 {
     $node1 = $this->_createTestNode();
     $dn1 = LDAP\DN::fromString('cn=name2,dc=example,dc=org');
     $node1->setDn($dn1);
     $dn1->prepend(array('cn' => 'name'));
     $this->assertNotEquals($dn1->toString(), $node1->getDn()->toString());
     $dn2 = LDAP\DN::fromString('cn=name2,dc=example,dc=org');
     $node2 = Node\Node::create($dn2);
     $dn2->prepend(array('cn' => 'name'));
     $this->assertNotEquals($dn2->toString(), $node2->getDn()->toString());
     $dn3 = LDAP\DN::fromString('cn=name2,dc=example,dc=org');
     $node3 = Node\Node::fromArray(array('dn' => $dn3, 'ou' => 'Test'), false);
     $dn3->prepend(array('cn' => 'name'));
     $this->assertNotEquals($dn3->toString(), $node3->getDn()->toString());
 }
Example #10
0
 public function testArrayAccessImplementation()
 {
     $dnString = 'cn=Baker\\, Alice,cn=Users,dc=example,dc=com';
     $dn = LDAP\DN::fromString($dnString);
     $this->assertEquals(array('cn' => 'Baker, Alice'), $dn[0]);
     $this->assertEquals(array('cn' => 'Users'), $dn[1]);
     $this->assertEquals(array('dc' => 'example'), $dn[2]);
     $this->assertEquals(array('dc' => 'com'), $dn[3]);
     $this->assertTrue(isset($dn[0]));
     $this->assertTrue(isset($dn[1]));
     $this->assertTrue(isset($dn[2]));
     $this->assertTrue(isset($dn[3]));
     $this->assertFalse(isset($dn[-1]));
     $this->assertFalse(isset($dn[4]));
     $dn = LDAP\DN::fromString($dnString);
     unset($dn[0]);
     $this->assertEquals('cn=Users,dc=example,dc=com', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     unset($dn[1]);
     $this->assertEquals('cn=Baker\\, Alice,dc=example,dc=com', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     unset($dn[2]);
     $this->assertEquals('cn=Baker\\, Alice,cn=Users,dc=com', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     unset($dn[3]);
     $this->assertEquals('cn=Baker\\, Alice,cn=Users,dc=example', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     $dn[0] = array('uid' => 'abaker');
     $this->assertEquals('uid=abaker,cn=Users,dc=example,dc=com', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     $dn[1] = array('ou' => 'Lab');
     $this->assertEquals('cn=Baker\\, Alice,ou=Lab,dc=example,dc=com', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     $dn[2] = array('dc' => 'example', 'ou' => 'Test');
     $this->assertEquals('cn=Baker\\, Alice,cn=Users,dc=example+ou=Test,dc=com', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     $dn[3] = array('dc' => 'de+fr');
     $this->assertEquals('cn=Baker\\, Alice,cn=Users,dc=example,dc=de\\+fr', $dn->toString());
 }
Example #11
0
 public function testEmptyStringDn()
 {
     $dnString = '';
     $dn = LDAP\DN::fromString($dnString);
     $this->assertEquals($dnString, $dn->toString());
 }
Example #12
0
 public function testLoadFromLDAPWithDnObject()
 {
     $dn = LDAP\DN::fromString($this->_createDn('ou=Test1,'));
     $node = Node\Node::fromLDAP($dn, $this->_getLDAP());
     $this->assertType('Zend\\LDAP\\Node\\Node', $node);
     $this->assertTrue($node->isAttached());
 }