summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGunnar Wrobel <wrobel@pardus.de>2010-02-21 09:00:49 (GMT)
committerGunnar Wrobel <wrobel@pardus.de>2010-02-21 09:00:49 (GMT)
commit1a6768be7adab331e2149a808c431ab54daa035d (patch)
treed01bf690457ffdc248168d373526e4331ba58664 /test
parentd7ab73f4a9a5afc41d985798c5fff3828f2c2cda (diff)
downloadkolab-webadmin-1a6768be7adab331e2149a808c431ab54daa035d.tar.gz
Provide an add method to the Ldap class and add unit testing for it.
The web admin uses ldap_add() directly in the views at the moment. This should later be refactored to use the add() method in the library.
Diffstat (limited to 'test')
-rw-r--r--test/KolabAdmin/Unit/BaseTest.php53
1 files changed, 51 insertions, 2 deletions
diff --git a/test/KolabAdmin/Unit/BaseTest.php b/test/KolabAdmin/Unit/BaseTest.php
index 9ee2d41..d75f49b 100644
--- a/test/KolabAdmin/Unit/BaseTest.php
+++ b/test/KolabAdmin/Unit/BaseTest.php
@@ -36,14 +36,63 @@ class KolabAdmin_Unit_BaseTest extends PHPUnit_Framework_TestCase
{
$_SESSION = array();
require '/kolab/etc/kolab/session_vars.php';
+ $this->ldap = new KolabLdap();
+ $this->ldap->bind(
+ 'cn=manager,cn=internal,' . $_SESSION['base_dn'],
+ 'test'
+ );
+ $this->cleanup = array();
+ }
+
+ public function tearDown()
+ {
+ foreach ($this->cleanup as $dn) {
+ if (!$this->ldap->deleteObject($dn, true)) {
+ throw new Exception('Deleting ' . $dn . ' failed!');
+ }
+ }
}
public function testCountmailReturnsZeroOnNonExistantMail()
{
- $ldap = new KolabLdap();
$this->assertEquals(
0,
- $ldap->countMail($_SESSION['base_dn'], 'certainly@does@not@exist')
+ $this->ldap->countMail(
+ $_SESSION['base_dn'],
+ 'certainly@does@not@exist'
+ )
+ );
+ }
+
+ public function testAddingObjectIsSuccessful()
+ {
+ $this->_add($this->_getTestUser());
+ }
+
+ private function _add($object)
+ {
+ if ($this->ldap->add($object['dn'], $object['attributes'])) {
+ $this->cleanup[] = $object['dn'];
+ } else {
+ throw new Exception('Adding ' . $object['dn'] . ' failed!');
+ }
+ }
+
+ private function _getTestUser($id = null)
+ {
+ return array(
+ 'dn' => 'cn=KolabAdmin TestUser' . $id . ',' . $_SESSION['base_dn'],
+ 'attributes' => array(
+ 'objectClass' => array(
+ 'top', 'inetOrgPerson', 'kolabInetOrgPerson'
+ ),
+ 'userPassword' => 'test',
+ 'sn' => 'TestUser' . $id,
+ 'cn' => 'KolabAdmin TestUser' . $id,
+ 'givenName' => 'KolabAdmin',
+ 'mail' => 'kolabadmin.test.' . $id . $_SESSION['base_dn'],
+ 'uid' => 'kolabadmin.test.' . $id,
+ )
);
}
}