@@ -70,10 +70,7 @@ public function testRegisterAction()
70
70
$ this ->dispatchUrI ("/user/register " );
71
71
72
72
$ userDao = $ this ->User ->getByEmail ($ this ->params ['email ' ]);
73
- if ($ userDao == false )
74
- {
75
- $ this ->fail ('Unable to register ' );
76
- }
73
+ $ this ->assertTrue ($ userDao != false , 'Unable to register ' );
77
74
}
78
75
79
76
/** test login*/
@@ -99,12 +96,8 @@ public function testLoginAction()
99
96
$ this ->params ['email ' ] = 'user1@user1.com ' ;
100
97
$ this ->params ['password ' ] = 'test ' ;
101
98
$ this ->request ->setMethod ('POST ' );
102
- $ this ->dispatchUrI ("/user/login " );
103
-
104
- if (strpos ($ this ->getBody (), 'Test Pass ' ) === false )
105
- {
106
- $ this ->fail ('Unable to authenticate ' );
107
- }
99
+ $ this ->dispatchUrI ('/user/login ' );
100
+ $ this ->assertTrue (strpos ($ this ->getBody (), 'Test Pass ' ) !== false , 'Unable to authenticate ' );
108
101
}
109
102
110
103
/** test terms */
@@ -136,10 +129,7 @@ public function testRecoverpasswordAction()
136
129
$ this ->dispatchUrI ("/user/recoverpassword " , null );
137
130
138
131
$ userDao2 = $ this ->User ->getByEmail ($ this ->params ['email ' ]);
139
- if ($ userDao ->getPassword () == $ userDao2 ->getPassword ())
140
- {
141
- $ this ->fail ('Unable to change password ' );
142
- }
132
+ $ this ->assertNotEquals ($ userDao ->getPassword (), $ userDao2 ->getPassword (), 'Unable to change password ' );
143
133
$ this ->setupDatabase (array ('default ' ));
144
134
}
145
135
@@ -149,10 +139,7 @@ public function testSettingsAction()
149
139
$ this ->resetAll ();
150
140
$ this ->dispatchUrI ("/user/settings " , null , false );
151
141
$ body = $ this ->getBody ();
152
- if (!empty ($ body ))
153
- {
154
- $ this ->fail ('Should return nothing ' );
155
- }
142
+ $ this ->assertTrue (empty ($ body ), 'Should return nothing ' );
156
143
157
144
$ usersFile = $ this ->loadData ('User ' , 'default ' );
158
145
$ userDao = $ this ->User ->load ($ usersFile [0 ]->getKey ());
@@ -170,10 +157,8 @@ public function testSettingsAction()
170
157
$ this ->dispatchUrI ("/user/settings " , $ userDao );
171
158
172
159
$ userCheckDao = $ this ->User ->getByEmail ($ userDao ->getEmail ());
173
- if ($ userDao ->getPassword () == $ userCheckDao ->getPassword ())
174
- {
175
- $ this ->fail ('Unable to change password ' );
176
- }
160
+ $ this ->assertNotEquals ($ userDao ->getPassword (), $ userCheckDao ->getPassword (), 'Unable to change password ' );
161
+
177
162
$ this ->setupDatabase (array ('default ' ));
178
163
179
164
$ this ->resetAll ();
@@ -187,10 +172,7 @@ public function testSettingsAction()
187
172
$ this ->dispatchUrI ("/user/settings " , $ userDao );
188
173
189
174
$ userCheckDao = $ this ->User ->load ($ userDao ->getKey ());
190
- if ($ this ->params ['firstname ' ] != $ userCheckDao ->getFirstname ())
191
- {
192
- $ this ->fail ('Unable to change account information ' );
193
- }
175
+ $ this ->assertEquals ($ this ->params ['firstname ' ], $ userCheckDao ->getFirstname (), 'Unable to change account information ' );
194
176
195
177
$ this ->resetAll ();
196
178
$ this ->params = array ();
@@ -201,10 +183,7 @@ public function testSettingsAction()
201
183
$ userCheckDao = $ this ->User ->load ($ userDao ->getKey ());
202
184
203
185
$ thumbnail = $ userCheckDao ->getThumbnail ();
204
- if (empty ($ thumbnail ))
205
- {
206
- $ this ->fail ('Unable to change avatar ' );
207
- }
186
+ $ this ->assertTrue (!empty ($ thumbnail ), 'Unable to change avatar ' );
208
187
209
188
$ this ->setupDatabase (array ('default ' ));
210
189
}
@@ -216,10 +195,7 @@ public function testManageAction()
216
195
$ this ->dispatchUrI ("/user/manage " , null , false );
217
196
218
197
$ body = $ this ->getBody ();
219
- if (!empty ($ body ))
220
- {
221
- $ this ->fail ('The page should be empty ' );
222
- }
198
+ $ this ->assertTrue (empty ($ body ), 'The page should be empty ' );
223
199
224
200
$ usersFile = $ this ->loadData ('User ' , 'default ' );
225
201
$ userDao = $ this ->User ->load ($ usersFile [0 ]->getKey ());
@@ -258,53 +234,141 @@ public function testUserpageAction()
258
234
public function testValidentryAction ()
259
235
{
260
236
$ this ->resetAll ();
261
- $ this ->dispatchUrI ("/user/validentry " );
262
- if (strpos ($ this ->getBody (), 'false ' ) === false )
263
- {
264
- $ this ->fail ();
265
- }
237
+ $ this ->dispatchUrI ('/user/validentry ' );
238
+ $ this ->assertTrue (strpos ($ this ->getBody (), 'false ' ) !== false );
266
239
267
240
$ this ->resetAll ();
268
241
$ this ->params = array ();
269
242
$ this ->params ['entry ' ] = 'user1@user1.com ' ;
270
243
$ this ->params ['type ' ] = 'dbuser ' ;
271
- $ this ->dispatchUrI ("/user/validentry " );
272
- if (strpos ($ this ->getBody (), 'true ' ) === false )
273
- {
274
- $ this ->fail ();
275
- }
244
+ $ this ->dispatchUrI ('/user/validentry ' );
245
+ $ this ->assertTrue (strpos ($ this ->getBody (), 'true ' ) !== false );
276
246
277
247
$ this ->resetAll ();
278
248
$ this ->params = array ();
279
249
$ this ->params ['entry ' ] = 'test_email_not_in_db ' ;
280
250
$ this ->params ['type ' ] = 'dbuser ' ;
281
- $ this ->dispatchUrI ("/user/validentry " );
282
- if (strpos ($ this ->getBody (), 'false ' ) === false )
283
- {
284
- $ this ->fail ();
285
- }
251
+ $ this ->dispatchUrI ('/user/validentry ' );
252
+ $ this ->assertTrue (strpos ($ this ->getBody (), 'false ' ) !== false );
286
253
287
254
$ this ->resetAll ();
288
255
$ this ->params = array ();
289
256
$ this ->params ['entry ' ] = 'user1@user1.com ' ;
290
257
$ this ->params ['type ' ] = 'login ' ;
291
258
$ this ->params ['password ' ] = 'wrong_password ' ;
292
- $ this ->dispatchUrI ("/user/validentry " );
293
- if (strpos ($ this ->getBody (), 'false ' ) === false )
294
- {
295
- $ this ->fail ();
296
- }
259
+ $ this ->dispatchUrI ('/user/validentry ' );
260
+ $ this ->assertTrue (strpos ($ this ->getBody (), 'false ' ) !== false );
297
261
298
262
$ this ->resetAll ();
299
263
$ this ->params = array ();
300
264
$ this ->params ['entry ' ] = 'user1@user1.com ' ;
301
265
$ this ->params ['type ' ] = 'login ' ;
302
266
$ this ->params ['password ' ] = 'test ' ;
303
- $ this ->dispatchUrI ("/user/validentry " );
304
- if (strpos ($ this ->getBody (), 'true ' ) === false )
267
+ $ this ->dispatchUrI ('/user/validentry ' );
268
+ $ this ->assertTrue (strpos ($ this ->getBody (), 'true ' ) !== false );
269
+ }
270
+
271
+ /** Test admin ability to delete a user */
272
+ public function testDeleteUserAction ()
273
+ {
274
+ $ modelLoader = new MIDAS_ModelLoader ();
275
+ $ settingModel = $ modelLoader ->loadModel ('Setting ' );
276
+ $ adminuserSetting = $ settingModel ->getValueByName ('adminuser ' );
277
+ $ usersFile = $ this ->loadData ('User ' , 'default ' );
278
+ $ user1 = $ this ->User ->load ($ usersFile [0 ]->getKey ());
279
+ $ user2 = $ this ->User ->load ($ usersFile [1 ]->getKey ());
280
+ $ adminUser = $ this ->User ->load ($ usersFile [2 ]->getKey ());
281
+
282
+ // Render the delete dialog and make sure it has correct text
283
+ $ this ->resetAll ();
284
+ $ this ->dispatchUrI ('/user/deletedialog?userId= ' .$ user1 ->getKey (), $ adminUser );
285
+ $ this ->assertQueryContentContains ('#deleteDialogUserName ' , $ user1 ->getFirstname ().' ' .$ user1 ->getLastname ());
286
+
287
+ // Should fail if we aren't logged in
288
+ $ this ->resetAll ();
289
+ $ this ->dispatchUrI ('/user/delete?userId= ' .$ user1 ->getKey (), null , true );
290
+
291
+ // Should fail if we try to delete an admin user
292
+ $ this ->resetAll ();
293
+ $ this ->dispatchUrI ('/user/delete?userId= ' .$ adminUser ->getKey (), $ adminUser , true );
294
+
295
+ // Should fail if a non admin user tries to delete a different user
296
+ $ this ->resetAll ();
297
+ $ this ->dispatchUrI ('/user/delete?userId= ' .$ user2 ->getKey (), $ user1 , true );
298
+
299
+ $ oldRevisions = $ user1 ->getItemrevisions ();
300
+ $ this ->assertTrue (count ($ oldRevisions ) > 0 );
301
+ $ revisionKeys = array ();
302
+ foreach ($ oldRevisions as $ oldRevision )
305
303
{
306
- $ this ->fail ();
304
+ $ this ->assertEquals ($ oldRevision ->getUserId (), $ user1 ->getKey ());
305
+ $ revisionKeys [] = $ oldRevision ->getKey ();
307
306
}
307
+ // Delete user 1 as administrator
308
+ $ key = $ user1 ->getKey ();
309
+ $ this ->resetAll ();
310
+ $ this ->dispatchUrI ('/user/delete?userId= ' .$ user1 ->getKey (), $ adminUser );
311
+
312
+ // Make sure user record is now gone
313
+ $ this ->assertFalse ($ this ->User ->load ($ key ));
314
+
315
+ // Make sure all of user's revisions that weren't removed are now listed as uploaded by superadmin
316
+ $ revisionModel = $ modelLoader ->loadModel ('ItemRevision ' );
317
+ $ revisionNotDeleted = false ;
318
+ foreach ($ revisionKeys as $ revisionKey )
319
+ {
320
+ $ revision = $ revisionModel ->load ($ revisionKey );
321
+ $ this ->assertTrue ($ revision === false || $ revision ->getUserId () == $ adminuserSetting );
322
+ if ($ revision !== false )
323
+ {
324
+ $ revisionNotDeleted = true ;
325
+ }
326
+ }
327
+ $ this ->assertTrue ($ revisionNotDeleted , 'At least one revision should not have been deleted ' );
308
328
}
309
329
330
+ /** Test user's ability to delete himself */
331
+ public function testDeleteSelfAction ()
332
+ {
333
+ $ modelLoader = new MIDAS_ModelLoader ();
334
+ $ settingModel = $ modelLoader ->loadModel ('Setting ' );
335
+ $ adminuserSetting = $ settingModel ->getValueByName ('adminuser ' );
336
+ $ usersFile = $ this ->loadData ('User ' , 'default ' );
337
+ $ user1 = $ this ->User ->load ($ usersFile [0 ]->getKey ());
338
+
339
+ // Render the delete dialog and make sure it has correct text for self-deletion
340
+ $ this ->resetAll ();
341
+ $ this ->dispatchUrI ('/user/deletedialog?userId= ' .$ user1 ->getKey (), $ user1 );
342
+ $ this ->assertTrue (strpos ($ this ->getBody (), 'Are you sure you want to delete your user account? ' ) !== false );
343
+
344
+ $ oldRevisions = $ user1 ->getItemrevisions ();
345
+ $ this ->assertTrue (count ($ oldRevisions ) > 0 );
346
+ $ revisionKeys = array ();
347
+ foreach ($ oldRevisions as $ oldRevision )
348
+ {
349
+ $ this ->assertEquals ($ oldRevision ->getUserId (), $ user1 ->getKey ());
350
+ $ revisionKeys [] = $ oldRevision ->getKey ();
351
+ }
352
+ // Delete user 1 as user 1
353
+ $ key = $ user1 ->getKey ();
354
+ $ this ->resetAll ();
355
+ $ this ->dispatchUrI ('/user/delete?userId= ' .$ user1 ->getKey (), $ user1 );
356
+
357
+ // Make sure user record is now gone
358
+ $ this ->assertFalse ($ this ->User ->load ($ key ));
359
+
360
+ // Make sure all of user's revisions that weren't removed are now listed as uploaded by superadmin
361
+ $ revisionModel = $ modelLoader ->loadModel ('ItemRevision ' );
362
+ $ revisionNotDeleted = false ;
363
+ foreach ($ revisionKeys as $ revisionKey )
364
+ {
365
+ $ revision = $ revisionModel ->load ($ revisionKey );
366
+ $ this ->assertTrue ($ revision === false || $ revision ->getUserId () == $ adminuserSetting );
367
+ if ($ revision !== false )
368
+ {
369
+ $ revisionNotDeleted = true ;
370
+ }
371
+ }
372
+ $ this ->assertTrue ($ revisionNotDeleted , 'At least one revision should not have been deleted ' );
373
+ }
310
374
}
0 commit comments