~ubuntu-branches/ubuntu/lucid/gallery2/lucid

« back to all changes in this revision

Viewing changes to modules/core/test/phpunit/CoreModuleTest.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 CoreModule functionality
23
 
 * @package GalleryCore
24
 
 * @subpackage PHPUnit
25
 
 * @author Bharat Mediratta <bharat@menalto.com>
26
 
 * @version $Revision: 15513 $
27
 
 */
28
 
class CoreModuleTest extends GalleryTestCase {
29
 
    var $_module;
30
 
 
31
 
    function CoreModuleTest($methodName) {
32
 
        $this->GalleryTestCase($methodName);
33
 
    }
34
 
 
35
 
    function setUp() {
36
 
        global $gallery;
37
 
        parent::setUp();
38
 
 
39
 
        list ($ret, $this->_module) = GalleryCoreApi::loadPlugin('module', 'core');
40
 
        if ($ret) {
41
 
            return $this->failWithStatus($ret);
42
 
        }
43
 
 
44
 
        list ($ret, $this->_parentAlbum) = $this->_createRandomAlbum($this->_getRootId());
45
 
        if ($ret) {
46
 
            print $ret->getAsHtml();
47
 
            return $this->failWithStatus($ret);
48
 
        }
49
 
 
50
 
        $this->_markForCleanup($this->_parentAlbum);
51
 
 
52
 
        $ret = GalleryCoreApi::addUserPermission($this->_parentAlbum->getId(),
53
 
                                                       $gallery->getActiveUserId(),
54
 
                                                       'core.all');
55
 
        if ($ret) {
56
 
            print $ret->getAsHtml();
57
 
            return $this->failWithStatus($ret);
58
 
        }
59
 
    }
60
 
 
61
 
    function testGetItemAdminViews() {
62
 
        list ($ret, $content) = $this->_module->getItemAdminViews($this->_parentAlbum);
63
 
        if ($ret) {
64
 
            return $this->failWithStatus($ret);
65
 
        }
66
 
 
67
 
        $this->assertEquals(
68
 
            array(
69
 
                array('name' => $this->_module->_translate(
70
 
                          array('text' => 'Edit %s',
71
 
                                'arg1' => $this->_module->translate('Album')),
72
 
                          'Album'),
73
 
                      'view' => 'core.ItemEdit'),
74
 
                array('name' => $this->_module->translate('Edit Permissions'),
75
 
                      'view' => 'core.ItemPermissions'),
76
 
                array('name' => $this->_module->_translate(
77
 
                          array('text' => 'Delete %s',
78
 
                                'arg1' => $this->_module->translate('Album')),
79
 
                          'Album'),
80
 
                      'view' => 'core.ItemDeleteSingle'),
81
 
                array('name' => $this->_module->_translate(
82
 
                          array('text' => 'Move %s',
83
 
                                'arg1' => $this->_module->translate('Album')),
84
 
                          'Album'),
85
 
                      'view' => 'core.ItemMoveSingle'),
86
 
                array('name' => $this->_module->translate('Add Items'),
87
 
                      'view' => 'core.ItemAdd'),
88
 
                array('name' => $this->_module->translate('Add Album'),
89
 
                      'view' => 'core.ItemAddAlbum')
90
 
                ),
91
 
            $content, 'empty album');
92
 
 
93
 
        list ($ret) = $this->_createRandomDataItem($this->_parentAlbum->getId());
94
 
        if ($ret) {
95
 
            return $this->failWithStatus($ret);
96
 
        }
97
 
 
98
 
        list ($ret, $content) = $this->_module->getItemAdminViews($this->_parentAlbum);
99
 
        if ($ret) {
100
 
            return $this->failWithStatus($ret);
101
 
        }
102
 
 
103
 
        $this->assertEquals(
104
 
            array(
105
 
                array('name' => $this->_module->translate('Edit Captions'),
106
 
                      'view' => 'core.ItemEditCaptions'),
107
 
                array('name' => $this->_module->_translate(
108
 
                          array('text' => 'Edit %s',
109
 
                                'arg1' => $this->_module->translate('Album')),
110
 
                          'Album'),
111
 
                      'view' => 'core.ItemEdit'),
112
 
                array('name' => $this->_module->translate('Edit Permissions'),
113
 
                      'view' => 'core.ItemPermissions'),
114
 
                array('name' => $this->_module->_translate(
115
 
                          array('text' => 'Delete %s',
116
 
                                'arg1' => $this->_module->translate('Album')),
117
 
                          'Album'),
118
 
                      'view' => 'core.ItemDeleteSingle'),
119
 
                array('name' => $this->_module->_translate(
120
 
                          array('text' => 'Move %s',
121
 
                                'arg1' => $this->_module->translate('Album')),
122
 
                          'Album'),
123
 
                      'view' => 'core.ItemMoveSingle'),
124
 
                array('name' => $this->_module->translate('Add Items'),
125
 
                      'view' => 'core.ItemAdd'),
126
 
                array('name' => $this->_module->translate('Add Album'),
127
 
                      'view' => 'core.ItemAddAlbum')
128
 
                ),
129
 
            $content, 'nonempty album');
130
 
    }
131
 
 
132
 
    function testGetConfigurationView() {
133
 
        $content = $this->_module->getConfigurationView();
134
 
        $this->assertEquals(null, $content);
135
 
    }
136
 
 
137
 
    function testGetSystemLinks() {
138
 
        global $gallery;
139
 
 
140
 
        list ($ret, $content) = $this->_module->getSystemLinks();
141
 
        if ($ret) {
142
 
            return $this->failWithStatus($ret);
143
 
        }
144
 
 
145
 
        $this->assertEquals(
146
 
            array('SiteAdmin' => array(
147
 
                      'text' => $this->_module->translate('Site Admin'),
148
 
                      'params' => array('view' => 'core.SiteAdmin',
149
 
                                        'return' => 1)),
150
 
                  'YourAccount' => array(
151
 
                      'text' => $this->_module->translate('Your Account'),
152
 
                      'params' => array('view' => 'core.UserAdmin',
153
 
                                        'subView' => 'core.UserPreferences',
154
 
                                        'return' => 1)),
155
 
                  'Logout' => array(
156
 
                      'text' => $this->_module->translate('Logout'),
157
 
                      'params' => array('controller' => 'core.Logout',
158
 
                                        'return' => 1))
159
 
                  ),
160
 
            $content, 'Admin User');
161
 
 
162
 
 
163
 
        list ($ret, $this->_user1) =
164
 
            $this->_createUser(array('hashedPassword' => GalleryUtilities::md5Salt('TestPassword'),
165
 
                                     'email' => 'test2@email.com',
166
 
                                     'fullName' => 'Test User 2',
167
 
                                     'language' => 'te',
168
 
                                     'locked' => 0));
169
 
        if ($ret) {
170
 
            return $this->failWithStatus($ret);
171
 
        }
172
 
 
173
 
        $this->_markForCleanup($this->_user1);
174
 
 
175
 
        $gallery->setActiveUser($this->_user1);
176
 
 
177
 
        list ($ret, $content) = $this->_module->getSystemLinks();
178
 
        if ($ret) {
179
 
            return $this->failWithStatus($ret);
180
 
        }
181
 
 
182
 
        $this->assertEquals(
183
 
            array('YourAccount' => array(
184
 
                      'text' => $this->_module->translate('Your Account'),
185
 
                      'params' => array('view' => 'core.UserAdmin',
186
 
                                        'subView' => 'core.UserPreferences',
187
 
                                        'return' => 1)),
188
 
                  'Logout' => array(
189
 
                      'text' => $this->_module->translate('Logout'),
190
 
                      'params' => array('controller' => 'core.Logout',
191
 
                                        'return' => 1))
192
 
                  ),
193
 
            $content, 'Normal User');
194
 
 
195
 
        list ($ret, $this->_user2) =
196
 
            $this->_createUser(array('hashedPassword' => GalleryUtilities::md5Salt('TestPassword'),
197
 
                                     'email' => 'test2@email.com',
198
 
                                     'fullName' => 'Test User 2',
199
 
                                     'language' => 'te',
200
 
                                     'locked' => 1));
201
 
        if ($ret) {
202
 
            return $this->failWithStatus($ret);
203
 
        }
204
 
 
205
 
        $this->_markForCleanup($this->_user2);
206
 
 
207
 
        $gallery->setActiveUser($this->_user2);
208
 
 
209
 
        list ($ret, $content) = $this->_module->getSystemLinks();
210
 
        if ($ret) {
211
 
            return $this->failWithStatus($ret);
212
 
        }
213
 
 
214
 
        $this->assertEquals(
215
 
            array('YourAccount' => array(
216
 
                      'text' => $this->_module->translate('Your Account'),
217
 
                      'params' => array('view' => 'core.UserAdmin',
218
 
                                        'subView' => 'core.UserPreferences',
219
 
                                        'return' => 1)),
220
 
                  'Logout' => array(
221
 
                      'text' => $this->_module->translate('Logout'),
222
 
                      'params' => array('controller' => 'core.Logout',
223
 
                                        'return' => 1))
224
 
                  ),
225
 
            $content, 'Locked User');
226
 
    }
227
 
 
228
 
    function testSetModuleParameter() {
229
 
        $key = 'test-key';
230
 
        $value = rand();
231
 
 
232
 
        $ret = $this->_module->setParameter($key, $value);
233
 
        if ($ret) {
234
 
            return $this->failWithStatus($ret);
235
 
        }
236
 
 
237
 
        list ($ret, $newValue) = $this->_module->getParameter($key);
238
 
        if ($ret) {
239
 
            return $this->failWithStatus($ret);
240
 
        }
241
 
 
242
 
        /* Clean up */
243
 
        $ret = GalleryCoreApi::removePluginParameter('module', 'core', $key);
244
 
        if ($ret) {
245
 
            return $this->failWithStatus($ret);
246
 
        }
247
 
 
248
 
        $this->assertEquals($value, (int)$newValue);
249
 
    }
250
 
}
251
 
 
252
 
/**
253
 
 * Mock template class
254
 
 *
255
 
 * @package GalleryCore
256
 
 * @subpackage PHPUnit
257
 
 */
258
 
class CoreModuleMockTemplate {
259
 
    function setVariable() {
260
 
    }
261
 
}
262
 
?>