~ubuntu-branches/ubuntu/hardy/gallery2/hardy-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-04-16 16:42:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060416164235-8uy0u4bfjdxpge2o
Tags: 2.1.1-1
* New upstream release (Closes: #362936)
  + Bugfixes for Postgres7 (Closes: #359000, #362152)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * $RCSfile: AlbumTest.class,v $
4
4
 *
5
5
 * Gallery - a web based photo album viewer and editor
6
 
 * Copyright (C) 2000-2005 Bharat Mediratta
 
6
 * Copyright (C) 2000-2006 Bharat Mediratta
7
7
 *
8
8
 * This program is free software; you can redistribute it and/or modify
9
9
 * it under the terms of the GNU General Public License as published by
20
20
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
21
21
 */
22
22
/**
23
 
 * @version $Revision: 1.38 $ $Date: 2005/08/30 04:02:53 $
 
23
 * @version $Revision: 1.41 $ $Date: 2006/01/13 03:39:32 $
24
24
 * @package GalleryCore
25
25
 * @subpackage PHPUnit
26
26
 * @author Bharat Mediratta <bharat@menalto.com>
43
43
        parent::setUp();
44
44
 
45
45
        list ($ret, $this->_parentAlbum) = $this->_createRandomAlbum($this->_getRootId());
46
 
        if ($ret->isError()) {
 
46
        if ($ret) {
47
47
            print $ret->getAsHtml();
48
48
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
49
49
        }
54
54
        $ret = GalleryCoreApi::registerFactoryImplementation(
55
55
            'GalleryToolkit', 'AlbumTestToolkit', 'AlbumTestToolkit',
56
56
            $path, 'coreTest', null);
57
 
        if ($ret->isError()) {
 
57
        if ($ret) {
58
58
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
59
59
        }
60
60
        $this->_markToolkitForCleanup('AlbumTestToolkit');
65
65
                array(array('type' => 'int', 'description' => 'test'),
66
66
                      array('type' => 'int', 'description' => 'test')),
67
67
                'test-description', '');
68
 
        if ($ret->isError()) {
 
68
        if ($ret) {
69
69
            print $ret->getAsHtml();
70
70
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
71
71
        }
72
72
 
73
73
        $ret = $this->_markPluginParametersForCleanup('module', 'core');
74
 
        if ($ret->isError()) {
 
74
        if ($ret) {
75
75
            print $ret->getAsHtml();
76
76
            return $ret->wrap(__FILE__, __LINE__);
77
77
        }
81
81
        global $gallery;
82
82
 
83
83
        list ($ret, $rootAlbum) = GalleryCoreApi::loadEntitiesById($this->_parentAlbum->getId());
84
 
        if ($ret->isError()) {
 
84
        if ($ret) {
85
85
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
86
86
        }
87
87
 
88
88
        if (!GalleryUtilities::isA($rootAlbum, 'GalleryAlbumItem')) {
89
89
            return $this->failWithStatus(
90
 
                GalleryStatus::error(ERROR_DELETED_OBJECT, __FILE__, __LINE__));
 
90
                GalleryCoreApi::error(ERROR_DELETED_OBJECT, __FILE__, __LINE__));
91
91
        }
92
92
    }
93
93
 
95
95
        global $gallery;
96
96
 
97
97
        list ($ret, $album) = $this->_createRandomAlbum($this->_parentAlbum->getId());
98
 
        if ($ret->isError()) {
 
98
        if ($ret) {
99
99
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
100
100
        }
101
101
 
102
102
        /* Verify it */
103
103
        $ret = $this->_verifyEntity($album);
104
 
        if ($ret->isError()) {
 
104
        if ($ret) {
105
105
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
106
106
        }
107
107
 
108
108
        /* Delete it */
109
109
        $ret = $this->_deleteAndVerifyEntity($album->getId());
110
 
        if ($ret->isError()) {
 
110
        if ($ret) {
111
111
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
112
112
        }
113
113
    }
116
116
        global $gallery;
117
117
 
118
118
        list ($ret, $album) = $this->_createRandomAlbum($this->_parentAlbum->getId());
119
 
        if ($ret->isError()) {
 
119
        if ($ret) {
120
120
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
121
121
        }
122
122
 
123
123
        /* Verify it */
124
124
        $ret = $this->_verifyEntity($album);
125
 
        if ($ret->isError()) {
 
125
        if ($ret) {
126
126
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
127
127
        }
128
128
 
129
129
        /* Lock and refresh it */
130
130
        list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($album->getId());
131
 
        if ($ret->isError()) {
 
131
        if ($ret) {
132
132
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
133
133
        }
134
134
 
135
135
        list ($ret, $album) = $album->refresh();
136
 
        if ($ret->isError()) {
 
136
        if ($ret) {
137
137
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
138
138
        }
139
139
 
140
140
        /* Rename it */
141
141
        $ret = $album->rename('newname-' . rand());
142
 
        if ($ret->isError()) {
 
142
        if ($ret) {
143
143
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
144
144
        }
145
145
 
146
146
        /* Save it */
147
147
        $ret = $album->save();
148
 
        if ($ret->isError()) {
 
148
        if ($ret) {
149
149
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
150
150
        }
151
151
 
152
152
        /* Unlock it */
153
153
        $ret = GalleryCoreApi::releaseLocks($lockId);
154
 
        if ($ret->isError()) {
 
154
        if ($ret) {
155
155
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
156
156
        }
157
157
 
158
158
        /* Verify it */
159
159
        $ret = $this->_verifyEntity($album);
160
 
        if ($ret->isError()) {
 
160
        if ($ret) {
161
161
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
162
162
        }
163
163
 
164
164
        /* Delete it */
165
165
        $ret = $this->_deleteAndVerifyEntity($album->getId());
166
 
        if ($ret->isError()) {
 
166
        if ($ret) {
167
167
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
168
168
        }
169
169
    }
178
178
            $gallery->guaranteeTimeLimit(5);
179
179
 
180
180
            list ($ret, $nested[$i]) = $this->_createRandomAlbum($parentId);
181
 
            if ($ret->isError()) {
 
181
            if ($ret) {
182
182
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
183
183
            }
184
184
 
186
186
        }
187
187
 
188
188
        $ret = $this->_deleteAndVerifyEntity($nested[0]->getId());
189
 
        if ($ret->isError()) {
 
189
        if ($ret) {
190
190
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
191
191
        }
192
192
 
193
193
        for ($i = 0; $i < $iterations; $i++) {
194
194
            $ret = $this->_verifyMissing($nested[$i]->getId());
195
 
            if ($ret->isError()) {
 
195
            if ($ret) {
196
196
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
197
197
            }
198
198
        }
211
211
        $parentId = $this->_parentAlbum->getId();
212
212
        for ($i = 0; $i < 3; $i++) {
213
213
            list ($ret, $album[$i]) = $this->_createRandomAlbum($parentId);
214
 
            if ($ret->isError()) {
 
214
            if ($ret) {
215
215
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
216
216
            }
217
217
            $parentId = $album[$i]->getId();
226
226
        for ($i = 0; $i < 3; $i++) {
227
227
            list ($ret, $parentSequence[$i]) =
228
228
                GalleryCoreApi::fetchParentSequence($album[$i]->getId());
229
 
            if ($ret->isError()) {
 
229
            if ($ret) {
230
230
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
231
231
            }
232
232
        }
250
250
        /* Read lock the root, write lock the two new albums */
251
251
        list ($ret, $lockIds[]) =
252
252
            GalleryCoreApi::acquireReadLock(array($this->_parentAlbum->getId()));
253
 
        if ($ret->isError()) {
 
253
        if ($ret) {
254
254
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
255
255
        }
256
256
 
257
257
        list ($ret, $lockIds[]) = GalleryCoreApi::acquireWriteLock(array($album[0]->getId(),
258
258
                                                                   $album[1]->getId(),
259
259
                                                                   ));
260
 
        if ($ret->isError()) {
 
260
        if ($ret) {
261
261
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
262
262
        }
263
263
 
264
264
        for ($i = 0; $i < 2; $i++) {
265
265
            list ($ret, $album[$i]) = $album[$i]->refresh();
266
 
            if ($ret->isError()) {
 
266
            if ($ret) {
267
267
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
268
268
            }
269
269
        }
270
270
 
271
271
        /* Move one of the target albums */
272
272
        $ret = $album[1]->move($this->_parentAlbum->getId());
273
 
        if ($ret->isError()) {
 
273
        if ($ret) {
274
274
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
275
275
        }
276
276
 
277
277
        /* Save it */
278
278
        $ret = $album[1]->save();
279
 
        if ($ret->isError()) {
 
279
        if ($ret) {
280
280
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
281
281
        }
282
282
 
283
283
        $ret = GalleryCoreApi::releaseLocks($lockIds);
284
 
        if ($ret->isError()) {
 
284
        if ($ret) {
285
285
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
286
286
        }
287
287
 
288
288
        /* Verify parents */
289
289
        for ($i = 0; $i < 2; $i++) {
290
290
            list ($ret, $album[$i]) = $album[$i]->refresh();
291
 
            if ($ret->isError()) {
 
291
            if ($ret) {
292
292
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
293
293
            }
294
294
        }
302
302
        for ($i = 0; $i < 3; $i++) {
303
303
            list ($ret, $parentSequence[$i]) =
304
304
                GalleryCoreApi::fetchParentSequence($album[$i]->getId());
305
 
            if ($ret->isError()) {
 
305
            if ($ret) {
306
306
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
307
307
            }
308
308
        }
333
333
            $gallery->guaranteeTimeLimit(5);
334
334
 
335
335
            list ($ret, $nested[$i]) = $this->_createRandomAlbum($parentId);
336
 
            if ($ret->isError()) {
 
336
            if ($ret) {
337
337
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
338
338
            }
339
339
 
342
342
 
343
343
        /* Now we've created our nested tree.  Fetch it all back again */
344
344
        list ($ret, $actual) = GalleryCoreApi::fetchParents($nested[$iterations-1]);
345
 
        if ($ret->isError()) {
 
345
        if ($ret) {
346
346
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
347
347
        }
348
348
 
349
349
        list ($ret, $expected[0]) = GalleryCoreApi::loadEntitiesById($this->_getRootId());
350
 
        if ($ret->isError()) {
 
350
        if ($ret) {
351
351
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
352
352
        }
353
353
        list ($ret, $expected[1]) = GalleryCoreApi::loadEntitiesById($this->_parentAlbum->getId());
354
 
        if ($ret->isError()) {
 
354
        if ($ret) {
355
355
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
356
356
        }
357
357
        for ($i = 0; $i < sizeof($nested)-1; $i++) {
363
363
 
364
364
    function testFetchParentsWithPermission() {
365
365
        list ($ret, $album) = $this->_createRandomAlbum($this->_parentAlbum->getId());
366
 
        if ($ret->isError()) {
 
366
        if ($ret) {
367
367
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
368
368
        }
369
369
        list ($ret, $subalbum) = $this->_createRandomAlbum($album->getId());
370
 
        if ($ret->isError()) {
 
370
        if ($ret) {
371
371
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
372
372
        }
373
373
        $ret = GalleryCoreApi::removeItemPermissions($this->_parentAlbum->getId());
374
 
        if ($ret->isError()) {
 
374
        if ($ret) {
375
375
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
376
376
        }
377
377
        list ($ret, $root) = GalleryCoreApi::loadEntitiesById($this->_getRootId());
378
 
        if ($ret->isError()) {
 
378
        if ($ret) {
379
379
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
380
380
        }
381
381
 
382
382
        list ($ret, $actual) = GalleryCoreApi::fetchParents($subalbum, 'core.view');
383
 
        if ($ret->isError()) {
 
383
        if ($ret) {
384
384
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
385
385
        }
386
386
 
392
392
        $this->_becomeGuestUser();
393
393
        GalleryDataCache::clearPermissionCache();
394
394
        $ret = GalleryCoreApi::assertHasItemPermission($this->_getRootId(), 'core.delete');
395
 
        if ($ret->isSuccess()) {
 
395
        if (!$ret) {
396
396
            $this->assert(false, 'Guest should not have core.delete on root album');
397
397
            return;
398
398
        }
399
399
 
400
400
        list ($ret, $actual) = GalleryCoreApi::fetchParents($this->_parentAlbum, 'core.delete');
401
 
        if ($ret->isError()) {
 
401
        if ($ret) {
402
402
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
403
403
        }
404
404
 
413
413
        global $gallery;
414
414
 
415
415
        list ($ret, $parent) = $this->_createRandomAlbum($this->_parentAlbum->getId());
416
 
        if ($ret->isError()) {
 
416
        if ($ret) {
417
417
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
418
418
        }
419
419
 
420
420
        list ($ret, $child) = $this->_createRandomAlbum($parent->getId());
421
 
        if ($ret->isError()) {
 
421
        if ($ret) {
422
422
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
423
423
        }
424
424
 
425
425
        GalleryDataCache::reset();
426
426
 
427
427
        list ($ret, $actual) = GalleryCoreApi::fetchChildItemIds($parent);
428
 
        if ($ret->isError()) {
 
428
        if ($ret) {
429
429
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
430
430
        }
431
431
 
436
436
        /* Album has no thumbnail, no children */
437
437
        list ($ret, $success) =
438
438
            GalleryCoreApi::guaranteeAlbumHasThumbnail($this->_parentAlbum->getId());
439
 
        if ($ret->isError()) {
 
439
        if ($ret) {
440
440
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
441
441
        }
442
442
 
448
448
        /* Album has no thumbnail, 1 child */
449
449
        list ($ret, $child) =
450
450
            $this->_createRandomDataItem($this->_parentAlbum->getId(), 'test/file');
451
 
        if ($ret->isError()) {
 
451
        if ($ret) {
452
452
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
453
453
        }
454
454
 
455
455
        list ($ret, $success) =
456
456
            GalleryCoreApi::guaranteeAlbumHasThumbnail($this->_parentAlbum->getId());
457
 
        if ($ret->isError()) {
 
457
        if ($ret) {
458
458
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
459
459
        }
460
460
 
463
463
 
464
464
        list ($ret, $thumbTable) =
465
465
            GalleryCoreApi::fetchThumbnailsByItemIds(array($this->_parentAlbum->getId()));
466
 
        if ($ret->isError()) {
 
466
        if ($ret) {
467
467
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
468
468
        }
469
469
 
478
478
    function testGuaranteeAlbumHasThumbnail3() {
479
479
        /* Album has a thumbnail but its source isn't in the album, 1 child */
480
480
        list ($ret, $subAlbum) = $this->_createRandomAlbum($this->_parentAlbum->getId());
481
 
        if ($ret->isError()) {
 
481
        if ($ret) {
482
482
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
483
483
        }
484
484
 
485
485
        /* Create a thumbnail sourced from the parent album */
486
486
        list ($ret, $derivative) =
487
487
            GalleryCoreApi::newFactoryInstanceByHint('GalleryDerivative', '*');
488
 
        if ($ret->isError()) {
 
488
        if ($ret) {
489
489
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
490
490
        }
491
491
 
492
 
        $ret = $derivative->create($subAlbum->getId(), DERIVATIVE_TYPE_IMAGE_THUMBNAIL, 'test/file');
493
 
        if ($ret->isError()) {
 
492
        $ret = $derivative->create($subAlbum->getId(), DERIVATIVE_TYPE_IMAGE_THUMBNAIL,
 
493
                                   'test/file');
 
494
        if ($ret) {
494
495
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
495
496
        }
496
497
        $derivative->setMimeType('test/file');
497
498
        $derivative->setDerivativeSourceId($this->_parentAlbum->getId());
498
499
        $derivative->setDerivativeOperations('thumbnail|150');
499
500
        $ret = $derivative->save();
500
 
        if ($ret->isError()) {
 
501
        if ($ret) {
501
502
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
502
503
        }
503
504
 
504
505
        list ($ret, $child) = $this->_createRandomDataItem($subAlbum->getId(), 'test/file');
505
 
        if ($ret->isError()) {
 
506
        if ($ret) {
506
507
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
507
508
        }
508
509
 
509
510
        list ($ret, $success) = GalleryCoreApi::guaranteeAlbumHasThumbnail($subAlbum->getId());
510
 
        if ($ret->isError()) {
 
511
        if ($ret) {
511
512
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
512
513
        }
513
514
 
517
518
        /* Reload the thumbnail and examine it */
518
519
        list ($ret, $thumbTable) =
519
520
            GalleryCoreApi::fetchThumbnailsByItemIds(array($subAlbum->getId()));
520
 
        if ($ret->isError()) {
 
521
        if ($ret) {
521
522
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
522
523
        }
523
524
 
538
539
        global $gallery;
539
540
 
540
541
        list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock($this->_parentAlbum->getId());
541
 
        if ($ret->isError()) {
 
542
        if ($ret) {
542
543
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
543
544
        }
544
545
 
545
546
        list ($ret, $basePath) = $this->_parentAlbum->fetchPath();
546
 
        if ($ret->isError()) {
 
547
        if ($ret) {
547
548
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
548
549
        }
549
550
 
550
 
        $platform = $gallery->getPlatform();
 
551
        $platform =& $gallery->getPlatform();
551
552
        $slash = $platform->getDirectorySeparator();
552
553
 
553
554
        for ($i = 0; $i < 3; $i++) {
554
555
            $entity[$i] = new GalleryAlbumItem();
555
556
            $ret = $entity[$i]->create($this->_parentAlbum->getId(), 'valid_path');
556
 
            if ($ret->isError()) {
 
557
            if ($ret) {
557
558
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
558
559
            }
559
560
 
560
561
            $ret = $entity[$i]->save();
561
 
            if ($ret->isError()) {
 
562
            if ($ret) {
562
563
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
563
564
            }
564
565
 
568
569
                                    'path component mismatch');
569
570
 
570
571
                list ($ret, $entityPath) = $entity[$i]->fetchPath();
571
 
                if ($ret->isError()) {
 
572
                if ($ret) {
572
573
                    return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
573
574
                }
574
575
 
581
582
        }
582
583
 
583
584
        $ret = GalleryCoreApi::releaseLocks($lockId);
584
 
        if ($ret->isError()) {
 
585
        if ($ret) {
585
586
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
586
587
        }
587
588
    }
590
591
        global $gallery;
591
592
 
592
593
        list ($ret, $outerAlbum) = $this->_createRandomAlbum($this->_parentAlbum->getId());
593
 
        if ($ret->isError()) {
 
594
        if ($ret) {
594
595
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
595
596
        }
596
597
 
597
598
        list ($ret, $innerAlbum) = $this->_createRandomAlbum($outerAlbum->getId());
598
 
        if ($ret->isError()) {
 
599
        if ($ret) {
599
600
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
600
601
        }
601
602
 
602
603
        list ($ret, $lockIds[]) = GalleryCoreApi::acquireReadLock(
603
604
            array($this->_getRootId(), $this->_parentAlbum->getId()));
 
605
        if ($ret) {
 
606
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
607
        }
604
608
 
605
609
        list ($ret, $lockIds[]) =
606
610
            GalleryCoreApi::acquireWriteLock(array($innerAlbum->getId(), $outerAlbum->getId()));
 
611
        if ($ret) {
 
612
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
613
        }
607
614
 
608
615
        $ret = $innerAlbum->rename('test');
609
 
        if ($ret->isError()) {
 
616
        if ($ret) {
610
617
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
611
618
        }
612
619
        $ret = $innerAlbum->save();
613
 
        if ($ret->isError()) {
 
620
        if ($ret) {
614
621
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
615
622
        }
616
623
 
617
624
        $ret = $outerAlbum->rename('test');
618
 
        if ($ret->isError()) {
 
625
        if ($ret) {
619
626
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
620
627
        }
621
628
        $ret = $outerAlbum->save();
622
 
        if ($ret->isError()) {
 
629
        if ($ret) {
623
630
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
624
631
        }
625
632
 
626
633
        $ret = $innerAlbum->move($this->_parentAlbum->getId());
627
 
        if ($ret->isError()) {
 
634
        if ($ret) {
628
635
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
629
636
        }
630
637
 
631
638
        list ($ret, $basePath) = $this->_parentAlbum->fetchPath();
632
 
        if ($ret->isError()) {
 
639
        if ($ret) {
633
640
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
634
641
        }
635
642
 
636
643
        list ($ret, $newPath) = $innerAlbum->fetchPath();
637
 
        if ($ret->isError()) {
 
644
        if ($ret) {
638
645
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
639
646
        }
640
647
 
641
 
        $platform = $gallery->getPlatform();
 
648
        $platform =& $gallery->getPlatform();
642
649
        $slash = $platform->getDirectorySeparator();
643
650
        $this->assertEquals($basePath . 'test_001' . $slash, $newPath, 'full path mismatch');
644
651
 
645
 
        $platform = $gallery->getPlatform();
646
652
        $this->assert($platform->file_exists($newPath), "$newPath does not exist");
647
653
        $this->assert($platform->is_dir($newPath), "$newPath is not a file");
648
654
 
649
655
        $ret = GalleryCoreApi::releaseLocks($lockIds);
650
 
        if ($ret->isError()) {
 
656
        if ($ret) {
651
657
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
652
658
        }
653
659
    }
658
664
        /* Create an album with one group of settings */
659
665
        list ($ret, $album) = $this->_createRandomAlbum(
660
666
            $this->_parentAlbum->getId(),
661
 
            array('theme' => 'a', 'orderby' => 'b', 'orderdirection' => 'c'));
662
 
        if ($ret->isError()) {
 
667
            array('theme' => 'a', 'orderBy' => 'b', 'orderDirection' => 'c'));
 
668
        if ($ret) {
663
669
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
664
670
        }
665
671
 
670
676
                       'default.newAlbumsUseDefaults' => 'false')
671
677
                 as $key => $value) {
672
678
            $ret = GalleryCoreApi::setPluginParameter('module', 'core', $key, $value);
673
 
            if ($ret->isError()) {
 
679
            if ($ret) {
674
680
                return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
675
681
            }
676
682
        }
677
683
 
678
684
        /* Create a sub album.  It should inherit from the parent */
679
685
        list ($ret, $child1) = $this->_createRandomAlbum($album->getId());
680
 
        if ($ret->isError()) {
 
686
        if ($ret) {
681
687
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
682
688
        }
683
689
 
688
694
        /* Now switch to using the defaults */
689
695
        $ret = GalleryCoreApi::setPluginParameter(
690
696
            'module', 'core', 'default.newAlbumsUseDefaults', 'true');
691
 
        if ($ret->isError()) {
 
697
        if ($ret) {
692
698
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
693
699
        }
694
700
 
695
701
        /* Create a sub album.  It should pick up the defaults */
696
702
        list ($ret, $child2) = $this->_createRandomAlbum($album->getId());
697
 
        if ($ret->isError()) {
 
703
        if ($ret) {
698
704
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
699
705
        }
700
706
 
712
718
         *                \_1-3 \_5--6--7  should appear as a child of 2 in the tree
713
719
         */
714
720
        list ($ret, $album[0]) = $this->_createRandomAlbum($this->_parentAlbum->getId());
715
 
        if ($ret->isError()) {
 
721
        if ($ret) {
716
722
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
717
723
        }
718
724
        list ($ret, $album[1]) = $this->_createRandomAlbum($this->_parentAlbum->getId());
719
 
        if ($ret->isError()) {
 
725
        if ($ret) {
720
726
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
721
727
        }
722
728
        list ($ret, $album[2]) = $this->_createRandomAlbum($album[0]->getId());
723
 
        if ($ret->isError()) {
 
729
        if ($ret) {
724
730
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
725
731
        }
726
732
        list ($ret, $album[3]) = $this->_createRandomAlbum($album[1]->getId());
727
 
        if ($ret->isError()) {
 
733
        if ($ret) {
728
734
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
729
735
        }
730
736
        list ($ret, $album[4]) = $this->_createRandomAlbum($album[2]->getId());
731
 
        if ($ret->isError()) {
 
737
        if ($ret) {
732
738
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
733
739
        }
734
740
        list ($ret, $album[5]) = $this->_createRandomAlbum($album[2]->getId());
735
 
        if ($ret->isError()) {
 
741
        if ($ret) {
736
742
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
737
743
        }
738
744
        list ($ret, $album[6]) = $this->_createRandomAlbum($album[5]->getId());
739
 
        if ($ret->isError()) {
 
745
        if ($ret) {
740
746
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
741
747
        }
742
748
        list ($ret, $album[7]) = $this->_createRandomAlbum($album[6]->getId());
743
 
        if ($ret->isError()) {
 
749
        if ($ret) {
744
750
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
745
751
        }
746
752
        $ret = GalleryCoreApi::removeItemPermissions($album[5]->getId());
747
 
        if ($ret->isError()) {
 
753
        if ($ret) {
748
754
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
749
755
        }
750
756
 
772
778
                        $album[3]->getId());
773
779
 
774
780
        list ($ret, $tree) = GalleryCoreApi::fetchAlbumTree($this->_parentAlbum->getId());
775
 
        if ($ret->isError()) {
 
781
        if ($ret) {
776
782
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
777
783
        }
778
784
        $this->assertEquals($fullTree, $tree, 'full tree');
781
787
        $this->assertEquals($allIds, $ids, 'all ids');
782
788
 
783
789
        list ($ret, $tree) = GalleryCoreApi::fetchAlbumTree($album[0]->getId());
784
 
        if ($ret->isError()) {
 
790
        if ($ret) {
785
791
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
786
792
        }
787
793
        $this->assertEquals($subTree, $tree, 'sub tree');
788
794
 
789
795
        list ($ret, $tree) = GalleryCoreApi::fetchAlbumTree($this->_parentAlbum->getId(), 2);
790
 
        if ($ret->isError()) {
 
796
        if ($ret) {
791
797
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
792
798
        }
793
799
        $this->assertEquals($depthTree, $tree, 'depth tree');
794
800
 
795
801
        list ($ret, $tree) = GalleryCoreApi::fetchAlbumTree(null, 1);
796
 
        if ($ret->isError()) {
 
802
        if ($ret) {
797
803
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
798
804
        }
799
805
        $this->assertEquals(array(), $tree[$this->_parentAlbum->getId()], 'test album');
803
809
 
804
810
    function testFetchAlbumTreeNoPermissions() {
805
811
        global $gallery;
 
812
        $session =& $gallery->getSession();
806
813
 
807
814
        list ($ret, $user) = $this->_createRandomUser();
808
 
        if ($ret->isError()) {
 
815
        if ($ret) {
809
816
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
810
817
        }
811
818
        $this->_markForCleanup($user);
812
819
 
813
820
        /* Delete all acls for this user */
814
 
        GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryAccessMap.class');
815
 
        $ret = GalleryAccessMap::removeMapEntry(array('userId' => $user->getId()));
816
 
        if ($ret->isError()) {
 
821
        $ret = GalleryCoreApi::removeMapEntry(
 
822
            'GalleryAccessMap', array('userOrGroupId' => $user->getId()));
 
823
        if ($ret) {
817
824
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
818
825
        }
819
826
        GalleryDataCache::reset();
823
830
         * some permissions.
824
831
         */
825
832
        $ret = GalleryCoreApi::removeUserFromAllGroups($user->getId());
826
 
        if ($ret->isError()) {
 
833
        if ($ret) {
827
834
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
828
835
        }
829
836
 
830
837
        /* Put user in some random group that has no permissions */
831
838
        list ($ret, $group) = $this->_createRandomGroup();
832
 
        if ($ret->isError()) {
 
839
        if ($ret) {
833
840
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
834
841
        }
835
842
        $this->_markForCleanup($group);
836
843
 
837
844
        $ret = GalleryCoreApi::addUserToGroup($user->getId(), $group->getId());
838
 
        if ($ret->isError()) {
 
845
        if ($ret) {
839
846
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
840
847
        }
841
848
 
 
849
        /* Clear any session permissions */
 
850
        $session->remove(GALLERY_PERMISSION_SESSION_KEY);
 
851
 
842
852
        $gallery->setActiveUser($user);
843
853
 
844
854
        /* Verify that the album tree is empty */
845
855
        list ($ret, $tree) = GalleryCoreApi::fetchAlbumTree($this->_getRootId());
846
 
        if ($ret->isError()) {
 
856
        if ($ret) {
847
857
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
848
858
        }
849
859
 
857
867
        list ($ret, $album) = GalleryCoreApi::createAlbum(
858
868
            $this->_parentAlbum->getId(), $albumName,
859
869
            'title', 'summary', 'description', 'keywords');
860
 
        if ($ret->isError()) {
 
870
        if ($ret) {
861
871
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
862
872
        }
863
873
 
864
874
        list ($ret, $album) = $album->refresh();
865
 
        if ($ret->isError()) {
 
875
        if ($ret) {
866
876
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
867
877
        }
868
878
 
869
879
        list ($ret, $path) = $album->fetchPath();
870
 
        if ($ret->isError()) {
 
880
        if ($ret) {
871
881
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
872
882
        }
873
883
 
878
888
         * Verify that the path in the database matches the path on disk, since we're expecting
879
889
         * that the whitespace will get trimmed on both sides.
880
890
         */
881
 
        $platform = $gallery->getPlatform();
 
891
        $platform =& $gallery->getPlatform();
882
892
        $this->assert($platform->file_exists($path), 'Path doesn\'t exist');
883
893
    }
884
894
 
886
896
        global $gallery;
887
897
 
888
898
        list ($ret, $album) = $this->_createRandomAlbum($this->_parentAlbum->getId());
889
 
        if ($ret->isError()) {
 
899
        if ($ret) {
890
900
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
891
901
        }
892
902
 
893
903
        $newAlbumName = sprintf(' album %d test ', rand());
894
904
 
895
905
        list ($ret, $locks[]) = GalleryCoreApi::acquireWriteLock($album->getId());
896
 
        if ($ret->isError()) {
 
906
        if ($ret) {
897
907
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
898
908
        }
899
909
 
900
910
        $ret = $album->rename($newAlbumName);
901
 
        if ($ret->isError()) {
 
911
        if ($ret) {
902
912
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
903
913
        }
904
914
 
905
915
        $ret = $album->save();
906
 
        if ($ret->isError()) {
 
916
        if ($ret) {
907
917
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
908
918
        }
909
919
 
910
920
        list ($ret, $album) = $album->refresh();
911
 
        if ($ret->isError()) {
 
921
        if ($ret) {
912
922
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
913
923
        }
914
924
 
915
925
        list ($ret, $path) = $album->fetchPath();
916
 
        if ($ret->isError()) {
 
926
        if ($ret) {
917
927
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
918
928
        }
919
929
 
920
930
        $ret = GalleryCoreApi::releaseLocks($locks);
921
 
        if ($ret->isError()) {
 
931
        if ($ret) {
922
932
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
923
933
        }
924
934
 
926
936
         * Verify that the path in the database matches the path on disk, since we're expecting
927
937
         * that the whitespace will get trimmed on both sides.
928
938
         */
929
 
        $platform = $gallery->getPlatform();
 
939
        $platform =& $gallery->getPlatform();
930
940
        $this->assert($platform->file_exists($path), 'Path doesn\'t exist');
931
941
 
932
942
        $this->assertEquals(trim($newAlbumName), basename($path));
937
947
/**
938
948
 * Required by our test toolkit
939
949
 */
940
 
GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryToolkit.class');
 
950
GalleryCoreApi::requireOnce('modules/core/classes/GalleryToolkit.class');
941
951
 
942
952
/**
943
953
 * Dummy test toolkit
954
964
                              $destFilename, $parameters, $context=array()) {
955
965
        global $gallery;
956
966
        if ($sourceFilename != $destFilename) {
957
 
            $platform = $gallery->getPlatform();
 
967
            $platform =& $gallery->getPlatform();
958
968
            $platform->copy($sourceFilename, $destFilename);
959
969
        }
960
 
        return array(GalleryStatus::success(), $mimeType, $context);
 
970
        return array(null, $mimeType, $context);
961
971
    }
962
972
}
963
973
?>