Línea 29... |
Línea 29... |
29 |
/**
|
29 |
/**
|
30 |
* Test setup.
|
30 |
* Test setup.
|
31 |
*/
|
31 |
*/
|
32 |
public function setUp(): void {
|
32 |
public function setUp(): void {
|
33 |
global $CFG;
|
33 |
global $CFG;
|
- |
|
34 |
require_once($CFG->dirroot.'/completion/criteria/completion_criteria.php');
|
34 |
require_once($CFG->dirroot.'/completion/criteria/completion_criteria_course.php');
|
35 |
require_once($CFG->dirroot.'/completion/criteria/completion_criteria_course.php');
|
35 |
require_once($CFG->dirroot.'/completion/criteria/completion_criteria_activity.php');
|
36 |
require_once($CFG->dirroot.'/completion/criteria/completion_criteria_activity.php');
|
36 |
require_once($CFG->dirroot.'/completion/criteria/completion_criteria_duration.php');
|
37 |
require_once($CFG->dirroot.'/completion/criteria/completion_criteria_duration.php');
|
37 |
require_once($CFG->dirroot.'/completion/criteria/completion_criteria_grade.php');
|
38 |
require_once($CFG->dirroot.'/completion/criteria/completion_criteria_grade.php');
|
38 |
require_once($CFG->dirroot.'/completion/criteria/completion_criteria_date.php');
|
39 |
require_once($CFG->dirroot.'/completion/criteria/completion_criteria_date.php');
|
Línea 110... |
Línea 111... |
110 |
|
111 |
|
111 |
// The course for User is supposed to be marked as completed at $timestarted + $durationperiod.
|
112 |
// The course for User is supposed to be marked as completed at $timestarted + $durationperiod.
|
112 |
$ccompletion = new \completion_completion(['userid' => $user->id, 'course' => $course->id]);
|
113 |
$ccompletion = new \completion_completion(['userid' => $user->id, 'course' => $course->id]);
|
113 |
$this->assertEquals($timestarted + $durationperiod, $ccompletion->timecompleted);
|
114 |
$this->assertEquals($timestarted + $durationperiod, $ccompletion->timecompleted);
|
- |
|
115 |
$this->assertTrue($ccompletion->is_complete());
|
- |
|
116 |
|
- |
|
117 |
// Now we want to check the scenario where "now" sits in the middle of the timestart + duration
|
- |
|
118 |
// and timecreated + duration window.
|
- |
|
119 |
$nowtime = time();
|
- |
|
120 |
$timestarted = $nowtime - $durationperiod + (2 * DAYSECS);
|
- |
|
121 |
$timecreated = $nowtime - $durationperiod - (2 * DAYSECS);
|
- |
|
122 |
|
- |
|
123 |
// Using a new user for this.
|
- |
|
124 |
$user = $this->getDataGenerator()->create_and_enrol($course, 'student', null, 'manual', $timestarted);
|
- |
|
125 |
|
- |
|
126 |
// We need to manually update the enrollment's time created.
|
- |
|
127 |
$DB->set_field('user_enrolments', 'timecreated', $timecreated, ['userid' => $user->id]);
|
- |
|
128 |
|
- |
|
129 |
// Run the completion cron. See MDL-33320.
|
- |
|
130 |
$task->execute();
|
- |
|
131 |
sleep(1);
|
- |
|
132 |
$task->execute();
|
- |
|
133 |
|
- |
|
134 |
// We do NOT expect the user to be complete currently.
|
- |
|
135 |
$ccompletion = new \completion_completion(['userid' => $user->id, 'course' => $course->id]);
|
- |
|
136 |
$this->assertFalse($ccompletion->is_complete());
|
- |
|
137 |
|
- |
|
138 |
// Now, finally, we will move the timestart to be in the past, but still after the timecreated.
|
- |
|
139 |
$timestarted = $timecreated + DAYSECS;
|
- |
|
140 |
$DB->set_field('user_enrolments', 'timestart', $timestarted, ['userid' => $user->id]);
|
- |
|
141 |
|
- |
|
142 |
// Run the completion cron. See MDL-33320.
|
- |
|
143 |
$task->execute();
|
- |
|
144 |
sleep(1);
|
- |
|
145 |
$task->execute();
|
- |
|
146 |
|
- |
|
147 |
// Now they should be complete.
|
- |
|
148 |
$ccompletion = new \completion_completion(['userid' => $user->id, 'course' => $course->id]);
|
- |
|
149 |
$this->assertEquals($timestarted + $durationperiod, $ccompletion->timecompleted);
|
114 |
$this->assertTrue($ccompletion->is_complete());
|
150 |
$this->assertTrue($ccompletion->is_complete());
|
Línea 115... |
Línea 151... |
115 |
}
|
151 |
}
|
116 |
|
152 |
|
117 |
/**
|
153 |
/**
|