@@ -54,6 +54,7 @@ public function setUp(): void {
54
54
* @covers \mod_customcert\task\email_certificate_task
55
55
*/
56
56
public function test_email_certificates_no_elements () {
57
+ global $ DB ;
57
58
// Create a course.
58
59
$ course = $ this ->getDataGenerator ()->create_course ();
59
60
@@ -66,6 +67,9 @@ public function test_email_certificates_no_elements() {
66
67
// Enrol the user as a student.
67
68
$ this ->getDataGenerator ()->enrol_user ($ user1 ->id , $ course ->id );
68
69
70
+ // Register activity in the course to make it valid to be sent.
71
+ $ DB ->insert_record ('user_lastaccess ' , ['userid ' => $ user1 ->id , 'courseid ' => $ course ->id , 'lastaccess ' => time ()]);
72
+
69
73
// Run the task.
70
74
$ sink = $ this ->redirectEmails ();
71
75
$ task = new email_certificate_task ();
@@ -101,6 +105,9 @@ public function test_email_certificates_no_cap() {
101
105
// Create a custom certificate.
102
106
$ customcert = $ this ->getDataGenerator ()->create_module ('customcert ' , ['course ' => $ course ->id , 'emailstudents ' => 1 ]);
103
107
108
+ // Register activity in the course to make it valid to be sent.
109
+ $ DB ->insert_record ('user_lastaccess ' , ['userid ' => $ user1 ->id , 'courseid ' => $ course ->id , 'lastaccess ' => time ()]);
110
+
104
111
// Create template object.
105
112
$ template = new stdClass ();
106
113
$ template ->id = $ customcert ->templateid ;
@@ -155,6 +162,9 @@ public function test_email_certificates_students() {
155
162
$ customcert = $ this ->getDataGenerator ()->create_module ('customcert ' , array ('course ' => $ course ->id ,
156
163
'emailstudents ' => 1 ));
157
164
165
+ // Register activity in the course to make it valid to be sent.
166
+ $ DB ->insert_record ('user_lastaccess ' , ['userid ' => $ user1 ->id , 'courseid ' => $ course ->id , 'lastaccess ' => time ()]);
167
+
158
168
// Create template object.
159
169
$ template = new stdClass ();
160
170
$ template ->id = $ customcert ->templateid ;
@@ -241,6 +251,8 @@ public function test_email_certificates_teachers() {
241
251
// Create a custom certificate.
242
252
$ customcert = $ this ->getDataGenerator ()->create_module ('customcert ' , array ('course ' => $ course ->id ,
243
253
'emailteachers ' => 1 ));
254
+ // Register activity in the course to make it valid to be sent.
255
+ $ DB ->insert_record ('user_lastaccess ' , ['userid ' => $ user1 ->id , 'courseid ' => $ course ->id , 'lastaccess ' => time ()]);
244
256
245
257
// Create template object.
246
258
$ template = new stdClass ();
@@ -297,6 +309,9 @@ public function test_email_certificates_others() {
297
309
$ customcert = $ this ->getDataGenerator ()->create_module ('customcert ' , array ('course ' => $ course ->id ,
298
310
'emailothers ' =>
'[email protected] , doo@dah ' ));
299
311
312
+ // Register activity in the course to make it valid to be sent.
313
+ $ DB ->insert_record ('user_lastaccess ' , ['userid ' => $ user1 ->id , 'courseid ' => $ course ->id , 'lastaccess ' => time ()]);
314
+
300
315
// Create template object.
301
316
$ template = new stdClass ();
302
317
$ template ->id = $ customcert ->templateid ;
@@ -350,6 +365,9 @@ public function test_email_certificates_students_not_visible() {
350
365
// Create a custom certificate.
351
366
$ customcert = $ this ->getDataGenerator ()->create_module ('customcert ' , ['course ' => $ course ->id , 'emailstudents ' => 1 ]);
352
367
368
+ // Register activity in the course to make it valid to be sent.
369
+ $ DB ->insert_record ('user_lastaccess ' , ['userid ' => $ user1 ->id , 'courseid ' => $ course ->id , 'lastaccess ' => time ()]);
370
+
353
371
// Create template object.
354
372
$ template = new stdClass ();
355
373
$ template ->id = $ customcert ->templateid ;
@@ -407,6 +425,9 @@ public function test_email_certificates_students_havent_met_required_time() {
407
425
$ customcert = $ this ->getDataGenerator ()->create_module ('customcert ' , array ('course ' => $ course ->id , 'emailstudents ' => 1 ,
408
426
'requiredtime ' => '60 ' ));
409
427
428
+ // Register activity in the course to make it valid to be sent.
429
+ $ DB ->insert_record ('user_lastaccess ' , ['userid ' => $ user1 ->id , 'courseid ' => $ course ->id , 'lastaccess ' => time ()]);
430
+
410
431
// Create template object.
411
432
$ template = new stdClass ();
412
433
$ template ->id = $ customcert ->templateid ;
0 commit comments