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 DynamicAlbum views
24
* @package DynamicAlbum
26
* @author Alan Harder <alan.harder@sun.com>
27
* @version $Revision: 15513 $
29
class DynamicAlbumTest extends GalleryTestCase {
31
function DynamicAlbumTest($methodName) {
32
$this->GalleryTestCase($methodName);
38
list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
40
print $ret->getAsHtml();
41
return $this->failWithStatus($ret);
43
$this->_markForCleanup($this->_album);
45
$time = array(1 => time() - 100, 2 => time(), 3 => time() - 50);
46
foreach (array(1 => 5, 2 => 0, 3 => 999999999) as $i => $viewCount) {
47
list ($ret, $this->_items[$i]) = $this->_createRandomDataItem($this->_album->getId(),
48
'test/item', array('creationTimestamp' => $time[$i]));
50
print $ret->getAsHtml();
51
return $this->failWithStatus($ret);
53
$ret = GalleryCoreApi::setItemViewCount($this->_items[$i]->getId(), $viewCount);
55
print $ret->getAsHtml();
56
return $this->failWithStatus($ret);
60
list ($ret, $this->_module) = GalleryCoreApi::loadPlugin('module', 'dynamicalbum');
62
print $ret->getAsHtml();
63
return $this->failWithStatus($ret);
65
list ($ret, $this->_updatesView) = GalleryView::loadView('dynamicalbum.UpdatesAlbum');
67
print $ret->getAsHtml();
68
return $this->failWithStatus($ret);
70
list ($ret, $this->_popularView) = GalleryView::loadView('dynamicalbum.PopularAlbum');
72
print $ret->getAsHtml();
73
return $this->failWithStatus($ret);
75
list ($ret, $this->_randomView) = GalleryView::loadView('dynamicalbum.RandomAlbum');
77
print $ret->getAsHtml();
78
return $this->failWithStatus($ret);
81
$ret = $this->_markPluginParametersForCleanup('module', 'dynamicalbum');
83
print $ret->getAsHtml();
84
return $this->failWithStatus($ret);
86
foreach (array('date', 'views', 'random') as $key) {
87
$ret = GalleryCoreApi::setPluginParameter('module', 'dynamicalbum',
90
print $ret->getAsHtml();
91
return $this->failWithStatus($ret);
95
GalleryCoreApi::requireOnce('modules/core/classes/GalleryTemplate.class');
97
new GalleryTemplate(dirname(dirname(dirname(dirname(dirname(__FILE__))))));
98
$this->_class = array('date' => 'UpdatesAlbum', 'views' => 'PopularAlbum',
99
'random' => 'RandomAlbum');
102
function testLoadThemeAndSettingsForAlbum() {
103
foreach (array('date' => $this->_updatesView, 'views' => $this->_popularView,
104
'random' => $this->_randomView) as $key => $view) {
105
$ret = GalleryCoreApi::setPluginParameter('module', 'dynamicalbum',
106
'description.' . $key, 'desc ' . $key);
108
return $this->failWithStatus($ret);
111
list ($ret, $theme, $params, $item) = $view->loadThemeAndParameters();
113
return $this->failWithStatus($ret);
116
$this->assert(GalleryUtilities::isA($theme, 'GalleryTheme'), $key . ': theme');
117
$this->assert(is_array($params), $key . ': theme settings');
118
$this->assert(GalleryUtilities::isA($item, 'GalleryDynamicAlbum'), $key . ': item');
119
$this->assert(!isset($item->parent), $key . ': item parent');
120
$this->assertEquals('desc ' . $key, $item->getDescription(), $key . ': description');
124
function testLoadThemeAndSettingsForItem() {
125
GalleryUtilities::putRequestVariable('itemId', $this->_items[1]->getId());
127
foreach (array('date' => $this->_updatesView, 'views' => $this->_popularView,
128
'random' => $this->_randomView) as $key => $view) {
129
$ret = GalleryCoreApi::setPluginParameter('module', 'dynamicalbum',
130
'description.' . $key, 'hi');
132
return $this->failWithStatus($ret);
135
list ($ret, $theme, $params, $item) = $view->loadThemeAndParameters();
137
return $this->failWithStatus($ret);
140
$this->assert(GalleryUtilities::isA($theme, 'GalleryTheme'), $key . ': theme');
141
$this->assert(is_array($params), $key . ': theme settings');
142
$this->assert(GalleryUtilities::isA($item, 'GalleryDataItem'), $key . ': item');
143
$this->assert(isset($item->parent), $key . ': item parent');
144
$this->assert(GalleryUtilities::isA($item->parent, 'GalleryDynamicAlbum'),
145
$key . ': parent type');
146
$this->assertEquals('hi', $item->parent->getDescription(),
147
$key . ': parent description');
148
$this->assertEquals(array(get_class($view), 'getChildIds'),
149
$item->parent->getChildrenFunction, $key . ': get children function');
153
function testLoadTemplateForAlbum() {
155
foreach (array('date' => $this->_updatesView, 'views' => $this->_popularView,
156
'random' => $this->_randomView) as $key => $view) {
157
$ret = GalleryCoreApi::setPluginParameter('module', 'dynamicalbum',
158
'type.' . $key, 'all');
160
return $this->failWithStatus($ret);
163
$template = new GalleryTemplate(dirname(dirname(dirname(dirname(dirname(__FILE__))))));
164
$theme =& $template->getVariableByReference('theme');
165
$theme['actingUserId'] = $gallery->getActiveUserId();
167
list ($ret, $result) = $view->loadTemplate($template, $form = array());
169
return $this->failWithStatus($ret);
172
$this->assertEquals(array('view' => 'dynamicalbum.' . $this->_class[$key]),
173
$theme['pageUrl'], $key . ': page url');
174
$this->assertEquals(4, count($theme['allChildIds']), $key . ': item count');
178
function testLoadTemplateForAlbumTree() {
180
GalleryUtilities::putRequestVariable('albumId', $this->_album->getId());
181
$type = array('date' => 'all', 'views' => 'data', 'random' => 'album');
183
foreach (array('date' => $this->_updatesView, 'views' => $this->_popularView,
184
'random' => $this->_randomView) as $key => $view) {
185
GalleryUtilities::putRequestVariable('show', $type[$key]);
187
$template = new GalleryTemplate(dirname(dirname(dirname(dirname(dirname(__FILE__))))));
188
$theme =& $template->getVariableByReference('theme');
189
$theme['actingUserId'] = $gallery->getActiveUserId();
191
list ($ret, $result) = $view->loadTemplate($template, $form = array());
193
return $this->failWithStatus($ret);
196
$this->assertEquals(array('view' => 'dynamicalbum.' . $this->_class[$key],
197
'albumId' => $this->_album->getId(), 'show' => $type[$key]),
198
$theme['pageUrl'], $key . ': page url');
199
$this->assertEquals($key == 'random' ? 0 : 3, count($theme['allChildIds']),
200
$key . ': item count');
201
if ($key == 'date') {
202
$this->assertEquals(array($this->_items[2]->getId(), $this->_items[3]->getId(),
203
$this->_items[1]->getId()), $theme['allChildIds'], 'date: child ids');
204
} else if ($key == 'views') {
205
$this->assertEquals(array($this->_items[3]->getId(), $this->_items[1]->getId(),
206
$this->_items[2]->getId()), $theme['allChildIds'], 'views: child ids');
211
function testLoadTemplateForItem() {
212
list ($ret, $count) = GalleryCoreApi::fetchItemViewCount($this->_items[2]->getId());
214
return $this->failWithStatus($ret);
216
$this->assertEquals(0, $count, 'count before');
218
GalleryUtilities::putRequestVariable('itemId', $this->_items[2]->getId());
220
list ($ret, $result) = $this->_updatesView->loadTemplate($this->_template, $form = array());
222
return $this->failWithStatus($ret);
225
$theme =& $this->_template->getVariableByReference('theme');
226
$this->assertEquals(array('view' => 'dynamicalbum.UpdatesAlbum'),
227
$theme['pageUrl'], 'page url');
229
list ($ret, $count) = GalleryCoreApi::fetchItemViewCount($this->_items[2]->getId());
231
return $this->failWithStatus($ret);
233
$this->assertEquals(1, $count, 'count after');
236
function testLoadTemplateForAlbumNoPermission() {
238
$theme =& $this->_template->getVariableByReference('theme');
239
$theme['actingUserId'] = $gallery->getActiveUserId();
241
$ret = GalleryCoreApi::setPluginParameter('module', 'dynamicalbum', 'size.views', '0');
243
return $this->failWithStatus($ret);
246
list ($ret, $result) = $this->_popularView->loadTemplate($this->_template, $form = array());
248
$this->assert($ret->getErrorCode() & ERROR_PERMISSION_DENIED, 'permission denied');
250
$this->assert(false, 'should get error');
254
function testLoadTemplateForItemNoPermission() {
255
$ret = GalleryCoreApi::removeItemPermissions($this->_items[3]->getId());
257
return $this->failWithStatus($ret);
260
GalleryUtilities::putRequestVariable('itemId', $this->_items[3]->getId());
262
list ($ret, $result) = $this->_randomView->loadTemplate($this->_template, $form = array());
264
return $this->failWithStatus($ret);
268
array('redirect' => array('view' => 'core.ShowItem', 'itemId' => $this->_getRootId())),
269
$result, 'redirect');
272
function testItemLinks() {
273
foreach (array('date', 'views', 'random') as $key) {
274
$ret = GalleryCoreApi::setPluginParameter('module', 'dynamicalbum',
275
'itemlink.' . $key, '1');
277
return $this->failWithStatus($ret);
280
$items = array($this->_album, $this->_items[2]);
282
list ($ret, $links) = $this->_module->getItemLinks($items,
283
array($this->_album->getId() => true, $this->_items[2]->getId() => true),
286
return $this->failWithStatus($ret);
289
array($this->_album->getId() => array(
290
array('text' => $this->_module->translate('View Latest Updates'),
291
'params' => array('view' => 'dynamicalbum.UpdatesAlbum',
292
'albumId' => $this->_album->getId())),
293
array('text' => $this->_module->translate('View Popular Items'),
294
'params' => array('view' => 'dynamicalbum.PopularAlbum',
295
'albumId' => $this->_album->getId())),
296
array('text' => $this->_module->translate('View Random Items'),
297
'params' => array('view' => 'dynamicalbum.RandomAlbum',
298
'albumId' => $this->_album->getId()))
302
$ret = GalleryCoreApi::setPluginParameter('module', 'dynamicalbum', 'itemlink.views', '0');
304
return $this->failWithStatus($ret);
307
list ($ret, $links) = $this->_module->getItemLinks($items,
308
array($this->_album->getId() => true, $this->_items[2]->getId() => true),
311
return $this->failWithStatus($ret);
314
array($this->_album->getId() => array(
315
array('text' => $this->_module->translate('View Latest Updates'),
316
'params' => array('view' => 'dynamicalbum.UpdatesAlbum',
317
'albumId' => $this->_album->getId())),
318
array('text' => $this->_module->translate('View Random Items'),
319
'params' => array('view' => 'dynamicalbum.RandomAlbum',
320
'albumId' => $this->_album->getId()))
324
list ($ret, $links) = $this->_module->getItemLinks($items,
325
array($this->_items[2]->getId() => true),
328
return $this->failWithStatus($ret);
330
$this->assertEquals(array(), $links, 'none');