~ubuntu-branches/ubuntu/quantal/gallery2/quantal

« back to all changes in this revision

Viewing changes to modules/core/test/phpunit/PermissionSetTest.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2007-09-10 20:22:19 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070910202219-0jsuntvqge4ade6b
Tags: 2.2.3-2
Add Slovak translation of Debconf templates.  (Thanks to 
Ivan Masá.  Closes: #441671)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Gallery - a web based photo album viewer and editor
4
 
 * Copyright (C) 2000-2007 Bharat Mediratta
5
 
 *
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.
10
 
 *
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.
15
 
 *
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.
19
 
 */
20
 
 
21
 
/**
22
 
 * Test PermissionSet functionality
23
 
 * @package GalleryCore
24
 
 * @subpackage PHPUnit
25
 
 * @author Bharat Mediratta <bharat@menalto.com>
26
 
 * @version $Revision: 15513 $
27
 
 */
28
 
class PermissionSetTest extends GalleryTestCase {
29
 
 
30
 
    function PermissionSetTest($methodName) {
31
 
        $this->GalleryTestCase($methodName);
32
 
    }
33
 
 
34
 
    function setUp() {
35
 
        parent::setUp();
36
 
 
37
 
        $ret = GalleryCoreApi::registerPermission('testModule',
38
 
                                                  'test.test1',
39
 
                                                  'regular permission');
40
 
        if ($ret) {
41
 
            return $this->failWithStatus($ret);
42
 
        }
43
 
 
44
 
        $ret = GalleryCoreApi::registerPermission('testModule',
45
 
                                                  'test.test2',
46
 
                                                  'another regular permission');
47
 
        if ($ret) {
48
 
            return $this->failWithStatus($ret);
49
 
        }
50
 
 
51
 
        $ret = GalleryCoreApi::registerPermission('testModule',
52
 
                                                  'test.test3',
53
 
                                                  'composite permission',
54
 
                                                  GALLERY_PERMISSION_COMPOSITE,
55
 
                                                  array('test.test1', 'test.test2'));
56
 
        if ($ret) {
57
 
            return $this->failWithStatus($ret);
58
 
        }
59
 
 
60
 
        $ret = GalleryCoreApi::registerPermission('testModule',
61
 
                                                  'test.test4',
62
 
                                                  'all access permission',
63
 
                                                  GALLERY_PERMISSION_ALL_ACCESS);
64
 
        if ($ret) {
65
 
            return $this->failWithStatus($ret);
66
 
        }
67
 
 
68
 
        $ret = GalleryCoreApi::registerPermission('testModule',
69
 
                                                  'test.test5',
70
 
                                                  'another regular permission');
71
 
        if ($ret) {
72
 
            return $this->failWithStatus($ret);
73
 
        }
74
 
 
75
 
        $ret = GalleryCoreApi::registerPermission('testModule',
76
 
                                                  'test.test6',
77
 
                                                  'overlap composite permission',
78
 
                                                  GALLERY_PERMISSION_COMPOSITE,
79
 
                                                  array('test.test1', 'test.test5'));
80
 
        if ($ret) {
81
 
            return $this->failWithStatus($ret);
82
 
        }
83
 
    }
84
 
 
85
 
    function tearDown() {
86
 
        $ret = GalleryCoreApi::unregisterModulePermissions('testModule');
87
 
        if ($ret) {
88
 
            return $this->failWithStatus($ret);
89
 
        }
90
 
 
91
 
        parent::tearDown();
92
 
    }
93
 
 
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);
101
 
 
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);
108
 
    }
109
 
 
110
 
    function testGetSubPermissions() {
111
 
        /* test.test3 is a composite of tests 1 and 2 */
112
 
        list ($ret, $ids) = GalleryCoreApi::getSubPermissions('test.test3');
113
 
 
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'),
123
 
              $ids);
124
 
    }
125
 
 
126
 
    /**
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
129
 
     */
130
 
    function testConvertRoundTrip1() {
131
 
        list ($ret, $bits) = GalleryCoreApi::convertPermissionIdsToBits(array('test.test1'));
132
 
        if ($ret) {
133
 
            return $this->failWithStatus($ret);
134
 
        }
135
 
 
136
 
        list ($ret, $ids) = GalleryCoreApi::convertPermissionBitsToIds($bits);
137
 
        if ($ret) {
138
 
            return $this->failWithStatus($ret);
139
 
        }
140
 
 
141
 
        $this->assertEquals(array(array('id' => 'test.test1',
142
 
                                        'module' => 'testModule',
143
 
                                        'description' => 'regular permission')),
144
 
                            $ids);
145
 
    }
146
 
 
147
 
    /**
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
150
 
     */
151
 
    function testConvertRoundTrip2() {
152
 
        list ($ret, $bits) = GalleryCoreApi::convertPermissionIdsToBits(array('test.test3'));
153
 
        if ($ret) {
154
 
            return $this->failWithStatus($ret);
155
 
        }
156
 
 
157
 
        list ($ret, $ids) = GalleryCoreApi::convertPermissionBitsToIds($bits);
158
 
        if ($ret) {
159
 
            return $this->failWithStatus($ret);
160
 
        }
161
 
 
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')),
171
 
                            $ids);
172
 
    }
173
 
 
174
 
    function testConvertBitsToIdsWithoutCompress() {
175
 
        list ($ret, $bits) =
176
 
            GalleryCoreApi::convertPermissionIdsToBits(array('test.test1',
177
 
                                                            'test.test2',
178
 
                                                            'test.test5'));
179
 
        if ($ret) {
180
 
            return $this->failWithStatus($ret);
181
 
        }
182
 
 
183
 
        list ($ret, $ids) = GalleryCoreApi::convertPermissionBitsToIds($bits);
184
 
        if ($ret) {
185
 
            return $this->failWithStatus($ret);
186
 
        }
187
 
 
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')),
203
 
                            $ids);
204
 
    }
205
 
 
206
 
    function testConvertBitsToIdsWithCompress() {
207
 
        list ($ret, $bits) =
208
 
            GalleryCoreApi::convertPermissionIdsToBits(array('test.test1',
209
 
                                                            'test.test2',
210
 
                                                            'test.test5'));
211
 
        if ($ret) {
212
 
            return $this->failWithStatus($ret);
213
 
        }
214
 
 
215
 
        list ($ret, $ids) = GalleryCoreApi::convertPermissionBitsToIds($bits, true);
216
 
        if ($ret) {
217
 
            return $this->failWithStatus($ret);
218
 
        }
219
 
 
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')),
226
 
                            $ids);
227
 
    }
228
 
 
229
 
    function testConvertBitsToIdsWithCompressAndAllAccess() {
230
 
        list ($ret, $bits) =
231
 
            GalleryCoreApi::convertPermissionIdsToBits(array('test.test1',
232
 
                                                            'test.test2',
233
 
                                                            'test.test5',
234
 
                                                            'core.all'));
235
 
        if ($ret) {
236
 
            return $this->failWithStatus($ret);
237
 
        }
238
 
 
239
 
        list ($ret, $ids) = GalleryCoreApi::convertPermissionBitsToIds($bits, true);
240
 
        if ($ret) {
241
 
            return $this->failWithStatus($ret);
242
 
        }
243
 
 
244
 
        $this->assertEquals(2, sizeof($ids));
245
 
 
246
 
        // Unordered comparison
247
 
        $this->assertEquals(array('core.all' => 1,
248
 
                                  'test.test4' => 1),
249
 
                            array($ids[0]['id'] => 1,
250
 
                                  $ids[1]['id'] => 1));
251
 
    }
252
 
}
253
 
?>