/**
* Test copy().
*/
public function testCopy()
{
$ldap = new Horde_Ldap(self::$ldapcfg['server']);
// Some testdata.
$base = self::$ldapcfg['server']['basedn'];
$ou1 = Horde_Ldap_Entry::createFresh('ou=Horde_Ldap_Test_pool,' . $base, array('objectClass' => array('top', 'organizationalUnit'), 'ou' => 'Horde_Ldap_Test_copy'));
$ou2 = Horde_Ldap_Entry::createFresh('ou=Horde_Ldap_Test_tgt,' . $base, array('objectClass' => array('top', 'organizationalUnit'), 'ou' => 'Horde_Ldap_Test_copy'));
$ldap->add($ou1);
$this->assertTrue($ldap->exists($ou1->dn()));
$ldap->add($ou2);
$this->assertTrue($ldap->exists($ou2->dn()));
$entry = Horde_Ldap_Entry::createFresh('l=cptest,' . $ou1->dn(), array('objectClass' => array('top', 'locality'), 'l' => 'cptest'));
$ldap->add($entry);
$ldap->exists($entry->dn());
// Copy over the entry to another tree with rename.
$entrycp = $ldap->copy($entry, 'l=test_copied,' . $ou2->dn());
$this->assertInstanceOf('Horde_Ldap_Entry', $entrycp);
$this->assertNotEquals($entry->dn(), $entrycp->dn());
$this->assertTrue($ldap->exists($entrycp->dn()));
// Copy same again (fails, entry exists).
try {
$entrycp_f = $ldap->copy($entry, 'l=test_copied,' . $ou2->dn());
$this->fail('Horde_Ldap_Exception expected.');
} catch (Horde_Ldap_Exception $e) {
}
// Use only DNs to copy (fails).
try {
$entrycp = $ldap->copy($entry->dn(), 'l=test_copied2,' . $ou2->dn());
$this->fail('Horde_Ldap_Exception expected.');
} catch (Horde_Ldap_Exception $e) {
}
}