1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
<?php
/**
* Test the webadmin code.
*
* PHP version 5
*
* @category Kolab
* @package KolabAdmin
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=KolabAdmin
*/
/**
* Require the tested classes.
*/
require_once dirname(__FILE__) . '/../../../lib/KolabAdmin/Ldap.php';
/**
* Test the webadmin code.
*
* Copyright 2010 Klarälvdalens Datakonsult AB
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @category Kolab
* @package KolabAdmin
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.fsf.org/copyleft/lgpl.html LGPL
* @link http://pear.horde.org/index.php?package=KolabAdmin
*/
class KolabAdmin_Unit_BaseTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$_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()
{
$this->assertEquals(
0,
$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,
)
);
}
}
/** short circuit the debug function. */
function debug() {};
|