3
* Gallery - a web based photo album viewer and editor
4
* Copyright (C) 2000-2007 Bharat Mediratta
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or (at
9
* your option) any later version.
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
22
* Test Item functionality
23
* @package GalleryCore
25
* @author Bharat Mediratta <bharat@menalto.com>
26
* @version $Revision: 15628 $
28
class ItemTest extends GalleryTestCase {
30
function ItemTest($methodName) {
31
$this->GalleryTestCase($methodName);
39
$this->_userId = $gallery->getActiveUserId();
40
list ($ret, $groupIds) = GalleryCoreApi::fetchGroupsForUser($this->_userId);
42
return $this->failWithStatus($ret);
45
$groupIds = array_keys($groupIds);
46
$this->_groupId = $groupIds[0];
48
list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
50
return $this->failWithStatus($ret);
53
$this->_markForCleanup($this->_album);
55
/* Register a dummy toolkit */
56
$path = 'modules/core/test/phpunit/ItemTest.class';
57
$ret = GalleryCoreApi::registerFactoryImplementation(
58
'GalleryToolkit', 'ItemTestToolkit', 'ItemTestToolkit',
59
$path, 'coreTest', null);
61
print $ret->getAsHtml();
62
return $this->failWithStatus($ret);
64
$this->_markToolkitForCleanup('ItemTestToolkit');
66
/* Register jpeg thumbnail/gif scale in case there are no other toolkits active */
67
$ret = GalleryCoreApi::registerToolkitOperation(
68
'ItemTestToolkit', array('test/image', 'image/jpeg', 'image/gif'), 'thumbnail',
69
array(array('type' => 'int', 'description' => 'foo'),
70
array('type' => 'int', 'description' => 'foo')),
71
'itemtest-description', '', 7);
73
print $ret->getAsHtml();
74
return $this->failWithStatus($ret);
76
$ret = GalleryCoreApi::registerToolkitOperation(
77
'ItemTestToolkit', array('image/gif'), 'scale',
78
array(array('type' => 'int', 'description' => 'foo'),
79
array('type' => 'int', 'description' => 'foo')),
80
'itemtest-description', '', 7);
82
print $ret->getAsHtml();
83
return $this->failWithStatus($ret);
85
$ret = GalleryCoreApi::registerToolkitProperty(
86
'ItemTestToolkit', array('image/gif', 'image/jpeg'),
87
'dimensions', 'int,int', 'Get the dimensions');
89
print $ret->getAsHtml();
90
return $this->failWithStatus($ret);
93
/* Register a conversion operation that we can perform on our mock data items */
94
$ret = GalleryCoreApi::registerToolkitOperation(
95
'ItemTestToolkit', array('test/movie', 'image/x-portable-pixmap'),
96
'convert-to-image/jpeg', array(), 'itemtest-description', 'image/jpeg', 7);
98
print $ret->getAsHtml();
99
return $this->failWithStatus($ret);
102
$ret = GalleryCoreApi::registerFactoryImplementation(
103
'GalleryItem', 'ItemTestMovieItem', 'ItemTestMovieItem',
104
$path, 'coreTest', array('test/movie'));
105
$this->_markFactoryModuleForCleanup('coreTest');
107
print $ret->getAsHtml();
108
return $this->failWithStatus($ret);
111
$ret = GalleryCoreApi::registerFactoryImplementation(
112
'GalleryRenderer', 'ItemTestRenderer', 'ItemTestRenderer', $path, 'coreTest', null);
114
print $ret->getAsHtml();
115
return $this->failWithStatus($ret);
119
function testNewItemByMimeType() {
120
list ($ret, $instance) = GalleryCoreApi::newItemByMimeType('image/jpeg');
122
return $this->failWithStatus($ret);
124
$this->assert(GalleryUtilities::isExactlyA($instance, 'GalleryPhotoItem'));
126
list ($ret, $instance) = GalleryCoreApi::newItemByMimeType('image/randomimagetype');
128
return $this->failWithStatus($ret);
130
$this->assert(GalleryUtilities::isExactlyA($instance, 'GalleryPhotoItem'));
132
list ($ret, $instance) = GalleryCoreApi::newItemByMimeType('video/x-msvideo');
134
return $this->failWithStatus($ret);
136
$this->assert(GalleryUtilities::isExactlyA($instance, 'GalleryMovieItem'));
138
list ($ret, $instance) = GalleryCoreApi::newItemByMimeType('randomtype/randomtype');
140
return $this->failWithStatus($ret);
142
$this->assert(GalleryUtilities::isExactlyA($instance, 'GalleryUnknownItem'));
145
function testCanBeViewedInlineImages() {
146
/* This list should be mime types accepted by browsers in the <img> tag */
147
$mimeTypesInline = array(
148
'image/jpeg' => true,
149
'image/pjpeg' => true,
152
'image/vnd.wap.wbmp' => true,
153
'image/tiff' => false,
154
'image/bmp' => false, /* only IE accepts this one */
155
'image/otherUnknown' => false,
156
'application/photoshop' => false,
158
foreach ($mimeTypesInline as $mimeType => $canBeViewedInline) {
159
list ($ret, $instance) = GalleryCoreApi::newItemByMimeType($mimeType);
161
return $this->failWithStatus($ret);
163
$this->assert(GalleryUtilities::isExactlyA($instance, 'GalleryPhotoItem'));
164
$instance->setMimeType($mimeType);
165
$this->assertEquals($canBeViewedInline, $instance->canBeViewedInline(), $mimeType);
170
function testCanBeViewedInlineOthers() {
173
SELECT [GalleryMimeTypeMap::mimeType]
174
FROM [GalleryMimeTypeMap]
175
WHERE [GalleryMimeTypeMap::mimeType] NOT LIKE \'image/%\'
177
list ($ret, $searchResults) = $gallery->search($query);
179
return $this->failWithStatus($ret);
181
while ($results = $searchResults->nextResult()) {
182
$mimeType = $results[0];
183
if ($mimeType == 'application/photoshop') {
186
list ($ret, $instance) = GalleryCoreApi::newItemByMimeType($mimeType);
188
return $this->failWithStatus($ret);
190
$instance->setMimeType($mimeType);
191
if (GalleryUtilities::isExactlyA($instance, 'GalleryMovieItem')
192
|| GalleryUtilities::isExactlyA($instance, 'GalleryAnimationItem')) {
193
$instance->setWidth(100);
194
$instance->setHeight(100);
196
/* We need to be able to render what we can view inline */
197
$html = $instance->render('HTML', array('fallback' => 'ERROR', 'class' => 'test'));
198
$inlineOk = ($html != 'ERROR' && $html != null);
199
$this->assertEquals($inlineOk, $instance->canBeViewedInline(), $mimeType);
203
function testCanBeViewedInlineRenderer() {
204
list ($ret, $instance) = GalleryCoreApi::newItemByMimeType('image/jpeg');
206
return $this->failWithStatus($ret);
208
$instance->setMimeType('image/jpeg');
209
$this->assert($instance->canBeViewedInline(), 'jpeg');
210
$instance->setRenderer('ItemTestRenderer');
211
$this->assert(!$instance->canBeViewedInline(), 'jpeg renderer');
213
list ($ret, $instance) = GalleryCoreApi::newItemByMimeType('test/item');
215
return $this->failWithStatus($ret);
217
$instance->setMimeType('test/item');
218
$this->assert(!$instance->canBeViewedInline(), 'test item');
219
$instance->setRenderer('ItemTestRenderer');
220
$this->assert($instance->canBeViewedInline(), 'test item renderer');
223
function testGetChildCounts() {
224
for ($i = 0; $i < 3; $i++) {
225
list ($ret, $child[$i]) = $this->_createRandomAlbum($this->_album->getId());
227
return $this->failWithStatus($ret);
230
/* Remove all permissions */
231
$ret = GalleryCoreApi::removeItemPermissions($child[$i]->getId());
233
return $this->failWithStatus($ret);
237
/* Set permissions */
238
$ret = GalleryCoreApi::addUserPermission(
239
$child[0]->getId(), $this->_userId, 'core.view', false);
241
return $this->failWithStatus($ret);
244
$ret = GalleryCoreApi::addGroupPermission(
245
$child[1]->getId(), $this->_groupId, 'core.view', false);
247
return $this->failWithStatus($ret);
250
list ($ret, $counts) = GalleryCoreApi::fetchChildCounts(array($this->_album->getId()));
252
return $this->failWithStatus($ret);
255
/* We can view child[0] and child[1] */
256
$this->assertEquals(array($this->_album->getId() => 2), $counts);
259
function testGetChildCountsDifferentUser() {
262
/* Create a new user and give him limited view permissions on our tree */
263
list ($ret, $user) = $this->_createRandomUser();
265
return $this->failWithStatus($ret);
267
$this->_markForCleanup($user);
269
for ($i = 0; $i < 3; $i++) {
270
list ($ret, $child[$i]) = $this->_createRandomAlbum($this->_album->getId());
272
return $this->failWithStatus($ret);
275
/* Remove all permissions */
276
$ret = GalleryCoreApi::removeItemPermissions($child[$i]->getId());
278
return $this->failWithStatus($ret);
281
/* Add back admin permission */
282
$ret = GalleryCoreApi::addUserPermission(
283
$child[$i]->getId(), $gallery->getActiveUserId(), 'core.view', false);
285
return $this->failWithStatus($ret);
289
/* Set permissions */
290
$ret = GalleryCoreApi::addUserPermission(
291
$child[0]->getId(), $user->getId(), 'core.view', false);
293
return $this->failWithStatus($ret);
295
$ret = GalleryCoreApi::addUserPermission(
296
$child[2]->getId(), $user->getId(), 'core.view', false);
298
return $this->failWithStatus($ret);
301
/* Used to have a bug where count was cached by itemId only, not itemId+userId */
302
list ($ret, $counts) = GalleryCoreApi::fetchChildCounts(array($this->_album->getId()));
304
return $this->failWithStatus($ret);
306
$this->assertEquals(array($this->_album->getId() => 3), $counts);
308
list ($ret, $counts) =
309
GalleryCoreApi::fetchChildCounts(array($this->_album->getId()), $user->getId());
311
return $this->failWithStatus($ret);
314
/* We can view child[0] and child[2] */
315
$this->assertEquals(array($this->_album->getId() => 2), $counts);
318
function testGetPermissions() {
320
for ($i = 0; $i < 3; $i++) {
321
list ($ret, $child[$i]) = $this->_createRandomAlbum($this->_album->getId());
323
return $this->failWithStatus($ret);
326
/* Remove all permissions */
327
$ret = GalleryCoreApi::removeItemPermissions($child[$i]->getId());
329
return $this->failWithStatus($ret);
335
$ret[0] = GalleryCoreApi::addUserPermission(
336
$child[$i]->getId(), $this->_userId, 'core.delete', false);
340
$ret[0] = GalleryCoreApi::addUserPermission(
341
$child[$i]->getId(), $this->_userId, 'core.view', false);
342
$ret[1] = GalleryCoreApi::addUserPermission(
343
$child[$i]->getId(), $this->_userId, 'core.addDataItem', false);
344
$ret[2] = GalleryCoreApi::addUserPermission(
345
$child[$i]->getId(), $this->_userId, 'core.edit', false);
349
$ret[0] = GalleryCoreApi::addGroupPermission(
350
$child[$i]->getId(), $this->_groupId, 'core.view', false);
351
$ret[1] = GalleryCoreApi::addGroupPermission(
352
$child[$i]->getId(), $this->_groupId, 'core.addDataItem', false);
356
for ($j = 0; $j < 3; $j++) {
357
if (isset($ret[$j])) {
358
return $this->failWithStatus($ret[$j]);
363
list ($ret, $perms) = GalleryCoreApi::getPermissions($child[0]->getId());
365
return $this->failWithStatus($ret);
367
$this->assertEquals(array('core.delete' => 1), $perms);
369
list ($ret, $perms) = GalleryCoreApi::getPermissions($child[1]->getId());
371
return $this->failWithStatus($ret);
373
$this->assertEquals(array('core.view' => 1,
374
'core.addDataItem' => 1,
375
'core.edit' => 1), $perms);
377
list ($ret, $perms) = GalleryCoreApi::getPermissions($child[2]->getId());
379
return $this->failWithStatus($ret);
381
$this->assertEquals(array('core.view' => 1,
382
'core.addDataItem' => 1), $perms);
385
function testFetchAllItemIds() {
386
for ($i = 0; $i < 3; $i++) {
387
list ($ret, $child[$i]) = $this->_createRandomAlbum($this->_album->getId());
389
return $this->failWithStatus($ret);
393
$ret = GalleryCoreApi::removeItemPermissions($child[$i]->getId());
395
return $this->failWithStatus($ret);
398
$ret = GalleryCoreApi::addUserPermission(
399
$child[$i]->getId(), $this->_userId, 'core.addDataItem', false);
401
return $this->failWithStatus($ret);
406
list ($ret, $ids) = GalleryCoreApi::fetchAllItemIds('GalleryAlbumItem');
408
return $this->failWithStatus($ret);
411
/* We should see children 0 & 2 and the parent */
412
$this->assert(in_array($this->_album->getId(), $ids), 'parent');
413
$this->assert(in_array($child[0]->getId(), $ids), 'child 0');
414
$this->assert(!in_array($child[1]->getId(), $ids), 'child 1');
415
$this->assert(in_array($child[2]->getId(), $ids), 'child 2');
417
/* Make sure there's no duplication */
418
$this->assertEquals(sizeof($ids), sizeof(array_flip(array_flip($ids))));
420
list ($ret, $ids) = GalleryCoreApi::fetchAllItemIds('GalleryAlbumItem', 'core.addDataItem');
422
return $this->failWithStatus($ret);
425
/* We should see them all */
426
$this->assert(in_array($child[0]->getId(), $ids), 'child 0');
427
$this->assert(in_array($child[1]->getId(), $ids), 'child 1');
428
$this->assert(in_array($child[2]->getId(), $ids), 'child 2');
430
/* Make sure there's no duplication */
431
$this->assertEquals(sizeof($ids), sizeof(array_flip(array_flip($ids))));
435
* Create a user, add some items, test the function
436
* fetchAllItemIdsByOwnerId() and verify
438
function testFetchAllItemIdsByOwnerId() {
441
/* Create a user that we can delete */
442
list ($ret, $user) = $this->_createRandomUser();
444
return $this->failWithStatus($ret);
446
$this->_markForCleanup($user);
448
/* Without permissions, the user can't add items */
449
$ret = GalleryCoreApi::addUserPermission(
450
$this->_album->getId(), $user->getId(),
451
array('core.addDataItem','core.addAlbumItem'), false);
453
return $this->failWithStatus($ret);
456
$this->_activeUserBackup = $gallery->getActiveUser();
457
$gallery->setActiveUser($user);
459
list ($ret, $album) = $this->_createRandomAlbum($this->_album->getId());
461
return $this->failWithStatus($ret);
466
for ($i = 0; $i < 3; $i++) {
467
list ($ret, $items[]) = $this->_createRandomAlbum($album->getId());
469
return $this->failWithStatus($ret);
471
list ($ret, $items[]) = $this->_createRandomDataItem($album->getId());
473
return $this->failWithStatus($ret);
477
/* Restore the activeUser, should be a Site Admin */
478
$gallery->setActiveUser($this->_activeUserBackup);
480
list ($ret, $ids) = GalleryCoreApi::fetchAllItemIdsByOwnerId($user->getId());
482
return $this->failWithStatus($ret);
484
GalleryDataCache::reset();
487
$this->assert(in_array($album->getId(), $ids), 'parent album not returned');
489
foreach ($items as $item) {
490
$this->assert(in_array($item->getId(), $ids), 'child '.$item->getId() .' not returned');
493
$this->assert(count($ids) == $itemCount,
494
'returned '. count($ids) .
495
' instead of ' . $itemCount.' items');
497
/* The teardown cleanup code deletes all item that are marked for deletion */
501
* Create test user1, test group1, add user1 to group1, create an item as user1,
502
* create test user2 and group2, assign user2 to group2, grant to user1, group1,
503
* user2 and group2 some permissions on the item, call remapOwnerId($user1Id, $user2Id)
504
* and verify the new owner and (new) permissions
506
function testRemapOwnerId() {
509
/* Create test user 1, the oldOwner */
510
list ($ret, $oldUser) = $this->_createRandomUser();
512
return $this->failWithStatus($ret);
514
$this->_markForCleanup($oldUser);
515
/* Create test user 2, the newOwner */
516
list ($ret, $newUser) = $this->_createRandomUser();
518
return $this->failWithStatus($ret);
520
$this->_markForCleanup($newUser);
521
/* Create Group 1 for user 1 for indirect permissions */
522
list ($ret, $group1) = $this->_createRandomGroup();
524
return $this->failWithStatus($ret);
526
$this->_markForCleanup($group1);
527
$ret = GalleryCoreApi::addUserToGroup($oldUser->getId(), $group1->getId());
529
return $this->failWithStatus($ret);
531
/* Create Group 2 for user2 for indirect permissions */
532
list ($ret, $group2) = $this->_createRandomGroup();
534
return $this->failWithStatus($ret);
536
$this->_markForCleanup($group2);
537
$ret = GalleryCoreApi::addUserToGroup($newUser->getId(), $group2->getId());
539
return $this->failWithStatus($ret);
542
/* Without permissions, the user can't add items */
543
$ret = GalleryCoreApi::addUserPermission($this->_album->getId(), $oldUser->getId(),
544
array('core.addDataItem'), false);
546
return $this->failWithStatus($ret);
549
$this->_activeUserBackup = $gallery->getActiveUser();
550
$gallery->setActiveUser($oldUser);
552
/* Add a test item with the old user as the owner */
553
list ($ret, $album) = $this->_createRandomAlbum($this->_album->getId());
555
return $this->failWithStatus($ret);
558
/* Restore the activeUser, should be a Site Admin */
559
$gallery->setActiveUser($this->_activeUserBackup);
561
/* Reset all permissions for this item */
562
$ret = GalleryCoreApi::removeItemPermissions($album->getId());
564
return $this->failWithStatus($ret);
566
list ($ret, $checkPermissions) =
567
GalleryCoreApi::fetchAllPermissionsForItem($album->getId(), false);
569
return $this->failWithStatus($ret);
571
$this->assertEquals(array(), $checkPermissions, 'could not reset item permissions');
573
/* Add indirect permissions to oldOwner by a group membership */
574
$ret = GalleryCoreApi::addGroupPermission(
575
$album->getId(), $group1->getId(), array('core.changePermissions', 'core.view'), false);
577
return $this->failWithStatus($ret);
579
/* Add direct permissions to oldOwner */
580
$ret = GalleryCoreApi::addUserPermission($album->getId(), $oldUser->getId(),
581
array('core.addDataItem', 'core.delete'), false);
583
return $this->failWithStatus($ret);
585
/* Add indirect permissions to newOwner by a group membership */
586
$ret = GalleryCoreApi::addGroupPermission($album->getId(),
587
$group2->getId(), array('core.edit', 'core.view'), false);
589
return $this->failWithStatus($ret);
591
/* Add direct permissions to newOwner */
592
$ret = GalleryCoreApi::addUserPermission(
593
$album->getId(), $newUser->getId(),
594
array('core.addDataItem', 'core.addAlbumItem'), false);
596
return $this->failWithStatus($ret);
599
/* Execute the call */
600
$ret = GalleryCoreApi::remapOwnerId($oldUser->getId(), $newUser->getId());
602
return $this->failWithStatus($ret);
604
GalleryDataCache::reset();
606
/* Verify the owner Id has changed */
607
list ($ret, $album) = $album->refresh();
609
return $this->failWithStatus($ret);
611
$this->assert($album->getOwnerId() == $newUser->getId(), 'ownerId was not changed');
612
/* Verify the old owner owns zero items */
613
list ($ret, $itemIds) = GalleryCoreApi::fetchAllItemIdsByOwnerId($oldUser->getId());
615
return $this->failWithStatus($ret);
617
$this->assert(count($itemIds) == 0, 'old owner still owns some items');
618
/* Verify the new owner owns exactly 1 item */
619
list ($ret, $itemIds) = GalleryCoreApi::fetchAllItemIdsByOwnerId($newUser->getId());
621
return $this->failWithStatus($ret);
623
$this->assert(count($itemIds) == 1, 'new owner owns not exactly 1 item');
624
/* Verify the permissions are direct / indirect */
625
list ($ret, $permissions) =
626
GalleryCoreApi::fetchAllPermissionsForItem($album->getId(), false);
628
return $this->failWithStatus($ret);
630
$groupPermissions = $userPermissions = array();
631
foreach ($permissions as $perm) {
632
if (isset($perm['userId'])) {
633
$userPermissions[$perm['userId']][$perm['permission']] = true;
634
} else if (isset($perm['groupId'])) {
635
$groupPermissions[$perm['groupId']][$perm['permission']] = true;
638
/* Verify the new user has the right permissions */
639
/* Verify direct permissions */
640
foreach (array('core.changePermissions', 'core.addDataItem',
641
'core.delete', 'core.addAlbumItem') as $permission) {
642
$this->assert(isset($userPermissions[$newUser->getId()][$permission]),
643
"direct permission '$permission' not granted");
645
$this->assert(count($userPermissions[$newUser->getId()]) == 4,
646
'too few/many direct permissions');
647
/* Verify indirect permissions */
648
foreach (array('core.edit', 'core.view') as $permission) {
649
$this->assert(isset($groupPermissions[$group2->getId()][$permission]),
650
'indirect permissions changed');
652
$this->assert(count($groupPermissions[$group2->getId()]) == 2,
653
'too few/many indirect group permissions');
654
/* Verify the old user's permissions have not been changed */
655
/* Verify direct permissions */
656
foreach (array('core.addDataItem', 'core.delete') as $permission) {
657
$this->assert(isset($userPermissions[$oldUser->getId()][$permission]),
658
"direct permission '$permission' of old owner changed");
660
$this->assert(count($userPermissions[$oldUser->getId()]) == 2,
661
'changed direct permissions of old owner');
662
/* Verify indirect permissions */
663
foreach (array('core.changePermissions', 'core.view') as $permission) {
664
$this->assert(isset($groupPermissions[$group1->getId()][$permission]),
665
"indirect permission '$permission' of old owner changed");
667
$this->assert(count($groupPermissions[$group1->getId()]) == 2,
668
'changed indirect permissions of old owner');
670
/* All test items/users/groups will be deleted in the teardown function */
673
function testSetThumbnailFromItem() {
674
/* Create album tree */
675
$parentId = $this->_album->getId();
676
for ($i = 0; $i < 3; $i++) {
677
list ($ret, $album[$i]) = $this->_createRandomAlbum($parentId);
679
return $this->failWithStatus($ret);
681
$parentId = $album[$i]->getId();
684
/* Set the preference for one album to something unusual */
685
$ret = GalleryCoreApi::removeDerivativePreferencesForItem($album[0]->getId());
687
return $this->failWithStatus($ret);
690
/* Add a thumbnail preference */
691
$ret = GalleryCoreApi::addDerivativePreference(0, $album[0]->getId(),
692
DERIVATIVE_TYPE_IMAGE_THUMBNAIL,
695
return $this->failWithStatus($ret);
698
/* Then attach a derivative to one item and associate it with another */
699
list ($ret, $derivative) =
700
$this->_createDerivative($album[2], $album[2]->getId(),
701
DERIVATIVE_TYPE_IMAGE_THUMBNAIL,
702
'itemtest-operation',
705
return $this->failWithStatus($ret);
708
list ($ret, $success) =
709
GalleryCoreApi::setThumbnailFromItem($album[1]->getId(), $album[2]->getId());
711
return $this->failWithStatus($ret);
713
$this->assert($success, 'should be able to set thumbnail');
716
* At this point, $album[1]'s thumbnail should match $album[0]'s preference,
717
* and $album[0]'s thumbnail should match $this->_album's preference
719
list ($ret, $thumbTable) =
720
GalleryCoreApi::fetchThumbnailsByItemIds(array($album[0]->getId(),
721
$album[1]->getId()));
723
return $this->failWithStatus($ret);
726
/* Make sure that child(1) has a thumbnail matching child(0)'s preference */
727
list ($ret, $preferences) =
728
GalleryCoreApi::fetchDerivativePreferencesForItem($album[0]->getId());
730
return $this->failWithStatus($ret);
732
$thumbnailPreference = null;
733
for ($i = 0; $i < sizeof($preferences); $i++) {
734
if (preg_match('/thumbnail/', $preferences[$i]['derivativeOperations'])) {
735
$thumbnailPreference = $preferences[$i];
739
$this->assert(isset($thumbnailPreference), 'missing thumbnail preference');
740
$this->assert(isset($thumbTable[$album[1]->getId()]), 'child(1) should have a thumbnail');
741
$this->assertEquals($thumbTable[$album[1]->getId()]->getDerivativeOperations(),
742
$thumbnailPreference['derivativeOperations']);
744
/* Make sure that child(0) has a thumbnail matching parentItem's preference */
745
list ($ret, $preferences) =
746
GalleryCoreApi::fetchDerivativePreferencesForItem($this->_album->getId());
748
return $this->failWithStatus($ret);
750
$thumbnailPreference = null;
751
for ($i = 0; $i < sizeof($preferences); $i++) {
752
if (preg_match('/thumbnail/', $preferences[$i]['derivativeOperations'])) {
753
$thumbnailPreference = $preferences[$i];
757
$this->assert(isset($thumbnailPreference), 'missing thumbnail preference');
758
$this->assert(isset($thumbTable[$album[0]->getId()]), 'child(0) should have a thumbnail');
759
$this->assertEquals($thumbTable[$album[0]->getId()]->getDerivativeOperations(),
760
$thumbnailPreference['derivativeOperations']);
762
/* Make sure that the derivatives are linked together properly */
763
$thumb0 = $thumbTable[$album[0]->getId()];
764
$thumb1 = $thumbTable[$album[1]->getId()];
765
$this->assertEquals($thumb0->getDerivativeSourceId(), $thumb1->getId());
769
* Exercise a bug: if you add an unknown item to a new album, it tries to make
770
* that item the thumbnail, but we can't thumbnail-ify it so we wind up throwing
771
* an ERROR_UNSUPPORTED_OPERATION. Don't let that happen!
773
function testSetThumbnailFromUnknownItem() {
774
list ($ret, $unknownItem) = $this->_createRandomDataItem($this->_album->getId(),
775
'application/unknown',
778
'GalleryUnknownItem');
780
return $this->failWithStatus($ret);
783
list ($ret, $success) =
784
GalleryCoreApi::setThumbnailFromItem($this->_album->getId(), $unknownItem->getId());
786
return $this->failWithStatus($ret);
789
$this->assert(!$success, 'should not be able to set thumbnail');
791
list ($ret, $thumbTable) =
792
GalleryCoreApi::fetchThumbnailsByItemIds(array($this->_album->getId()));
794
return $this->failWithStatus($ret);
797
$this->assert(!isset($thumbTable[$this->_album->getId()]));
801
* Exercise a bug: if you add an unknown item and a photo to an album (album highlight
802
* automatically becomes the photo) and then move the photo to another album then the
803
* highlight source is changed to the unknown item --> ERROR_UNSUPPORTED_OPERATION
805
function testSetThumbnailDontChangeToUnknownItem() {
806
list ($ret, $unknownItem) = $this->_createRandomDataItem($this->_album->getId(),
807
'application/unknown',
810
'GalleryUnknownItem');
812
return $this->failWithStatus($ret);
815
list ($ret, $photoItem) =
816
$this->_createRandomDataItem($this->_album->getId(), 'test/image');
818
return $this->failWithStatus($ret);
821
list ($ret, $thumb) = $this->_createDerivative($photoItem, $photoItem->getId(),
822
DERIVATIVE_TYPE_IMAGE_THUMBNAIL,
823
'itemtest-operation', 'test/image');
825
return $this->failWithStatus($ret);
828
list ($ret, $highlight) = $this->_createDerivative($this->_album, $thumb->getId(),
829
DERIVATIVE_TYPE_IMAGE_THUMBNAIL,
830
'itemtest-operation', 'test/image');
832
return $this->failWithStatus($ret);
835
list ($ret, $success) =
836
GalleryCoreApi::setThumbnailFromItem($this->_album->getId(), $unknownItem->getId());
838
return $this->failWithStatus($ret);
841
$this->assert(!$success, 'should not be able to set thumbnail');
844
function testAddItemToAlbum() {
846
$gallery->_shutdownActions = null;
848
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_album->getId());
850
return $this->failWithStatus($ret);
853
list ($ret, $maxWeight) =
854
GalleryCoreApi::fetchExtremeChildWeight($this->_album->getId(), HIGHER_WEIGHT);
856
return $this->failWithStatus($ret);
859
list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum(
860
__FILE__, 'itemName', 'title', 'caption', 'description',
861
'application/unknown', $this->_album->getId());
863
return $this->failWithStatus($ret);
866
$ret = GalleryCoreApi::releaseLocks($lockId);
868
return $this->failWithStatus($ret);
871
$this->assert(GalleryUtilities::isA($newItem, 'GalleryDataItem'),
872
'newItem is not a GalleryDataItem');
873
$this->assertEquals('itemName', $newItem->getPathComponent());
874
$this->assertEquals('title', $newItem->getTitle());
875
$this->assertEquals('caption', $newItem->getSummary());
876
$this->assertEquals('description', $newItem->getDescription());
877
$this->assertEquals('application/unknown', $newItem->getMimeType());
878
$this->assertEquals($this->_album->getId(), $newItem->getParentId(), 'parent id');
880
/* Test the order weight */
881
list ($ret, $weights) = GalleryCoreApi::fetchItemOrderWeights(array($newItem->getId()));
883
return $this->failWithStatus($ret);
886
$this->assert(isset($weights[$newItem->getId()]));
887
$this->assert($weights[$newItem->getId()] > $maxWeight);
889
/* Test that shutdown actions will update parent album's modification timestamp */
890
sleep(1); /* Make sure new timestamp won't equal old one even after update */
891
$gallery->performShutdownActions();
892
list ($ret, $album) = $this->_album->refresh();
894
return $this->failWithStatus($ret);
897
$album->getModificationTimestamp() > $this->_album->getModificationTimestamp(),
898
'parent modification timestamp');
902
* Check that when adding a file to an album, the originationTimestamp
903
* provided by some toolkit gets added
905
function testAddItemToAlbumWithOriginationTimestamp() {
906
/* Register the originationTimestamp property that we can get from our mock data items */
907
$ret = GalleryCoreApi::registerToolkitProperty('ItemTestToolkit',
908
array('test/imageWithTimestamp'),
909
'originationTimestamp',
911
'Get the origination timestamp');
913
return $this->failWithStatus($ret);
916
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_album->getId());
918
return $this->failWithStatus($ret);
920
list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum(__FILE__,
925
'test/imageWithTimestamp',
926
$this->_album->getId());
928
return $this->failWithStatus($ret);
931
$ret = GalleryCoreApi::releaseLocks($lockId);
933
return $this->failWithStatus($ret);
936
$this->assertEquals((int)12345, $newItem->getOriginationTimestamp());
939
function testAddMovieToAlbum() {
940
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_album->getId());
942
return $this->failWithStatus($ret);
945
/* Delete existing derivative preferences */
946
$ret = GalleryCoreApi::removeDerivativePreferencesForItem($this->_album->getId());
948
return $this->failWithStatus($ret);
951
/* Add a thumbnail preference */
952
$ret = GalleryCoreApi::addDerivativePreference(
953
0, $this->_album->getId(), DERIVATIVE_TYPE_IMAGE_THUMBNAIL, 'thumbnail|101');
955
return $this->failWithStatus($ret);
958
/* Add our item to the album */
959
list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum(
960
__FILE__, 'itemName', 'title', 'caption', 'description',
961
'test/movie', $this->_album->getId());
963
return $this->failWithStatus($ret);
966
$ret = GalleryCoreApi::releaseLocks($lockId);
968
return $this->failWithStatus($ret);
972
* Verify that the new item's derivatives.. note we don't expect a preferred derivative
973
* with convert-to-image/jpeg.. we only do this for image/* mime types.
975
list ($ret, $derivativeTable) =
976
GalleryCoreApi::fetchDerivativesByItemIds(array($newItem->getId()));
978
return $this->failWithStatus($ret);
981
if (!isset($derivativeTable[$newItem->getId()])) {
982
return $this->assert(false, 'Missing item derivative');
984
$derivs = $derivativeTable[$newItem->getId()];
985
if (count($derivs) != 1) {
986
return $this->assertEquals(1, count($derivs), 'Wrong number of derivatives');
989
$this->assertEquals(DERIVATIVE_TYPE_IMAGE_THUMBNAIL, $derivs[0]->getDerivativeType());
990
$this->assertEquals('convert-to-image/jpeg;thumbnail|101',
991
$derivs[0]->getDerivativeOperations());
994
function testFetchItemIdCount() {
997
/* Switch to the anonymous user id so that this returns false */
998
$this->_becomeGuestUser();
1000
list ($ret, $count) =
1001
GalleryCoreApi::fetchItemIdCount('GalleryAlbumItem', 'core.changePermissions');
1003
return $this->failWithStatus($ret);
1006
$this->assertEquals(0, $count, 'Should not have permission');
1009
function testFetchItemIdCount2() {
1010
/* We're the admin user so this should return a positive value */
1011
list ($ret, $count) =
1012
GalleryCoreApi::fetchItemIdCount('GalleryAlbumItem', 'core.changePermissions');
1014
return $this->failWithStatus($ret);
1017
$this->assert($count > 0, 'Should have permission');
1020
function testDeletingLinks() {
1022
$platform =& $gallery->getPlatform();
1024
/* Create a target item */
1025
list ($ret, $item) = $this->_createRandomDataItem($this->_album->getId());
1027
return $this->failWithStatus($ret);
1030
/* Create a couple of linked items */
1031
for ($i = 0; $i < 2; $i++) {
1032
list ($ret, $linkedItem[$i]) = $this->_createLinkedItem($this->_album->getId(), $item);
1034
return $this->failWithStatus($ret);
1038
/* Create a thumbnail */
1039
list ($ret, $thumb) = $this->_createDerivative($linkedItem[0], $item->getId(),
1040
DERIVATIVE_TYPE_IMAGE_THUMBNAIL,
1041
'itemtest-operation', 'test/image');
1043
return $this->failWithStatus($ret);
1046
/* All links should point to the original */
1047
list ($ret, $truePath) = $item->fetchPath();
1049
return $this->failWithStatus($ret);
1051
$this->assert($platform->file_exists($truePath), "Path [$truePath] should exist");
1053
for ($i = 0; $i < 2; $i++) {
1054
list ($ret, $linkPath) = $linkedItem[$i]->fetchPath();
1056
return $this->failWithStatus($ret);
1059
$this->assertEquals($truePath, $linkPath, "Link $i doesn't point to the original");
1062
/* Delete the original, now all links should point to the first link */
1063
$ret = GalleryCoreApi::deleteEntityById($item->getId());
1065
return $this->failWithStatus($ret);
1068
/* Deleting changed our items out from under us -- adapt */
1069
list ($ret, $linkedItem[0]) = $linkedItem[0]->refresh();
1071
return $this->failWithStatus($ret);
1073
list ($ret, $linkedItem[1]) = $linkedItem[1]->refresh();
1075
return $this->failWithStatus($ret);
1077
list ($ret, $thumb) = $thumb->refresh();
1079
return $this->failWithStatus($ret);
1082
list ($ret, $truePath) = $linkedItem[0]->fetchPath();
1084
return $this->failWithStatus($ret);
1086
$this->assert($platform->file_exists($truePath), "Path [$truePath] should exist");
1088
list ($ret, $linkPath) = $linkedItem[1]->fetchPath();
1090
return $this->failWithStatus($ret);
1093
$this->assertEquals($truePath, $linkPath, "Link doesn't point to the original (link)");
1095
$this->assertEquals($linkedItem[0]->getId(), $thumb->getDerivativeSourceId(),
1096
'Bad thumbnail source (deleted item was ' . $item->getId() . ')');
1099
function testDelete() {
1101
list ($ret, $album) = $this->_createRandomAlbum($this->_album->getId());
1103
return $this->failWithStatus($ret);
1105
list ($ret, $item) = $this->_createRandomDataItem($album->getId());
1107
return $this->failWithStatus($ret);
1109
$gallery->_shutdownActions = null;
1111
$ret = GalleryCoreApi::deleteEntityById($album->getId());
1113
return $this->failWithStatus($ret);
1116
list ($ret, $ids) = GalleryCoreApi::fetchChildItemIds($this->_album);
1118
return $this->failWithStatus($ret);
1120
$this->assertEquals(array(), $ids, 'child item ids');
1123
* Test that shutdown actions will update parent album's modification timestamp
1124
* Also ensure invalid id in shutdown action is ignored (delete of $item will
1125
* trigger shutdown action for $album which was deleted too...)
1127
sleep(1); /* Make sure new timestamp won't equal old one even after update */
1128
$gallery->performShutdownActions();
1129
list ($ret, $album) = $this->_album->refresh();
1131
return $this->failWithStatus($ret);
1134
$album->getModificationTimestamp() > $this->_album->getModificationTimestamp(),
1135
'parent modification timestamp');
1138
function testMove() {
1141
/* Create a destination album */
1142
list ($ret, $album) = $this->_createRandomAlbum($this->_album->getId());
1144
return $this->failWithStatus($ret);
1147
/* Create a target item */
1148
list ($ret, $item) = $this->_createRandomDataItem($this->_album->getId());
1150
return $this->failWithStatus($ret);
1152
$gallery->_shutdownActions = null;
1154
list ($ret, $parentSequence) = GalleryCoreApi::fetchParentSequence($item->getId());
1156
return $this->failWithStatus($ret);
1159
$this->assertEquals($this->_album->getId(), $item->getParentId(), 'Wrong original parent');
1160
$this->assertEquals(array($this->_getRootId(),
1161
$this->_album->getId()),
1163
'Wrong original parent sequence');
1165
list ($ret, $locks[]) =
1166
GalleryCoreApi::acquireReadLock(array($this->_album->getId(),
1169
return $this->failWithStatus($ret);
1172
list ($ret, $locks[]) = GalleryCoreApi::acquireWriteLock($item->getId());
1174
return $this->failWithStatus($ret);
1177
list ($ret, $item) = $item->refresh();
1179
return $this->failWithStatus($ret);
1182
$ret = $item->move($album->getId());
1184
return $this->failWithStatus($ret);
1187
$ret = $item->save();
1189
return $this->failWithStatus($ret);
1192
GalleryDataCache::reset();
1194
list ($ret, $parentSequence) = GalleryCoreApi::fetchParentSequence($item->getId());
1196
return $this->failWithStatus($ret);
1199
$this->assertEquals($album->getId(), $item->getParentId(), 'Wrong parent');
1200
$this->assertEquals(array($this->_getRootId(),
1201
$this->_album->getId(),
1204
'Wrong parent sequence');
1206
$ret = GalleryCoreApi::releaseLocks($locks);
1208
return $this->failWithStatus($ret);
1211
/* Test that shutdown actions will update parent album's modification timestamp */
1212
sleep(1); /* Make sure new timestamp won't equal old one even after update */
1213
$gallery->performShutdownActions();
1214
list ($ret, $refreshedAlbum) = $album->refresh();
1216
return $this->failWithStatus($ret);
1219
$refreshedAlbum->getModificationTimestamp() > $album->getModificationTimestamp(),
1220
'destination album modification timestamp');
1221
list ($ret, $refreshedAlbum) = $this->_album->refresh();
1223
return $this->failWithStatus($ret);
1226
$refreshedAlbum->getModificationTimestamp() > $this->_album->getModificationTimestamp(),
1227
'source album modification timestamp');
1231
* Add a small (dimension wise) photo to an album and make sure that we don't create
1232
* resizes that are larger (dimension wise) than the original.
1234
function testAddSmallPhotoToAlbum() {
1235
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_album->getId());
1237
return $this->failWithStatus($ret);
1241
* Set the album preferences such that we have one resize that's smaller than the
1242
* original, and one that's larger. We know that the image we're using is 62x75
1244
$ret = GalleryCoreApi::removeDerivativePreferencesForItem($this->_album->getId());
1246
return $this->failWithStatus($ret);
1249
$ret = GalleryCoreApi::addDerivativePreference(1, $this->_album->getId(),
1250
DERIVATIVE_TYPE_IMAGE_RESIZE,
1253
return $this->failWithStatus($ret);
1256
$ret = GalleryCoreApi::addDerivativePreference(2, $this->_album->getId(),
1257
DERIVATIVE_TYPE_IMAGE_RESIZE,
1260
return $this->failWithStatus($ret);
1263
$ret = GalleryCoreApi::addDerivativePreference(3, $this->_album->getId(),
1264
DERIVATIVE_TYPE_IMAGE_RESIZE,
1267
return $this->failWithStatus($ret);
1270
$ret = GalleryCoreApi::addDerivativePreference(4, $this->_album->getId(),
1271
DERIVATIVE_TYPE_IMAGE_THUMBNAIL,
1274
return $this->failWithStatus($ret);
1277
list ($ret, $photo) = GalleryCoreApi::newItemByMimeType('image/jpeg');
1279
return $this->failWithStatus($ret);
1282
$ret = $photo->create($this->_album->getId(),
1283
dirname(__FILE__) . '/../data/test1.gif',
1287
return $this->failWithStatus($ret);
1290
$ret = GalleryCoreApi::addExistingItemToAlbum($photo, $this->_album->getId());
1292
return $this->failWithStatus($ret);
1295
$ret = $photo->save();
1297
return $this->failWithStatus($ret);
1300
$ret = GalleryCoreApi::releaseLocks($lockId);
1302
return $this->failWithStatus($ret);
1305
/* Now verify that we didn't upsample our resizes */
1306
list ($ret, $resizes) = GalleryCoreApi::fetchResizesByItemIds(array($photo->getId()));
1308
return $this->failWithStatus($ret);
1311
$this->assert(isset($resizes[$photo->getId()]), 'Missing resizes for new photo');
1312
if (isset($resizes[$photo->getId()])) {
1313
$resizes = $resizes[$photo->getId()];
1314
$this->assertEquals(1, sizeof($resizes), 'There should only be one resize');
1315
$this->assertEquals('scale|50', $resizes[0]->getDerivativeOperations(),
1316
'The resize operation should be scale|50');
1319
/* Now verify the photo has been made the highlight of the album.. */
1320
list ($ret, $thumbTable) = GalleryCoreApi::fetchThumbnailsByItemIds(
1321
array($this->_album->getId(), $photo->getId()));
1323
return $this->failWithStatus($ret);
1325
$this->assert(isset($thumbTable[$this->_album->getId()]), 'Missing highlight for album');
1326
$this->assert(isset($thumbTable[$photo->getId()]), 'Missing thumbnail for photo');
1327
if (count($thumbTable) == 2) {
1328
$this->assertEquals(
1329
$thumbTable[$photo->getId()]->getId(),
1330
$thumbTable[$this->_album->getId()]->getDerivativeSourceId(), 'highlight id');
1333
/* Make sure setting the same highlight doesn't throw an error.. */
1334
list ($ret, $success) =
1335
GalleryCoreApi::setThumbnailFromItem($this->_album->getId(), $photo->getId());
1337
return $this->failWithStatus($ret);
1339
$this->assert($success, 'should be able to set highlight');
1342
function testAddNonViewableImage() {
1343
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_album->getId());
1345
return $this->failWithStatus($ret);
1348
/* Get rid of all album preferences */
1349
$ret = GalleryCoreApi::removeDerivativePreferencesForItem($this->_album->getId());
1351
return $this->failWithStatus($ret);
1354
/* Register operations to convert from our test types */
1355
$ret = GalleryCoreApi::registerToolkitOperation(
1356
'ItemTestToolkit', array('image/nonviewable'), 'convert-to-image/x-portable-pixmap',
1357
array(), 'itemtest-description', 'image/x-portable-pixmap');
1359
return $this->failWithStatus($ret);
1361
$ret = GalleryCoreApi::registerToolkitOperation(
1362
'ItemTestToolkit', array('test/document'), 'convert-to-image/jpeg',
1363
array(), 'itemtest-description', 'image/jpeg');
1365
return $this->failWithStatus($ret);
1368
/* Test one image type and one document type */
1369
foreach (array('image/nonviewable', 'test/document') as $i => $mimeType) {
1370
list ($ret, $item) = GalleryCoreApi::newItemByMimeType($mimeType);
1372
return $this->failWithStatus($ret);
1375
$ret = $item->create($this->_album->getId(), __FILE__, $mimeType, 'test item');
1377
return $this->failWithStatus($ret);
1379
if (method_exists($item, 'setwidth')) {
1380
$item->setWidth(1234);
1381
$item->setHeight(567);
1384
$ret = GalleryCoreApi::addExistingItemToAlbum($item, $this->_album->getId());
1386
return $this->failWithStatus($ret);
1389
$ret = $item->save();
1391
return $this->failWithStatus($ret);
1394
/* Make sure that we have a preferred that contains the proper convert operations */
1395
$itemId = $item->getId();
1396
list ($ret, $preferreds) = GalleryCoreApi::fetchPreferredsByItemIds(array($itemId));
1398
$this->failWithStatus($ret);
1400
if (isset($preferreds[$itemId])) {
1401
$this->assertEquals(
1402
($i ? '' : 'convert-to-image/x-portable-pixmap;') . 'convert-to-image/jpeg',
1403
$preferreds[$itemId]->getDerivativeOperations(), $mimeType . ' operations');
1405
$this->assertEquals(1234, $preferreds[$itemId]->getWidth(), 'width');
1406
$this->assertEquals(567, $preferreds[$itemId]->getHeight(), 'height');
1409
$this->assert(false, 'missing preferred for ' . $mimeType);
1413
$ret = GalleryCoreApi::releaseLocks($lockId);
1415
return $this->failWithStatus($ret);
1419
function testAddNonViewableImageWithPreExistingPreferred() {
1420
list ($ret, $lockId[]) = GalleryCoreApi::acquireReadLock($this->_album->getId());
1422
return $this->failWithStatus($ret);
1425
/* Get rid of all album preferences */
1426
$ret = GalleryCoreApi::removeDerivativePreferencesForItem($this->_album->getId());
1428
return $this->failWithStatus($ret);
1431
/* Register an operation for our preferred to perform */
1432
$ret = GalleryCoreApi::registerToolkitOperation(
1433
'ItemTestToolkit', array('image/nonviewable'), 'test-operation',
1434
array(), 'itemtest-description');
1436
return $this->failWithStatus($ret);
1439
/* Register an operation to convert from our test type */
1440
$ret = GalleryCoreApi::registerToolkitOperation(
1441
'ItemTestToolkit', array('image/nonviewable'), 'convert-to-image/x-portable-pixmap',
1442
array(), 'itemtest-description', 'image/x-portable-pixmap');
1444
return $this->failWithStatus($ret);
1447
list ($ret, $photo) = GalleryCoreApi::newItemByMimeType('image/nonviewable');
1449
return $this->failWithStatus($ret);
1452
$ret = $photo->create($this->_album->getId(), __FILE__, 'image/nonviewable', 'test image');
1454
return $this->failWithStatus($ret);
1457
$ret = $photo->save();
1459
return $this->failWithStatus($ret);
1462
/* Add a preferred */
1463
list ($ret, $preferred) = $this->_createDerivative(
1464
$photo, $photo->getId(), DERIVATIVE_TYPE_IMAGE_PREFERRED,
1465
'test-operation', 'image/nonviewable');
1467
return $this->failWithStatus($ret);
1470
list ($ret, $lockId[]) = GalleryCoreApi::acquireWriteLock($photo->getId());
1472
return $this->failWithStatus($ret);
1475
$ret = GalleryCoreApi::addExistingItemToAlbum($photo, $this->_album->getId());
1477
return $this->failWithStatus($ret);
1480
$ret = GalleryCoreApi::releaseLocks($lockId);
1482
return $this->failWithStatus($ret);
1485
/* Make sure that we have a preferred that contains the proper convert operations */
1486
list ($ret, $preferreds) = GalleryCoreApi::fetchPreferredsByItemIds(array($photo->getId()));
1488
return $this->failWithStatus($ret);
1490
$preferred = $preferreds[$photo->getId()];
1491
$this->assertEquals(
1492
'test-operation;convert-to-image/x-portable-pixmap;convert-to-image/jpeg',
1493
$preferred->getDerivativeOperations());
1496
function testSymlinkTwice() {
1498
$platform =& $gallery->getPlatform();
1499
if (!$platform->isSymlinkSupported()) {
1500
/* Skip this test if symlink is not supported */
1504
/* Register the dimensions property for our mock data item */
1505
$ret = GalleryCoreApi::registerToolkitProperty('ItemTestToolkit',
1506
array('image/test'), 'dimensions', 'int,int', 'Get the dimensions');
1508
return $this->failWithStatus($ret);
1512
* Ensure we don't error out if we add-with-symlink and a problem with the datafile
1513
* requires falling back to GalleryUnknownItem (so we try the symlink twice).
1515
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_album->getId());
1517
return $this->failWithStatus($ret);
1520
list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum(
1521
__FILE__, 'itemName', 'title', 'caption', 'description',
1522
'image/test', $this->_album->getId(), true);
1524
GalleryCoreApi::releaseLocks($lockId);
1525
return $this->failWithStatus($ret);
1528
$ret = GalleryCoreApi::releaseLocks($lockId);
1530
return $this->failWithStatus($ret);
1533
/* Just verify a GalleryUnknownItem was created */
1534
$this->assert(GalleryUtilities::isA($newItem, 'GalleryUnknownItem'),
1535
'newItem is not a GalleryUnknownItem');
1538
function testDeleteSortOrderFromAlbums() {
1539
foreach (array('ItemTestOrder', 'ItemTestOrder|something', 'something|ItemTestOrder')
1541
list ($ret, $albums[$order]) = $this->_createRandomAlbum(
1542
$this->_album->getId(),
1543
array('orderBy' => $order, 'orderDirection' => ORDER_ASCENDING));
1545
return $this->failWithStatus($ret);
1549
$ret = GalleryCoreApi::deleteSortOrder('ItemTestOrder');
1551
return $this->failWithStatus($ret);
1554
foreach ($albums as $order => $album) {
1555
list ($ret, $album) = $album->refresh();
1557
return $this->failWithStatus($ret);
1560
$this->assertEquals('', $album->getOrderBy(), "orderBy not removed for '$order'");
1561
$this->assertEquals(ORDER_ASCENDING, $album->getOrderDirection(),
1562
"orderDirection changed for '$order'");
1566
function testDeleteSortOrderFromDefault() {
1567
$ret = $this->_markPluginParametersForCleanup('module', 'core');
1569
return $this->failWithStatus($ret);
1572
foreach (array(array('sort' => array('MyTestSortOrder', 'orderWeight'),
1573
'order' => array(ORDER_ASCENDING, ORDER_ASCENDING)),
1574
array('sort' => array('MyPresort|MyTestSortOrder', 'orderWeight'),
1575
'order' => array(ORDER_DESCENDING, ORDER_DESCENDING)),
1576
array('sort' => array('SomeOtherSortOrder', 'SomeOtherSortOrder'),
1577
'order' => array(ORDER_ASCENDING, ORDER_ASCENDING)))
1578
as $index => $test) {
1579
$ret = GalleryCoreApi::setPluginParameter(
1580
'module', 'core', 'default.orderBy', $test['sort'][0]);
1582
return $this->failWithStatus($ret);
1585
$ret = GalleryCoreApi::setPluginParameter(
1586
'module', 'core', 'default.orderDirection', $test['order'][0]);
1588
return $this->failWithStatus($ret);
1591
$ret = GalleryCoreApi::deleteSortOrder('MyTestSortOrder');
1593
return $this->failWithStatus($ret);
1596
list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'core');
1598
return $this->failWithStatus($ret);
1601
$this->assertEquals($test['sort'][1], $params['default.orderBy'],
1602
"orderBy: $index test case");
1603
$this->assertEquals($test['order'][1], $params['default.orderDirection'],
1604
"orderDirection: $index test case");
1608
function testMultipleThumbnailPreferences() {
1609
$ret = GalleryCoreApi::removeDerivativePreferencesForItem($this->_album->getId());
1611
return $this->failWithStatus($ret);
1614
/* Add 2 thumbnail preferences */
1615
for ($i = 0; $i < 2; $i++) {
1616
$ret = GalleryCoreApi::addDerivativePreference(
1617
0, $this->_album->getId(), DERIVATIVE_TYPE_IMAGE_THUMBNAIL, "thumbnail|[$i]");
1619
return $this->failWithStatus($ret);
1623
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($this->_album->getId());
1625
return $this->failWithStatus($ret);
1628
list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum(
1629
dirname(__FILE__) . '/../data/test1.jpg', 'itemName',
1630
'title', 'caption', 'description', 'image/jpeg', $this->_album->getId());
1632
return $this->failWithStatus($ret);
1635
$ret = GalleryCoreApi::releaseLocks($lockId);
1637
return $this->failWithStatus($ret);
1640
/* We should have ignored the duplicate preference */
1641
list ($ret, $thumbTable) = GalleryCoreApi::fetchThumbnailsByItemIds(
1642
array($newItem->getId()));
1644
return $this->failWithStatus($ret);
1647
$this->assert(!empty($thumbTable[$newItem->getId()]), 'missing thumbnail');
1648
$operation = $thumbTable[$newItem->getId()]->getDerivativeOperations();
1649
$this->assert(($operation == 'thumbnail|[0]' ||
1650
$operation == 'thumbnail|[1]'), 'Wrong operation');
1653
function testDeleteRenderer() {
1654
foreach (array('ItemTestRendererToDelete', 'ItemTestRendererToKeep') as $rendererClass) {
1655
list ($ret, $items[]) = $this->_createRandomDataItem(
1656
$this->_album->getId(), 'application/unknown', array('renderer' => $rendererClass));
1658
return $this->failWithStatus($ret);
1662
$ret = GalleryCoreApi::deleteRenderer('ItemTestRendererToDelete');
1664
return $this->failWithStatus($ret);
1667
for ($i = 0; $i < 2; $i++) {
1668
list ($ret, $items[$i]) = $items[$i]->refresh();
1670
return $this->failWithStatus($ret);
1674
/* For Oracle, null is replaced with '' when loading data from the database */
1675
$this->assert(in_array($items[0]->getRenderer(), array(null, '')));
1676
$this->assertEquals('ItemTestRendererToKeep', $items[1]->getRenderer());
1679
function testCreateLinkCopiesRenderer() {
1680
/* Create target item */
1681
list ($ret, $item) = $this->_createRandomDataItem($this->_album->getId(),
1682
'application/unknown', array('renderer' => 'TEST_RENDERER'));
1684
return $this->failWithStatus($ret);
1687
list ($ret, $linkedItem) = $this->_createLinkedItem($this->_album->getId(), $item);
1689
return $this->failWithStatus($ret);
1692
$this->assertEquals('TEST_RENDERER', $linkedItem->getRenderer());
1699
* @package GalleryCore
1700
* @subpackage PHPUnit
1702
class ItemTestToolkit extends GalleryToolkit {
1704
function getProperty($mimeType, $propertyName, $sourceFilename) {
1705
/* This will be called by addItemToAlbum */
1706
if ($propertyName == 'originationTimestamp') {
1708
if (basename($sourceFilename) == 'itemNameWts') {
1709
$results = array(12345);
1711
return array(null, $results);
1712
} else if ($propertyName == 'dimensions'
1713
&& in_array($mimeType, array('image/gif', 'image/jpeg'))) {
1714
return array(null, array(62, 75));
1716
/* We'll reach this point in testSymlinkTwice, but we want to return an error */
1717
return array(GalleryCoreApi::error(ERROR_UNIMPLEMENTED), null);
1722
GalleryCoreApi::requireOnce('modules/core/classes/GalleryMovieItem.class');
1723
GalleryCoreApi::requireOnce('modules/core/classes/GalleryRenderer.class');
1728
class ItemTestMovieItem extends GalleryMovieItem {
1730
* @see GalleryEntity::getClassName
1732
function getClassName() {
1733
return 'ItemTestMovieItem';
1740
class ItemTestRenderer extends GalleryRenderer {
1742
* @see GalleryRenderer::canBeViewedInline
1744
function canBeViewedInline($item) {
1745
return (substr($item->getMimeType(), 0, 5) == 'test/');
1749
* @see GalleryRenderer::render
1751
function render($format, $entity, $item, $params) {