MDL-40081 completion: clean up criteria records for deleted courses.
This commit is contained in:
@@ -875,6 +875,44 @@ class core_completionlib_testcase extends advanced_testcase {
|
||||
$this->assertFalse($c2->has_activities());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that data is cleaned up when we delete courses that are set as completion criteria for other courses
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_course_delete_prerequisite() {
|
||||
global $DB;
|
||||
|
||||
$this->setup_data();
|
||||
|
||||
$courseprerequisite = $this->getDataGenerator()->create_course(['enablecompletion' => true]);
|
||||
|
||||
$criteriadata = (object) [
|
||||
'id' => $this->course->id,
|
||||
'criteria_course' => [$courseprerequisite->id],
|
||||
];
|
||||
|
||||
/** @var completion_criteria_course $criteria */
|
||||
$criteria = completion_criteria::factory(['criteriatype' => COMPLETION_CRITERIA_TYPE_COURSE]);
|
||||
$criteria->update_config($criteriadata);
|
||||
|
||||
// Sanity test.
|
||||
$this->assertTrue($DB->record_exists('course_completion_criteria', [
|
||||
'course' => $this->course->id,
|
||||
'criteriatype' => COMPLETION_CRITERIA_TYPE_COURSE,
|
||||
'courseinstance' => $courseprerequisite->id,
|
||||
]));
|
||||
|
||||
// Deleting the prerequisite course should remove the completion criteria.
|
||||
delete_course($courseprerequisite, false);
|
||||
|
||||
$this->assertFalse($DB->record_exists('course_completion_criteria', [
|
||||
'course' => $this->course->id,
|
||||
'criteriatype' => COMPLETION_CRITERIA_TYPE_COURSE,
|
||||
'courseinstance' => $courseprerequisite->id,
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test course module completion update event.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user