diff --git a/public/admin/tool/uploadcourse/classes/course.php b/public/admin/tool/uploadcourse/classes/course.php index 6600bf0b1be..b4a35053d3a 100644 --- a/public/admin/tool/uploadcourse/classes/course.php +++ b/public/admin/tool/uploadcourse/classes/course.php @@ -1150,7 +1150,7 @@ class tool_uploadcourse_course { // Now update values. // Sort out plugin specific fields. - $modifiedinstance = $plugin->update_enrol_plugin_data($course->id, $method, $instance); + $modifiedinstance = $plugin->update_enrol_plugin_data($course->id, $method, clone $instance); $plugin->update_instance($instance, $modifiedinstance); } else { foreach ($errors as $key => $message) { diff --git a/public/admin/tool/uploadcourse/tests/behat/cohorts.feature b/public/admin/tool/uploadcourse/tests/behat/cohorts.feature index 9a3676c6ea6..a1096362328 100644 --- a/public/admin/tool/uploadcourse/tests/behat/cohorts.feature +++ b/public/admin/tool/uploadcourse/tests/behat/cohorts.feature @@ -126,3 +126,19 @@ Feature: An admin can create courses with cohort enrolments using a CSV file And I press "Cancel" And I click on "Edit" "link" in the "Cohort 4" "table_row" And the field "Assign role" matches value "Non-editing teacher" + + @javascript + Scenario: Uploading a cohort enrolment method with a non-default role applies only the specified role + Given the following "users" exist: + | username | firstname | lastname | email | + | t1 | Teacher | 1 | s1@example.com | + And the following "cohort members" exist: + | user | cohort | + | t1 | CV4 | + And I upload "admin/tool/uploadcourse/tests/fixtures/enrolment_cohort_multiple.csv" file to "File" filemanager + And I click on "Preview" "button" + And I click on "Upload courses" "button" + When I am on the "Course 1" "course" page + And I navigate to course participants + Then I should see "Non-editing teacher" in the "Teacher 1" "table_row" + And I should not see "Student" in the "Teacher 1" "table_row" diff --git a/public/enrol/cohort/tests/behat/enrolcohorts.feature b/public/enrol/cohort/tests/behat/enrolcohorts.feature index a59b8a48029..a68c63ca86a 100644 --- a/public/enrol/cohort/tests/behat/enrolcohorts.feature +++ b/public/enrol/cohort/tests/behat/enrolcohorts.feature @@ -110,3 +110,26 @@ Feature: Cohort enrolment management And I set the field "groups[]" to "Beta2 cohort (2)" Then the "members" select box should contain "Bianca McAfee (s3@example.com)" And the "members" select box should contain "Abigail Wyatt (s5@example.com)" + + @javascript + Scenario: Editing a cohort enrolment method's role should change participants' role + Given the following "users" exist: + | username | firstname | lastname | email | + | s1 | Sandra | Cole | s1@example.com | + And the following "cohort members" exist: + | user | cohort | + | s1 | A1 | + When I log in as "teacher001" + And I add "Cohort sync" enrolment method in "Course 001" with: + | Cohort | Alpha1 | + And I should see "Cohort sync (Alpha1 - Student)" + And I navigate to course participants + And I should see "Student" in the "Sandra Cole" "table_row" + And I am on the "Course 001" "enrolment methods" page + And I click on "Edit" "link" in the "Alpha1" "table_row" + And I set the field "Assign role" to "Non-editing teacher" + And I click on "Save" "button" + Then I should see "Cohort sync (Alpha1 - Non-editing teacher)" + And I navigate to course participants + And I should see "Non-editing teacher" in the "Sandra Cole" "table_row" + And I should not see "Student" in the "Sandra Cole" "table_row" diff --git a/public/enrol/editinstance.php b/public/enrol/editinstance.php index 047ab93e933..7623df24c8e 100644 --- a/public/enrol/editinstance.php +++ b/public/enrol/editinstance.php @@ -89,12 +89,6 @@ if ($mform->is_cancelled()) { $reset = ($instance->status != $data->status); } - foreach ($data as $key => $value) { - $instance->$key = $value; - } - - $instance->timemodified = time(); - $plugin->update_instance($instance, $data); if ($reset) {