~ubuntu-branches/ubuntu/hardy/gallery2/hardy-security

« back to all changes in this revision

Viewing changes to modules/core/test/phpunit/UserPreferencesControllerTest.class

  • Committer: Bazaar Package Importer
  • Author(s): Michael C. Schultheiss
  • Date: 2006-04-16 16:42:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060416164235-8uy0u4bfjdxpge2o
Tags: 2.1.1-1
* New upstream release (Closes: #362936)
  + Bugfixes for Postgres7 (Closes: #359000, #362152)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 * $RCSfile: UserPreferencesControllerTest.class,v $
4
4
 *
5
5
 * Gallery - a web based photo album viewer and editor
6
 
 * Copyright (C) 2000-2005 Bharat Mediratta
 
6
 * Copyright (C) 2000-2006 Bharat Mediratta
7
7
 *
8
8
 * This program is free software; you can redistribute it and/or modify
9
9
 * it under the terms of the GNU General Public License as published by
20
20
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
21
21
 */
22
22
/**
23
 
 * @version $Revision: 1.24 $ $Date: 2005/08/23 03:49:33 $
 
23
 * @version $Revision: 1.28 $ $Date: 2006/03/06 06:56:06 $
24
24
 * @package GalleryCore
25
25
 * @subpackage PHPUnit
26
26
 * @author Bharat Mediratta <bharat@menalto.com>
43
43
 
44
44
        $session =& $gallery->getSession();
45
45
        $this->_currentLanguage = $session->get('core.language');
46
 
        list ($ret, $this->_user) = $this->_createUser();
47
 
        if ($ret->isError()) {
 
46
        list ($ret, $this->_user) =
 
47
            $this->_createUser(array('hashedPassword' => GalleryUtilities::md5Salt('TestPassword'),
 
48
                                     'email' => 'test@email.com',
 
49
                                     'fullName' => 'Test User',
 
50
                                     'language' => 'te'));
 
51
        if ($ret) {
48
52
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
49
53
        }
50
54
 
91
95
        GalleryUtilities::putRequestVariable('form[fullName]', 'full name');
92
96
        GalleryUtilities::putRequestVariable('form[email]', 'email@test.me');
93
97
        GalleryUtilities::putRequestVariable('form[language]', 'language');
 
98
        GalleryUtilities::putRequestVariable('form[currentPassword]', 'TestPassword');
94
99
 
95
100
        $results = $this->handleRequest();
96
101
        $this->assertEquals(array('redirect' => array('view' => 'core.UserAdmin',
101
106
 
102
107
        /* Load back the user object and make sure the data got saved */
103
108
        list ($ret, $this->_user) = $this->_user->refresh();
104
 
        if ($ret->isError()) {
 
109
        if ($ret) {
105
110
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
106
111
        }
107
112
 
108
 
        $this->assertEquals($this->_user->getFullName(), 'full name');
109
 
        $this->assertEquals($this->_user->getEmail(), 'email@test.me');
110
 
        $this->assertEquals($this->_user->getLanguage(), 'language');
111
 
    $this->assertEquals('language', $session->get('core.language'), 'Language');
 
113
        $this->assertEquals('full name', $this->_user->getFullName());
 
114
        $this->assertEquals('email@test.me', $this->_user->getEmail());
 
115
        $this->assertEquals('language', $this->_user->getLanguage());
 
116
        $this->assertEquals('language', $session->get('core.language'), 'Language');
112
117
    }
113
118
 
114
119
    function testEditRequiredOnly() {
115
120
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
116
121
        GalleryUtilities::putRequestVariable('form[fullName]', 'full name');
117
 
        GalleryUtilities::putRequestVariable('form[email]', '  email_with-leading@space.test-o.com');
 
122
        GalleryUtilities::putRequestVariable('form[email]',
 
123
                                             '  email_with-leading@space.test-o.com');
 
124
        GalleryUtilities::putRequestVariable('form[currentPassword]', 'TestPassword');
118
125
 
119
126
        $results = $this->handleRequest();
120
127
        $this->assertEquals(array('redirect' => array('view' => 'core.UserAdmin',
125
132
 
126
133
        /* Load back the user object and make sure the data got saved */
127
134
        list ($ret, $this->_user) = $this->_user->refresh();
128
 
        if ($ret->isError()) {
 
135
        if ($ret) {
129
136
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
130
137
        }
131
138
 
132
 
        $this->assertEquals($this->_user->getFullName(), 'full name');
133
 
        $this->assertEquals($this->_user->getEmail(), 'email_with-leading@space.test-o.com');
 
139
        $this->assertEquals('full name', $this->_user->getFullName());
 
140
        $this->assertEquals('email_with-leading@space.test-o.com', $this->_user->getEmail());
134
141
    }
135
142
 
136
143
    function testEditMissingEmail() {
137
144
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
138
145
        GalleryUtilities::putRequestVariable('form[fullName]', 'full name');
 
146
        GalleryUtilities::putRequestVariable('form[currentPassword]', 'TestPassword');
139
147
 
140
148
        /* As a non-admin, we'll get an error about it being missing */
141
149
        $results = $this->handleRequest();
166
174
            GalleryUtilities::putRequestVariable('form[action][save]', 1);
167
175
            GalleryUtilities::putRequestVariable('form[fullName]', 'full name');
168
176
            GalleryUtilities::putRequestVariable('form[email]', 'no-at.test.com');
 
177
            GalleryUtilities::putRequestVariable('form[currentPassword]', 'TestPassword');
169
178
 
170
179
            $results = $this->handleRequest();
171
180
            $this->assertEquals(array('delegate' => array('view' => 'core.UserAdmin',
212
221
        }
213
222
    }
214
223
 
 
224
    /* No password is needed for non-email changes */
 
225
    function testEditOtherThanEmailWithoutPassword() {
 
226
        global $gallery;
 
227
        $session =& $gallery->getSession();
 
228
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
 
229
        GalleryUtilities::putRequestVariable('form[fullName]', 'full name');
 
230
        GalleryUtilities::putRequestVariable('form[email]', 'test@email.com');
 
231
        GalleryUtilities::putRequestVariable('form[language]', 'language');
 
232
        /* Make sure the test suit actually unsets previous request vars */
 
233
        $form = GalleryUtilities::getFormVariables('form');
 
234
        $this->assert(!isset($form['currentPassword']),
 
235
                      'precondition failed, password was specified');
 
236
 
 
237
        $results = $this->handleRequest();
 
238
        $this->assertEquals(array('redirect' => array('view' => 'core.UserAdmin',
 
239
                                                      'subView' => 'core.UserPreferences'),
 
240
                                  'status' => array('saved' => 1),
 
241
                                  'error' => array()),
 
242
                            $results);
 
243
 
 
244
        /* Load back the user object and make sure the data got saved */
 
245
        list ($ret, $this->_user) = $this->_user->refresh();
 
246
        if ($ret) {
 
247
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
248
        }
 
249
 
 
250
        $this->assertEquals('full name', $this->_user->getFullName());
 
251
        $this->assertEquals('test@email.com', $this->_user->getEmail());
 
252
        $this->assertEquals('language', $this->_user->getLanguage());
 
253
        $this->assertEquals('language', $session->get('core.language'), 'Language');
 
254
    }
 
255
 
 
256
    /* If you provide an email, then return a error message if it's invalid */
 
257
    function testEditOtherThanEmailInvalidPassword() {
 
258
        global $gallery;
 
259
        $session =& $gallery->getSession();
 
260
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
 
261
        GalleryUtilities::putRequestVariable('form[fullName]', 'full name');
 
262
        GalleryUtilities::putRequestVariable('form[email]', 'test@email.com');
 
263
        GalleryUtilities::putRequestVariable('form[language]', 'language');
 
264
        GalleryUtilities::putRequestVariable('form[currentPassword]', 'invalid');
 
265
 
 
266
        $results = $this->handleRequest();
 
267
         $this->assertEquals(array('delegate' => array('view' => 'core.UserAdmin',
 
268
                                                          'subView' => 'core.UserPreferences'),
 
269
                                      'status' => array(),
 
270
                                      'error' => array('form[error][currentPassword][incorrect]')),
 
271
                                $results, 'invalid password');
 
272
 
 
273
        /* Load back the user object and make sure the data got not saved */
 
274
        list ($ret, $this->_user) = $this->_user->refresh();
 
275
        if ($ret) {
 
276
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
277
        }
 
278
 
 
279
        $this->assertEquals('Test User', $this->_user->getFullName());
 
280
        $this->assertEquals('test@email.com', $this->_user->getEmail());
 
281
        $this->assertEquals('te', $this->_user->getLanguage());
 
282
    }
 
283
 
 
284
    function testEditEmailWithInvalidPassword() {
 
285
        global $gallery;
 
286
        $session =& $gallery->getSession();
 
287
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
 
288
        GalleryUtilities::putRequestVariable('form[fullName]', 'full name');
 
289
        GalleryUtilities::putRequestVariable('form[email]', 'new@email.com');
 
290
        GalleryUtilities::putRequestVariable('form[language]', 'language');
 
291
        GalleryUtilities::putRequestVariable('form[currentPassword]', 'invalid');
 
292
 
 
293
        $results = $this->handleRequest();
 
294
         $this->assertEquals(array('delegate' => array('view' => 'core.UserAdmin',
 
295
                                                          'subView' => 'core.UserPreferences'),
 
296
                                      'status' => array(),
 
297
                                      'error' => array('form[error][currentPassword][incorrect]')),
 
298
                                $results, 'invalid password');
 
299
 
 
300
        /* Load back the user object and make sure the data got not saved */
 
301
        list ($ret, $this->_user) = $this->_user->refresh();
 
302
        if ($ret) {
 
303
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
304
        }
 
305
 
 
306
        $this->assertEquals('Test User', $this->_user->getFullName());
 
307
        $this->assertEquals('test@email.com', $this->_user->getEmail());
 
308
        $this->assertEquals('te', $this->_user->getLanguage());
 
309
    }
 
310
 
 
311
    function testEditEmailWithoutPassword() {
 
312
        global $gallery;
 
313
        $session =& $gallery->getSession();
 
314
        GalleryUtilities::putRequestVariable('form[action][save]', 1);
 
315
        GalleryUtilities::putRequestVariable('form[fullName]', 'full name');
 
316
        GalleryUtilities::putRequestVariable('form[email]', 'new@email.com');
 
317
        GalleryUtilities::putRequestVariable('form[language]', 'language');
 
318
 
 
319
        $results = $this->handleRequest();
 
320
         $this->assertEquals(array('delegate' => array('view' => 'core.UserAdmin',
 
321
                                                          'subView' => 'core.UserPreferences'),
 
322
                                      'status' => array(),
 
323
                                      'error' => array('form[error][currentPassword][missing]')),
 
324
                                $results, 'missing password');
 
325
 
 
326
        /* Load back the user object and make sure the data got not saved */
 
327
        list ($ret, $this->_user) = $this->_user->refresh();
 
328
        if ($ret) {
 
329
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
 
330
        }
 
331
 
 
332
        $this->assertEquals('Test User', $this->_user->getFullName());
 
333
        $this->assertEquals('test@email.com', $this->_user->getEmail());
 
334
        $this->assertEquals('te', $this->_user->getLanguage());
 
335
    }
 
336
    
215
337
    function _addUserToAdminGroup() {
216
338
        /* Make ourselves an admin */
217
339
        list ($ret, $adminGroupId) =
218
340
            GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup');
219
 
        if ($ret->isError()) {
 
341
        if ($ret) {
220
342
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
221
343
        }
222
344
 
223
345
        $ret = GalleryCoreApi::addUserToGroup($this->_user->getId(), $adminGroupId);
224
 
        if ($ret->isError()) {
 
346
        if ($ret) {
225
347
            return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
226
348
        }
227
349
    }