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.
21
GalleryCoreApi::requireOnce('modules/imageblock/Callbacks.inc');
24
* ImageBlockOption tests
27
* @author Jay Rossiter <cryptographite@users.sf.net>
28
* @version $Revision: 15513 $
30
class ImageBlockDisabledTest extends GalleryTestCase {
32
function ImageBlockDisabledTest($methodName) {
33
$this->GalleryTestCase($methodName);
37
* Create an album for testing
42
/* Register a dummy toolkit and operation */
43
$ret = GalleryCoreApi::registerFactoryImplementation(
44
'GalleryToolkit', 'ImageBlockToolkit', 'ImageBlockToolkit',
45
'modules/imageblock/test/phpunit/ImageBlockDisabledTest.class', 'imageblock', null);
47
print $ret->getAsHtml();
48
return $this->failWithStatus($ret);
50
$this->_markToolkitForCleanup('ImageBlockToolkit');
52
$ret = GalleryCoreApi::registerToolkitOperation(
53
'ImageBlockToolkit', array('image/gif'), 'testoperation',
54
array(array('type' => 'int', 'description' => 'size')), 'desc');
56
print $ret->getAsHtml();
57
return $this->failWithStatus($ret);
60
list ($ret, $this->_module) = GalleryCoreApi::loadPlugin('module', 'imageblock');
61
if ($ret || !isset($this->_module)) {
62
print $ret->getAsHtml();
63
return $this->failWithStatus($ret);
66
list ($ret, $this->_topAlbum, $this->_topItems) =
67
$this->_createSubAlbumWithItems($this->_getRootId());
69
print $ret->getAsHtml();
70
return $this->failWithStatus($ret);
73
$this->_markForCleanup($this->_topAlbum);
75
list ($ret, $this->_subAlbum, $this->_subItems) =
76
$this->_createSubAlbumWithItems($this->_topAlbum->getId());
78
print $ret->getAsHtml();
79
return $this->failWithStatus($ret);
82
/* Set the ImageBlockDisabled flag */
83
$ret = ImageBlockHelper::setDisabledFlag($this->_topAlbum, true, true);
85
print $ret->getAsHtml();
86
return $this->failWithStatus($ret);
89
list ($ret, $this->_itemId) = $this->_module->getParameter('itemId');
91
print $ret->getAsHtml();
92
return $this->failWithStatus($ret);
95
$ret = $this->_module->setParameter('itemId', $this->_topAlbum->getId());
97
print $ret->getAsHtml();
98
return $this->failWithStatus($ret);
103
* Delete the album that was used for testing
105
function tearDown() {
106
$ret = GalleryCoreApi::removePluginParameter(
107
$this->_module->getPluginType(), $this->_module->getId(), 'itemId');
109
print $ret->getAsHtml();
110
return $this->failWithStatus($ret);
113
/* Unset the ImageBlockDisabled flag */
114
$ret = ImageBlockHelper::setDisabledFlag($this->_topAlbum, true, false);
116
print $ret->getAsHtml();
117
return $this->failWithStatus($ret);
123
function _createSubAlbumWithItems($parentId) {
124
/* Create a new album and image, set thumbnail and highlight */
125
list ($ret, $album) = $this->_createRandomAlbum($parentId);
127
return array($ret, null, null);
130
list ($ret, $lockId) = GalleryCoreApi::acquireReadLock($album->getId());
132
return array($ret, null, null);
135
$imagePath = GalleryCoreApi::getPluginBaseDir('module', 'core')
136
. 'modules/core/test/data/test1.gif';
137
list ($ret, $photo, $thumbId) = $this->_addPhoto($album->getId(), $imagePath);
139
return array($ret, null, null);
141
$ret = GalleryCoreApi::releaseLocks($lockId);
143
return array($ret, null, null);
145
list ($ret, $tmpId) =
146
$this->_addDerivative($album, $photo, DERIVATIVE_TYPE_IMAGE_THUMBNAIL, 150);
148
return array($ret, null, null);
152
$items[] = $photo->getId();
153
return array(null, $album, $items);
156
function _addPhoto($parentId, $imagePath) {
157
list ($ret, $photo) =
158
GalleryCoreApi::newFactoryInstance('GalleryEntity', 'GalleryPhotoItem');
160
return array($ret, null, null);
162
list ($ret, $mimeType) = GalleryCoreApi::getMimeType($imagePath);
164
return array($ret, null, null);
166
$ret = $photo->create($parentId, $imagePath, $mimeType,
167
'testitem_' . time() . substr($imagePath, -4));
169
return array($ret, null, null);
171
$photo->setTitle('Test Item');
172
$ret = $photo->save();
174
return array($ret, null, null);
177
list ($ret, $thumbId) = $this->_addDerivative($photo, $photo,
178
DERIVATIVE_TYPE_IMAGE_THUMBNAIL, 150);
180
return array($ret, null, null);
182
return array(null, $photo, $thumbId);
185
function _addDerivative(&$item, &$src, $derivativeType, $size) {
186
list ($ret, $derivative) =
187
GalleryCoreApi::newFactoryInstanceByHint('GalleryDerivative', $item->getEntityType());
189
return array($ret, null);
191
if (!isset($derivative)) {
192
return array(GalleryCoreApi::error(ERROR_MISSING_OBJECT), null);
194
$ret = $derivative->create($item->getId(), $derivativeType);
196
return array($ret, null);
198
$derivative->setDerivativeSourceId($src->getId());
199
$derivative->setMimeType($src->getMimeType());
200
$derivative->setDerivativeOperations('testoperation|0');
202
/* Set scaled size: */
203
$w = $src->getWidth();
204
$h = $src->getHeight();
205
if ($w <= $size && $h <= $size && $derivativeType == DERIVATIVE_TYPE_IMAGE_THUMBNAIL) {
206
$derivative->setWidth($w);
207
$derivative->setHeight($h);
208
} else if ($w >= $h) {
209
$derivative->setWidth($size);
210
$derivative->setHeight((int)($size*$h/$w));
212
$derivative->setHeight($size);
213
$derivative->setWidth((int)($size*$w/$h));
216
/* Set rotated size (swap wd/ht): */
217
$derivative->setWidth($src->getHeight());
218
$derivative->setHeight($src->getWidth());
220
$ret = $derivative->save();
222
return array($ret, null);
224
return array(null, $derivative->getId());
227
function assertBlock($block) {
228
$this->assert(isset($block['id']), 'Missing id');
229
$this->assert(isset($block['viewCount']), 'Missing viewCount');
230
$this->assert(isset($block['title']), 'Missing title');
231
$this->assert(isset($block['item']), 'Missing item');
232
$this->assert(isset($block['thumb']), 'Missing thumb');
235
function testImageBlockDisabledNoItemsReturned() {
236
$smarty = new GallerySmarty();
237
$callbacks = new ImageBlockCallbacks();
238
$ret = $callbacks->callback(array('useDefaults' => true), $smarty, 'LoadImageBlock');
240
return $this->failWithStatus($ret);
242
$data = $smarty->_tpl_vars;
243
$this->assert(!isset($data['ImageBlockData']['blocks']), 'Block should not exist');
246
function testImageBlockDisabledOneItemReturned() {
247
/* Unset the ImageBlockDisabled flag on the subAlbum */
248
$ret = ImageBlockHelper::setDisabledFlag($this->_subAlbum, true, false);
250
return $this->failWithStatus($ret);
253
$smarty = new GallerySmarty();
254
$callbacks = new ImageBlockCallbacks();
255
$ret = $callbacks->callback(array('useDefaults' => true), $smarty, 'LoadImageBlock');
257
return $this->failWithStatus($ret);
259
$data = $smarty->_tpl_vars;
261
$this->assert(1 == count($data['ImageBlockData']['blocks']), 'One block');
262
$this->assertBlock($data['ImageBlockData']['blocks'][0]);