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

« back to all changes in this revision

Viewing changes to modules/password/test/phpunit/PasswordOptionTest.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
 
GalleryCoreApi::requireOnce('modules/password/classes/PasswordHelper.class');
22
 
 
23
 
/**
24
 
 * PasswordOption tests - adding and removing passwords on items and albums.
25
 
 * Also tests PasswordInterface.
26
 
 *
27
 
 * @package Password
28
 
 * @subpackage PHPUnit
29
 
 * @author Alan Harder <alan.harder@sun.com>
30
 
 * @author Jess Martin <jmartin@cs.unc.edu>
31
 
 * @version $Revision: 15513 $
32
 
 */
33
 
class PasswordOptionTest extends ItemEditOptionTestCase {
34
 
 
35
 
    function PasswordOptionTest($methodName) {
36
 
        $this->ItemEditOptionTestCase($methodName, 'password', 'PasswordOption');
37
 
    }
38
 
 
39
 
    function setUp() {
40
 
        parent::setUp();
41
 
 
42
 
        list ($ret, $this->_coreParams) =
43
 
            GalleryCoreApi::fetchAllPluginParameters('module', 'core');
44
 
        if ($ret) {
45
 
            print $ret->getAsHtml();
46
 
            return $this->failWithStatus($ret);
47
 
        }
48
 
        list ($ret, $this->_topAlbum, $this->_topItems) =
49
 
            $this->_createSubAlbumWithItems($this->_getRootId(), true);
50
 
        if ($ret) {
51
 
            print $ret->getAsHtml();
52
 
            return $this->failWithStatus($ret);
53
 
        }
54
 
        $this->_markForCleanup($this->_topAlbum);
55
 
 
56
 
        list ($ret, $this->_subAlbum, $this->_subItems) =
57
 
            $this->_createSubAlbumWithItems($this->_topAlbum->getId());
58
 
        if ($ret) {
59
 
            print $ret->getAsHtml();
60
 
            return $this->failWithStatus($ret);
61
 
        }
62
 
 
63
 
        list ($ret, $this->_hidden) = GalleryCoreApi::newFactoryInstance('HiddenInterface_1_0');
64
 
        if ($ret) {
65
 
            print $ret->getAsHtml();
66
 
            return $this->failWithStatus($ret);
67
 
        }
68
 
    }
69
 
 
70
 
    function _createSubAlbumWithItems($parentId, $top=false) {
71
 
        list ($ret, $album) = $this->_createRandomAlbum($parentId);
72
 
        if ($ret) {
73
 
            return array($ret, null, null);
74
 
        }
75
 
 
76
 
        if ($top) {
77
 
            /* Setup permissions */
78
 
            $albumId = $album->getId();
79
 
            $ret = GalleryCoreApi::removeItemPermissions($albumId);
80
 
            if ($ret) {
81
 
                return array($ret, null, null);
82
 
            }
83
 
            $ret = GalleryCoreApi::addGroupPermission(
84
 
                    $albumId, $this->_coreParams['id.adminGroup'], 'core.all');
85
 
            if ($ret) {
86
 
                return array($ret, null, null);
87
 
            }
88
 
            $ret = GalleryCoreApi::addUserPermission(
89
 
                    $albumId, $this->_coreParams['id.anonymousUser'], 'core.edit');
90
 
            if ($ret) {
91
 
                return array($ret, null, null);
92
 
            }
93
 
            $ret = GalleryCoreApi::addUserPermission(
94
 
                    $albumId, $this->_coreParams['id.anonymousUser'], 'core.changePermissions');
95
 
            if ($ret) {
96
 
                return array($ret, null, null);
97
 
            }
98
 
            $ret = GalleryCoreApi::addGroupPermission(
99
 
                    $albumId, $this->_coreParams['id.everybodyGroup'], 'core.viewAll');
100
 
            if ($ret) {
101
 
                return array($ret, null, null);
102
 
            }
103
 
        } else {
104
 
            /* No public viewSource permission in subalbum */
105
 
            $ret = GalleryCoreApi::removeGroupPermission(
106
 
                    $album->getId(), $this->_coreParams['id.everybodyGroup'], 'core.viewSource');
107
 
            if ($ret) {
108
 
                return array($ret, null, null);
109
 
            }
110
 
        }
111
 
 
112
 
        $items = array();
113
 
        for ($i = 0; $i < 3; $i++) {
114
 
            list ($ret, $items[$i]) = $this->_createRandomDataItem($album->getId());
115
 
            if ($ret) {
116
 
                return array($ret, null, null);
117
 
            }
118
 
        }
119
 
 
120
 
        return array(null, $album, $items);
121
 
    }
122
 
 
123
 
    function _fetchViewPermissions($itemId) {
124
 
        list ($ret, $permissions) = GalleryCoreApi::fetchAllPermissionsForItem($itemId, true);
125
 
        if ($ret) {
126
 
            $this->failWithStatus($ret);
127
 
        }
128
 
        $result = array();
129
 
        foreach ($permissions as $permission) {
130
 
            if (strncmp($permission['permission'], 'core.view', 9)) {
131
 
                continue;
132
 
            }
133
 
            if (isset($permission['entityId'])) {
134
 
                $result['entity-' . $permission['entityId']][] = $permission['permission'];
135
 
            } else if (isset($permission['userId'])) {
136
 
                $result['user-' . $permission['userId']][] = $permission['permission'];
137
 
            } else if (isset($permission['groupId']) &&
138
 
                       $permission['groupId'] != $this->_coreParams['id.adminGroup']) {
139
 
                $result['group-' . $permission['groupId']][] = $permission['permission'];
140
 
            }
141
 
        }
142
 
        ksort($result);
143
 
        foreach (array_keys($result) as $key) {
144
 
            sort($result[$key]);
145
 
        }
146
 
        return $result;
147
 
    }
148
 
 
149
 
    function _assertPassword(&$item, $protectedBy, $messagePrefix,
150
 
                             $viewSource=true, $parentProtect=0, $hidden=0, $password=null) {
151
 
        list ($ret, $item) = $item->refresh();
152
 
        if ($ret) {
153
 
            return $ret;
154
 
        }
155
 
        $itemId = $item->getId();
156
 
        $everybodyId = 'group-' . $this->_coreParams['id.everybodyGroup'];
157
 
        list ($ret, $hash) =
158
 
            GalleryCoreApi::getPluginParameter('module', 'password', 'password', $itemId);
159
 
        if ($ret) {
160
 
            return $ret;
161
 
        }
162
 
        $this->assertEquals($itemId == $protectedBy, !empty($hash),
163
 
                            $messagePrefix . ' has password');
164
 
        if ($password) {
165
 
            $this->assert(GalleryUtilities::isCorrectPassword($password, $hash), 'hashed password');
166
 
        }
167
 
        $this->assertEquals($itemId == $protectedBy,
168
 
                            $item->hasOnLoadHandler('Password'), $messagePrefix . ' onLoadHander');
169
 
 
170
 
        $result = $this->_fetchViewPermissions($itemId);
171
 
        $expected = array();
172
 
        if ($parentProtect) {
173
 
            $expected['entity-' . $parentProtect] = array('core.view');
174
 
        }
175
 
        $expected[ $protectedBy ? 'entity-' . $protectedBy : $everybodyId ] =
176
 
            $viewSource ? ($hidden ? array('core.viewResizes', 'core.viewSource')
177
 
                                   : array('core.viewAll'))
178
 
                        : ($hidden ? array('core.viewResizes')
179
 
                                   : array('core.view', 'core.viewResizes'));
180
 
        if ($itemId == $protectedBy && !$parentProtect) {
181
 
            $expected[$everybodyId] = array('core.view');
182
 
        }
183
 
        $this->assertEquals($expected, $result, $messagePrefix . ' permissions');
184
 
    }
185
 
 
186
 
    function _moveItem(&$item, $newParentId) {
187
 
        list ($ret, $lockIds[]) = GalleryCoreApi::acquireWriteLock($item->getId());
188
 
        if ($ret) {
189
 
            return $ret;
190
 
        }
191
 
        list ($ret, $lockIds[]) =
192
 
            GalleryCoreApi::acquireReadLock(array($item->getParentId(), $newParentId));
193
 
        if ($ret) {
194
 
            return $ret;
195
 
        }
196
 
        $ret = $item->move($newParentId);
197
 
        if ($ret) {
198
 
            GalleryCoreApi::releaseLocks($lockIds);
199
 
            return $ret;
200
 
        }
201
 
        $ret = $item->save();
202
 
        if ($ret) {
203
 
            GalleryCoreApi::releaseLocks($lockIds);
204
 
            return $ret;
205
 
        }
206
 
        $ret = GalleryCoreApi::releaseLocks($lockIds);
207
 
        if ($ret) {
208
 
            return $ret;
209
 
        }
210
 
        return null;
211
 
    }
212
 
 
213
 
 
214
 
    function testPasswordMismatch() {
215
 
        $form['PasswordOption']['password1'] = 'abc';
216
 
        $form['PasswordOption']['password2'] = 'abd';
217
 
        $result = $this->_handleRequestAfterEdit($form, $this->_topItems[1]);
218
 
        $this->assertEquals(array(array('form[error][PasswordOption][mismatch]'), array()),
219
 
                            $result);
220
 
 
221
 
        $ret = $this->_assertPassword($this->_topItems[1], false, 'item:');
222
 
        if ($ret) {
223
 
            return $this->failWithStatus($ret);
224
 
        }
225
 
    }
226
 
 
227
 
    function testPasswordItem() {
228
 
        GalleryUtilities::putRequestVariable('form[PasswordOption][password1]', 'abc');
229
 
        GalleryUtilities::putRequestVariable('form[PasswordOption][password2]', 'abc');
230
 
        $form = GalleryUtilities::getFormVariables('form');
231
 
        $result = $this->_handleRequestAfterEdit($form, $this->_topItems[1]);
232
 
        $this->assertEquals(array(array(), array()), $result);
233
 
 
234
 
        $ret = $this->_assertPassword($this->_topItems[1], $this->_topItems[1]->getId(),
235
 
                                      'viewSource item:');
236
 
        if ($ret) {
237
 
            return $this->failWithStatus($ret);
238
 
        }
239
 
 
240
 
        $result = $this->_handleRequestAfterEdit($form, $this->_subItems[1]);
241
 
        $this->assertEquals(array(array(), array()), $result);
242
 
 
243
 
        $ret = $this->_assertPassword($this->_subItems[1], $this->_subItems[1]->getId(),
244
 
                                      'viewResizes item:', false, 0, 0, 'abc');
245
 
        if ($ret) {
246
 
            return $this->failWithStatus($ret);
247
 
        }
248
 
 
249
 
        GalleryDataCache::reset();
250
 
        $form['PasswordOption'] = array('remove' => 1);
251
 
        $result = $this->_handleRequestAfterEdit($form, $this->_topItems[1]);
252
 
        $this->assertEquals(array(array(), array()), $result);
253
 
 
254
 
        $ret = $this->_assertPassword($this->_topItems[1], false, 'unpw viewSource:');
255
 
        if ($ret) {
256
 
            return $this->failWithStatus($ret);
257
 
        }
258
 
 
259
 
        $result = $this->_handleRequestAfterEdit($form, $this->_subItems[1]);
260
 
        $this->assertEquals(array(array(), array()), $result);
261
 
 
262
 
        $ret = $this->_assertPassword($this->_subItems[1], false, 'unpw viewResizes:', false);
263
 
        if ($ret) {
264
 
            return $this->failWithStatus($ret);
265
 
        }
266
 
    }
267
 
 
268
 
    function testPermission() {
269
 
        $ret = GalleryCoreApi::removeUserPermission($this->_topItems[1]->getId(),
270
 
                $this->_coreParams['id.anonymousUser'], 'core.changePermissions');
271
 
        if ($ret) {
272
 
            return $this->failWithStatus($ret);
273
 
        }
274
 
 
275
 
        $this->_becomeGuestUser();
276
 
 
277
 
        /* Permissions ok for topItems[0] */
278
 
        $form['PasswordOption']['password1'] = $form['PasswordOption']['password2'] = 'abc';
279
 
        $result = $this->_handleRequestAfterEdit($form, $this->_topItems[0]);
280
 
        $this->assertEquals(array(array(), array()), $result);
281
 
 
282
 
        $ret = $this->_assertPassword($this->_topItems[0], $this->_topItems[0]->getId(), 'item0:');
283
 
        if ($ret) {
284
 
            return $this->failWithStatus($ret);
285
 
        }
286
 
 
287
 
        /* No core.changePermissions permission for topItems[1] */
288
 
        $result = $this->_handleRequestAfterEdit($form, $this->_topItems[1],
289
 
                                                 ERROR_PERMISSION_DENIED);
290
 
 
291
 
        $ret = $this->_assertPassword($this->_topItems[1], false, 'item1:');
292
 
        if ($ret) {
293
 
            return $this->failWithStatus($ret);
294
 
        }
295
 
    }
296
 
 
297
 
    function testPasswordAlbum() {
298
 
        global $gallery;
299
 
        $mockAdapter = new MockTemplateAdapter();
300
 
        $gallery->_templateAdapter =& $mockAdapter;
301
 
 
302
 
        $albumId = $this->_topAlbum->getId();
303
 
        GalleryUtilities::putRequestVariable('form[PasswordOption][password1]', 'ab"d>');
304
 
        GalleryUtilities::putRequestVariable('form[PasswordOption][password2]', 'ab"d>');
305
 
        $form = GalleryUtilities::getFormVariables('form');
306
 
        $result = $this->_handleRequestAfterEdit($form, $this->_topAlbum);
307
 
        $this->assertEquals(array(array(), array()), $result);
308
 
 
309
 
        $ret = $this->_assertPassword($this->_topAlbum, $albumId, 'pw album:', true, 0, 0, 'ab"d>');
310
 
        if ($ret) {
311
 
            return $this->failWithStatus($ret);
312
 
        }
313
 
        $ret = $this->_assertPassword($this->_subAlbum, $albumId, 'pw subalbum:', false);
314
 
        if ($ret) {
315
 
            return $this->failWithStatus($ret);
316
 
        }
317
 
        for ($i = 0; $i < 3; $i++) {
318
 
            $ret = $this->_assertPassword($this->_topItems[$i], $albumId, "pw item$i:");
319
 
            if ($ret) {
320
 
                return $this->failWithStatus($ret);
321
 
            }
322
 
            $ret = $this->_assertPassword($this->_subItems[$i], $albumId, "pw subitem$i:", false);
323
 
            if ($ret) {
324
 
                return $this->failWithStatus($ret);
325
 
            }
326
 
        }
327
 
        $progress = $mockAdapter->getProgressBarDump();
328
 
        $this->assert(count($progress) > 3, 'progress bar: ' . print_r($progress, true));
329
 
        $mockAdapter = new MockTemplateAdapter();
330
 
        $gallery->_templateAdapter =& $mockAdapter;
331
 
 
332
 
        GalleryDataCache::reset();
333
 
        $form['PasswordOption']['remove'] = 1;
334
 
        $result = $this->_handleRequestAfterEdit($form, $this->_topAlbum);
335
 
        $this->assertEquals(array(array(), array()), $result);
336
 
 
337
 
        $ret = $this->_assertPassword($this->_topAlbum, false, 'unpw album:');
338
 
        if ($ret) {
339
 
            return $this->failWithStatus($ret);
340
 
        }
341
 
        $ret = $this->_assertPassword($this->_subAlbum, false, 'unpw subalbum:', false);
342
 
        if ($ret) {
343
 
            return $this->failWithStatus($ret);
344
 
        }
345
 
        for ($i = 0; $i < 3; $i++) {
346
 
            $ret = $this->_assertPassword($this->_topItems[$i], false, "unpw item$i:");
347
 
            if ($ret) {
348
 
                return $this->failWithStatus($ret);
349
 
            }
350
 
            $ret = $this->_assertPassword($this->_subItems[$i], false, "unpw subitem$i:", false);
351
 
            if ($ret) {
352
 
                return $this->failWithStatus($ret);
353
 
            }
354
 
        }
355
 
        $progress = $mockAdapter->getProgressBarDump();
356
 
        $this->assert(count($progress) > 3, 'progress bar: ' . print_r($progress, true));
357
 
    }
358
 
 
359
 
    function testPasswordAlbumWithPasswordItem() {
360
 
        global $gallery;
361
 
        $mockAdapter = new MockTemplateAdapter();
362
 
        $gallery->_templateAdapter =& $mockAdapter;
363
 
 
364
 
        $ret = PasswordHelper::setPassword($this->_subItems[0], 'abc');
365
 
        if ($ret) {
366
 
            return $this->failWithStatus($ret);
367
 
        }
368
 
        GalleryDataCache::reset();
369
 
        $ret = $this->_assertPassword($this->_subItems[0], $this->_subItems[0]->getId(),
370
 
                                      'setup:', false);
371
 
        if ($ret) {
372
 
            return $this->failWithStatus($ret);
373
 
        }
374
 
 
375
 
        $form['PasswordOption']['password1'] = $form['PasswordOption']['password2'] = 'xyz';
376
 
        $result = $this->_handleRequestAfterEdit($form, $this->_subAlbum);
377
 
        $this->assertEquals(array(array(), array()), $result);
378
 
 
379
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_subAlbum->getId(),
380
 
                                      'pw album:', false);
381
 
        if ($ret) {
382
 
            return $this->failWithStatus($ret);
383
 
        }
384
 
        for ($i = 0; $i < 3; $i++) {
385
 
            $ret = $this->_assertPassword($this->_subItems[$i],
386
 
                    $i ? $this->_subAlbum->getId() : $this->_subItems[0]->getId(),
387
 
                    "pw item$i:", false, $i ? 0 : $this->_subAlbum->getId());
388
 
            if ($ret) {
389
 
                return $this->failWithStatus($ret);
390
 
            }
391
 
        }
392
 
 
393
 
        GalleryDataCache::reset();
394
 
        $form['PasswordOption']['remove'] = 1;
395
 
        $result = $this->_handleRequestAfterEdit($form, $this->_subAlbum);
396
 
        $this->assertEquals(array(array(), array()), $result);
397
 
 
398
 
        $ret = $this->_assertPassword($this->_subAlbum, false, 'unpw album:', false);
399
 
        if ($ret) {
400
 
            return $this->failWithStatus($ret);
401
 
        }
402
 
        for ($i = 0; $i < 3; $i++) {
403
 
            $ret = $this->_assertPassword($this->_subItems[$i],
404
 
                    $i ? false : $this->_subItems[0]->getId(), "item$i:", false);
405
 
            if ($ret) {
406
 
                return $this->failWithStatus($ret);
407
 
            }
408
 
        }
409
 
    }
410
 
 
411
 
    function testPasswordAlbumWithPasswordAlbum() {
412
 
        global $gallery;
413
 
        $mockAdapter = new MockTemplateAdapter();
414
 
        $gallery->_templateAdapter =& $mockAdapter;
415
 
 
416
 
        $ret = PasswordHelper::setPassword($this->_subAlbum, 'abc');
417
 
        if ($ret) {
418
 
            return $this->failWithStatus($ret);
419
 
        }
420
 
        GalleryDataCache::reset();
421
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_subAlbum->getId(), 'setup:', false);
422
 
        if ($ret) {
423
 
            return $this->failWithStatus($ret);
424
 
        }
425
 
 
426
 
        $form['PasswordOption']['password1'] = $form['PasswordOption']['password2'] = '123';
427
 
        $result = $this->_handleRequestAfterEdit($form, $this->_topAlbum);
428
 
        $this->assertEquals(array(array(), array()), $result);
429
 
 
430
 
        $ret = $this->_assertPassword($this->_topAlbum, $this->_topAlbum->getId(), 'pw album:');
431
 
        if ($ret) {
432
 
            return $this->failWithStatus($ret);
433
 
        }
434
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_subAlbum->getId(),
435
 
                                      'pw subalbum:', false, $this->_topAlbum->getId());
436
 
        if ($ret) {
437
 
            return $this->failWithStatus($ret);
438
 
        }
439
 
        for ($i = 0; $i < 3; $i++) {
440
 
            $ret = $this->_assertPassword($this->_topItems[$i], $this->_topAlbum->getId(),
441
 
                                          "pw item$i:");
442
 
            if ($ret) {
443
 
                return $this->failWithStatus($ret);
444
 
            }
445
 
            $ret = $this->_assertPassword($this->_subItems[$i], $this->_subAlbum->getId(),
446
 
                                          "pw subitem$i:", false);
447
 
            if ($ret) {
448
 
                return $this->failWithStatus($ret);
449
 
            }
450
 
        }
451
 
 
452
 
        GalleryDataCache::reset();
453
 
        $form['PasswordOption']['remove'] = 1;
454
 
        $result = $this->_handleRequestAfterEdit($form, $this->_topAlbum);
455
 
        $this->assertEquals(array(array(), array()), $result);
456
 
 
457
 
        $ret = $this->_assertPassword($this->_topAlbum, false, 'unpw album:');
458
 
        if ($ret) {
459
 
            return $this->failWithStatus($ret);
460
 
        }
461
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_subAlbum->getId(),
462
 
                                      'subalbum:', false);
463
 
        if ($ret) {
464
 
            return $this->failWithStatus($ret);
465
 
        }
466
 
        for ($i = 0; $i < 3; $i++) {
467
 
            $ret = $this->_assertPassword($this->_topItems[$i], false, "unpw item$i:");
468
 
            if ($ret) {
469
 
                return $this->failWithStatus($ret);
470
 
            }
471
 
            $ret = $this->_assertPassword($this->_subItems[$i], $this->_subAlbum->getId(),
472
 
                                          "subitem$i:", false);
473
 
            if ($ret) {
474
 
                return $this->failWithStatus($ret);
475
 
            }
476
 
        }
477
 
    }
478
 
 
479
 
    function testPasswordItemInPasswordAlbum() {
480
 
        $ret = PasswordHelper::setPassword($this->_topAlbum, 'abc');
481
 
        if ($ret) {
482
 
            return $this->failWithStatus($ret);
483
 
        }
484
 
        GalleryDataCache::reset();
485
 
        $ret = $this->_assertPassword($this->_topItems[1], $this->_topAlbum->getId(), 'setup:');
486
 
        if ($ret) {
487
 
            return $this->failWithStatus($ret);
488
 
        }
489
 
 
490
 
        $form['PasswordOption']['password1'] = $form['PasswordOption']['password2'] = 'ab!';
491
 
        $result = $this->_handleRequestAfterEdit($form, $this->_topItems[1]);
492
 
        $this->assertEquals(array(array(), array()), $result);
493
 
 
494
 
        $ret = $this->_assertPassword($this->_topItems[1], $this->_topItems[1]->getId(),
495
 
                                      'item:', true, $this->_topAlbum->getId());
496
 
        if ($ret) {
497
 
            return $this->failWithStatus($ret);
498
 
        }
499
 
 
500
 
        GalleryDataCache::reset();
501
 
        $form = array('PasswordOption' => array('remove' => 1));
502
 
        $result = $this->_handleRequestAfterEdit($form, $this->_topItems[1]);
503
 
        $this->assertEquals(array(array(), array()), $result);
504
 
 
505
 
        $ret = $this->_assertPassword($this->_topItems[1], $this->_topAlbum->getId(), 'unpw:');
506
 
        if ($ret) {
507
 
            return $this->failWithStatus($ret);
508
 
        }
509
 
    }
510
 
 
511
 
    function testPasswordAlbumInPasswordAlbum() {
512
 
        global $gallery;
513
 
        $mockAdapter = new MockTemplateAdapter();
514
 
        $gallery->_templateAdapter =& $mockAdapter;
515
 
 
516
 
        $ret = PasswordHelper::setPassword($this->_topAlbum, 'abc');
517
 
        if ($ret) {
518
 
            return $this->failWithStatus($ret);
519
 
        }
520
 
        GalleryDataCache::reset();
521
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_topAlbum->getId(), 'setup:', false);
522
 
        if ($ret) {
523
 
            return $this->failWithStatus($ret);
524
 
        }
525
 
 
526
 
        $form['PasswordOption']['password1'] = $form['PasswordOption']['password2'] = '123';
527
 
        $result = $this->_handleRequestAfterEdit($form, $this->_subAlbum);
528
 
        $this->assertEquals(array(array(), array()), $result);
529
 
 
530
 
        $ret = $this->_assertPassword($this->_topAlbum, $this->_topAlbum->getId(), 'pw album:');
531
 
        if ($ret) {
532
 
            return $this->failWithStatus($ret);
533
 
        }
534
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_subAlbum->getId(), 'pw subalbum:',
535
 
                                      false, $this->_topAlbum->getId());
536
 
        if ($ret) {
537
 
            return $this->failWithStatus($ret);
538
 
        }
539
 
        for ($i = 0; $i < 3; $i++) {
540
 
            $ret = $this->_assertPassword($this->_topItems[$i], $this->_topAlbum->getId(),
541
 
                                          "pw item$i:");
542
 
            if ($ret) {
543
 
                return $this->failWithStatus($ret);
544
 
            }
545
 
            $ret = $this->_assertPassword($this->_subItems[$i], $this->_subAlbum->getId(),
546
 
                                          "pw subitem$i:", false);
547
 
            if ($ret) {
548
 
                return $this->failWithStatus($ret);
549
 
            }
550
 
        }
551
 
 
552
 
        GalleryDataCache::reset();
553
 
        $form['PasswordOption']['remove'] = 1;
554
 
        $result = $this->_handleRequestAfterEdit($form, $this->_subAlbum);
555
 
        $this->assertEquals(array(array(), array()), $result);
556
 
 
557
 
        $ret = $this->_assertPassword($this->_topAlbum, $this->_topAlbum->getId(), 'unpw album:');
558
 
        if ($ret) {
559
 
            return $this->failWithStatus($ret);
560
 
        }
561
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_topAlbum->getId(),
562
 
                                      'unpw subalbum:', false);
563
 
        if ($ret) {
564
 
            return $this->failWithStatus($ret);
565
 
        }
566
 
        for ($i = 0; $i < 3; $i++) {
567
 
            $ret = $this->_assertPassword($this->_topItems[$i], $this->_topAlbum->getId(),
568
 
                                          "unpw item$i:");
569
 
            if ($ret) {
570
 
                return $this->failWithStatus($ret);
571
 
            }
572
 
            $ret = $this->_assertPassword($this->_subItems[$i], $this->_topAlbum->getId(),
573
 
                                          "unpw subitem$i:", false);
574
 
            if ($ret) {
575
 
                return $this->failWithStatus($ret);
576
 
            }
577
 
        }
578
 
    }
579
 
 
580
 
    function testAddItemToPasswordAlbum() {
581
 
        $ret = PasswordHelper::setPassword($this->_topAlbum, '123');
582
 
        if ($ret) {
583
 
            return $this->failWithStatus($ret);
584
 
        }
585
 
        GalleryDataCache::reset();
586
 
        $ret = $this->_assertPassword($this->_topAlbum, $this->_topAlbum->getId(), 'setup:');
587
 
        if ($ret) {
588
 
            return $this->failWithStatus($ret);
589
 
        }
590
 
 
591
 
        list ($ret, $item) = $this->_createRandomDataItem($this->_topAlbum->getId());
592
 
        if ($ret) {
593
 
            return $this->failWithStatus($ret);
594
 
        }
595
 
        $ret = $this->_assertPassword($item, $this->_topAlbum->getId(), 'item:');
596
 
        if ($ret) {
597
 
            return $this->failWithStatus($ret);
598
 
        }
599
 
 
600
 
        list ($ret, $item) = $this->_createRandomDataItem($this->_subAlbum->getId());
601
 
        if ($ret) {
602
 
            return $this->failWithStatus($ret);
603
 
        }
604
 
        $ret = $this->_assertPassword($item, $this->_topAlbum->getId(), 'deep item:', false);
605
 
        if ($ret) {
606
 
            return $this->failWithStatus($ret);
607
 
        }
608
 
    }
609
 
 
610
 
    function testMoveItemIntoPasswordAlbum() {
611
 
        $ret = PasswordHelper::setPassword($this->_subAlbum, 'p{|w');
612
 
        if ($ret) {
613
 
            return $this->failWithStatus($ret);
614
 
        }
615
 
        GalleryDataCache::reset();
616
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_subAlbum->getId(), 'setup:', false);
617
 
        if ($ret) {
618
 
            return $this->failWithStatus($ret);
619
 
        }
620
 
 
621
 
        $ret = $this->_moveItem($this->_topItems[2], $this->_subAlbum->getId());
622
 
        if ($ret) {
623
 
            return $this->failWithStatus($ret);
624
 
        }
625
 
 
626
 
        $ret = $this->_assertPassword($this->_topItems[2], $this->_subAlbum->getId(), 'item:');
627
 
        if ($ret) {
628
 
            return $this->failWithStatus($ret);
629
 
        }
630
 
    }
631
 
 
632
 
    function testMoveItemDeepIntoPasswordAlbum() {
633
 
        list ($ret, $album) = $this->_createRandomAlbum($this->_subAlbum->getId());
634
 
        if ($ret) {
635
 
            return $this->failWithStatus($ret);
636
 
        }
637
 
        $ret = GalleryCoreApi::addGroupPermission(
638
 
                $album->getId(), $this->_coreParams['id.everybodyGroup'], 'core.viewSource');
639
 
        if ($ret) {
640
 
            return $this->failWithStatus($ret);
641
 
        }
642
 
        list ($ret, $subAlbum) = $this->_createRandomAlbum($album->getId());
643
 
        if ($ret) {
644
 
            return $this->failWithStatus($ret);
645
 
        }
646
 
        $ret = PasswordHelper::setPassword($this->_subAlbum, '(*)');
647
 
        if ($ret) {
648
 
            return $this->failWithStatus($ret);
649
 
        }
650
 
        GalleryDataCache::reset();
651
 
        $ret = $this->_assertPassword($subAlbum, $this->_subAlbum->getId(), 'setup:');
652
 
        if ($ret) {
653
 
            return $this->failWithStatus($ret);
654
 
        }
655
 
 
656
 
        $ret = $this->_moveItem($this->_topItems[2], $subAlbum->getId());
657
 
        if ($ret) {
658
 
            return $this->failWithStatus($ret);
659
 
        }
660
 
 
661
 
        $ret = $this->_assertPassword($this->_topItems[2], $this->_subAlbum->getId(), 'item:');
662
 
        if ($ret) {
663
 
            return $this->failWithStatus($ret);
664
 
        }
665
 
    }
666
 
 
667
 
    function testMoveItemOutOfPasswordAlbum() {
668
 
        $ret = PasswordHelper::setPassword($this->_subAlbum, '%^&#');
669
 
        if ($ret) {
670
 
            return $this->failWithStatus($ret);
671
 
        }
672
 
        GalleryDataCache::reset();
673
 
        $ret = $this->_assertPassword($this->_subItems[2], $this->_subAlbum->getId(),
674
 
                                      'setup:', false);
675
 
        if ($ret) {
676
 
            return $this->failWithStatus($ret);
677
 
        }
678
 
 
679
 
        $ret = $this->_moveItem($this->_subItems[2], $this->_topAlbum->getId());
680
 
        if ($ret) {
681
 
            return $this->failWithStatus($ret);
682
 
        }
683
 
 
684
 
        $ret = $this->_assertPassword($this->_subItems[2], false, 'item:', false);
685
 
        if ($ret) {
686
 
            return $this->failWithStatus($ret);
687
 
        }
688
 
    }
689
 
 
690
 
    function testMoveItemBetweenPasswordAlbums() {
691
 
        list ($ret, $album) = $this->_createRandomAlbum($this->_topAlbum->getId());
692
 
        if ($ret) {
693
 
            return $this->failWithStatus($ret);
694
 
        }
695
 
        $ret = PasswordHelper::setPassword($album, 'abc');
696
 
        if ($ret) {
697
 
            return $this->failWithStatus($ret);
698
 
        }
699
 
        $ret = PasswordHelper::setPassword($this->_subAlbum, '123');
700
 
        if ($ret) {
701
 
            return $this->failWithStatus($ret);
702
 
        }
703
 
        GalleryDataCache::reset();
704
 
        $ret = $this->_assertPassword($this->_subItems[2], $this->_subAlbum->getId(),
705
 
                                      'setup:', false);
706
 
        if ($ret) {
707
 
            return $this->failWithStatus($ret);
708
 
        }
709
 
 
710
 
        $ret = $this->_moveItem($this->_subItems[2], $album->getId());
711
 
        if ($ret) {
712
 
            return $this->failWithStatus($ret);
713
 
        }
714
 
 
715
 
        $ret = $this->_assertPassword($this->_subItems[2], $album->getId(), 'item:', false);
716
 
        if ($ret) {
717
 
            return $this->failWithStatus($ret);
718
 
        }
719
 
    }
720
 
 
721
 
    function testMoveAlbumIntoPasswordAlbum() {
722
 
        list ($ret, $album) = $this->_createRandomAlbum($this->_topAlbum->getId());
723
 
        if ($ret) {
724
 
            return $this->failWithStatus($ret);
725
 
        }
726
 
        $ret = PasswordHelper::setPassword($album, 'abc');
727
 
        if ($ret) {
728
 
            return $this->failWithStatus($ret);
729
 
        }
730
 
        GalleryDataCache::reset();
731
 
        $ret = $this->_assertPassword($album, $album->getId(), 'setup:');
732
 
        if ($ret) {
733
 
            return $this->failWithStatus($ret);
734
 
        }
735
 
 
736
 
        $ret = $this->_moveItem($this->_subAlbum, $album->getId());
737
 
        if ($ret) {
738
 
            return $this->failWithStatus($ret);
739
 
        }
740
 
 
741
 
        $ret = $this->_assertPassword($this->_subAlbum, $album->getId(), 'album:', false);
742
 
        if ($ret) {
743
 
            return $this->failWithStatus($ret);
744
 
        }
745
 
        for ($i = 0; $i < 3; $i++) {
746
 
            $ret = $this->_assertPassword($this->_subItems[$i], $album->getId(), "item$i:", false);
747
 
            if ($ret) {
748
 
                return $this->failWithStatus($ret);
749
 
            }
750
 
        }
751
 
    }
752
 
 
753
 
    function testMoveAlbumOutOfPasswordAlbum() {
754
 
        list ($ret, $album) = $this->_createRandomAlbum($this->_getRootId());
755
 
        if ($ret) {
756
 
            return $this->failWithStatus($ret);
757
 
        }
758
 
        $this->_markForCleanup($album);
759
 
        $ret = PasswordHelper::setPassword($this->_topAlbum, '123');
760
 
        if ($ret) {
761
 
            return $this->failWithStatus($ret);
762
 
        }
763
 
        GalleryDataCache::reset();
764
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_topAlbum->getId(), 'setup:', false);
765
 
        if ($ret) {
766
 
            return $this->failWithStatus($ret);
767
 
        }
768
 
 
769
 
        $ret = $this->_moveItem($this->_subAlbum, $album->getId());
770
 
        if ($ret) {
771
 
            return $this->failWithStatus($ret);
772
 
        }
773
 
 
774
 
        $ret = $this->_assertPassword($this->_subAlbum, false, 'album:', false);
775
 
        if ($ret) {
776
 
            return $this->failWithStatus($ret);
777
 
        }
778
 
        for ($i = 0; $i < 3; $i++) {
779
 
            $ret = $this->_assertPassword($this->_subItems[$i], false, "item$i:", false);
780
 
            if ($ret) {
781
 
                return $this->failWithStatus($ret);
782
 
            }
783
 
        }
784
 
    }
785
 
 
786
 
    function testMoveAlbumBetweenPasswordAlbums() {
787
 
        list ($ret, $album) = $this->_createRandomAlbum($this->_getRootId());
788
 
        if ($ret) {
789
 
            return $this->failWithStatus($ret);
790
 
        }
791
 
        $this->_markForCleanup($album);
792
 
        $ret = PasswordHelper::setPassword($album, 'abc');
793
 
        if ($ret) {
794
 
            return $this->failWithStatus($ret);
795
 
        }
796
 
        $ret = PasswordHelper::setPassword($this->_topAlbum, '123');
797
 
        if ($ret) {
798
 
            return $this->failWithStatus($ret);
799
 
        }
800
 
        GalleryDataCache::reset();
801
 
        $ret = $this->_assertPassword($this->_subItems[1], $this->_topAlbum->getId(),
802
 
                                      'setup:', false);
803
 
        if ($ret) {
804
 
            return $this->failWithStatus($ret);
805
 
        }
806
 
 
807
 
        $ret = $this->_moveItem($this->_subAlbum, $album->getId());
808
 
        if ($ret) {
809
 
            return $this->failWithStatus($ret);
810
 
        }
811
 
 
812
 
        $ret = $this->_assertPassword($this->_subAlbum, $album->getId(), 'album:', false);
813
 
        if ($ret) {
814
 
            return $this->failWithStatus($ret);
815
 
        }
816
 
        for ($i = 0; $i < 3; $i++) {
817
 
            $ret = $this->_assertPassword($this->_subItems[$i], $album->getId(), "item$i:", false);
818
 
            if ($ret) {
819
 
                return $this->failWithStatus($ret);
820
 
            }
821
 
        }
822
 
    }
823
 
 
824
 
    function testMovePasswordItemIntoPasswordAlbum() {
825
 
        $ret = PasswordHelper::setPassword($this->_topItems[1], 'abc');
826
 
        if ($ret) {
827
 
            return $this->failWithStatus($ret);
828
 
        }
829
 
        $ret = PasswordHelper::setPassword($this->_subAlbum, '123');
830
 
        if ($ret) {
831
 
            return $this->failWithStatus($ret);
832
 
        }
833
 
        GalleryDataCache::reset();
834
 
 
835
 
        $ret = $this->_moveItem($this->_topItems[1], $this->_subAlbum->getId());
836
 
        if ($ret) {
837
 
            return $this->failWithStatus($ret);
838
 
        }
839
 
 
840
 
        $ret = $this->_assertPassword($this->_topItems[1], $this->_topItems[1]->getId(), 'item:',
841
 
                                      true, $this->_subAlbum->getId());
842
 
        if ($ret) {
843
 
            return $this->failWithStatus($ret);
844
 
        }
845
 
    }
846
 
 
847
 
    function testMovePasswordAlbumIntoPasswordAlbum() {
848
 
        list ($ret, $album) = $this->_createRandomAlbum($this->_getRootId());
849
 
        if ($ret) {
850
 
            return $this->failWithStatus($ret);
851
 
        }
852
 
        $this->_markForCleanup($album);
853
 
        $ret = PasswordHelper::setPassword($album, 'abc');
854
 
        if ($ret) {
855
 
            return $this->failWithStatus($ret);
856
 
        }
857
 
        $ret = PasswordHelper::setPassword($this->_subAlbum, '123');
858
 
        if ($ret) {
859
 
            return $this->failWithStatus($ret);
860
 
        }
861
 
        GalleryDataCache::reset();
862
 
        $ret = $this->_assertPassword($this->_subItems[1], $this->_subAlbum->getId(),
863
 
                                      'setup:', false);
864
 
        if ($ret) {
865
 
            return $this->failWithStatus($ret);
866
 
        }
867
 
 
868
 
        $ret = $this->_moveItem($this->_subAlbum, $album->getId());
869
 
        if ($ret) {
870
 
            return $this->failWithStatus($ret);
871
 
        }
872
 
 
873
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_subAlbum->getId(), 'album:',
874
 
                                      false, $album->getId());
875
 
        if ($ret) {
876
 
            return $this->failWithStatus($ret);
877
 
        }
878
 
        for ($i = 0; $i < 3; $i++) {
879
 
            $ret = $this->_assertPassword($this->_subItems[$i], $this->_subAlbum->getId(),
880
 
                                          "item$i:", false);
881
 
            if ($ret) {
882
 
                return $this->failWithStatus($ret);
883
 
            }
884
 
        }
885
 
    }
886
 
 
887
 
    function testPasswordInterface() {
888
 
        list ($ret, $interface) = GalleryCoreApi::newFactoryInstance('PasswordInterface_1_0');
889
 
        if ($ret) {
890
 
            return $this->failWithStatus($ret);
891
 
        }
892
 
        if (isset($interface)) {
893
 
            $ret = $interface->setPassword($this->_topItems[1], '@abc123');
894
 
            if ($ret) {
895
 
                return $this->failWithStatus($ret);
896
 
            }
897
 
            $ret = $this->_assertPassword($this->_topItems[1], $this->_topItems[1]->getId(),
898
 
                                          'item:');
899
 
            if ($ret) {
900
 
                return $this->failWithStatus($ret);
901
 
            }
902
 
            list ($ret, $hasPassword) = $interface->hasPassword($this->_topItems[1]);
903
 
            if ($ret) {
904
 
                return $this->failWithStatus($ret);
905
 
            }
906
 
            $this->assert($hasPassword, 'hasPassword item');
907
 
            list ($ret, $hasPassword) = $interface->hasPassword($this->_topItems[2]);
908
 
            if ($ret) {
909
 
                return $this->failWithStatus($ret);
910
 
            }
911
 
            $this->assert(!$hasPassword, 'hasPassword other item');
912
 
            $ret = $interface->setPassword($this->_subAlbum, ')=pw=(');
913
 
            if ($ret) {
914
 
                return $this->failWithStatus($ret);
915
 
            }
916
 
            $ret = $this->_assertPassword($this->_subAlbum, $this->_subAlbum->getId(),
917
 
                                          'album:', false);
918
 
            if ($ret) {
919
 
                return $this->failWithStatus($ret);
920
 
            }
921
 
            list ($ret, $hasPassword) = $interface->hasPassword($this->_subAlbum);
922
 
            if ($ret) {
923
 
                return $this->failWithStatus($ret);
924
 
            }
925
 
            $this->assert($hasPassword, 'hasPassword album');
926
 
            $ret = $interface->removePassword($this->_topItems[1]);
927
 
            if ($ret) {
928
 
                return $this->failWithStatus($ret);
929
 
            }
930
 
            list ($ret, $hasPassword) = $interface->hasPassword($this->_topItems[1]);
931
 
            if ($ret) {
932
 
                return $this->failWithStatus($ret);
933
 
            }
934
 
            $this->assert(!$hasPassword, 'hasPassword after remove');
935
 
        } else {
936
 
            $this->assert(false, 'failed to create factory instance');
937
 
        }
938
 
    }
939
 
 
940
 
    /*** Test interactions with Hidden items ***/
941
 
 
942
 
    function testHideAlbumWithPasswordAlbum() {
943
 
        if (!isset($this->_hidden)) {
944
 
            /* Hidden module not active; skip test */
945
 
            return;
946
 
        }
947
 
        $ret = PasswordHelper::setPassword($this->_subAlbum, 'abc');
948
 
        if ($ret) {
949
 
            return $this->failWithStatus($ret);
950
 
        }
951
 
        GalleryDataCache::reset();
952
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_subAlbum->getId(), 'setup:', false);
953
 
        if ($ret) {
954
 
            return $this->failWithStatus($ret);
955
 
        }
956
 
 
957
 
        $ret = $this->_hidden->hideItem($this->_topAlbum);
958
 
        if ($ret) {
959
 
            return $this->failWithStatus($ret);
960
 
        }
961
 
 
962
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_subAlbum->getId(), 'album:',
963
 
                                      false, $this->_topAlbum->getId());
964
 
        if ($ret) {
965
 
            return $this->failWithStatus($ret);
966
 
        }
967
 
        for ($i = 0; $i < 3; $i++) {
968
 
            $ret = $this->_assertPassword($this->_subItems[$i], $this->_subAlbum->getId(),
969
 
                                          "item$i:", false);
970
 
            if ($ret) {
971
 
                return $this->failWithStatus($ret);
972
 
            }
973
 
        }
974
 
 
975
 
        GalleryDataCache::reset();
976
 
        $ret = $this->_hidden->unHideItem($this->_topAlbum);
977
 
        if ($ret) {
978
 
            return $this->failWithStatus($ret);
979
 
        }
980
 
 
981
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_subAlbum->getId(), 'un album:',
982
 
                                      false);
983
 
        if ($ret) {
984
 
            return $this->failWithStatus($ret);
985
 
        }
986
 
        for ($i = 0; $i < 3; $i++) {
987
 
            $ret = $this->_assertPassword($this->_subItems[$i], $this->_subAlbum->getId(),
988
 
                                          "un item$i:", false);
989
 
            if ($ret) {
990
 
                return $this->failWithStatus($ret);
991
 
            }
992
 
        }
993
 
    }
994
 
 
995
 
    function testPasswordAlbumInHiddenAlbum() {
996
 
        if (!isset($this->_hidden)) {
997
 
            /* Hidden module not active; skip test */
998
 
            return;
999
 
        }
1000
 
        $ret = $this->_hidden->hideItem($this->_topAlbum);
1001
 
        if ($ret) {
1002
 
            return $this->failWithStatus($ret);
1003
 
        }
1004
 
        GalleryDataCache::reset();
1005
 
        $permissions[] = $this->_fetchViewPermissions($this->_subAlbum->getId());
1006
 
        for ($i = 0; $i < 3; $i++) {
1007
 
            $permissions[] = $this->_fetchViewPermissions($this->_subItems[$i]->getId());
1008
 
        }
1009
 
 
1010
 
        $ret = PasswordHelper::setPassword($this->_subAlbum, 'abc');
1011
 
        if ($ret) {
1012
 
            return $this->failWithStatus($ret);
1013
 
        }
1014
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_subAlbum->getId(), 'album:',
1015
 
                                      false, $this->_topAlbum->getId());
1016
 
        if ($ret) {
1017
 
            return $this->failWithStatus($ret);
1018
 
        }
1019
 
        for ($i = 0; $i < 3; $i++) {
1020
 
            $ret = $this->_assertPassword($this->_subItems[$i], $this->_subAlbum->getId(),
1021
 
                                          "item$i:", false);
1022
 
            if ($ret) {
1023
 
                return $this->failWithStatus($ret);
1024
 
            }
1025
 
        }
1026
 
 
1027
 
        GalleryDataCache::reset();
1028
 
        $ret = PasswordHelper::removePassword($this->_subAlbum);
1029
 
        if ($ret) {
1030
 
            return $this->failWithStatus($ret);
1031
 
        }
1032
 
        $this->assertEquals($permissions[0],
1033
 
                            $this->_fetchViewPermissions($this->_subAlbum->getId()), 'unpw album');
1034
 
        for ($i = 0; $i < 3; $i++) {
1035
 
            $this->assertEquals($permissions[$i+1],
1036
 
                                $this->_fetchViewPermissions($this->_subItems[$i]->getId()),
1037
 
                                "unpw item$i");
1038
 
        }
1039
 
    }
1040
 
 
1041
 
    function testPasswordAlbumWithHiddenAlbum() {
1042
 
        if (!isset($this->_hidden)) {
1043
 
            /* Hidden module not active; skip test */
1044
 
            return;
1045
 
        }
1046
 
        $ret = $this->_hidden->hideItem($this->_subAlbum);
1047
 
        if ($ret) {
1048
 
            return $this->failWithStatus($ret);
1049
 
        }
1050
 
        GalleryDataCache::reset();
1051
 
        $permissions[] = $this->_fetchViewPermissions($this->_subAlbum->getId());
1052
 
        for ($i = 0; $i < 3; $i++) {
1053
 
            $permissions[] = $this->_fetchViewPermissions($this->_subItems[$i]->getId());
1054
 
        }
1055
 
 
1056
 
        $ret = PasswordHelper::setPassword($this->_topAlbum, 'abc');
1057
 
        if ($ret) {
1058
 
            return $this->failWithStatus($ret);
1059
 
        }
1060
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_topAlbum->getId(), 'album:',
1061
 
                                      false, $this->_subAlbum->getId(), true);
1062
 
        if ($ret) {
1063
 
            return $this->failWithStatus($ret);
1064
 
        }
1065
 
        for ($i = 0; $i < 3; $i++) {
1066
 
            $ret = $this->_assertPassword($this->_subItems[$i], $this->_topAlbum->getId(),
1067
 
                                          "item$i:", false, $this->_subAlbum->getId(), true);
1068
 
            if ($ret) {
1069
 
                return $this->failWithStatus($ret);
1070
 
            }
1071
 
        }
1072
 
 
1073
 
        GalleryDataCache::reset();
1074
 
        $ret = PasswordHelper::removePassword($this->_topAlbum);
1075
 
        if ($ret) {
1076
 
            return $this->failWithStatus($ret);
1077
 
        }
1078
 
        $this->assertEquals($permissions[0],
1079
 
                            $this->_fetchViewPermissions($this->_subAlbum->getId()), 'unpw album');
1080
 
        for ($i = 0; $i < 3; $i++) {
1081
 
            $this->assertEquals($permissions[$i+1],
1082
 
                                $this->_fetchViewPermissions($this->_subItems[$i]->getId()),
1083
 
                                "unpw item$i");
1084
 
        }
1085
 
    }
1086
 
 
1087
 
    function testHideAlbumInPasswordAlbum() {
1088
 
        if (!isset($this->_hidden)) {
1089
 
            /* Hidden module not active; skip test */
1090
 
            return;
1091
 
        }
1092
 
        $ret = PasswordHelper::setPassword($this->_topAlbum, 'abc');
1093
 
        if ($ret) {
1094
 
            return $this->failWithStatus($ret);
1095
 
        }
1096
 
        GalleryDataCache::reset();
1097
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_topAlbum->getId(), 'setup:', false);
1098
 
        if ($ret) {
1099
 
            return $this->failWithStatus($ret);
1100
 
        }
1101
 
 
1102
 
        $ret = $this->_hidden->hideItem($this->_subAlbum);
1103
 
        if ($ret) {
1104
 
            return $this->failWithStatus($ret);
1105
 
        }
1106
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_topAlbum->getId(), 'album:',
1107
 
                                      false, $this->_subAlbum->getId(), true);
1108
 
        if ($ret) {
1109
 
            return $this->failWithStatus($ret);
1110
 
        }
1111
 
        for ($i = 0; $i < 3; $i++) {
1112
 
            $ret = $this->_assertPassword($this->_subItems[$i], $this->_topAlbum->getId(),
1113
 
                                          "item$i:", false, $this->_subAlbum->getId(), true);
1114
 
            if ($ret) {
1115
 
                return $this->failWithStatus($ret);
1116
 
            }
1117
 
        }
1118
 
 
1119
 
        GalleryDataCache::reset();
1120
 
        $ret = $this->_hidden->unHideItem($this->_subAlbum);
1121
 
        if ($ret) {
1122
 
            return $this->failWithStatus($ret);
1123
 
        }
1124
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_topAlbum->getId(),
1125
 
                                      'un album:', false);
1126
 
        if ($ret) {
1127
 
            return $this->failWithStatus($ret);
1128
 
        }
1129
 
        for ($i = 0; $i < 3; $i++) {
1130
 
            $ret = $this->_assertPassword($this->_subItems[$i], $this->_topAlbum->getId(),
1131
 
                                          "un item$i:", false);
1132
 
            if ($ret) {
1133
 
                return $this->failWithStatus($ret);
1134
 
            }
1135
 
        }
1136
 
    }
1137
 
 
1138
 
    function testHidePasswordAlbum() {
1139
 
        if (!isset($this->_hidden)) {
1140
 
            /* Hidden module not active; skip test */
1141
 
            return;
1142
 
        }
1143
 
        $ret = PasswordHelper::setPassword($this->_topAlbum, 'abc');
1144
 
        if ($ret) {
1145
 
            return $this->failWithStatus($ret);
1146
 
        }
1147
 
        GalleryDataCache::reset();
1148
 
        $ret = $this->_assertPassword($this->_topAlbum, $this->_topAlbum->getId(), 'setup:');
1149
 
        if ($ret) {
1150
 
            return $this->failWithStatus($ret);
1151
 
        }
1152
 
 
1153
 
        $ret = $this->_hidden->hideItem($this->_topAlbum);
1154
 
        if ($ret) {
1155
 
            return $this->failWithStatus($ret);
1156
 
        }
1157
 
        $ret = $this->_assertPassword($this->_topAlbum, $this->_topAlbum->getId(), 'album:',
1158
 
                                      true, $this->_topAlbum->getId());
1159
 
        if ($ret) {
1160
 
            return $this->failWithStatus($ret);
1161
 
        }
1162
 
        for ($i = 0; $i < 3; $i++) {
1163
 
            $ret = $this->_assertPassword($this->_topItems[$i], $this->_topAlbum->getId(),
1164
 
                                          "item$i:");
1165
 
            if ($ret) {
1166
 
                return $this->failWithStatus($ret);
1167
 
            }
1168
 
        }
1169
 
 
1170
 
        GalleryDataCache::reset();
1171
 
        $ret = $this->_hidden->unHideItem($this->_topAlbum);
1172
 
        if ($ret) {
1173
 
            return $this->failWithStatus($ret);
1174
 
        }
1175
 
        $ret = $this->_assertPassword($this->_topAlbum, $this->_topAlbum->getId(), 'un album:');
1176
 
        if ($ret) {
1177
 
            return $this->failWithStatus($ret);
1178
 
        }
1179
 
        for ($i = 0; $i < 3; $i++) {
1180
 
            $ret = $this->_assertPassword($this->_topItems[$i], $this->_topAlbum->getId(),
1181
 
                                          "un item$i:");
1182
 
            if ($ret) {
1183
 
                return $this->failWithStatus($ret);
1184
 
            }
1185
 
        }
1186
 
    }
1187
 
 
1188
 
    function testPasswordHiddenAlbum() {
1189
 
        if (!isset($this->_hidden)) {
1190
 
            /* Hidden module not active; skip test */
1191
 
            return;
1192
 
        }
1193
 
        $ret = $this->_hidden->hideItem($this->_subAlbum);
1194
 
        if ($ret) {
1195
 
            return $this->failWithStatus($ret);
1196
 
        }
1197
 
        GalleryDataCache::reset();
1198
 
        $permissions[] = $this->_fetchViewPermissions($this->_subAlbum->getId());
1199
 
        for ($i = 0; $i < 3; $i++) {
1200
 
            $permissions[] = $this->_fetchViewPermissions($this->_subItems[$i]->getId());
1201
 
        }
1202
 
 
1203
 
        $ret = PasswordHelper::setPassword($this->_subAlbum, 'abc');
1204
 
        if ($ret) {
1205
 
            return $this->failWithStatus($ret);
1206
 
        }
1207
 
        $ret = $this->_assertPassword($this->_subAlbum, $this->_subAlbum->getId(), 'album:',
1208
 
                                      false, $this->_subAlbum->getId());
1209
 
        if ($ret) {
1210
 
            return $this->failWithStatus($ret);
1211
 
        }
1212
 
        for ($i = 0; $i < 3; $i++) {
1213
 
            $ret = $this->_assertPassword($this->_subItems[$i], $this->_subAlbum->getId(),
1214
 
                                          "item$i:", false);
1215
 
            if ($ret) {
1216
 
                return $this->failWithStatus($ret);
1217
 
            }
1218
 
        }
1219
 
 
1220
 
        GalleryDataCache::reset();
1221
 
        $ret = PasswordHelper::removePassword($this->_subAlbum);
1222
 
        if ($ret) {
1223
 
            return $this->failWithStatus($ret);
1224
 
        }
1225
 
        $this->assertEquals($permissions[0],
1226
 
                            $this->_fetchViewPermissions($this->_subAlbum->getId()), 'unpw album');
1227
 
        for ($i = 0; $i < 3; $i++) {
1228
 
            $this->assertEquals($permissions[$i+1],
1229
 
                                $this->_fetchViewPermissions($this->_subItems[$i]->getId()),
1230
 
                                "unpw item$i");
1231
 
        }
1232
 
    }
1233
 
}
1234
 
?>