3
* Gallery - a web based photo album viewer and editor
4
* Copyright (C) 2000-2007 Bharat Mediratta
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or (at
9
* your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
22
* Test PermissionSet functionality
23
* @package GalleryCore
25
* @author Bharat Mediratta <bharat@menalto.com>
26
* @version $Revision: 15513 $
28
class PermissionSetTest extends GalleryTestCase {
30
function PermissionSetTest($methodName) {
31
$this->GalleryTestCase($methodName);
37
$ret = GalleryCoreApi::registerPermission('testModule',
39
'regular permission');
41
return $this->failWithStatus($ret);
44
$ret = GalleryCoreApi::registerPermission('testModule',
46
'another regular permission');
48
return $this->failWithStatus($ret);
51
$ret = GalleryCoreApi::registerPermission('testModule',
53
'composite permission',
54
GALLERY_PERMISSION_COMPOSITE,
55
array('test.test1', 'test.test2'));
57
return $this->failWithStatus($ret);
60
$ret = GalleryCoreApi::registerPermission('testModule',
62
'all access permission',
63
GALLERY_PERMISSION_ALL_ACCESS);
65
return $this->failWithStatus($ret);
68
$ret = GalleryCoreApi::registerPermission('testModule',
70
'another regular permission');
72
return $this->failWithStatus($ret);
75
$ret = GalleryCoreApi::registerPermission('testModule',
77
'overlap composite permission',
78
GALLERY_PERMISSION_COMPOSITE,
79
array('test.test1', 'test.test5'));
81
return $this->failWithStatus($ret);
86
$ret = GalleryCoreApi::unregisterModulePermissions('testModule');
88
return $this->failWithStatus($ret);
94
function testGetPermissionIds() {
95
/* Four defined perms */
96
list ($ret, $ids) = GalleryCoreApi::getPermissionIds();
97
$this->assertEquals($ids['test.test1'], 'regular permission', $ids);
98
$this->assertEquals($ids['test.test2'], 'another regular permission', $ids);
99
$this->assertEquals($ids['test.test3'], 'composite permission', $ids);
100
$this->assertEquals($ids['test.test4'], 'all access permission', $ids);
102
/* Only one all access perm */
103
list ($ret, $ids) = GalleryCoreApi::getPermissionIds(GALLERY_PERMISSION_ALL_ACCESS);
104
$this->assert(!isset($ids['test.test1']));
105
$this->assert(!isset($ids['test.test2']));
106
$this->assert(!isset($ids['test.test3']));
107
$this->assertEquals($ids['test.test4'], 'all access permission', $ids);
110
function testGetSubPermissions() {
111
/* test.test3 is a composite of tests 1 and 2 */
112
list ($ret, $ids) = GalleryCoreApi::getSubPermissions('test.test3');
114
array(array('id' => 'test.test1',
115
'module' => 'testModule',
116
'description' => 'regular permission'),
117
array('id' => 'test.test2',
118
'module' => 'testModule',
119
'description' => 'another regular permission'),
120
array('id' => 'test.test3',
121
'module' => 'testModule',
122
'description' => 'composite permission'),
127
* We don't know what the exact bits are so don't try to assert on them.
128
* Instead, make sure our round trip works
130
function testConvertRoundTrip1() {
131
list ($ret, $bits) = GalleryCoreApi::convertPermissionIdsToBits(array('test.test1'));
133
return $this->failWithStatus($ret);
136
list ($ret, $ids) = GalleryCoreApi::convertPermissionBitsToIds($bits);
138
return $this->failWithStatus($ret);
141
$this->assertEquals(array(array('id' => 'test.test1',
142
'module' => 'testModule',
143
'description' => 'regular permission')),
148
* We don't know what the exact bits are so don't try to assert on them.
149
* Instead, make sure our round trip works
151
function testConvertRoundTrip2() {
152
list ($ret, $bits) = GalleryCoreApi::convertPermissionIdsToBits(array('test.test3'));
154
return $this->failWithStatus($ret);
157
list ($ret, $ids) = GalleryCoreApi::convertPermissionBitsToIds($bits);
159
return $this->failWithStatus($ret);
162
$this->assertEquals(array(array('id' => 'test.test1',
163
'module' => 'testModule',
164
'description' => 'regular permission'),
165
array('id' => 'test.test2',
166
'module' => 'testModule',
167
'description' => 'another regular permission'),
168
array('id' => 'test.test3',
169
'module' => 'testModule',
170
'description' => 'composite permission')),
174
function testConvertBitsToIdsWithoutCompress() {
176
GalleryCoreApi::convertPermissionIdsToBits(array('test.test1',
180
return $this->failWithStatus($ret);
183
list ($ret, $ids) = GalleryCoreApi::convertPermissionBitsToIds($bits);
185
return $this->failWithStatus($ret);
188
$this->assertEquals(array(array('id' => 'test.test1',
189
'module' => 'testModule',
190
'description' => 'regular permission'),
191
array('id' => 'test.test2',
192
'module' => 'testModule',
193
'description' => 'another regular permission'),
194
array('id' => 'test.test3',
195
'module' => 'testModule',
196
'description' => 'composite permission'),
197
array('id' => 'test.test5',
198
'module' => 'testModule',
199
'description' => 'another regular permission'),
200
array('id' => 'test.test6',
201
'module' => 'testModule',
202
'description' => 'overlap composite permission')),
206
function testConvertBitsToIdsWithCompress() {
208
GalleryCoreApi::convertPermissionIdsToBits(array('test.test1',
212
return $this->failWithStatus($ret);
215
list ($ret, $ids) = GalleryCoreApi::convertPermissionBitsToIds($bits, true);
217
return $this->failWithStatus($ret);
220
$this->assertEquals(array(array('id' => 'test.test3',
221
'module' => 'testModule',
222
'description' => 'composite permission'),
223
array('id' => 'test.test6',
224
'module' => 'testModule',
225
'description' => 'overlap composite permission')),
229
function testConvertBitsToIdsWithCompressAndAllAccess() {
231
GalleryCoreApi::convertPermissionIdsToBits(array('test.test1',
236
return $this->failWithStatus($ret);
239
list ($ret, $ids) = GalleryCoreApi::convertPermissionBitsToIds($bits, true);
241
return $this->failWithStatus($ret);
244
$this->assertEquals(2, sizeof($ids));
246
// Unordered comparison
247
$this->assertEquals(array('core.all' => 1,
249
array($ids[0]['id'] => 1,
250
$ids[1]['id'] => 1));