MDL-56789 core: Added unit test for course_modules_pending_deletion

This commit is contained in:
Shamim Rezaie
2019-08-07 14:18:11 +10:00
parent 414eca8923
commit 6cdf0207ff
+35
View File
@@ -6511,4 +6511,39 @@ class core_course_courselib_testcase extends advanced_testcase {
$result = course_get_course_dates_for_user_ids($course, [$user2->id]);
$this->assertEquals($user2start, $result[$user2->id]['start']);
}
/**
* Data provider for test_course_modules_pending_deletion.
*
* @return array An array of arrays contain test data
*/
public function provider_course_modules_pending_deletion() {
return [
['forum', true],
['assign', true],
];
}
/**
* Tests the function course_modules_pending_deletion.
*
* @param string $module The module we want to test with
* @param bool $expected The expected result
* @dataProvider provider_course_modules_pending_deletion
*/
public function test_course_modules_pending_deletion(string $module, bool $expected) {
$this->resetAfterTest();
// Ensure recyclebin is enabled.
set_config('coursebinenable', true, 'tool_recyclebin');
// Create course and modules.
$generator = $this->getDataGenerator();
$course = $generator->create_course();
$moduleinstance = $generator->create_module($module, array('course' => $course->id));
course_delete_module($moduleinstance->cmid, true); // Try to delete the instance asynchronously.
$this->assertEquals($expected, course_modules_pending_deletion($course->id));
}
}