mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 14:02:32 +02:00
MDL-73076 completion: split criteria duration test into two tests
This commit is contained in:
parent
896e126a66
commit
2afa4488cd
@ -79,26 +79,16 @@ class completion_criteria_test extends \advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that enrolment timestart/timecreated are used when duration criteria is marked as completed.
|
||||
* Test that enrolment timestart are used when duration criteria is marked as completed.
|
||||
*/
|
||||
public function test_completion_criteria_duration(): void {
|
||||
public function test_completion_criteria_duration_timestart(): void {
|
||||
global $DB;
|
||||
$timestarted = 1610000000;
|
||||
$timecreated = 1620000000;
|
||||
$durationperiod = DAYSECS;
|
||||
|
||||
// Create a course and users.
|
||||
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]);
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$studentrole = $DB->get_record('role', ['shortname' => 'student']);
|
||||
|
||||
// Enrol User 1 with time start = $timestarted.
|
||||
$this->getDataGenerator()->enrol_user($user1->id, $course->id, $studentrole->id, 'manual', $timestarted);
|
||||
|
||||
// Enrol User 2 with an empty time start, but update the record like it was created at $timecreated.
|
||||
$this->getDataGenerator()->enrol_user($user2->id, $course->id, $studentrole->id);
|
||||
$DB->set_field('user_enrolments', 'timecreated', $timecreated, ['userid' => $user2->id]);
|
||||
$user = $this->getDataGenerator()->create_and_enrol($course, 'student', null, 'manual', $timestarted);
|
||||
|
||||
// Set completion criteria.
|
||||
$criteriadata = (object) [
|
||||
@ -118,13 +108,49 @@ class completion_criteria_test extends \advanced_testcase {
|
||||
sleep(1);
|
||||
$task->execute();
|
||||
|
||||
// The course for User 1 is supposed to be marked as completed at $timestarted + $durationperiod.
|
||||
$ccompletion = new \completion_completion(['userid' => $user1->id, 'course' => $course->id]);
|
||||
// The course for User is supposed to be marked as completed at $timestarted + $durationperiod.
|
||||
$ccompletion = new \completion_completion(['userid' => $user->id, 'course' => $course->id]);
|
||||
$this->assertEquals($timestarted + $durationperiod, $ccompletion->timecompleted);
|
||||
$this->assertTrue($ccompletion->is_complete());
|
||||
}
|
||||
|
||||
// The course for User 2 is supposed to be marked as completed at $timecreated + $durationperiod.
|
||||
$ccompletion = new \completion_completion(['userid' => $user2->id, 'course' => $course->id]);
|
||||
/**
|
||||
* Test that enrolment timecreated are used when duration criteria is marked as completed.
|
||||
*/
|
||||
public function test_completion_criteria_duration_timecreated(): void {
|
||||
global $DB;
|
||||
|
||||
$timecreated = 1620000000;
|
||||
$durationperiod = DAYSECS;
|
||||
|
||||
// Create a course and users.
|
||||
$course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]);
|
||||
|
||||
// Create and enrol user with an empty time start, but update the record like it was created at $timecreated.
|
||||
$user = $this->getDataGenerator()->create_and_enrol($course);
|
||||
$DB->set_field('user_enrolments', 'timecreated', $timecreated, ['userid' => $user->id]);
|
||||
|
||||
// Set completion criteria.
|
||||
$criteriadata = (object) [
|
||||
'id' => $course->id,
|
||||
'criteria_duration' => 1,
|
||||
'criteria_duration_days' => $durationperiod,
|
||||
];
|
||||
$criterion = new \completion_criteria_duration();
|
||||
$criterion->update_config($criteriadata);
|
||||
|
||||
// Run completion scheduled task.
|
||||
$task = new \core\task\completion_regular_task();
|
||||
$this->expectOutputRegex("/Marking complete/");
|
||||
$task->execute();
|
||||
|
||||
// Hopefully, some day MDL-33320 will be fixed and all these sleeps
|
||||
// and double cron calls in behat and unit tests will be removed.
|
||||
sleep(1);
|
||||
$task->execute();
|
||||
|
||||
// The course for user is supposed to be marked as completed at $timecreated + $durationperiod.
|
||||
$ccompletion = new \completion_completion(['userid' => $user->id, 'course' => $course->id]);
|
||||
$this->assertEquals($timecreated + $durationperiod, $ccompletion->timecompleted);
|
||||
$this->assertTrue($ccompletion->is_complete());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user