MDL-63827 qformat_gift: fix notice when importing categories
authorTim Hunt <T.J.Hunt@open.ac.uk>
Wed, 31 Oct 2018 15:00:03 +0000 (15:00 +0000)
committerTim Hunt <T.J.Hunt@open.ac.uk>
Wed, 31 Oct 2018 15:14:51 +0000 (15:14 +0000)
question/format.php
question/format/gift/tests/behat/import_export.feature
question/format/gift/tests/fixtures/questions_in_category.gift.txt [new file with mode: 0644]

index d2261db..2db3d24 100644 (file)
@@ -576,10 +576,10 @@ class qformat_default {
                 // Do nothing unless the child category appears before the parent category
                 // in the imported xml file. Because the parent was created without info being available
                 // at that time, this allows the info to be added from the xml data.
-                if ($key == (count($catnames) - 1) && $lastcategoryinfo && $lastcategoryinfo->info !== null &&
-                        $lastcategoryinfo->info !== "" && $category->info == "") {
+                if ($key == (count($catnames) - 1) && $lastcategoryinfo && isset($lastcategoryinfo->info) &&
+                        $lastcategoryinfo->info !== '' && $category->info === '') {
                     $category->info = $lastcategoryinfo->info;
-                    if ($lastcategoryinfo->infoformat !== null && $lastcategoryinfo->infoformat !== "") {
+                    if (isset($lastcategoryinfo->infoformat) && $lastcategoryinfo->infoformat !== '') {
                         $category->infoformat = $lastcategoryinfo->infoformat;
                     }
                     $DB->update_record('question_categories', $category);
@@ -601,10 +601,10 @@ class qformat_default {
                 $category->name = $catname;
                 $category->info = '';
                 // Only add info (category description) for the final category in the catpath.
-                if ($key == (count($catnames) - 1) && $lastcategoryinfo && $lastcategoryinfo->info !== null &&
-                        $lastcategoryinfo->info !== "") {
+                if ($key == (count($catnames) - 1) && $lastcategoryinfo && isset($lastcategoryinfo->info) &&
+                        $lastcategoryinfo->info !== '') {
                     $category->info = $lastcategoryinfo->info;
-                    if ($lastcategoryinfo->infoformat !== null && $lastcategoryinfo->infoformat !== "") {
+                    if (isset($lastcategoryinfo->infoformat) && $lastcategoryinfo->infoformat !== '') {
                         $category->infoformat = $lastcategoryinfo->infoformat;
                     }
                 }
@@ -703,7 +703,7 @@ class qformat_default {
         $question = new stdClass();
         $question->shuffleanswers = $defaultshuffleanswers;
         $question->defaultmark = 1;
-        $question->image = "";
+        $question->image = '';
         $question->usecase = 0;
         $question->multiplier = array();
         $question->questiontextformat = FORMAT_MOODLE;
@@ -874,7 +874,7 @@ class qformat_default {
 
         // results are first written into string (and then to a file)
         // so create/initialize the string here
-        $expout = "";
+        $expout = '';
 
         // track which category questions are in
         // if it changes we will record the category change in the output
index 42c929b..48f0227 100644 (file)
@@ -34,3 +34,15 @@ Feature: Test importing questions from GIFT format.
     And I set the field "id_format_gift" to "1"
     And I press "Export questions to file"
     And following "click here" should download between "1500" and "1800" bytes
+
+  @javascript @_file_upload
+  Scenario: import a GIFT file which specifies the category
+    When I navigate to "Question bank > Import" in current page administration
+    And I set the field "id_format_gift" to "1"
+    And I upload "question/format/gift/tests/fixtures/questions_in_category.gift.txt" file to "Import" filemanager
+    And I press "id_submitbutton"
+    Then I should see "Parsing questions from import file."
+    And I should see "Importing 4 questions from file"
+    And I should see "Match the activity to the description."
+    When I press "Continue"
+    Then I should see "Moodle activities"
diff --git a/question/format/gift/tests/fixtures/questions_in_category.gift.txt b/question/format/gift/tests/fixtures/questions_in_category.gift.txt
new file mode 100644 (file)
index 0000000..953ae19
--- /dev/null
@@ -0,0 +1,27 @@
+// question: 0  name: switch category to $course$/Default for New Features
+$CATEGORY: $course$/Default for New Features
+
+// question: 44  name: Moodle activities
+::Moodle activities::[html]Match the activity to the description.{
+       =An activity supporting asynchronous discussions. -> Forum
+       =A teacher asks a question and specifies a choice of multiple responses. -> Choice
+       =A bank of record entries which participants can add to. -> Database
+       =A collection of web pages that anyone can add to or edit. -> Wiki
+       = -> Chat
+}
+
+// question: 43  name: Greeting
+::Greeting::[html]<a href\="http\://demo.moodle.net/file.php/5/media/bonjour.mp3">Listen to this greeting\:</a><br /><br />What language is being spoken?{
+       ~English#Sorry, listen again.
+       =French#Yes, well done!
+       ~German#Sorry, listen again.
+       ~Spanish#Sorry, listen again.
+}
+
+// question: 46  name: Moodle user
+::Moodle user::[html]Anyone who uses Moodle is a ...{
+       =%100%Moodler#
+}
+
+// question: 45  name: Moodle acronym
+::Moodle acronym::[html]Moodle is an acronym for <span style\="font-style\: italic;">Modular Object-Oriented Dynamic Learning Environment</span>.{TRUE}