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()) {
105
110
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
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');
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');
119
126
$results = $this->handleRequest();
120
127
$this->assertEquals(array('redirect' => array('view' => 'core.UserAdmin',
224
/* No password is needed for non-email changes */
225
function testEditOtherThanEmailWithoutPassword() {
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');
237
$results = $this->handleRequest();
238
$this->assertEquals(array('redirect' => array('view' => 'core.UserAdmin',
239
'subView' => 'core.UserPreferences'),
240
'status' => array('saved' => 1),
244
/* Load back the user object and make sure the data got saved */
245
list ($ret, $this->_user) = $this->_user->refresh();
247
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
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');
256
/* If you provide an email, then return a error message if it's invalid */
257
function testEditOtherThanEmailInvalidPassword() {
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');
266
$results = $this->handleRequest();
267
$this->assertEquals(array('delegate' => array('view' => 'core.UserAdmin',
268
'subView' => 'core.UserPreferences'),
270
'error' => array('form[error][currentPassword][incorrect]')),
271
$results, 'invalid password');
273
/* Load back the user object and make sure the data got not saved */
274
list ($ret, $this->_user) = $this->_user->refresh();
276
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
279
$this->assertEquals('Test User', $this->_user->getFullName());
280
$this->assertEquals('test@email.com', $this->_user->getEmail());
281
$this->assertEquals('te', $this->_user->getLanguage());
284
function testEditEmailWithInvalidPassword() {
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');
293
$results = $this->handleRequest();
294
$this->assertEquals(array('delegate' => array('view' => 'core.UserAdmin',
295
'subView' => 'core.UserPreferences'),
297
'error' => array('form[error][currentPassword][incorrect]')),
298
$results, 'invalid password');
300
/* Load back the user object and make sure the data got not saved */
301
list ($ret, $this->_user) = $this->_user->refresh();
303
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
306
$this->assertEquals('Test User', $this->_user->getFullName());
307
$this->assertEquals('test@email.com', $this->_user->getEmail());
308
$this->assertEquals('te', $this->_user->getLanguage());
311
function testEditEmailWithoutPassword() {
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');
319
$results = $this->handleRequest();
320
$this->assertEquals(array('delegate' => array('view' => 'core.UserAdmin',
321
'subView' => 'core.UserPreferences'),
323
'error' => array('form[error][currentPassword][missing]')),
324
$results, 'missing password');
326
/* Load back the user object and make sure the data got not saved */
327
list ($ret, $this->_user) = $this->_user->refresh();
329
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
332
$this->assertEquals('Test User', $this->_user->getFullName());
333
$this->assertEquals('test@email.com', $this->_user->getEmail());
334
$this->assertEquals('te', $this->_user->getLanguage());
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()) {
220
342
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));
223
345
$ret = GalleryCoreApi::addUserToGroup($this->_user->getId(), $adminGroupId);
224
if ($ret->isError()) {
225
347
return $this->failWithStatus($ret->wrap(__FILE__, __LINE__));