From 49a9803144939ec3bae18e8dfb602cb06f5746c3 Mon Sep 17 00:00:00 2001 From: Stephan Robotta Date: Fri, 17 May 2024 10:18:05 +0200 Subject: [PATCH] MDL-81952 questions: Fix warning in export of multitype --- question/editlib.php | 3 +- .../multianswer/tests/behat/export.feature | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 question/type/multianswer/tests/behat/export.feature diff --git a/question/editlib.php b/question/editlib.php index 2f196a064e6..c23772426ff 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -99,8 +99,9 @@ function get_questions_category(object $category, bool $noparent, bool $recurse // Iterate through questions, getting stuff we need. $qresults = []; - foreach($questions as $key => $question) { + foreach ($questions as $question) { $question->export_process = $export; + $question->categoryobject = $category; $qtype = question_bank::get_qtype($question->qtype, false); if ($export && $qtype->name() === 'missingtype') { // Unrecognised question type. Skip this question when exporting. diff --git a/question/type/multianswer/tests/behat/export.feature b/question/type/multianswer/tests/behat/export.feature new file mode 100644 index 00000000000..d712b5e4a4c --- /dev/null +++ b/question/type/multianswer/tests/behat/export.feature @@ -0,0 +1,46 @@ +@qtype @qtype_multianswer +Feature: Exporting Multianswer (Cloze) questions + As a teacher + In order to reuse my questions + I need to be able to export a Cloze question or a category containing a Cloze question. + + Background: + Given the following "users" exist: + | username | + | teacher | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher | C1 | editingteacher | + And the following "question categories" exist: + | contextlevel | reference | name | + | Course | C1 | Test questions | + And the following "questions" exist: + | questioncategory | qtype | name | questiontext | + | Test questions | multianswer | TF1 | {1:SHORTANSWER:=Berlin} is the capital of Germany. | + And I am on the "Course 1" "core_question > course question bank" page logged in as "teacher" + + @javascript + Scenario: Edit a previously created multichoice question + When I choose "Edit question" action for "TF1" in the question bank + And I set the following fields to these values: + | Question name | Capital | + | Question text | {1:SHORTANSWER:=Berlin} is the capital of Germany. | + And I press "id_submitbutton" + Then I should see "Capital" + And I should not see "TF1" + + @javascript + Scenario: Export the single multichoice question as XML + When I choose "Export as Moodle XML" action for "TF1" in the question bank + #Next step does not work as a check, however, when the download cannot be triggered, an error should appear and stop the test. + #Then following "Download" should download between "1" and "180000" bytes + + @javascript + Scenario: Export the category containing the multichoice question as XML + When I select "Export" from the "Question bank tertiary navigation" singleselect + And I set the field "Moodle XML format" to "1" + And I click on "Export questions to file" "button" + And I click on "click here" "link"