1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace common\unit\models; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use Codeception\Specify; |
7
|
|
|
use common\models\User; |
8
|
|
|
|
9
|
|
|
date_default_timezone_set('UTC'); |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* User test |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
class UserTest extends \Codeception\Test\Unit { |
16
|
|
|
use Specify; |
17
|
|
|
|
18
|
|
|
private $user; |
19
|
|
|
private $time; |
20
|
|
|
private $question; |
21
|
|
|
|
22
|
|
|
public $questionData = [ |
23
|
|
|
[ |
24
|
|
|
'id' => 641, |
25
|
|
|
'user_id' => 2, |
26
|
|
|
'behavior_id' => 13, |
27
|
|
|
'user_behavior_id' => 821, |
28
|
|
|
'question' => 1, |
29
|
|
|
'answer' => 'alsgn', |
30
|
|
|
'date' => '2016-09-10 19:27:43', |
31
|
|
|
'behavior' => |
32
|
|
|
[ |
33
|
|
|
'id' => 13, |
34
|
|
|
'name' => 'less time/energy for God, meetings, and church', |
35
|
|
|
'category_id' => 2, |
36
|
|
|
], |
37
|
|
|
], |
38
|
|
|
[ |
39
|
|
|
'id' => 642, |
40
|
|
|
'user_id' => 2, |
41
|
|
|
'behavior_id' => 13, |
42
|
|
|
'user_behavior_id' => 821, |
43
|
|
|
'question' => 2, |
44
|
|
|
'answer' => 'loiun', |
45
|
|
|
'date' => '2016-09-10 19:27:43', |
46
|
|
|
'behavior' => |
47
|
|
|
[ |
48
|
|
|
'id' => 13, |
49
|
|
|
'name' => 'less time/energy for God, meetings, and church', |
50
|
|
|
'category_id' => 2, |
51
|
|
|
], |
52
|
|
|
], |
53
|
|
|
[ |
54
|
|
|
'id' => 643, |
55
|
|
|
'user_id' => 2, |
56
|
|
|
'behavior_id' => 13, |
57
|
|
|
'user_behavior_id' => 821, |
58
|
|
|
'question' => 3, |
59
|
|
|
'answer' => 'liun', |
60
|
|
|
'date' => '2016-09-10 19:27:43', |
61
|
|
|
'behavior' => |
62
|
|
|
[ |
63
|
|
|
'id' => 13, |
64
|
|
|
'name' => 'less time/energy for God, meetings, and church', |
65
|
|
|
'category_id' => 2, |
66
|
|
|
], |
67
|
|
|
], |
68
|
|
|
[ |
69
|
|
|
'id' => 644, |
70
|
|
|
'user_id' => 2, |
71
|
|
|
'behavior_id' => 29, |
72
|
|
|
'user_behavior_id' => 823, |
73
|
|
|
'question' => 1, |
74
|
|
|
'answer' => 'ljnb', |
75
|
|
|
'date' => '2016-09-10 19:27:43', |
76
|
|
|
'behavior' => |
77
|
|
|
[ |
78
|
|
|
'id' => 29, |
79
|
|
|
'name' => 'using profanity', |
80
|
|
|
'category_id' => 3, |
81
|
|
|
], |
82
|
|
|
], |
83
|
|
|
[ |
84
|
|
|
'id' => 645, |
85
|
|
|
'user_id' => 2, |
86
|
|
|
'behavior_id' => 29, |
87
|
|
|
'user_behavior_id' => 823, |
88
|
|
|
'question' => 2, |
89
|
|
|
'answer' => 'liunb', |
90
|
|
|
'date' => '2016-09-10 19:27:43', |
91
|
|
|
'behavior' => |
92
|
|
|
[ |
93
|
|
|
'id' => 29, |
94
|
|
|
'name' => 'using profanity', |
95
|
|
|
'category_id' => 3, |
96
|
|
|
], |
97
|
|
|
], |
98
|
|
|
[ |
99
|
|
|
'id' => 646, |
100
|
|
|
'user_id' => 2, |
101
|
|
|
'behavior_id' => 29, |
102
|
|
|
'user_behavior_id' => 823, |
103
|
|
|
'question' => 3, |
104
|
|
|
'answer' => 'ilub ', |
105
|
|
|
'date' => '2016-09-10 19:27:43', |
106
|
|
|
'behavior' => |
107
|
|
|
[ |
108
|
|
|
'id' => 29, |
109
|
|
|
'name' => 'using profanity', |
110
|
|
|
'category_id' => 3, |
111
|
|
|
], |
112
|
|
|
], |
113
|
|
|
[ |
114
|
|
|
'id' => 647, |
115
|
|
|
'user_id' => 2, |
116
|
|
|
'behavior_id' => 48, |
117
|
|
|
'user_behavior_id' => 825, |
118
|
|
|
'question' => 1, |
119
|
|
|
'answer' => 'liub', |
120
|
|
|
'date' => '2016-09-10 19:27:43', |
121
|
|
|
'behavior' => |
122
|
|
|
[ |
123
|
|
|
'id' => 48, |
124
|
|
|
'name' => 'workaholic', |
125
|
|
|
'category_id' => 4, |
126
|
|
|
], |
127
|
|
|
], |
128
|
|
|
[ |
129
|
|
|
'id' => 648, |
130
|
|
|
'user_id' => 2, |
131
|
|
|
'behavior_id' => 48, |
132
|
|
|
'user_behavior_id' => 825, |
133
|
|
|
'question' => 2, |
134
|
|
|
'answer' => 'liub', |
135
|
|
|
'date' => '2016-09-10 19:27:43', |
136
|
|
|
'behavior' => |
137
|
|
|
[ |
138
|
|
|
'id' => 48, |
139
|
|
|
'name' => 'workaholic', |
140
|
|
|
'category_id' => 4, |
141
|
|
|
], |
142
|
|
|
], |
143
|
|
|
[ |
144
|
|
|
'id' => 649, |
145
|
|
|
'user_id' => 2, |
146
|
|
|
'behavior_id' => 48, |
147
|
|
|
'user_behavior_id' => 825, |
148
|
|
|
'question' => 3, |
149
|
|
|
'answer' => 'liub ', |
150
|
|
|
'date' => '2016-09-10 19:27:43', |
151
|
|
|
'behavior' => |
152
|
|
|
[ |
153
|
|
|
'id' => 48, |
154
|
|
|
'name' => 'workaholic', |
155
|
|
|
'category_id' => 4, |
156
|
|
|
], |
157
|
|
|
], |
158
|
|
|
[ |
159
|
|
|
'id' => 650, |
160
|
|
|
'user_id' => 2, |
161
|
|
|
'behavior_id' => 89, |
162
|
|
|
'user_behavior_id' => 828, |
163
|
|
|
'question' => 1, |
164
|
|
|
'answer' => 'liub', |
165
|
|
|
'date' => '2016-09-10 19:27:43', |
166
|
|
|
'behavior' => |
167
|
|
|
[ |
168
|
|
|
'id' => 89, |
169
|
|
|
'name' => 'obsessive (stuck) thoughts', |
170
|
|
|
'category_id' => 5, |
171
|
|
|
], |
172
|
|
|
], |
173
|
|
|
[ |
174
|
|
|
'id' => 651, |
175
|
|
|
'user_id' => 2, |
176
|
|
|
'behavior_id' => 89, |
177
|
|
|
'user_behavior_id' => 828, |
178
|
|
|
'question' => 2, |
179
|
|
|
'answer' => 'liuby', |
180
|
|
|
'date' => '2016-09-10 19:27:43', |
181
|
|
|
'behavior' => |
182
|
|
|
[ |
183
|
|
|
'id' => 89, |
184
|
|
|
'name' => 'obsessive (stuck) thoughts', |
185
|
|
|
'category_id' => 5, |
186
|
|
|
], |
187
|
|
|
], |
188
|
|
|
[ |
189
|
|
|
'id' => 652, |
190
|
|
|
'user_id' => 2, |
191
|
|
|
'behavior_id' => 89, |
192
|
|
|
'user_behavior_id' => 828, |
193
|
|
|
'question' => 3, |
194
|
|
|
'answer' => 'uiylb', |
195
|
|
|
'date' => '2016-09-10 19:27:43', |
196
|
|
|
'behavior' => |
197
|
|
|
[ |
198
|
|
|
'id' => 89, |
199
|
|
|
'name' => 'obsessive (stuck) thoughts', |
200
|
|
|
'category_id' => 5, |
201
|
|
|
], |
202
|
|
|
], |
203
|
|
|
[ |
204
|
|
|
'id' => 653, |
205
|
|
|
'user_id' => 2, |
206
|
|
|
'behavior_id' => 111, |
207
|
|
|
'user_behavior_id' => 829, |
208
|
|
|
'question' => 1, |
209
|
|
|
'answer' => 'liub', |
210
|
|
|
'date' => '2016-09-10 19:27:43', |
211
|
|
|
'behavior' => |
212
|
|
|
[ |
213
|
|
|
'id' => 111, |
214
|
|
|
'name' => 'seeking out old unhealthy people and places', |
215
|
|
|
'category_id' => 6, |
216
|
|
|
], |
217
|
|
|
], |
218
|
|
|
[ |
219
|
|
|
'id' => 654, |
220
|
|
|
'user_id' => 2, |
221
|
|
|
'behavior_id' => 111, |
222
|
|
|
'user_behavior_id' => 829, |
223
|
|
|
'question' => 2, |
224
|
|
|
'answer' => 'liuyb', |
225
|
|
|
'date' => '2016-09-10 19:27:43', |
226
|
|
|
'behavior' => |
227
|
|
|
[ |
228
|
|
|
'id' => 111, |
229
|
|
|
'name' => 'seeking out old unhealthy people and places', |
230
|
|
|
'category_id' => 6, |
231
|
|
|
], |
232
|
|
|
], |
233
|
|
|
[ |
234
|
|
|
'id' => 655, |
235
|
|
|
'user_id' => 2, |
236
|
|
|
'behavior_id' => 111, |
237
|
|
|
'user_behavior_id' => 829, |
238
|
|
|
'question' => 3, |
239
|
|
|
'answer' => 'iuyb', |
240
|
|
|
'date' => '2016-09-10 19:27:43', |
241
|
|
|
'behavior' => |
242
|
|
|
[ |
243
|
|
|
'id' => 111, |
244
|
|
|
'name' => 'seeking out old unhealthy people and places', |
245
|
|
|
'category_id' => 6, |
246
|
|
|
], |
247
|
|
|
], |
248
|
|
|
[ |
249
|
|
|
'id' => 656, |
250
|
|
|
'user_id' => 2, |
251
|
|
|
'behavior_id' => 122, |
252
|
|
|
'user_behavior_id' => 831, |
253
|
|
|
'question' => 1, |
254
|
|
|
'answer' => 'iuyb', |
255
|
|
|
'date' => '2016-09-10 19:27:43', |
256
|
|
|
'behavior' => |
257
|
|
|
[ |
258
|
|
|
'id' => 122, |
259
|
|
|
'name' => 'returning to the place you swore you would never go again', |
260
|
|
|
'category_id' => 7, |
261
|
|
|
], |
262
|
|
|
], |
263
|
|
|
[ |
264
|
|
|
'id' => 657, |
265
|
|
|
'user_id' => 2, |
266
|
|
|
'behavior_id' => 122, |
267
|
|
|
'user_behavior_id' => 831, |
268
|
|
|
'question' => 2, |
269
|
|
|
'answer' => 'iuyb', |
270
|
|
|
'date' => '2016-09-10 19:27:43', |
271
|
|
|
'behavior' => |
272
|
|
|
[ |
273
|
|
|
'id' => 122, |
274
|
|
|
'name' => 'returning to the place you swore you would never go again', |
275
|
|
|
'category_id' => 7, |
276
|
|
|
], |
277
|
|
|
], |
278
|
|
|
[ |
279
|
|
|
'id' => 658, |
280
|
|
|
'user_id' => 2, |
281
|
|
|
'behavior_id' => 122, |
282
|
|
|
'user_behavior_id' => 831, |
283
|
|
|
'question' => 3, |
284
|
|
|
'answer' => 'liuyb', |
285
|
|
|
'date' => '2016-09-10 19:27:43', |
286
|
|
|
'behavior' => |
287
|
|
|
[ |
288
|
|
|
'id' => 122, |
289
|
|
|
'name' => 'returning to the place you swore you would never go again', |
290
|
|
|
'category_id' => 7, |
291
|
|
|
], |
292
|
|
|
], |
293
|
|
|
]; |
294
|
|
|
public $userQuestions = [ |
295
|
|
|
13 => [ |
296
|
|
|
'question' => [ |
297
|
|
|
'id' => 13, |
298
|
|
|
'title' => 'less time/energy for God, meetings, and church', |
299
|
|
|
], |
300
|
|
|
'answers' => [ |
301
|
|
|
[ |
302
|
|
|
'title' => 'How does it affect me? How do I act and feel?', |
303
|
|
|
'answer' => 'alsgn', |
304
|
|
|
], [ |
305
|
|
|
'title' => 'How does it affect the important people in my life?', |
306
|
|
|
'answer' => 'loiun', |
307
|
|
|
], [ |
308
|
|
|
'title' => 'Why do I do this? What is the benefit for me?', |
309
|
|
|
'answer' => 'liun', |
310
|
|
|
], |
311
|
|
|
], |
312
|
|
|
], |
313
|
|
|
29 => [ |
314
|
|
|
'question' => [ |
315
|
|
|
'id' => 29, |
316
|
|
|
'title' => 'using profanity', |
317
|
|
|
], |
318
|
|
|
'answers' => [ |
319
|
|
|
[ |
320
|
|
|
'title' => 'How does it affect me? How do I act and feel?', |
321
|
|
|
'answer' => 'ljnb', |
322
|
|
|
], [ |
323
|
|
|
'title' => 'How does it affect the important people in my life?', |
324
|
|
|
'answer' => 'liunb', |
325
|
|
|
], [ |
326
|
|
|
'title' => 'Why do I do this? What is the benefit for me?', |
327
|
|
|
'answer' => 'ilub ', |
328
|
|
|
], |
329
|
|
|
], |
330
|
|
|
], |
331
|
|
|
48 => [ |
332
|
|
|
'question' => [ |
333
|
|
|
'id' => 48, |
334
|
|
|
'title' => 'workaholic', |
335
|
|
|
], |
336
|
|
|
'answers' => [ |
337
|
|
|
[ |
338
|
|
|
'title' => 'How does it affect me? How do I act and feel?', |
339
|
|
|
'answer' => 'liub', |
340
|
|
|
], [ |
341
|
|
|
'title' => 'How does it affect the important people in my life?', |
342
|
|
|
'answer' => 'liub', |
343
|
|
|
], [ |
344
|
|
|
'title' => 'Why do I do this? What is the benefit for me?', |
345
|
|
|
'answer' => 'liub ', |
346
|
|
|
], |
347
|
|
|
], |
348
|
|
|
], |
349
|
|
|
89 => [ |
350
|
|
|
'question' => [ |
351
|
|
|
'id' => 89, |
352
|
|
|
'title' => 'obsessive (stuck) thoughts', |
353
|
|
|
], |
354
|
|
|
'answers' => [ |
355
|
|
|
[ |
356
|
|
|
'title' => 'How does it affect me? How do I act and feel?', |
357
|
|
|
'answer' => 'liub', |
358
|
|
|
], [ |
359
|
|
|
'title' => 'How does it affect the important people in my life?', |
360
|
|
|
'answer' => 'liuby', |
361
|
|
|
], [ |
362
|
|
|
'title' => 'Why do I do this? What is the benefit for me?', |
363
|
|
|
'answer' => 'uiylb', |
364
|
|
|
], |
365
|
|
|
], |
366
|
|
|
], |
367
|
|
|
111 => [ |
368
|
|
|
'question' => [ |
369
|
|
|
'id' => 111, |
370
|
|
|
'title' => 'seeking out old unhealthy people and places', |
371
|
|
|
], |
372
|
|
|
'answers' => [ |
373
|
|
|
[ |
374
|
|
|
'title' => 'How does it affect me? How do I act and feel?', |
375
|
|
|
'answer' => 'liub', |
376
|
|
|
], [ |
377
|
|
|
'title' => 'How does it affect the important people in my life?', |
378
|
|
|
'answer' => 'liuyb', |
379
|
|
|
], [ |
380
|
|
|
'title' => 'Why do I do this? What is the benefit for me?', |
381
|
|
|
'answer' => 'iuyb', |
382
|
|
|
], |
383
|
|
|
], |
384
|
|
|
], |
385
|
|
|
122 => [ |
386
|
|
|
'question' => [ |
387
|
|
|
'id' => 122, |
388
|
|
|
'title' => 'returning to the place you swore you would never go again', |
389
|
|
|
], |
390
|
|
|
'answers' => [ |
391
|
|
|
[ |
392
|
|
|
'title' => 'How does it affect me? How do I act and feel?', |
393
|
|
|
'answer' => 'iuyb', |
394
|
|
|
], [ |
395
|
|
|
'title' => 'How does it affect the important people in my life?', |
396
|
|
|
'answer' => 'iuyb', |
397
|
|
|
], [ |
398
|
|
|
'title' => 'Why do I do this? What is the benefit for me?', |
399
|
|
|
'answer' => 'liuyb', |
400
|
|
|
], |
401
|
|
|
], |
402
|
|
|
], |
403
|
|
|
]; |
404
|
|
|
|
405
|
|
|
public $exportData = [ |
406
|
|
|
[ |
407
|
|
|
'id' => 485, |
408
|
|
|
'date' => '2017-07-29 10:40:29', |
409
|
|
|
'behavior_id' => 59, |
410
|
|
|
'question1' => 'q1', |
411
|
|
|
'question2' => 'q2', |
412
|
|
|
'question3' => 'q3', |
413
|
|
|
'behavior' => [ |
414
|
|
|
'id' => 59, |
415
|
|
|
'name' => 'repetitive, negative thoughts', |
416
|
|
|
], |
417
|
|
|
'category' => [ |
418
|
|
|
'id' => 4, |
419
|
|
|
'name' => 'Speeding Up', |
420
|
|
|
], |
421
|
|
|
], [ |
422
|
|
|
'id' => 487, |
423
|
|
|
'date' => '2017-07-29 10:40:29', |
424
|
|
|
'behavior_id' => 106, |
425
|
|
|
'question1' => 'q1', |
426
|
|
|
'question2' => 'q2', |
427
|
|
|
'question3' => 'q3', |
428
|
|
|
'behavior' => [ |
429
|
|
|
'id' => 106, |
430
|
|
|
'name' => 'tired', |
431
|
|
|
], |
432
|
|
|
'category' => [ |
433
|
|
|
'id' => 6, |
434
|
|
|
'name' => 'Exhausted', |
435
|
|
|
], |
436
|
|
|
], [ |
437
|
|
|
'id' => 488, |
438
|
|
|
'date' => '2017-07-29 10:40:29', |
439
|
|
|
'behavior_id' => 125, |
440
|
|
|
'question1' => 'q1', |
441
|
|
|
'question2' => 'q2', |
442
|
|
|
'question3' => 'q3', |
443
|
|
|
'behavior' => [ |
444
|
|
|
'id' => 125, |
445
|
|
|
'name' => 'out of control', |
446
|
|
|
], |
447
|
|
|
'category' => [ |
448
|
|
|
'id' => 7, |
449
|
|
|
'name' => 'Relapse/Moral Failure', |
450
|
|
|
], |
451
|
|
|
], [ |
452
|
|
|
'id' => 486, |
453
|
|
|
'date' => '2017-07-29 10:40:29', |
454
|
|
|
'behavior_id' => 89, |
455
|
|
|
'question1' => 'q1', |
456
|
|
|
'question2' => 'q2', |
457
|
|
|
'question3' => 'q3', |
458
|
|
|
'behavior' => [ |
459
|
|
|
'id' => 89, |
460
|
|
|
'name' => 'obsessive (stuck) thoughts', |
461
|
|
|
], |
462
|
|
|
'category' => [ |
463
|
|
|
'id' => 5, |
464
|
|
|
'name' => 'Ticked Off', |
465
|
|
|
], |
466
|
|
|
] |
467
|
|
|
]; |
468
|
|
|
|
469
|
|
|
public function setUp() { |
470
|
|
|
$this->container = new \yii\di\Container; |
|
|
|
|
471
|
|
|
$this->container->set('common\interfaces\UserInterface', '\site\tests\_support\MockUser'); |
472
|
|
|
$this->container->set('common\interfaces\UserBehaviorInterface', '\site\tests\_support\MockUserBehavior'); |
473
|
|
|
$this->container->set('common\interfaces\TimeInterface', function () { |
474
|
|
|
return new \common\components\Time('America/Los_Angeles'); |
475
|
|
|
}); |
476
|
|
|
|
477
|
|
|
$user_behavior = $this->container->get('common\interfaces\UserBehaviorInterface'); |
478
|
|
|
$this->time = $this->container->get('common\interfaces\TimeInterface'); |
479
|
|
|
|
480
|
|
|
$this->question = $this->getMockBuilder('\common\models\Question') |
481
|
|
|
->setMethods(['save', 'attributes']) |
482
|
|
|
->getMock(); |
483
|
|
|
|
484
|
|
|
$this->user = $this->getMockBuilder('\common\models\User') |
485
|
|
|
->setConstructorArgs([$user_behavior, $this->question, $this->time]) |
486
|
|
|
->setMethods(['save', 'attributes']) |
487
|
|
|
->getMock(); |
488
|
|
|
$this->user->method('save')->willReturn(true); |
489
|
|
|
$this->user->method('attributes')->willReturn([ |
490
|
|
|
'id', |
491
|
|
|
'password_hash', |
492
|
|
|
'password_reset_token', |
493
|
|
|
'verify_email_token', |
494
|
|
|
'change_email_token', |
495
|
|
|
'email', |
496
|
|
|
'auth_key', |
497
|
|
|
'role', |
498
|
|
|
'status', |
499
|
|
|
'created_at', |
500
|
|
|
'updated_at', |
501
|
|
|
'password', |
502
|
|
|
'timezone', |
503
|
|
|
'send_email', |
504
|
|
|
'email_category', |
505
|
|
|
'partner_email1', |
506
|
|
|
'partner_email2', |
507
|
|
|
'partner_email3', |
508
|
|
|
]); |
509
|
|
|
|
510
|
|
|
parent::setUp(); |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
protected function tearDown() { |
514
|
|
|
$this->user = null; |
515
|
|
|
parent::tearDown(); |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
public function testParseQuestionData() { |
519
|
|
|
$this->specify('parseQuestionData should function correctly', function () { |
520
|
|
|
expect('parseQuestionData should return the correct structure with expected data', $this->assertEquals($this->user->parseQuestionData($this->questionData), $this->userQuestions)); |
|
|
|
|
521
|
|
|
expect('parseQuestionData should return empty with the empty set', $this->assertEmpty($this->user->parseQuestionData([]))); |
|
|
|
|
522
|
|
|
}); |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
public function testIsTokenCurrent() { |
526
|
|
|
$this->specify('isTokenCurrent should function correctly', function () { |
527
|
|
|
$good_token = \Yii::$app |
528
|
|
|
->getSecurity() |
529
|
|
|
->generateRandomString() . '_' . time(); |
530
|
|
|
expect('isTokenCurrent should return true if the token is still current/alive', $this->assertTrue($this->user->isTokenCurrent($good_token))); |
|
|
|
|
531
|
|
|
$expire = \Yii::$app->params['user.passwordResetTokenExpire']; |
532
|
|
|
$bad_token = \Yii::$app |
533
|
|
|
->getSecurity() |
534
|
|
|
->generateRandomString() . '_' . (time() - $expire - 1); // subtract the expiration time and a little more from the current time |
535
|
|
|
expect('isTokenCurrent should return false if the token is expired', $this->assertFalse($this->user->isTokenCurrent($bad_token))); |
|
|
|
|
536
|
|
|
}); |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
public function testIsTokenConfirmed() { |
540
|
|
|
expect('isTokenConfirmed should return true if the token has been confirmed', $this->assertTrue($this->user->isTokenConfirmed('token123_confirmed'))); |
|
|
|
|
541
|
|
|
expect('isTokenConfirmed should return false if the token has not been confirmed', $this->assertFalse($this->user->isTokenConfirmed('token123'))); |
|
|
|
|
542
|
|
|
expect('isTokenConfirmed should return false if the token has not been confirmed', $this->assertFalse($this->user->isTokenConfirmed('token123_not_blah'))); |
|
|
|
|
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
public function testGeneratePasswordResetToken() { |
546
|
|
|
expect('password_reset_token should be null by default', $this->assertNull($this->user->password_reset_token)); |
|
|
|
|
547
|
|
|
$this->user->generatePasswordResetToken(); |
548
|
|
|
expect('password_reset_token should now have a verification token set', $this->assertRegExp('/.*_[0-9]+/', $this->user->password_reset_token)); |
|
|
|
|
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
public function testGenerateVerifyEmailToken() { |
552
|
|
|
expect('verify_email_token should be null by default', $this->assertNull($this->user->verify_email_token)); |
|
|
|
|
553
|
|
|
$this->user->generateVerifyEmailToken(); |
554
|
|
|
expect('verify_email_token should now have a verification token set', $this->assertRegExp('/.*_[0-9]+/', $this->user->verify_email_token)); |
|
|
|
|
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
public function testConfirmVerifyEmailToken() { |
558
|
|
|
$this->user->verify_email_token = 'hello_world'; |
559
|
|
|
$this->user->confirmVerifyEmailToken(); |
560
|
|
|
expect('confirmVerifyEmailToken should append User::CONFIRMED_STRING to the end of the verify_email_token property', $this->assertEquals($this->user->verify_email_token, 'hello_world'.$this->user::CONFIRMED_STRING)); |
|
|
|
|
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
public function testIsVerified() { |
564
|
|
|
$this->user->verify_email_token = null; |
565
|
|
|
expect('isVerified should return true if the token is null', $this->assertTrue($this->user->isVerified())); |
|
|
|
|
566
|
|
|
$this->user->verify_email_token = ''; |
567
|
|
|
expect('isVerified should return false if the token is the empty string', $this->assertFalse($this->user->isVerified())); |
|
|
|
|
568
|
|
|
$this->user->verify_email_token = 'this_looks_truthy'; |
569
|
|
|
expect('isVerified should return false if the token is still present', $this->assertFalse($this->user->isVerified())); |
|
|
|
|
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
public function testRemoveVerifyEmailToken() { |
573
|
|
|
$this->user->verify_email_token = 'faketoken_1234'; |
574
|
|
|
$this->user->removeVerifyEmailToken(); |
575
|
|
|
expect('removeVerifyEmailToken should set the verify_email_token to be null', $this->assertNull($this->user->verify_email_token)); |
|
|
|
|
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
public function testGetIdHash() { |
579
|
|
|
$hash = 'iegYQgiPZUF48kk5bneuPn9_6ZOZhkMEGJ6Y8yICgKc'; |
580
|
|
|
|
581
|
|
|
$this->user->id = 12345; |
582
|
|
|
$this->user->created_at = "2017-12-31 23:59:59"; |
583
|
|
|
expect('getIdHash should return a url-safe string', $this->assertEquals($this->user->getidHash(), $hash)); |
|
|
|
|
584
|
|
|
|
585
|
|
|
$this->user->created_at = "2018-01-01 00:00:00"; |
586
|
|
|
expect('getIdHash should return a DIFFERENT url-safe string for different params', $this->assertNotEquals($this->user->getidHash(), $hash)); |
|
|
|
|
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
public function testCleanExportData() { |
590
|
|
|
// need this for the convertUTCToLocal call |
591
|
|
|
Yii::configure(Yii::$app, [ |
592
|
|
|
'components' => [ |
593
|
|
|
'user' => [ |
594
|
|
|
'class' => 'yii\web\User', |
595
|
|
|
'identityClass' => 'common\tests\unit\FakeUser', |
596
|
|
|
], |
597
|
|
|
], |
598
|
|
|
]); |
599
|
|
|
$identity = new \common\tests\unit\FakeUser(); |
600
|
|
|
$identity->timezone = "America/Los_Angeles"; |
601
|
|
|
// logs in the user |
602
|
|
|
Yii::$app->user->setIdentity($identity); |
|
|
|
|
603
|
|
|
|
604
|
|
|
expect('cleanExportData should clean and mutate the queried data to be suitable for downloading', $this->assertEquals([ |
|
|
|
|
605
|
|
|
[ |
606
|
|
|
'date' => '2017-07-29 03:40:29', |
607
|
|
|
'behavior' => 'repetitive, negative thoughts', |
608
|
|
|
'category' => 'Speeding Up', |
609
|
|
|
'question1' => 'q1', |
610
|
|
|
'question2' => 'q2', |
611
|
|
|
'question3' => 'q3', |
612
|
|
|
], [ |
613
|
|
|
'date' => '2017-07-29 03:40:29', |
614
|
|
|
'behavior' => 'tired', |
615
|
|
|
'category' => 'Exhausted', |
616
|
|
|
'question1' => 'q1', |
617
|
|
|
'question2' => 'q2', |
618
|
|
|
'question3' => 'q3', |
619
|
|
|
], [ |
620
|
|
|
'date' => '2017-07-29 03:40:29', |
621
|
|
|
'behavior' => 'out of control', |
622
|
|
|
'category' => 'Relapse/Moral Failure', |
623
|
|
|
'question1' => 'q1', |
624
|
|
|
'question2' => 'q2', |
625
|
|
|
'question3' => 'q3', |
626
|
|
|
], [ |
627
|
|
|
'date' => '2017-07-29 03:40:29', |
628
|
|
|
'behavior' => 'obsessive (stuck) thoughts', |
629
|
|
|
'category' => 'Ticked Off', |
630
|
|
|
'question1' => 'q1', |
631
|
|
|
'question2' => 'q2', |
632
|
|
|
'question3' => 'q3', |
633
|
|
|
] |
634
|
|
|
], $this->user->cleanExportData($this->exportData))); |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
public function testGenerateChangeEmailToken() { |
638
|
|
|
expect('change_email_token should be null by default', $this->assertNull($this->user->change_email_token)); |
|
|
|
|
639
|
|
|
$this->user->generateChangeEmailToken(); |
640
|
|
|
expect('change_email_token should now have a verification token set', $this->assertRegExp('/.*_[0-9]+/', $this->user->change_email_token)); |
|
|
|
|
641
|
|
|
} |
642
|
|
|
|
643
|
|
|
public function testRemoveChangeEmailToken() { |
644
|
|
|
$this->user->change_email_token = 'faketoken_1234'; |
645
|
|
|
$this->user->removeChangeEmailToken(); |
646
|
|
|
expect('removeChangeEmailToken should set the change_email_token to be null', $this->assertNull($this->user->change_email_token)); |
|
|
|
|
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
public function testSendEmailReport() { |
650
|
|
|
$user_behavior = $this->getMockBuilder('common\models\UserBehavior') |
651
|
|
|
->disableOriginalConstructor() |
652
|
|
|
->setMethods(['save', 'attributes', 'getCheckinBreakdown']) |
653
|
|
|
->getMock(); |
654
|
|
|
$expected = require(__DIR__.'/../data/expected_getCheckinBreakdown.php'); |
655
|
|
|
$user_behavior->method('getCheckinBreakdown')->willReturn($expected); |
656
|
|
|
|
657
|
|
|
$user = $this->getMockBuilder('\common\models\User') |
658
|
|
|
->setConstructorArgs([$user_behavior, $this->question, $this->time]) |
659
|
|
|
->setMethods(['save', 'attributes']) |
660
|
|
|
->getMock(); |
661
|
|
|
$user->method('save')->willReturn(true); |
662
|
|
|
$user->method('attributes')->willReturn([ |
663
|
|
|
'send_email', |
664
|
|
|
'email_category', |
665
|
|
|
]); |
666
|
|
|
|
667
|
|
|
$user->send_email = false; |
|
|
|
|
668
|
|
|
$user->email_category = 6; |
|
|
|
|
669
|
|
|
expect('it should not send any emails if the user has disabled send_email', $this->assertFalse($user->sendEmailReport('2019-01-01'))); |
|
|
|
|
670
|
|
|
expect('it should not send any emails if the user did not select any behaviors for the given day', $this->assertFalse($user->sendEmailReport('2018-01-01'))); |
|
|
|
|
671
|
|
|
expect('it should not send any emails if the user did not select any behaviors for the given day', $this->assertFalse($user->sendEmailReport('2018-03-02'))); |
|
|
|
|
672
|
|
|
expect('it should not send any emails if the user did not meet or exceed their email_category', $this->assertFalse($user->sendEmailReport('2019-03-01'))); |
|
|
|
|
673
|
|
|
} |
674
|
|
|
} |
675
|
|
|
|