gunnar: server/kolab-webadmin/kolab-webadmin/test/KolabAdmin/Unit BaseTest.php, 1.3, 1.4
cvs at kolab.org
cvs at kolab.org
Sun Feb 21 10:00:51 CET 2010
Author: gunnar
Update of /kolabrepository/server/kolab-webadmin/kolab-webadmin/test/KolabAdmin/Unit
In directory doto:/tmp/cvs-serv3910/kolab-webadmin/test/KolabAdmin/Unit
Modified Files:
BaseTest.php
Log Message:
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.
Index: BaseTest.php
===================================================================
RCS file: /kolabrepository/server/kolab-webadmin/kolab-webadmin/test/KolabAdmin/Unit/BaseTest.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- BaseTest.php 21 Feb 2010 08:19:02 -0000 1.3
+++ BaseTest.php 21 Feb 2010 09:00:49 -0000 1.4
@@ -36,14 +36,63 @@
{
$_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 at does@not at exist')
+ $this->ldap->countMail(
+ $_SESSION['base_dn'],
+ 'certainly at does@not at 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,
+ )
);
}
}
More information about the commits
mailing list