mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-68843 enrol_lti: add tests covering disabled instances in tasks
Verify the expected behaviour of the sync_members and sync_grades tasks when enrolment instances are disabled, whether as a byproduct of module deletion, or as status change made by the user.
This commit is contained in:
parent
3387e63736
commit
273d9d561d
@ -412,6 +412,35 @@ class sync_grades_test extends \lti_advantage_testcase {
|
||||
$task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test syncing grades when the enrolment instance is disabled.
|
||||
*
|
||||
* @covers ::execute
|
||||
*/
|
||||
public function test_sync_grades_disabled_instance() {
|
||||
$this->resetAfterTest();
|
||||
global $DB;
|
||||
|
||||
[$course, $resource, $resource2, $resource3] = $this->create_test_environment();
|
||||
|
||||
// Disable resource 1.
|
||||
$enrol = (object) ['id' => $resource->enrolid, 'status' => ENROL_INSTANCE_DISABLED];
|
||||
$DB->update_record('enrol', $enrol);
|
||||
|
||||
// Delete the activity being shared by resource 2, leaving resource 2 disabled as a result.
|
||||
$modcontext = \context::instance_by_id($resource2->contextid);
|
||||
course_delete_module($modcontext->instanceid);
|
||||
|
||||
// Only the enabled resource 3 should sync grades.
|
||||
$task = $this->get_task_with_mocked_grade_service();
|
||||
$this->expectOutputRegex(
|
||||
"/^Starting - LTI Advantage grade sync for shared resource '$resource3->id' in course '$course->id'.\n".
|
||||
"Completed - Synced grades for tool '$resource3->id' in the course '$course->id'. Processed 0 users; ".
|
||||
"sent 0 grades.\n$/"
|
||||
);
|
||||
$task->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the grade sync when the context has been deleted in between launch and when the grade sync task is run.
|
||||
*
|
||||
@ -432,7 +461,7 @@ class sync_grades_test extends \lti_advantage_testcase {
|
||||
// Delete the activity, then enable the enrolment method (it is disabled during activity deletion).
|
||||
$modcontext = \context::instance_by_id($resource->contextid);
|
||||
course_delete_module($modcontext->instanceid);
|
||||
$enrol = ['id' => $resource->enrolid, 'status' => ENROL_INSTANCE_ENABLED];
|
||||
$enrol = (object) ['id' => $resource->enrolid, 'status' => ENROL_INSTANCE_ENABLED];
|
||||
$DB->update_record('enrol', $enrol);
|
||||
|
||||
$task = $this->get_task_with_mocked_grade_service();
|
||||
|
@ -609,6 +609,38 @@ class sync_members_test extends \lti_advantage_testcase {
|
||||
$this->assertCount(1, $userrepo->find_by_resource($resource->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test syncing members when the enrolment instance is disabled.
|
||||
*
|
||||
* @covers ::execute
|
||||
*/
|
||||
public function test_sync_members_disabled_instance() {
|
||||
$this->resetAfterTest();
|
||||
global $DB;
|
||||
|
||||
[$course, $resource, $resource2, $resource3] = $this->create_test_environment();
|
||||
$userrepo = new user_repository();
|
||||
|
||||
// Disable resource 1.
|
||||
$enrol = (object) ['id' => $resource->enrolid, 'status' => ENROL_INSTANCE_DISABLED];
|
||||
$DB->update_record('enrol', $enrol);
|
||||
|
||||
// Delete the activity being shared by resource2, leaving resource 2 disabled as a result.
|
||||
$modcontext = \context::instance_by_id($resource2->contextid);
|
||||
course_delete_module($modcontext->instanceid);
|
||||
|
||||
// Only the enabled resource 3 should sync members.
|
||||
$task = $this->get_mock_task_with_users($this->get_mock_members_with_ids(range(1, 1)));
|
||||
$task->execute();
|
||||
|
||||
$this->expectOutputRegex(
|
||||
"/^Starting - Member sync for published resource '$resource3->id' for course '$course->id'.\n".
|
||||
"Completed - Synced members for tool '$resource3->id' in the course '$course->id'. Processed 0 users; ".
|
||||
"enrolled 0 members; unenrolled 0 members.\n$/"
|
||||
);
|
||||
$this->assertCount(0, $userrepo->find_by_resource($resource->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test syncing members for a membersync-enabled resource when the launch omits the NRPS service endpoints.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user