~ubuntu-branches/ubuntu/maverick/gallery2/maverick

« back to all changes in this revision

Viewing changes to modules/dynamicalbum/test/phpunit/DynamicAlbumTest.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2007-09-10 20:22:19 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070910202219-0jsuntvqge4ade6b
Tags: 2.2.3-2
Add Slovak translation of Debconf templates.  (Thanks to 
Ivan Masá.  Closes: #441671)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Gallery - a web based photo album viewer and editor
4
 
 * Copyright (C) 2000-2007 Bharat Mediratta
5
 
 *
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.
10
 
 *
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.
15
 
 *
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.
19
 
 */
20
 
 
21
 
/**
22
 
 * Test DynamicAlbum views
23
 
 *
24
 
 * @package DynamicAlbum
25
 
 * @subpackage PHPUnit
26
 
 * @author Alan Harder <alan.harder@sun.com>
27
 
 * @version $Revision: 15513 $
28
 
 */
29
 
class DynamicAlbumTest extends GalleryTestCase {
30
 
 
31
 
    function DynamicAlbumTest($methodName) {
32
 
        $this->GalleryTestCase($methodName);
33
 
    }
34
 
 
35
 
    function setUp() {
36
 
        parent::setUp();
37
 
 
38
 
        list ($ret, $this->_album) = $this->_createRandomAlbum($this->_getRootId());
39
 
        if ($ret) {
40
 
            print $ret->getAsHtml();
41
 
            return $this->failWithStatus($ret);
42
 
        }
43
 
        $this->_markForCleanup($this->_album);
44
 
 
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]));
49
 
            if ($ret) {
50
 
                print $ret->getAsHtml();
51
 
                return $this->failWithStatus($ret);
52
 
            }
53
 
            $ret = GalleryCoreApi::setItemViewCount($this->_items[$i]->getId(), $viewCount);
54
 
            if ($ret) {
55
 
                print $ret->getAsHtml();
56
 
                return $this->failWithStatus($ret);
57
 
            }
58
 
        }
59
 
 
60
 
        list ($ret, $this->_module) = GalleryCoreApi::loadPlugin('module', 'dynamicalbum');
61
 
        if ($ret) {
62
 
            print $ret->getAsHtml();
63
 
            return $this->failWithStatus($ret);
64
 
        }
65
 
        list ($ret, $this->_updatesView) = GalleryView::loadView('dynamicalbum.UpdatesAlbum');
66
 
        if ($ret) {
67
 
            print $ret->getAsHtml();
68
 
            return $this->failWithStatus($ret);
69
 
        }
70
 
        list ($ret, $this->_popularView) = GalleryView::loadView('dynamicalbum.PopularAlbum');
71
 
        if ($ret) {
72
 
            print $ret->getAsHtml();
73
 
            return $this->failWithStatus($ret);
74
 
        }
75
 
        list ($ret, $this->_randomView) = GalleryView::loadView('dynamicalbum.RandomAlbum');
76
 
        if ($ret) {
77
 
            print $ret->getAsHtml();
78
 
            return $this->failWithStatus($ret);
79
 
        }
80
 
 
81
 
        $ret = $this->_markPluginParametersForCleanup('module', 'dynamicalbum');
82
 
        if ($ret) {
83
 
            print $ret->getAsHtml();
84
 
            return $this->failWithStatus($ret);
85
 
        }
86
 
        foreach (array('date', 'views', 'random') as $key) {
87
 
            $ret = GalleryCoreApi::setPluginParameter('module', 'dynamicalbum',
88
 
                                                      'size.' . $key, '4');
89
 
            if ($ret) {
90
 
                print $ret->getAsHtml();
91
 
                return $this->failWithStatus($ret);
92
 
            }
93
 
        }
94
 
 
95
 
        GalleryCoreApi::requireOnce('modules/core/classes/GalleryTemplate.class');
96
 
        $this->_template =
97
 
            new GalleryTemplate(dirname(dirname(dirname(dirname(dirname(__FILE__))))));
98
 
        $this->_class = array('date' => 'UpdatesAlbum', 'views' => 'PopularAlbum',
99
 
                              'random' => 'RandomAlbum');
100
 
    }
101
 
 
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);
107
 
            if ($ret) {
108
 
                return $this->failWithStatus($ret);
109
 
            }
110
 
 
111
 
            list ($ret, $theme, $params, $item) = $view->loadThemeAndParameters();
112
 
            if ($ret) {
113
 
                return $this->failWithStatus($ret);
114
 
            }
115
 
 
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');
121
 
        }
122
 
    }
123
 
 
124
 
    function testLoadThemeAndSettingsForItem() {
125
 
        GalleryUtilities::putRequestVariable('itemId', $this->_items[1]->getId());
126
 
 
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');
131
 
            if ($ret) {
132
 
                return $this->failWithStatus($ret);
133
 
            }
134
 
 
135
 
            list ($ret, $theme, $params, $item) = $view->loadThemeAndParameters();
136
 
            if ($ret) {
137
 
                return $this->failWithStatus($ret);
138
 
            }
139
 
 
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');
150
 
        }
151
 
    }
152
 
 
153
 
    function testLoadTemplateForAlbum() {
154
 
        global $gallery;
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');
159
 
            if ($ret) {
160
 
                return $this->failWithStatus($ret);
161
 
            }
162
 
 
163
 
            $template = new GalleryTemplate(dirname(dirname(dirname(dirname(dirname(__FILE__))))));
164
 
            $theme =& $template->getVariableByReference('theme');
165
 
            $theme['actingUserId'] = $gallery->getActiveUserId();
166
 
 
167
 
            list ($ret, $result) = $view->loadTemplate($template, $form = array());
168
 
            if ($ret) {
169
 
                return $this->failWithStatus($ret);
170
 
            }
171
 
 
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');
175
 
        }
176
 
    }
177
 
 
178
 
    function testLoadTemplateForAlbumTree() {
179
 
        global $gallery;
180
 
        GalleryUtilities::putRequestVariable('albumId', $this->_album->getId());
181
 
        $type = array('date' => 'all', 'views' => 'data', 'random' => 'album');
182
 
 
183
 
        foreach (array('date' => $this->_updatesView, 'views' => $this->_popularView,
184
 
                       'random' => $this->_randomView) as $key => $view) {
185
 
            GalleryUtilities::putRequestVariable('show', $type[$key]);
186
 
 
187
 
            $template = new GalleryTemplate(dirname(dirname(dirname(dirname(dirname(__FILE__))))));
188
 
            $theme =& $template->getVariableByReference('theme');
189
 
            $theme['actingUserId'] = $gallery->getActiveUserId();
190
 
 
191
 
            list ($ret, $result) = $view->loadTemplate($template, $form = array());
192
 
            if ($ret) {
193
 
                return $this->failWithStatus($ret);
194
 
            }
195
 
 
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');
207
 
            }
208
 
        }
209
 
    }
210
 
 
211
 
    function testLoadTemplateForItem() {
212
 
        list ($ret, $count) = GalleryCoreApi::fetchItemViewCount($this->_items[2]->getId());
213
 
        if ($ret) {
214
 
            return $this->failWithStatus($ret);
215
 
        }
216
 
        $this->assertEquals(0, $count, 'count before');
217
 
 
218
 
        GalleryUtilities::putRequestVariable('itemId', $this->_items[2]->getId());
219
 
 
220
 
        list ($ret, $result) = $this->_updatesView->loadTemplate($this->_template, $form = array());
221
 
        if ($ret) {
222
 
            return $this->failWithStatus($ret);
223
 
        }
224
 
 
225
 
        $theme =& $this->_template->getVariableByReference('theme');
226
 
        $this->assertEquals(array('view' => 'dynamicalbum.UpdatesAlbum'),
227
 
                            $theme['pageUrl'], 'page url');
228
 
 
229
 
        list ($ret, $count) = GalleryCoreApi::fetchItemViewCount($this->_items[2]->getId());
230
 
        if ($ret) {
231
 
            return $this->failWithStatus($ret);
232
 
        }
233
 
        $this->assertEquals(1, $count, 'count after');
234
 
    }
235
 
 
236
 
    function testLoadTemplateForAlbumNoPermission() {
237
 
        global $gallery;
238
 
        $theme =& $this->_template->getVariableByReference('theme');
239
 
        $theme['actingUserId'] = $gallery->getActiveUserId();
240
 
 
241
 
        $ret = GalleryCoreApi::setPluginParameter('module', 'dynamicalbum', 'size.views', '0');
242
 
        if ($ret) {
243
 
            return $this->failWithStatus($ret);
244
 
        }
245
 
 
246
 
        list ($ret, $result) = $this->_popularView->loadTemplate($this->_template, $form = array());
247
 
        if ($ret) {
248
 
            $this->assert($ret->getErrorCode() & ERROR_PERMISSION_DENIED, 'permission denied');
249
 
        } else {
250
 
            $this->assert(false, 'should get error');
251
 
        }
252
 
    }
253
 
 
254
 
    function testLoadTemplateForItemNoPermission() {
255
 
        $ret = GalleryCoreApi::removeItemPermissions($this->_items[3]->getId());
256
 
        if ($ret) {
257
 
            return $this->failWithStatus($ret);
258
 
        }
259
 
 
260
 
        GalleryUtilities::putRequestVariable('itemId', $this->_items[3]->getId());
261
 
 
262
 
        list ($ret, $result) = $this->_randomView->loadTemplate($this->_template, $form = array());
263
 
        if ($ret) {
264
 
            return $this->failWithStatus($ret);
265
 
        }
266
 
 
267
 
        $this->assertEquals(
268
 
            array('redirect' => array('view' => 'core.ShowItem', 'itemId' => $this->_getRootId())),
269
 
            $result, 'redirect');
270
 
    }
271
 
 
272
 
    function testItemLinks() {
273
 
        foreach (array('date', 'views', 'random') as $key) {
274
 
            $ret = GalleryCoreApi::setPluginParameter('module', 'dynamicalbum',
275
 
                                                      'itemlink.' . $key, '1');
276
 
            if ($ret) {
277
 
                return $this->failWithStatus($ret);
278
 
            }
279
 
        }
280
 
        $items = array($this->_album, $this->_items[2]);
281
 
 
282
 
        list ($ret, $links) = $this->_module->getItemLinks($items,
283
 
                array($this->_album->getId() => true, $this->_items[2]->getId() => true),
284
 
                array());
285
 
        if ($ret) {
286
 
            return $this->failWithStatus($ret);
287
 
        }
288
 
        $this->assertEquals(
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()))
299
 
                        )),
300
 
                $links, 'all');
301
 
 
302
 
        $ret = GalleryCoreApi::setPluginParameter('module', 'dynamicalbum', 'itemlink.views', '0');
303
 
        if ($ret) {
304
 
            return $this->failWithStatus($ret);
305
 
        }
306
 
 
307
 
        list ($ret, $links) = $this->_module->getItemLinks($items,
308
 
                array($this->_album->getId() => true, $this->_items[2]->getId() => true),
309
 
                array());
310
 
        if ($ret) {
311
 
            return $this->failWithStatus($ret);
312
 
        }
313
 
        $this->assertEquals(
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()))
321
 
                        )),
322
 
                $links, 'just 2');
323
 
 
324
 
        list ($ret, $links) = $this->_module->getItemLinks($items,
325
 
                array($this->_items[2]->getId() => true),
326
 
                array());
327
 
        if ($ret) {
328
 
            return $this->failWithStatus($ret);
329
 
        }
330
 
        $this->assertEquals(array(), $links, 'none');
331
 
    }
332
 
}
333
 
?>