{
$admin = $this->provideBasicAdmin();
$this->assertNoError($admin);
- $uid = $this->ldap->generateUid('Horde_Kolab_Server_Object_Kolab_Administrator', $admin);
- $this->assertNoError($uid);
- $this->assertEquals('cn=The Administrator,dc=example,dc=org', $uid);
+ $user = new Horde_Kolab_Server_Object_Kolab_Administrator($this->ldap, null, $admin);
+ $this->assertNoError($user);
+ $this->assertEquals('cn=The Administrator,dc=example,dc=org', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID));
}
/**
public function testGenerateId()
{
$groups = $this->validGroups();
- $this->assertEquals('cn=empty.group@example.org,dc=example,dc=org',
- $this->ldap->generateUid('Horde_Kolab_Server_Object_Kolabgroupofnames', $groups[0][0]));
+ $user = new Horde_Kolab_Server_Object_Kolabgroupofnames($this->ldap, null, $groups[0][0]);
+ $this->assertNoError($user);
+ $this->assertEquals('cn=empty.group@example.org,dc=example,dc=org', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID));
}
/**
}
/**
- * Test construction of the class.
- *
- * @expectedException Horde_Kolab_Server_Exception
- *
- * @return NULL
- */
- public function testConstructFailureWithoutUid()
- {
- $ko = &new Horde_Kolab_Server_Object($this->_dummydb);
- }
-
- /**
* Provide test data for the ConstructDn test.
*
* @return array The test object data.
Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN => 'Kolab_Server_PersonTest_123',
Horde_Kolab_Server_Object_Person::ATTRIBUTE_USERPASSWORD => 'Kolab_Server_PersonTest_123',
),
+ /* Person with problematic characters */
+ array(
+ 'type' => 'Horde_Kolab_Server_Object_Person',
+ Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN => 'Kolab_Server_PersonTest_!"$%&()=?',
+ Horde_Kolab_Server_Object_Person::ATTRIBUTE_SN => 'Kolab_Server_PersonTest_!"$%&()=?',
+ Horde_Kolab_Server_Object_Person::ATTRIBUTE_USERPASSWORD => 'Kolab_Server_PersonTest_!"$%&()=?',
+ ),
+ /* Person with difficult encoding */
+ array(
+ 'type' => 'Horde_Kolab_Server_Object_Person',
+ Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN => 'Kolab_Server_PersonTest_ügöräß§',
+ Horde_Kolab_Server_Object_Person::ATTRIBUTE_SN => 'Kolab_Server_PersonTest_ügöräß§',
+ Horde_Kolab_Server_Object_Person::ATTRIBUTE_USERPASSWORD => 'Kolab_Server_PersonTest_ügöräß§',
+ ),
+ /* Person with forward slash */
+ array(
+ 'type' => 'Horde_Kolab_Server_Object_Person',
+ Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN => 'Kolab_Server_PersonTest_/',
+ Horde_Kolab_Server_Object_Person::ATTRIBUTE_SN => 'Kolab_Server_PersonTest_/',
+ Horde_Kolab_Server_Object_Person::ATTRIBUTE_USERPASSWORD => 'Kolab_Server_PersonTest_/',
+ ),
);
/**
* Test ID generation for a person.
*
+ * @dataProvider provideServers
+ *
* @return NULL
*/
- public function testGenerateId()
+ public function testGenerateId($server)
{
- $this->assertEquals(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN . '=' . $this->objects[0][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN],
- Horde_Kolab_Server_Object_Person::generateId($this->objects[0]));
+ $a = new Horde_Kolab_Server_Object_Person($server, null, $this->objects[0]);
+ $this->assertContains(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN . '=' . $this->objects[0][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN],
+ $a->get(Horde_Kolab_Server_Object_Person::ATTRIBUTE_UID));
}
/**
*/
public function testAddPerson($server)
{
- $result = $server->add($this->objects[0]);
- $this->assertNoError($result);
- $cn_result = $server->uidForCn($this->objects[0][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN]);
- $this->assertContains(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN . '=' . $this->objects[0][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN],
- $cn_result);
- $result = $server->delete($cn_result);
- $this->assertNoError($result);
- $cn_result = $server->uidForCn($this->objects[0][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN]);
- $this->assertFalse($server->uidForCn($this->objects[0][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN]));
+ $adds = array(0, 2, 3, 4);
+ foreach ($adds as $add) {
+ $result = $server->add($this->objects[$add]);
+ $this->assertNoError($result);
+ $cn_result = $server->uidForCn($this->objects[$add][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN]);
+ $this->assertNoError($cn_result);
+ $dn_parts = Net_LDAP2_Util::ldap_explode_dn($cn_result, array('casefold' => 'lower'));
+ $dnpart = Net_LDAP2_Util::unescape_dn_value($dn_parts[0]);
+ /**
+ * FIXME: I currently do not really understand why the forward slash
+ * is not correctly converted back but I lack the time to analyse it
+ * in detail. The server entry looks okay.
+ */
+ $dnpart = str_replace('\/', '/', $dnpart);
+ $this->assertContains(Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN . '=' . $this->objects[$add][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN],
+ $dnpart[0]);
+ $result = $server->delete($cn_result);
+ $this->assertNoError($result);
+ $cn_result = $server->uidForCn($this->objects[$add][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN]);
+ $this->assertNoError($cn_result);
+ $this->assertFalse($server->uidForCn($this->objects[$add][Horde_Kolab_Server_Object_Person::ATTRIBUTE_CN]));
+ }
}
}
public function testGenerateUid()
{
$ks = &Horde_Kolab_Server::factory('none');
- $uid = $ks->generateUid('Horde_Kolab_Server_Object', array());
- $this->assertEquals(preg_replace('/[0-9a-f]*/', '', $uid), '');
+ $user = new Horde_Kolab_Server_Object($ks, null, null);
+ $this->assertEquals(preg_replace('/[0-9a-f]*/', '', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID)), '');
}
/**
*
* @return string|PEAR_Error The UID.
*/
- protected function generateServerUid($type, $id, $info)
+ public function generateServerUid($type, $id, $info)
{
return $id;
}
*/
public function testSearch()
{
-/* $db = &Horde_Kolab_Server::factory('test', */
-/* array('data' => */
-/* array( */
-/* 'cn=a' => array( */
-/* 'dn' => 'cn=a', */
-/* 'data' => array( */
-/* 'a' => '1', */
-/* 'b' => '1', */
-/* 'c' => '1', */
-/* ) */
-/* ), */
-/* 'cn=b' => array( */
-/* 'dn' => 'cn=b', */
-/* 'data' => array( */
-/* 'a' => '1', */
-/* 'b' => '2', */
-/* 'c' => '2', */
-/* ) */
-/* ), */
-/* 'cn=c' => array( */
-/* 'dn' => 'cn=c', */
-/* 'data' => array( */
-/* 'a' => '1', */
-/* 'b' => '2', */
-/* 'c' => '3', */
-/* ) */
-/* ), */
-/* 'cn=d' => array( */
-/* 'dn' => 'cn=d', */
-/* 'data' => array( */
-/* 'a' => '2', */
-/* 'b' => '2', */
-/* 'c' => '1', */
-/* ) */
-/* ), */
-/* ) */
-/* ) */
-/* ); */
-
-/* $a = $db->search('(c=1)'); */
-/* $this->assertNoError($a); */
-/* $this->assertEquals( */
-/* array( */
-/* array( */
-/* 'dn' => 'cn=a', */
-/* 'data' => array( */
-/* 'a' => '1', */
-/* 'b' => '1', */
-/* 'c' => '1', */
-/* ) */
-/* ), */
-/* array( */
-/* 'dn' => 'cn=d', */
-/* 'data' => array( */
-/* 'a' => '2', */
-/* 'b' => '2', */
-/* 'c' => '1', */
-/* ) */
-/* ), */
-/* ), */
-/* $a */
-/* ); */
-
-/* $a = $db->_search('(c=3)'); */
-/* $this->assertNoError($a); */
-/* $this->assertEquals( */
-/* array( */
-/* array( */
-/* 'dn' => 'cn=c', */
-/* 'data' => array( */
-/* 'a' => '1', */
-/* 'b' => '2', */
-/* 'c' => '3', */
-/* ) */
-/* ), */
-/* ), */
-/* $a */
-/* ); */
-
-/* $a = $db->_search('(c=3)', array('a')); */
-/* $this->assertNoError($a); */
-/* $this->assertEquals( */
-/* array( */
-/* array( */
-/* 'dn' => 'cn=c', */
-/* 'data' => array( */
-/* 'a' => '1', */
-/* ) */
-/* ), */
-/* ), */
-/* $a */
-/* ); */
-
-/* $a = $db->_search('(&(a=1)(b=2))', array('a', 'b')); */
-/* $this->assertNoError($a); */
-/* $this->assertEquals( */
-/* array( */
-/* array( */
-/* 'dn' => 'cn=b', */
-/* 'data' => array( */
-/* 'a' => '1', */
-/* 'b' => '2', */
-/* ) */
-/* ), */
-/* array( */
-/* 'dn' => 'cn=c', */
-/* 'data' => array( */
-/* 'a' => '1', */
-/* 'b' => '2', */
-/* ) */
-/* ), */
-/* ), */
-/* $a */
-/* ); */
-
-/* $a = $db->_search('(&(b=2))', array('b')); */
-/* $this->assertNoError($a); */
-/* $this->assertEquals( */
-/* array( */
-/* array( */
-/* 'dn' => 'cn=b', */
-/* 'data' => array( */
-/* 'b' => '2', */
-/* ) */
-/* ), */
-/* array( */
-/* 'dn' => 'cn=c', */
-/* 'data' => array( */
-/* 'b' => '2', */
-/* ) */
-/* ), */
-/* array( */
-/* 'dn' => 'cn=d', */
-/* 'data' => array( */
-/* 'b' => '2', */
-/* ) */
-/* ), */
-/* ), */
-/* $a */
-/* ); */
-
-/* $a = $db->_search('(!(b=2))', array('a', 'b')); */
-/* $this->assertNoError($a); */
-/* $this->assertEquals( */
-/* array( */
-/* array( */
-/* 'dn' => 'cn=a', */
-/* 'data' => array( */
-/* 'a' => '1', */
-/* 'b' => '1', */
-/* ) */
-/* ), */
-/* ), */
-/* $a */
-/* ); */
-
-/* $a = $db->_search('(&(!(x=2))(b=1))', array('b')); */
-/* $this->assertNoError($a); */
-/* $this->assertEquals( */
-/* array( */
-/* array( */
-/* 'dn' => 'cn=a', */
-/* 'data' => array( */
-/* 'b' => '1', */
-/* ) */
-/* ), */
-/* ), */
-/* $a */
-/* ); */
+ $db = &Horde_Kolab_Server::factory('test',
+ array('data' =>
+ array(
+ 'cn=a' => array(
+ 'dn' => 'cn=a',
+ 'data' => array(
+ 'a' => '1',
+ 'b' => '1',
+ 'c' => '1',
+ )
+ ),
+ 'cn=b' => array(
+ 'dn' => 'cn=b',
+ 'data' => array(
+ 'a' => '1',
+ 'b' => '2',
+ 'c' => '2',
+ )
+ ),
+ 'cn=c' => array(
+ 'dn' => 'cn=c',
+ 'data' => array(
+ 'a' => '1',
+ 'b' => '2',
+ 'c' => '3',
+ )
+ ),
+ 'cn=d' => array(
+ 'dn' => 'cn=d',
+ 'data' => array(
+ 'a' => '2',
+ 'b' => '2',
+ 'c' => '1',
+ )
+ ),
+ )
+ )
+ );
+
+ $a = $db->search('(c=1)');
+ $this->assertNoError($a);
+ $this->assertEquals(
+ array(
+ 'cn=a' => array(
+ 'a' => '1',
+ 'b' => '1',
+ 'c' => '1',
+ 'dn' => 'cn=a',
+ ),
+ 'cn=d' => array(
+ 'a' => '2',
+ 'b' => '2',
+ 'c' => '1',
+ 'dn' => 'cn=d',
+ ),
+ ),
+ $a->as_struct()
+ );
+
+ $a = $db->search('(c=3)');
+ $this->assertNoError($a);
+ $this->assertEquals(
+ array(
+ 'cn=c' => array(
+ 'a' => '1',
+ 'b' => '2',
+ 'c' => '3',
+ 'dn' => 'cn=c',
+ ),
+ ),
+ $a->as_struct()
+ );
+
+ $a = $db->search('(c=3)', array('attributes' => array('a')));
+ $this->assertNoError($a);
+ $this->assertEquals(
+ array(
+ 'cn=c' => array(
+ 'a' => '1',
+ 'dn' => 'cn=c',
+ ),
+ ),
+ $a->as_struct()
+ );
+
+ $a = $db->search('(&(a=1)(b=2))', array('attributes' => array('a', 'b')));
+ $this->assertNoError($a);
+ $this->assertEquals(
+ array(
+ 'cn=b' => array(
+ 'a' => '1',
+ 'b' => '2',
+ 'dn' => 'cn=b',
+ ),
+ 'cn=c' => array(
+ 'a' => '1',
+ 'b' => '2',
+ 'dn' => 'cn=c',
+ ),
+ ),
+ $a->as_struct()
+ );
+
+ $a = $db->search('(&(b=2))', array('attributes' => array('b')));
+ $this->assertNoError($a);
+ $this->assertEquals(
+ array(
+ 'cn=b' => array(
+ 'b' => '2',
+ 'dn' => 'cn=b',
+ ),
+ 'cn=c' => array(
+ 'b' => '2',
+ 'dn' => 'cn=c',
+ ),
+ 'cn=d' => array(
+ 'b' => '2',
+ 'dn' => 'cn=d',
+ ),
+ ),
+ $a->as_struct()
+ );
+
+ $a = $db->search('(!(b=2))', array('attributes' => array('a', 'b')));
+ $this->assertNoError($a);
+ $this->assertEquals(
+ array(
+ 'cn=a' => array(
+ 'a' => '1',
+ 'b' => '1',
+ 'dn' => 'cn=a',
+ ),
+ ),
+ $a->as_struct()
+ );
+
+ $a = $db->search('(&(!(x=2))(b=1))', array('attributes' => array('b')));
+ $this->assertNoError($a);
+ $this->assertEquals(
+ array(
+ 'cn=a' => array(
+ 'b' => '1',
+ 'dn' => 'cn=a',
+ ),
+ ),
+ $a->as_struct()
+ );
}
}
public function testGenerateId()
{
$users = $this->validUsers();
- $this->assertEquals('cn=Gunnar Wrobel',
- Horde_Kolab_Server_Object_Kolab_User::generateId($users[0][0]));
-
- $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org',
- $this->server->generateUid('Horde_Kolab_Server_Object_Kolab_User',
- $users[0][0]));
+ $user = new Horde_Kolab_Server_Object_Kolab_User($this->server, null, $users[0][0]);
+ $this->assertNoError($user);
+ $this->assertEquals('cn=Gunnar Wrobel,dc=example,dc=org', $user->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID));
}
/**