diff --git a/mod/lti/backup/moodle2/restore_lti_stepslib.php b/mod/lti/backup/moodle2/restore_lti_stepslib.php index cfed5c9c4bd..90b4edb4d22 100644 --- a/mod/lti/backup/moodle2/restore_lti_stepslib.php +++ b/mod/lti/backup/moodle2/restore_lti_stepslib.php @@ -117,14 +117,16 @@ class restore_lti_activity_structure_step extends restore_activity_structure_ste if ($this->task->is_samesite() && $ltitype->course != SITEID && $ltitype->state == LTI_TOOL_STATE_CONFIGURED) { // If restoring into the same course, use existing data, else re-create. - $course = $this->get_courseid(); - if ($ltitype->course != $course) { - $data->course = $course; + $courseid = $this->get_courseid(); + if ($ltitype->course != $courseid) { + // Override course field of restore data with current courseid. + $data->course = $courseid; $ltitype = new stdClass(); $ltitype->id = $DB->insert_record('lti_types', $data); } } else if (!$this->task->is_samesite() || !isset($ltitype->id)) { // Either we are restoring into a new site, or didn't find a database match. + // Override course field of restore data with current courseid. $data->course = $this->get_courseid(); $ltitype = new stdClass(); $ltitype->id = $DB->insert_record('lti_types', $data); diff --git a/mod/lti/tests/behat/config_test.feature b/mod/lti/tests/behat/config_test.feature new file mode 100644 index 00000000000..32c6245b130 --- /dev/null +++ b/mod/lti/tests/behat/config_test.feature @@ -0,0 +1,35 @@ +@mod @mod_lti @core_backup @javascript +Feature: Restoring Moodle 2 backup restores LTI configuration + + Background: + Given the following "courses" exist: + | fullname | shortname | category | idnumber | + | Course 1 | C1 | 0 | C1 | + And I log in as "admin" + + Scenario: Backup and restore course 1 + Given I navigate to "Manage external tool types" node in "Site administration > Plugins > Activity modules > LTI" + And I follow "Add external tool configuration" + And I set the following fields to these values: + | Tool name | Site Netspot Tool | + | Tool base URL | http://www.netspot.com.au | + | lti_coursevisible | 1 | + And I press "Save changes" + And I wait to be redirected + Given I am on site homepage + Then I follow "Course 1" + Then I turn editing mode on + And I add a "External tool" to section "1" and I fill the form with: + | Activity name | Site Netspot Tool | + | External tool type | Site Netspot Tool | + | Launch container | Embed | + And I follow "Course 1" + Then I should see "Site Netspot Tool" + Then I backup "Course 1" course using this options: + | Confirmation | Filename | test_backup.mbz | + And I restore "test_backup.mbz" backup into a new course using this options: + Then I am on site homepage + And I follow "Course 1 copy 1" + And I open "Site Netspot Tool" actions menu + And I click on "Edit settings" "link" in the "Site Netspot Tool" activity + Then the field "External tool type" matches value "Site Netspot Tool" \ No newline at end of file