mirror of
https://github.com/moodle/moodle.git
synced 2025-03-19 23:20:09 +01:00
Merge branch 'MDL-37616' of https://github.com/tsmilan/moodle
This commit is contained in:
commit
3f11a01e4b
@ -113,7 +113,10 @@ class enrol_cohort_handler {
|
||||
if ($ue->status != ENROL_USER_SUSPENDED) {
|
||||
$plugin->update_user_enrol($instance, $ue->userid, ENROL_USER_SUSPENDED);
|
||||
$context = context_course::instance($instance->courseid);
|
||||
role_unassign_all(array('userid'=>$ue->userid, 'contextid'=>$context->id, 'component'=>'enrol_cohort', 'itemid'=>$instance->id));
|
||||
if ($unenrolaction != ENROL_EXT_REMOVED_SUSPEND) {
|
||||
role_unassign_all(array('userid' => $ue->userid, 'contextid' => $context->id,
|
||||
'component' => 'enrol_cohort', 'itemid' => $instance->id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -138,9 +141,12 @@ class enrol_cohort_handler {
|
||||
$unenrolaction = $plugin->get_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL);
|
||||
|
||||
foreach ($instances as $instance) {
|
||||
if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
|
||||
if ($unenrolaction != ENROL_EXT_REMOVED_UNENROL) {
|
||||
$context = context_course::instance($instance->courseid);
|
||||
role_unassign_all(array('contextid'=>$context->id, 'component'=>'enrol_cohort', 'itemid'=>$instance->id));
|
||||
if ($unenrolaction != ENROL_EXT_REMOVED_SUSPEND) {
|
||||
role_unassign_all(array('contextid' => $context->id, 'component' => 'enrol_cohort',
|
||||
'itemid' => $instance->id));
|
||||
}
|
||||
$plugin->update_status($instance, ENROL_INSTANCE_DISABLED);
|
||||
} else {
|
||||
$plugin->delete_instance($instance);
|
||||
@ -233,8 +239,12 @@ function enrol_cohort_sync(progress_trace $trace, $courseid = NULL) {
|
||||
if ($ue->status != ENROL_USER_SUSPENDED) {
|
||||
$plugin->update_user_enrol($instance, $ue->userid, ENROL_USER_SUSPENDED);
|
||||
$context = context_course::instance($instance->courseid);
|
||||
role_unassign_all(array('userid'=>$ue->userid, 'contextid'=>$context->id, 'component'=>'enrol_cohort', 'itemid'=>$instance->id));
|
||||
$trace->output("suspending and unsassigning all roles: $ue->userid ==> $instance->courseid", 1);
|
||||
if ($unenrolaction != ENROL_EXT_REMOVED_SUSPEND) {
|
||||
role_unassign_all(array('userid' => $ue->userid, 'contextid' => $context->id,
|
||||
'component' => 'enrol_cohort', 'itemid' => $instance->id));
|
||||
$trace->output("unsassigning all roles: $ue->userid ==> $instance->courseid", 1);
|
||||
}
|
||||
$trace->output("suspending: $ue->userid ==> $instance->courseid", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -265,28 +275,28 @@ function enrol_cohort_sync(progress_trace $trace, $courseid = NULL) {
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
if ($unenrolaction != ENROL_EXT_REMOVED_SUSPEND) {
|
||||
// Remove unwanted roles - sync role can not be changed, we only remove role when unenrolled.
|
||||
$onecourse = $courseid ? "AND e.courseid = :courseid" : "";
|
||||
$sql = "SELECT ra.roleid, ra.userid, ra.contextid, ra.itemid, e.courseid
|
||||
FROM {role_assignments} ra
|
||||
JOIN {context} c ON (c.id = ra.contextid AND c.contextlevel = :coursecontext)
|
||||
JOIN {enrol} e ON (e.id = ra.itemid AND e.enrol = 'cohort' $onecourse)
|
||||
LEFT JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = ra.userid AND ue.status = :useractive)
|
||||
WHERE ra.component = 'enrol_cohort' AND (ue.id IS NULL OR e.status <> :statusenabled)";
|
||||
$params = array();
|
||||
$params['statusenabled'] = ENROL_INSTANCE_ENABLED;
|
||||
$params['useractive'] = ENROL_USER_ACTIVE;
|
||||
$params['coursecontext'] = CONTEXT_COURSE;
|
||||
$params['courseid'] = $courseid;
|
||||
|
||||
// Remove unwanted roles - sync role can not be changed, we only remove role when unenrolled.
|
||||
$onecourse = $courseid ? "AND e.courseid = :courseid" : "";
|
||||
$sql = "SELECT ra.roleid, ra.userid, ra.contextid, ra.itemid, e.courseid
|
||||
FROM {role_assignments} ra
|
||||
JOIN {context} c ON (c.id = ra.contextid AND c.contextlevel = :coursecontext)
|
||||
JOIN {enrol} e ON (e.id = ra.itemid AND e.enrol = 'cohort' $onecourse)
|
||||
LEFT JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = ra.userid AND ue.status = :useractive)
|
||||
WHERE ra.component = 'enrol_cohort' AND (ue.id IS NULL OR e.status <> :statusenabled)";
|
||||
$params = array();
|
||||
$params['statusenabled'] = ENROL_INSTANCE_ENABLED;
|
||||
$params['useractive'] = ENROL_USER_ACTIVE;
|
||||
$params['coursecontext'] = CONTEXT_COURSE;
|
||||
$params['courseid'] = $courseid;
|
||||
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach($rs as $ra) {
|
||||
role_unassign($ra->roleid, $ra->userid, $ra->contextid, 'enrol_cohort', $ra->itemid);
|
||||
$trace->output("unassigning role: $ra->userid ==> $ra->courseid as ".$allroles[$ra->roleid]->shortname, 1);
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($rs as $ra) {
|
||||
role_unassign($ra->roleid, $ra->userid, $ra->contextid, 'enrol_cohort', $ra->itemid);
|
||||
$trace->output("unassigning role: $ra->userid ==> $ra->courseid as ".$allroles[$ra->roleid]->shortname, 1);
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
|
||||
// Finally sync groups.
|
||||
$affectedusers = groups_sync_with_enrolment('cohort', $courseid);
|
||||
|
@ -40,6 +40,7 @@ if ($ADMIN->fulltree) {
|
||||
|
||||
$options = array(
|
||||
ENROL_EXT_REMOVED_UNENROL => get_string('extremovedunenrol', 'enrol'),
|
||||
ENROL_EXT_REMOVED_SUSPEND => get_string('extremovedsuspend', 'enrol'),
|
||||
ENROL_EXT_REMOVED_SUSPENDNOROLES => get_string('extremovedsuspendnoroles', 'enrol'));
|
||||
$settings->add(new admin_setting_configselect('enrol_cohort/unenrolaction', get_string('extremovedaction', 'enrol'), get_string('extremovedaction_help', 'enrol'), ENROL_EXT_REMOVED_UNENROL, $options));
|
||||
}
|
||||
|
93
enrol/cohort/tests/behat/unenrolactionsuspendonly.feature
Normal file
93
enrol/cohort/tests/behat/unenrolactionsuspendonly.feature
Normal file
@ -0,0 +1,93 @@
|
||||
@enrol @enrol_cohort
|
||||
Feature: Unenrol action to disable course enrolment
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher001 | Teacher | 001 | teacher001@example.com |
|
||||
| student001 | Student | 001 | student001@example.com |
|
||||
| student002 | Student | 002 | student002@example.com |
|
||||
| student003 | Student | 003 | student003@example.com |
|
||||
| student004 | Student | 004 | student004@example.com |
|
||||
And the following "cohorts" exist:
|
||||
| name | idnumber | visible |
|
||||
| System cohort | CVO | 1 |
|
||||
And the following "cohort members" exist:
|
||||
| user | cohort |
|
||||
| student001 | CVO |
|
||||
| student002 | CVO |
|
||||
| student003 | CVO |
|
||||
| student004 | CVO |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | format | startdate |
|
||||
| Course 001 | C001 | weeks | ##1 month ago## |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role | timestart |
|
||||
| teacher001 | C001 | editingteacher | ##1 month ago## |
|
||||
|
||||
@javascript
|
||||
Scenario: Removing the user from the cohort will suspend the enrolment but keep the role
|
||||
When I log in as "teacher001"
|
||||
And I am on "Course 001" course homepage
|
||||
And I navigate to course participants
|
||||
And I navigate to "Users > Enrolment methods" in current page administration
|
||||
And I select "Cohort sync" from the "Add method" singleselect
|
||||
And I open the autocomplete suggestions list
|
||||
Then "System cohort" "autocomplete_suggestions" should exist
|
||||
And I set the field "Cohort" to "System cohort"
|
||||
And I press "Add method"
|
||||
And I am on "Course 001" course homepage
|
||||
And I navigate to "Users > Enrolled users" in current page administration
|
||||
And I should see "student001@example.com"
|
||||
And I should see "student002@example.com"
|
||||
And I should see "student003@example.com"
|
||||
And I should see "student004@example.com"
|
||||
And I log out
|
||||
When I log in as "admin"
|
||||
Then I navigate to "Plugins > Enrolments > Cohort sync" in site administration
|
||||
And I select "Disable course enrolment" from the "External unenrol action" singleselect
|
||||
And I press "Save changes"
|
||||
And I navigate to "Users > Accounts > Cohorts" in site administration
|
||||
When I click on "Assign" "link" in the "System cohort" "table_row"
|
||||
And I set the field "removeselect_searchtext" to "Student 001"
|
||||
And I set the field "Current users" to "Student 001 (student001@example.com)"
|
||||
And I wait "1" seconds
|
||||
And I press "Remove"
|
||||
And I am on "Course 001" course homepage
|
||||
And I navigate to course participants
|
||||
And I should see "Suspended" in the "Student 001" "table_row"
|
||||
And I should see "Active" in the "Student 002" "table_row"
|
||||
And I should see "Active" in the "Student 003" "table_row"
|
||||
And I should see "Active" in the "Student 004" "table_row"
|
||||
|
||||
@javascript
|
||||
Scenario: Deleting non-empty cohort will suspend the enrolment but keep the role
|
||||
When I log in as "teacher001"
|
||||
And I am on "Course 001" course homepage
|
||||
And I navigate to course participants
|
||||
And I navigate to "Users > Enrolment methods" in current page administration
|
||||
And I select "Cohort sync" from the "Add method" singleselect
|
||||
And I open the autocomplete suggestions list
|
||||
Then "System cohort" "autocomplete_suggestions" should exist
|
||||
And I set the field "Cohort" to "System cohort"
|
||||
And I press "Add method"
|
||||
And I am on "Course 001" course homepage
|
||||
And I navigate to "Users > Enrolled users" in current page administration
|
||||
And I should see "student001@example.com"
|
||||
And I should see "student002@example.com"
|
||||
And I should see "student003@example.com"
|
||||
And I should see "student004@example.com"
|
||||
And I log out
|
||||
When I log in as "admin"
|
||||
Then I navigate to "Plugins > Enrolments > Cohort sync" in site administration
|
||||
And I select "Disable course enrolment" from the "External unenrol action" singleselect
|
||||
And I press "Save changes"
|
||||
And I navigate to "Users > Accounts > Cohorts" in site administration
|
||||
When I click on "Delete" "link" in the "System cohort" "table_row"
|
||||
And I press "Continue"
|
||||
And I am on "Course 001" course homepage
|
||||
And I navigate to course participants
|
||||
And I should see "Suspended" in the "Student 001" "table_row"
|
||||
And I should see "Suspended" in the "Student 002" "table_row"
|
||||
And I should see "Suspended" in the "Student 003" "table_row"
|
||||
And I should see "Suspended" in the "Student 004" "table_row"
|
@ -135,4 +135,82 @@ class enrol_cohort_lib_testcase extends advanced_testcase {
|
||||
// Cohort-sync has enrol actions for suspended students -- unenrol.
|
||||
$this->assertCount(1, $actions);
|
||||
}
|
||||
|
||||
public function test_enrol_cohort_unenrolaction_suspend_only() {
|
||||
global $CFG, $DB, $PAGE;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$trace = new null_progress_trace();
|
||||
|
||||
$cohortplugin = enrol_get_plugin('cohort');
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPEND);
|
||||
|
||||
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
|
||||
$this->assertNotEmpty($studentrole);
|
||||
|
||||
// Setup a test course.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$user3 = $this->getDataGenerator()->create_user();
|
||||
$user4 = $this->getDataGenerator()->create_user();
|
||||
|
||||
$cohort = $this->getDataGenerator()->create_cohort();
|
||||
|
||||
$cohortplugin->add_instance($course, ['customint1' => $cohort->id,
|
||||
'roleid' => $studentrole->id]
|
||||
);
|
||||
|
||||
cohort_add_member($cohort->id, $user1->id);
|
||||
cohort_add_member($cohort->id, $user2->id);
|
||||
cohort_add_member($cohort->id, $user3->id);
|
||||
cohort_add_member($cohort->id, $user4->id);
|
||||
|
||||
// Test sync.
|
||||
enrol_cohort_sync($trace, $course->id);
|
||||
|
||||
// All users should be enrolled.
|
||||
$this->assertTrue(is_enrolled(context_course::instance($course->id), $user1));
|
||||
$this->assertTrue(is_enrolled(context_course::instance($course->id), $user2));
|
||||
$this->assertTrue(is_enrolled(context_course::instance($course->id), $user3));
|
||||
$this->assertTrue(is_enrolled(context_course::instance($course->id), $user4));
|
||||
|
||||
// Remove cohort member.
|
||||
cohort_remove_member($cohort->id, $user1->id);
|
||||
$this->assertTrue(is_enrolled(context_course::instance($course->id), $user1));
|
||||
|
||||
// Run the sync again.
|
||||
enrol_cohort_sync($trace, $course->id);
|
||||
|
||||
$enrolid = $DB->get_field('enrol', 'id', ['enrol' => 'cohort', 'customint1' => $cohort->id]);
|
||||
$ue = $DB->get_record('user_enrolments', ['enrolid' => $enrolid, 'userid' => $user1->id]);
|
||||
|
||||
// Check user is suspended.
|
||||
$this->assertEquals($ue->status, ENROL_USER_SUSPENDED);
|
||||
// Check that user4 still have student role.
|
||||
$userrole = $DB->get_record('role_assignments', ['userid' => $user1->id]);
|
||||
$this->assertNotEmpty($userrole);
|
||||
$this->assertEquals($studentrole->id, $userrole->roleid);
|
||||
|
||||
// Delete the cohort.
|
||||
cohort_delete_cohort($cohort);
|
||||
|
||||
// Run the sync again.
|
||||
enrol_cohort_sync($trace, $course->id);
|
||||
|
||||
$ue = $DB->get_records('user_enrolments', ['enrolid' => $enrolid], '', 'userid, status, enrolid');
|
||||
|
||||
// Check users are suspended.
|
||||
$this->assertEquals($ue[$user2->id]->status, ENROL_USER_SUSPENDED);
|
||||
$this->assertEquals($ue[$user3->id]->status, ENROL_USER_SUSPENDED);
|
||||
$this->assertEquals($ue[$user4->id]->status, ENROL_USER_SUSPENDED);
|
||||
|
||||
// Check that users still have student role.
|
||||
$usersrole = $DB->get_records('role_assignments', ['itemid' => $enrolid], '', 'userid, roleid');
|
||||
$this->assertNotEmpty($usersrole);
|
||||
$this->assertEquals($studentrole->id, $usersrole[$user2->id]->roleid);
|
||||
$this->assertEquals($studentrole->id, $usersrole[$user3->id]->roleid);
|
||||
$this->assertEquals($studentrole->id, $usersrole[$user4->id]->roleid);
|
||||
}
|
||||
}
|
||||
|
@ -77,10 +77,12 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$user3 = $this->getDataGenerator()->create_user();
|
||||
$user4 = $this->getDataGenerator()->create_user();
|
||||
$user5 = $this->getDataGenerator()->create_user();
|
||||
|
||||
$cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat1->id)->id));
|
||||
$cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat2->id)->id));
|
||||
$cohort3 = $this->getDataGenerator()->create_cohort();
|
||||
$cohort4 = $this->getDataGenerator()->create_cohort();
|
||||
|
||||
$this->enable_plugin();
|
||||
|
||||
@ -102,6 +104,9 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
$id = $cohortplugin->add_instance($course2, array('customint1' => $cohort2->id, 'roleid' => $studentrole->id, 'status' => ENROL_INSTANCE_DISABLED));
|
||||
$cohortinstance4 = $DB->get_record('enrol', array('id' => $id));
|
||||
|
||||
$id = $cohortplugin->add_instance($course3, array('customint1' => $cohort4->id, 'roleid' => $studentrole->id));
|
||||
$cohortinstance5 = $DB->get_record('enrol', array('id' => $id));
|
||||
|
||||
// Test cohort member add event.
|
||||
|
||||
cohort_add_member($cohort1->id, $user1->id);
|
||||
@ -126,8 +131,9 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course2->id)->id, 'userid'=>$user3->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance3->id)));
|
||||
|
||||
cohort_add_member($cohort3->id, $user3->id);
|
||||
$this->assertEquals(7, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(7, $DB->count_records('role_assignments', array()));
|
||||
cohort_add_member($cohort4->id, $user5->id);
|
||||
$this->assertEquals(8, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(8, $DB->count_records('role_assignments', array()));
|
||||
|
||||
// Test cohort remove action.
|
||||
|
||||
@ -136,33 +142,74 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
|
||||
cohort_remove_member($cohort1->id, $user2->id);
|
||||
cohort_remove_member($cohort1->id, $user4->id);
|
||||
$this->assertEquals(7, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(5, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(8, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(6, $DB->count_records('role_assignments', array()));
|
||||
$this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
$this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
$this->assertEquals(ENROL_USER_SUSPENDED, $DB->get_field('user_enrolments', 'status',
|
||||
array('userid' => $user2->id, 'enrolid' => $cohortinstance1->id)));
|
||||
$this->assertEquals(ENROL_USER_SUSPENDED, $DB->get_field('user_enrolments', 'status',
|
||||
array('userid' => $user4->id, 'enrolid' => $cohortinstance1->id)));
|
||||
|
||||
cohort_add_member($cohort1->id, $user2->id);
|
||||
cohort_add_member($cohort1->id, $user4->id);
|
||||
$this->assertEquals(7, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(7, $DB->count_records('role_assignments', array()));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
$this->assertEquals(8, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(8, $DB->count_records('role_assignments', array()));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array(
|
||||
'contextid' => context_course::instance($course1->id)->id,
|
||||
'userid' => $user2->id, 'roleid' => $studentrole->id,
|
||||
'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array(
|
||||
'contextid' => context_course::instance($course1->id)->id,
|
||||
'userid' => $user4->id, 'roleid' => $studentrole->id,
|
||||
'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPEND);
|
||||
cohort_remove_member($cohort1->id, $user2->id);
|
||||
cohort_remove_member($cohort1->id, $user4->id);
|
||||
$this->assertEquals(8, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(8, $DB->count_records('role_assignments', array()));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array(
|
||||
'contextid' => context_course::instance($course1->id)->id,
|
||||
'userid' => $user2->id, 'roleid' => $studentrole->id,
|
||||
'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array(
|
||||
'contextid' => context_course::instance($course1->id)->id,
|
||||
'userid' => $user4->id, 'roleid' => $studentrole->id,
|
||||
'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
|
||||
$this->assertEquals(ENROL_USER_SUSPENDED, $DB->get_field('user_enrolments', 'status',
|
||||
array('userid' => $user2->id, 'enrolid' => $cohortinstance1->id)));
|
||||
$this->assertEquals(ENROL_USER_SUSPENDED, $DB->get_field('user_enrolments', 'status',
|
||||
array('userid' => $user4->id, 'enrolid' => $cohortinstance1->id)));
|
||||
|
||||
cohort_add_member($cohort1->id, $user2->id);
|
||||
cohort_add_member($cohort1->id, $user4->id);
|
||||
$this->assertEquals(8, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(8, $DB->count_records('role_assignments', array()));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array(
|
||||
'contextid' => context_course::instance($course1->id)->id,
|
||||
'userid' => $user2->id, 'roleid' => $studentrole->id,
|
||||
'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array(
|
||||
'contextid' => context_course::instance($course1->id)->id,
|
||||
'userid' => $user4->id, 'roleid' => $studentrole->id,
|
||||
'component' => 'enrol_cohort', 'itemid' => $cohortinstance1->id)));
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL);
|
||||
cohort_remove_member($cohort1->id, $user2->id);
|
||||
cohort_remove_member($cohort1->id, $user4->id);
|
||||
$this->assertEquals(5, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(6, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance1->id, 'userid'=>$user2->id)));
|
||||
$this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance1->id, 'userid'=>$user4->id)));
|
||||
$this->assertEquals(5, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(6, $DB->count_records('role_assignments', array()));
|
||||
$this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
$this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
|
||||
cohort_remove_member($cohort2->id, $user3->id);
|
||||
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(4, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance2->id, 'userid'=>$user3->id)));
|
||||
$this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance3->id, 'userid'=>$user3->id)));
|
||||
$this->assertEquals(3, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(4, $DB->count_records('role_assignments', array()));
|
||||
$this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id)));
|
||||
$this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course2->id)->id, 'userid'=>$user3->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance3->id)));
|
||||
|
||||
@ -172,13 +219,20 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
cohort_add_member($cohort1->id, $user2->id);
|
||||
cohort_add_member($cohort1->id, $user4->id);
|
||||
cohort_add_member($cohort2->id, $user3->id);
|
||||
$this->assertEquals(7, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(7, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(8, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(8, $DB->count_records('role_assignments', array()));
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPEND);
|
||||
cohort_delete_cohort($cohort4);
|
||||
$this->assertEquals(8, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(8, $DB->count_records('role_assignments', array()));
|
||||
$cohortinstance5 = $DB->get_record('enrol', array('id' => $cohortinstance5->id), '*', MUST_EXIST);
|
||||
$this->assertEquals(ENROL_INSTANCE_DISABLED, $cohortinstance5->status);
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
|
||||
cohort_delete_cohort($cohort2);
|
||||
$this->assertEquals(7, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(5, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(8, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(6, $DB->count_records('role_assignments', array()));
|
||||
|
||||
$cohortinstance2 = $DB->get_record('enrol', array('id'=>$cohortinstance2->id), '*', MUST_EXIST);
|
||||
$cohortinstance3 = $DB->get_record('enrol', array('id'=>$cohortinstance3->id), '*', MUST_EXIST);
|
||||
@ -190,14 +244,14 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL);
|
||||
cohort_delete_cohort($cohort1);
|
||||
$this->assertEquals(4, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(2, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(5, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(3, $DB->count_records('role_assignments', array()));
|
||||
$this->assertFalse($DB->record_exists('enrol', array('id'=>$cohortinstance1->id)));
|
||||
$this->assertFalse($DB->record_exists('role_assignments', array('component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
|
||||
// Cleanup after previous test (remove the extra user_enrolment).
|
||||
enrol_cohort_sync($trace, $course1->id);
|
||||
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(4, $DB->count_records('user_enrolments', array()));
|
||||
|
||||
// Test group sync.
|
||||
|
||||
@ -210,8 +264,8 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
$id = $cohortplugin->add_instance($course1, array('customint1'=>$cohort1->id, 'roleid'=>$studentrole->id, 'customint2'=>$group1->id));
|
||||
$cohortinstance1 = $DB->get_record('enrol', array('id'=>$id));
|
||||
|
||||
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(2, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(4, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(3, $DB->count_records('role_assignments', array()));
|
||||
|
||||
$this->assertTrue(is_enrolled(context_course::instance($course1->id), $user4));
|
||||
$this->assertTrue(groups_add_member($group1, $user4));
|
||||
@ -241,6 +295,11 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
cohort_remove_member($cohort1->id, $user1->id);
|
||||
$this->assertTrue(groups_is_member($group1->id, $user1->id));
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPEND);
|
||||
cohort_add_member($cohort1->id, $user1->id);
|
||||
|
||||
cohort_remove_member($cohort1->id, $user1->id);
|
||||
$this->assertTrue(groups_is_member($group1->id, $user1->id));
|
||||
|
||||
// Test deleting of instances.
|
||||
|
||||
@ -248,16 +307,16 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
cohort_add_member($cohort1->id, $user2->id);
|
||||
cohort_add_member($cohort1->id, $user3->id);
|
||||
|
||||
$this->assertEquals(6, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(5, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(7, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(6, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(3, $DB->count_records('role_assignments', array('component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
$this->assertEquals(5, $DB->count_records('groups_members', array()));
|
||||
$this->assertEquals(3, $DB->count_records('groups_members', array('component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
|
||||
$cohortplugin->delete_instance($cohortinstance1);
|
||||
|
||||
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(2, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(4, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(3, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(0, $DB->count_records('role_assignments', array('component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
$this->assertEquals(2, $DB->count_records('groups_members', array()));
|
||||
$this->assertEquals(0, $DB->count_records('groups_members', array('component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
@ -294,10 +353,12 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$user3 = $this->getDataGenerator()->create_user();
|
||||
$user4 = $this->getDataGenerator()->create_user();
|
||||
$user5 = $this->getDataGenerator()->create_user();
|
||||
|
||||
$cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat1->id)->id));
|
||||
$cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat2->id)->id));
|
||||
$cohort3 = $this->getDataGenerator()->create_cohort();
|
||||
$cohort4 = $this->getDataGenerator()->create_cohort();
|
||||
|
||||
$this->disable_plugin(); // Prevents event sync.
|
||||
|
||||
@ -319,11 +380,15 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
$id = $cohortplugin->add_instance($course2, array('customint1' => $cohort2->id, 'roleid' => $studentrole->id, 'status' => ENROL_INSTANCE_DISABLED));
|
||||
$cohortinstance4 = $DB->get_record('enrol', array('id' => $id));
|
||||
|
||||
$id = $cohortplugin->add_instance($course3, array('customint1' => $cohort4->id, 'roleid' => $studentrole->id));
|
||||
$cohortinstance5 = $DB->get_record('enrol', array('id' => $id));
|
||||
|
||||
cohort_add_member($cohort1->id, $user1->id);
|
||||
cohort_add_member($cohort1->id, $user2->id);
|
||||
cohort_add_member($cohort1->id, $user4->id);
|
||||
cohort_add_member($cohort2->id, $user3->id);
|
||||
cohort_add_member($cohort3->id, $user3->id);
|
||||
cohort_add_member($cohort4->id, $user5->id);
|
||||
|
||||
$this->assertEquals(2, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(2, $DB->count_records('user_enrolments', array()));
|
||||
@ -356,6 +421,18 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id)));
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPEND);
|
||||
// Use low level DB api to prevent events!
|
||||
$DB->delete_records('cohort_members', array('cohortid' => $cohort2->id, 'userid' => $user3->id));
|
||||
enrol_cohort_sync($trace, $course1->id);
|
||||
$this->assertEquals(7, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(7, $DB->count_records('role_assignments', array()));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array(
|
||||
'contextid' => context_course::instance($course1->id)->id,
|
||||
'userid' => $user3->id, 'roleid' => $teacherrole->id,
|
||||
'component' => 'enrol_cohort', 'itemid' => $cohortinstance2->id)));
|
||||
|
||||
cohort_add_member($cohort2->id, $user3->id);
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
|
||||
$DB->delete_records('cohort_members', array('cohortid'=>$cohort2->id, 'userid'=>$user3->id)); // Use low level DB api to prevent events!
|
||||
enrol_cohort_sync($trace, $course1->id);
|
||||
@ -373,6 +450,13 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
$this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id)));
|
||||
$this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPEND);
|
||||
$DB->delete_records('cohort_members', array('cohortid' => $cohort4->id));
|
||||
$DB->delete_records('cohort', array('id' => $cohort4->id));
|
||||
enrol_cohort_sync($trace, $course3->id);
|
||||
$this->assertEquals(5, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(5, $DB->count_records('role_assignments', array()));
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
|
||||
$DB->delete_records('cohort_members', array('cohortid'=>$cohort1->id)); // Use low level DB api to prevent events!
|
||||
$DB->delete_records('cohort', array('id'=>$cohort1->id)); // Use low level DB api to prevent events!
|
||||
@ -482,10 +566,12 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$user3 = $this->getDataGenerator()->create_user();
|
||||
$user4 = $this->getDataGenerator()->create_user();
|
||||
$user5 = $this->getDataGenerator()->create_user();
|
||||
|
||||
$cohort1 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat1->id)->id));
|
||||
$cohort2 = $this->getDataGenerator()->create_cohort(array('contextid'=>context_coursecat::instance($cat2->id)->id));
|
||||
$cohort3 = $this->getDataGenerator()->create_cohort();
|
||||
$cohort4 = $this->getDataGenerator()->create_cohort();
|
||||
|
||||
$this->disable_plugin(); // Prevents event sync.
|
||||
|
||||
@ -504,11 +590,15 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
$id = $cohortplugin->add_instance($course2, array('customint1'=>$cohort2->id, 'roleid'=>$studentrole->id));
|
||||
$cohortinstance3 = $DB->get_record('enrol', array('id'=>$id));
|
||||
|
||||
$id = $cohortplugin->add_instance($course3, array('customint1' => $cohort4->id, 'roleid' => $studentrole->id));
|
||||
$cohortinstance4 = $DB->get_record('enrol', array('id' => $id));
|
||||
|
||||
cohort_add_member($cohort1->id, $user1->id);
|
||||
cohort_add_member($cohort1->id, $user2->id);
|
||||
cohort_add_member($cohort1->id, $user4->id);
|
||||
cohort_add_member($cohort2->id, $user3->id);
|
||||
cohort_add_member($cohort3->id, $user3->id);
|
||||
cohort_add_member($cohort4->id, $user5->id);
|
||||
|
||||
$this->assertEquals(2, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(2, $DB->count_records('user_enrolments', array()));
|
||||
@ -523,45 +613,64 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
|
||||
$this->enable_plugin();
|
||||
enrol_cohort_sync($trace, null);
|
||||
$this->assertEquals(7, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(8, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance1->id, 'userid'=>$user1->id)));
|
||||
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance1->id, 'userid'=>$user2->id)));
|
||||
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance1->id, 'userid'=>$user4->id)));
|
||||
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance2->id, 'userid'=>$user3->id)));
|
||||
$this->assertEquals(7, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(8, $DB->count_records('role_assignments', array()));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id)));
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPEND);
|
||||
$DB->delete_records('cohort_members', array('cohortid' => $cohort2->id, 'userid' => $user3->id));
|
||||
enrol_cohort_sync($trace, $course1->id);
|
||||
$this->assertEquals(8, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(8, $DB->count_records('role_assignments', array()));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array(
|
||||
'contextid' => context_course::instance($course1->id)->id,
|
||||
'userid' => $user3->id, 'roleid' => $teacherrole->id,
|
||||
'component' => 'enrol_cohort', 'itemid' => $cohortinstance2->id)));
|
||||
|
||||
cohort_add_member($cohort2->id, $user3->id);
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
|
||||
$DB->delete_records('cohort_members', array('cohortid'=>$cohort2->id, 'userid'=>$user3->id)); // Use low level DB api to prevent events!
|
||||
enrol_cohort_sync($trace, $course1->id);
|
||||
$this->assertEquals(7, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(6, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(8, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(7, $DB->count_records('role_assignments', array()));
|
||||
$this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id)));
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL);
|
||||
$DB->delete_records('cohort_members', array('cohortid'=>$cohort1->id, 'userid'=>$user1->id)); // Use low level DB api to prevent events!
|
||||
enrol_cohort_sync($trace, $course1->id);
|
||||
$this->assertEquals(5, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(6, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance2->id, 'userid'=>$user3->id)));
|
||||
$this->assertFalse($DB->record_exists('user_enrolments', array('enrolid'=>$cohortinstance1->id, 'userid'=>$user1->id)));
|
||||
$this->assertEquals(5, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(6, $DB->count_records('role_assignments', array()));
|
||||
$this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance2->id)));
|
||||
$this->assertFalse($DB->record_exists('role_assignments', array('contextid'=>context_course::instance($course1->id)->id, 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'component'=>'enrol_cohort', 'itemid'=>$cohortinstance1->id)));
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPEND);
|
||||
$DB->delete_records('cohort_members', array('cohortid' => $cohort4->id)); // Use low level DB api to prevent events!
|
||||
$DB->delete_records('cohort', array('id' => $cohort4->id)); // Use low level DB api to prevent events!
|
||||
enrol_cohort_sync($trace, $course3->id);
|
||||
$this->assertEquals(6, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(6, $DB->count_records('role_assignments', array()));
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
|
||||
$DB->delete_records('cohort_members', array('cohortid'=>$cohort1->id)); // Use low level DB api to prevent events!
|
||||
$DB->delete_records('cohort', array('id'=>$cohort1->id)); // Use low level DB api to prevent events!
|
||||
$DB->delete_records('cohort_members', array('cohortid' => $cohort1->id)); // Use low level DB api to prevent events!
|
||||
$DB->delete_records('cohort', array('id' => $cohort1->id)); // Use low level DB api to prevent events!
|
||||
enrol_cohort_sync($trace, $course1->id);
|
||||
$this->assertEquals(5, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(3, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(6, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(4, $DB->count_records('role_assignments', array()));
|
||||
|
||||
$cohortplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL);
|
||||
enrol_cohort_sync($trace, $course1->id);
|
||||
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(3, $DB->count_records('role_assignments', array()));
|
||||
$this->assertEquals(4, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(4, $DB->count_records('role_assignments', array()));
|
||||
|
||||
|
||||
// Test group sync.
|
||||
@ -585,7 +694,7 @@ class enrol_cohort_testcase extends advanced_testcase {
|
||||
$this->assertTrue(groups_add_member($group1, $user4));
|
||||
$this->assertTrue(groups_add_member($group2, $user4));
|
||||
|
||||
$this->assertEquals(3, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(4, $DB->count_records('user_enrolments', array()));
|
||||
$this->assertEquals(2, $DB->count_records('role_assignments', array()));
|
||||
|
||||
$this->assertFalse(groups_is_member($group1->id, $user1->id));
|
||||
|
Loading…
x
Reference in New Issue
Block a user