testAcl.php
5.94 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
require_once (KTAPI_TEST_DIR . '/test.php');
require_once (KT_DIR . '/ktapi/ktapi.inc.php');
class APIAclTestCase extends KTUnitTestCase {
/**
* @var KTAPI
*/
var $ktapi;
var $session;
/**
* Setup the session
*
*/
function setUp() {
$this->ktapi = new KTAPI();
$this->session = $this->ktapi->start_system_session();
}
/**
* Logout of the session.
*
*/
function tearDown() {
$this->session->logout();
}
/**
*
* Test KTAPI_User getList(), getById(), getByName, getByUsername()
*
* @TODO KTAPI_User::getByEmail()
*/
function testUsers()
{
// getList()
$list = KTAPI_User::getList();
$this->assertTrue(count($list) > 0);
// getById()
$user = KTAPI_User::getById(1);
$this->assertTrue($user->Username == 'admin');
$this->assertTrue($user->Name == 'Administrator');
// getByName()
$user = KTAPI_User::getByName('Anonymous');
$this->assertTrue($user->Id == -2);
// getByUsername()
$user = KTAPI_User::getByUsername('admin');
$this->assertTrue($user->Id == 1);
}
/**
* Test KTAPI_Group getList(), getById(), getByName
*
*/
function testGroups()
{
// getList()
$list = KTAPI_Group::getList();
$this->assertTrue(count($list) > 0);
// getById()
$group = KTAPI_Group::getById(1);
$this->assertTrue($group->Name == 'System Administrators');
// getByName()
$group = KTAPI_Group::getByName('System Administrators');
$this->assertTrue($group->Id == 1);
$this->assertTrue($group->IsSystemAdministrator);
}
/**
* Test KTAPI_Role getList(), getById(), getByName
*
*/
function testRoles()
{
// getList()
$list = KTAPI_Role::getList();
$this->assertTrue(count($list) > 0);
// getById()
$role = KTAPI_Role::getById(-2);
$this->assertTrue($role->Name == 'Owner');
// getByName()
$role = KTAPI_Role::getByName('Publisher');
$this->assertTrue($role->Id == 2);
}
/**
* Test KTAPI_Permission getList(), getById(), getByNamespace()
*
*/
function testPermission()
{
// getList()
$list = KTAPI_Permission::getList();
$this->assertTrue(count($list) > 0);
// getById()
$permission = KTAPI_Permission::getById(1);
$this->assertTrue($permission->Namespace == 'ktcore.permissions.read');
$this->assertTrue($permission->Name == 'Read');
// getByNamespace()
$permission = KTAPI_Permission::getByNamespace('ktcore.permissions.write');
$this->assertTrue($permission->Name == 'Write');
}
/**
* Test KTAPI_RoleAllocation getAllocation(), add(), remove(), save()
*
* @TODO finish
*
*/
function testRoleAllocation()
{
$root = $this->ktapi->get_root_folder();
$folder = $this->ktapi->get_folder_by_name('/test123');
$allocation = KTAPI_RoleAllocation::getAllocation($this->ktapi, $folder);
$role2 = KTAPI_Role::getByName('Reviewer');
$role = KTAPI_Role::getByName('Publisher');
$user = KTAPI_User::getByUsername('admin');
$user2 = KTAPI_User::getByUsername('anonymous');
$group = KTAPI_Group::getByName('System Administrators');
// $this->assertFalse($allocation->doesRoleHaveMember($role, $user));
// $this->assertTrue($allocation->doesRoleHaveMember($role2, $user));
$allocation->add($role2, $user);
$allocation->add($role, $user);
$allocation->add($role, $group);
$allocation->save();
/* $allocation->add($role, $user2);
$allocation->add($role, $user2); // yup. this is a dup. just to test.
$allocation->add($role, $group);
$this->assertTrue($allocation->doesRoleHaveMember($role, $user));
$allocation->remove($role, $user);
$this->assertFalse($allocation->doesRoleHaveMember($role, $user));
$allocation->remove($role, $user2);
$this->assertFalse($allocation->doesRoleHaveMember($role, $user2));
$allocation->save();
// now, just overwrite the allocation variable, and check that the assertions still hold.
$allocation = KTAPI_RoleAllocation::getAllocation($this->ktapi, $root);
$this->assertFalse($allocation->doesRoleHaveMember($role, $user));
$this->assertFalse($allocation->doesRoleHaveMember($role, $user2));*/
}
/**
* Test KTAPI_PermissionAllocation getAllocation(), add(), remove(), save()
*
*/
function testPermissionAllocation()
{
$root = $this->ktapi->get_root_folder();
$folder = $this->ktapi->get_folder_by_name('/test123');
$allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $root);
$group = KTAPI_Group::getByName('System Administrators');
$user = KTAPI_User::getByUsername('anonymous');
$read = KTAPI_Permission::getByNamespace('ktcore.permissions.read');
$write = KTAPI_Permission::getByNamespace('ktcore.permissions.write');
$addFolder = KTAPI_Permission::getByNamespace('ktcore.permissions.addFolder');
$security = KTAPI_Permission::getByNamespace('ktcore.permissions.security');
$allocation->add($user, $read);
$allocation->add($user, $write);
$allocation->add($user, $addFolder);
$allocation->add($user, $security);
$allocation->remove($group, $write);
$allocation->save();
$root2 = $this->ktapi->get_root_folder();
$allocation = KTAPI_PermissionAllocation::getAllocation($this->ktapi, $root2);
$this->assertTrue($allocation->isMemberPermissionSet($user, $read));
$this->assertTrue($allocation->isMemberPermissionSet($user, $write));
$this->assertFalse($allocation->isMemberPermissionSet($group, $write));
}
}
?>