diff --git a/question/format.php b/question/format.php index d2261db7c29..2db3d24cb59 100644 --- a/question/format.php +++ b/question/format.php @@ -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 diff --git a/question/format/gift/tests/behat/import_export.feature b/question/format/gift/tests/behat/import_export.feature index 42c929bb7da..48f0227321f 100644 --- a/question/format/gift/tests/behat/import_export.feature +++ b/question/format/gift/tests/behat/import_export.feature @@ -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 index 00000000000..953ae19c64d --- /dev/null +++ b/question/format/gift/tests/fixtures/questions_in_category.gift.txt @@ -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]Listen to this greeting\:

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 Modular Object-Oriented Dynamic Learning Environment.{TRUE}