MDL-52811 course: fix unit tests broken by setforcedlanguage
authorDavo Smith <davo.smith@synergy-learning.com>
Thu, 1 Feb 2018 16:48:14 +0000 (16:48 +0000)
committerDavo Smith <davo.smith@synergy-learning.com>
Thu, 1 Feb 2018 17:07:23 +0000 (17:07 +0000)
admin/tool/uploadcourse/tests/course_test.php
backup/moodle2/restore_stepslib.php
course/tests/externallib_test.php

index 3356163..1d329fd 100644 (file)
@@ -266,6 +266,8 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
         global $DB;
         $this->resetAfterTest(true);
 
+        cron_setup_user(); // To avoid warnings related to 'moodle/course:setforcedlanguage' capability check.
+
         // Create.
         $mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
         $updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
index e0eb1f2..1814dae 100644 (file)
@@ -1895,7 +1895,7 @@ class restore_course_structure_step extends restore_structure_step {
             $data->completionnotify = 0;
         }
         $languages = get_string_manager()->get_list_of_translations(); // Get languages for quick search
-        if (!array_key_exists($data->lang, $languages)) {
+        if (isset($data->lang) && !array_key_exists($data->lang, $languages)) {
             $data->lang = '';
         }
 
index 2b6e4bd..ba36ab0 100644 (file)
@@ -412,6 +412,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
         $contextid = context_system::instance()->id;
         $roleid = $this->assignUserCapability('moodle/course:create', $contextid);
         $this->assignUserCapability('moodle/course:visibility', $contextid, $roleid);
+        $this->assignUserCapability('moodle/course:setforcedlanguage', $contextid, $roleid);
 
         $category  = self::getDataGenerator()->create_category();
 
@@ -1129,6 +1130,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
         $this->assignUserCapability('moodle/course:changesummary', $contextid, $roleid);
         $this->assignUserCapability('moodle/course:visibility', $contextid, $roleid);
         $this->assignUserCapability('moodle/course:viewhiddencourses', $contextid, $roleid);
+        $this->assignUserCapability('moodle/course:setforcedlanguage', $contextid, $roleid);
 
         // Create category and course.
         $category1  = self::getDataGenerator()->create_category();