mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
Merge branch 'MDL-77781-master' of https://github.com/sarjona/moodle
This commit is contained in:
commit
025690347d
@ -928,7 +928,9 @@ class completion_info {
|
||||
$DB->delete_records_select('course_modules_completion',
|
||||
'coursemoduleid IN (SELECT id FROM {course_modules} WHERE course=?)',
|
||||
array($this->course_id));
|
||||
|
||||
$DB->delete_records_select('course_modules_viewed',
|
||||
'coursemoduleid IN (SELECT id FROM {course_modules} WHERE course=?)',
|
||||
[$this->course_id]);
|
||||
// Wipe course completion data too.
|
||||
$this->delete_course_completion_data();
|
||||
}
|
||||
|
@ -1992,6 +1992,49 @@ class completionlib_test extends advanced_testcase {
|
||||
$this->assertEquals(1, count($completions));
|
||||
$this->assertEquals(reset($completions)->id, $completionid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that data is cleaned when we reset a course completion data
|
||||
*
|
||||
* @covers ::delete_all_completion_data
|
||||
*/
|
||||
public function test_course_reset_completion() {
|
||||
global $DB;
|
||||
|
||||
$this->setup_data();
|
||||
|
||||
$page = $this->getDataGenerator()->create_module('page', [
|
||||
'course' => $this->course->id,
|
||||
'completion' => COMPLETION_ENABLED,
|
||||
'completionview' => COMPLETION_VIEW_REQUIRED,
|
||||
]);
|
||||
$cm = cm_info::create(get_coursemodule_from_instance('page', $page->id));
|
||||
$completion = new completion_info($this->course);
|
||||
$completion->set_module_viewed($cm, $this->user->id);
|
||||
// Sanity test.
|
||||
$this->assertTrue($DB->record_exists_select('course_modules_completion',
|
||||
'coursemoduleid IN (SELECT id FROM {course_modules} WHERE course=:course)',
|
||||
['course' => $this->course->id]
|
||||
));
|
||||
$this->assertTrue($DB->record_exists_select('course_modules_viewed',
|
||||
'coursemoduleid IN (SELECT id FROM {course_modules} WHERE course=:course)',
|
||||
['course' => $this->course->id]
|
||||
));
|
||||
// Deleting the prerequisite course should remove the completion criteria.
|
||||
$resetdata = new \stdClass();
|
||||
$resetdata->id = $this->course->id;
|
||||
$resetdata->reset_completion = true;
|
||||
reset_course_userdata($resetdata);
|
||||
|
||||
$this->assertFalse($DB->record_exists_select('course_modules_completion',
|
||||
'coursemoduleid IN (SELECT id FROM {course_modules} WHERE course=:course)',
|
||||
['course' => $this->course->id]
|
||||
));
|
||||
$this->assertFalse($DB->record_exists_select('course_modules_viewed',
|
||||
'coursemoduleid IN (SELECT id FROM {course_modules} WHERE course=:course)',
|
||||
['course' => $this->course->id]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
class core_completionlib_fake_recordset implements Iterator {
|
||||
|
Loading…
x
Reference in New Issue
Block a user