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 Image Block helper
25
* @author Jay Rossiter <cryptographite@users.sf.net>
26
* @version $Revision: 15875 $
28
class ImageBlockHelperTest extends GalleryTestCase {
30
function ImageBlockHelperTest($methodName) {
31
$this->GalleryTestCase($methodName);
34
function _createTopAlbum() {
35
/* Create a new album and image, set thumbnail and highlight */
36
list ($ret, $album) = $this->_createRandomAlbum($this->_getRootId());
38
return array($ret, null);
40
$this->_markForCleanup($album);
41
return array(null, $album);
44
function _createHierarchy() {
45
list ($ret, $this->_topAlbum, $this->_topItems) =
46
$this->_createSubAlbumWithItems($this->_getRootId());
48
return $this->failWithStatus($ret);
50
$this->_markForCleanup($this->_topAlbum);
52
list ($ret, $this->_subAlbum, $this->_subItems) =
53
$this->_createSubAlbumWithItems($this->_topAlbum->getId());
55
return $this->failWithStatus($ret);
59
function _createSubAlbumWithItems($parentId) {
60
/* Create a new album and image, set thumbnail and highlight */
61
list ($ret, $album) = $this->_createRandomAlbum($parentId);
63
return array($ret, null, null);
67
for ($i = 0; $i < 5; $i++) {
68
list ($ret, $items[$i]) = $this->_createRandomDataItem($album->getId());
70
return array($ret, null, null);
74
return array(null, $album, $items);
77
function testImageBlockHelperGetDisabledFlag() {
78
$ret = $this->_createHierarchy();
80
return $this->failWithStatus($ret);
83
$ret = GalleryCoreApi::addMapEntry(
84
'ImageBlockDisabledMap', array('itemId' => $this->_topAlbum->getId()));
86
return $this->failWithStatus($ret);
88
list ($ret, $disabledFlag) = ImageBlockHelper::getDisabledFlag($this->_topAlbum->getId());
89
$this->assert($disabledFlag, 'getDisabledFlag returned false');
91
$ret = GalleryCoreApi::removeMapEntry(
92
'ImageBlockDisabledMap', array('itemId' => $this->_topAlbum->getId()));
94
return $this->failWithStatus($ret);
97
list ($ret, $disabledFlag) = ImageBlockHelper::getDisabledFlag($this->_topAlbum->getId());
98
$this->assert(!$disabledFlag, 'getDisabledFlag returned true');
101
function testImageBlockHelperSetDisabledFlag() {
104
$ret = $this->_createHierarchy();
106
return $this->failWithStatus($ret);
109
$ret = ImageBlockHelper::setDisabledFlag($this->_topAlbum, false, true);
111
return $this->failWithStatus($ret);
115
foreach ($this->_topItems as $item) {
116
$itemIds[] = (int)$item->getId();
118
$itemIds[] = (int)$this->_topAlbum->getId();
121
$query = 'SELECT [ImageBlockDisabledMap::itemId] ' .
122
'FROM [ImageBlockDisabledMap] ' .
123
'WHERE [ImageBlockDisabledMap::itemId] IN (' .
124
GalleryUtilities::makeMarkers(sizeof($itemIds)) .
127
list ($ret, $searchResults) = $gallery->search($query, $itemIds);
129
return $this->failWithStatus($ret);
132
$dbItemIds = array();
133
while ($rec = $searchResults->nextResult()) {
134
$dbItemIds[] = (int)$rec[0];
138
$this->assertEquals($itemIds, $dbItemIds, 'Items not added to the DisableMap');
140
$ret = ImageBlockHelper::setDisabledFlag($this->_topAlbum, false, false);
142
return $this->failWithStatus($ret);
145
list ($ret, $searchResults) = $gallery->search($query, $itemIds);
147
return $this->failWithStatus($ret);
150
$dbItemIds = array();
151
while ($rec = $searchResults->nextResult()) {
152
$dbItemIds[] = (int)$rec[0];
154
$this->assertEquals(array(), $dbItemIds, 'Items not removed from the DisabledMap');
157
function testImageBlockHelperSetDisabledFlagRecursive() {
160
$ret = $this->_createHierarchy();
162
return $this->failWithStatus($ret);
165
$mockAdapter = new MockTemplateAdapter();
166
$gallery->_templateAdapter =& $mockAdapter;
168
$ret = ImageBlockHelper::setDisabledFlag($this->_topAlbum, true, true);
170
return $this->failWithStatus($ret);
174
foreach (array_merge($this->_topItems, $this->_subItems) as $item) {
175
$itemIds[] = (int)$item->getId();
177
$itemIds[] = (int)$this->_topAlbum->getId();
178
$itemIds[] = (int)$this->_subAlbum->getId();
181
$query = 'SELECT [ImageBlockDisabledMap::itemId] ' .
182
'FROM [ImageBlockDisabledMap] ' .
183
'WHERE [ImageBlockDisabledMap::itemId] IN (' .
184
GalleryUtilities::makeMarkers(sizeof($itemIds)) .
187
list ($ret, $searchResults) = $gallery->search($query, $itemIds);
189
return $this->failWithStatus($ret);
192
$dbItemIds = array();
193
while ($rec = $searchResults->nextResult()) {
194
$dbItemIds[] = (int)$rec[0];
197
$this->assertEquals($itemIds, $dbItemIds, 'Items not added to the DisableMap');
199
$ret = ImageBlockHelper::setDisabledFlag($this->_topAlbum, true, false);
201
return $this->failWithStatus($ret);
204
$query = 'SELECT [ImageBlockDisabledMap::itemId] ' .
205
'FROM [ImageBlockDisabledMap] ' .
206
'WHERE [ImageBlockDisabledMap::itemId] IN (' .
207
GalleryUtilities::makeMarkers(sizeof($itemIds)) .
210
list ($ret, $searchResults) = $gallery->search($query, $itemIds);
212
return $this->failWithStatus($ret);
215
$dbItemIds = array();
216
while ($rec = $searchResults->nextResult()) {
217
$dbItemIds[] = (int)$rec[0];
219
$this->assertEquals(array(), $dbItemIds, 'Items not removed from the DisabledMap');
222
function testImageBlockHelperSetDisabledFlagFirstSubAlbumThenRecursive() {
225
$ret = $this->_createHierarchy();
227
return $this->failWithStatus($ret);
230
/* Prepare the test by first disabling the subalbum */
231
$ret = ImageBlockHelper::setDisabledFlag($this->_subAlbum, false, true);
233
return $this->failWithStatus($ret);
237
foreach ($this->_subItems as $item) {
238
$itemIds[] = (int)$item->getId();
240
$itemIds[] = (int)$this->_subAlbum->getId();
242
/* Verify the precondition of the test */
243
list ($ret, $searchResults) = GalleryCoreApi::getMapEntry('ImageBlockDisabledMap',
245
array('itemId' => $itemIds));
247
return $this->failWithStatus($ret);
250
$dbItemIds = array();
251
while ($rec = $searchResults->nextResult()) {
252
$dbItemIds[] = (int)$rec[0];
257
$this->assertEquals($itemIds, $dbItemIds,
258
'Precondition: Items not added to the DisableMap');
260
/* Execute the test: Ensure that we succeed and don't attempt to insert duplicate rows. */
261
$ret = ImageBlockHelper::setDisabledFlag($this->_topAlbum, true, true);
263
return $this->failWithStatus($ret);
266
foreach ($this->_topItems as $item) {
267
$itemIds[] = (int)$item->getId();
269
$itemIds[] = (int)$this->_topAlbum->getId();
271
/* Verify the results */
272
list ($ret, $searchResults) = GalleryCoreApi::getMapEntry('ImageBlockDisabledMap',
274
array('itemId' => $itemIds));
276
return $this->failWithStatus($ret);
279
$dbItemIds = array();
280
while ($rec = $searchResults->nextResult()) {
281
$dbItemIds[] = (int)$rec[0];
286
$this->assertEquals($itemIds, $dbItemIds, 'Not all items have been flagged as disabled');
290
* Verify the fix for bug 1536395
291
* http://sourceforge.net/tracker/index.php?func=detail&aid=1536395&group_id=7130&atid=107130
293
function testMaxSizeWithoutViewSourcePermission() {
296
list ($ret, $top) = $this->_createTopAlbum();
298
return $this->failWithStatus($ret);
301
list ($ret, $album) = $this->_createRandomAlbum($top->getId());
303
return $this->failWithStatus($ret);
306
list ($ret, $photo) = $this->_createRandomDataItem($album->getId());
308
return $this->failWithStatus($ret);
311
list ($ret, $thumbnail) = $this->_createDerivative(
312
$album, $photo->getId(), DERIVATIVE_TYPE_IMAGE_THUMBNAIL);
314
return $this->failWithStatus($ret);
317
$ret = GalleryCoreApi::removeItemPermissions($photo->getId());
319
return $this->failWithStatus($ret);
322
$ret = GalleryCoreApi::addUserPermission(
323
$photo->getId(), $gallery->getActiveUserId(), 'core.view');
325
return $this->failWithStatus($ret);
328
list ($ret, $results) = ImageBlockHelper::_getBlockData(
329
'Album', 'recent', 1, $top->getId(), false, null, 200 /* maxSize */);
331
return $this->failWithStatus($ret);
334
$this->assertEquals($thumbnail->getId(), $results[0]['thumb']['id']);