From 1796eb181bed125e2f7b3b5899f13deff3a52162 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Tue, 6 Mar 2018 14:23:34 +0800 Subject: [PATCH] MDL-61410 question: fix unit tests failures --- question/format/xml/format.php | 7 +++---- question/format/xml/tests/xmlformat_test.php | 20 ++++++++++--------- .../type/ddwtos/tests/questiontype_test.php | 2 +- .../gapselect/tests/questiontype_test.php | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/question/format/xml/format.php b/question/format/xml/format.php index 00588623fbfd2..dabec480b66db 100644 --- a/question/format/xml/format.php +++ b/question/format/xml/format.php @@ -1476,12 +1476,11 @@ public function writequestion($question) { // Write the question tags. if (core_tag_tag::is_enabled('core_question', 'question')) { - $tagobjects = core_tag_tag::get_items_tags('core_question', 'question', $question->id); + $tagobjects = core_tag_tag::get_item_tags('core_question', 'question', $question->id); if (!is_null($tagobjects)) { - $tagobjects = $tagobjects[$question->id]; - $categorycontext = context::instance_by_id($this->category->contextid); - $sortedtagobjects = question_sort_tags($tagobjects, $categorycontext); + $context = context::instance_by_id($contextid); + $sortedtagobjects = question_sort_tags($tagobjects, $context, [$this->course]); if (!empty($sortedtagobjects->coursetags)) { // Set them on the form to be rendered as existing tags. diff --git a/question/format/xml/tests/xmlformat_test.php b/question/format/xml/tests/xmlformat_test.php index 8ed027164fba1..5b923a0d48fd1 100644 --- a/question/format/xml/tests/xmlformat_test.php +++ b/question/format/xml/tests/xmlformat_test.php @@ -147,6 +147,7 @@ public function test_xml_escape_code_that_looks_like_cdata_end_ok() { public function test_write_hint_basic() { $q = $this->make_test_question(); + $q->contextid = \context_system::instance()->id; $q->name = 'Short answer question'; $q->questiontext = 'Name an amphibian: __________'; $q->generalfeedback = 'Generalfeedback: frog or toad would have been OK.'; @@ -176,6 +177,7 @@ public function test_write_hint_basic() { public function test_write_hint_with_parts() { $q = $this->make_test_question(); + $q->contextid = \context_system::instance()->id; $q->name = 'Matching question'; $q->questiontext = 'Classify the animals.'; $q->generalfeedback = 'Frogs and toads are amphibians, the others are mammals.'; @@ -329,7 +331,7 @@ public function test_import_description() { public function test_export_description() { $qdata = new stdClass(); $qdata->id = 123; - $qdata->contextid = 0; + $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'description'; $qdata->name = 'A description'; $qdata->questiontext = 'The question text.'; @@ -474,7 +476,7 @@ public function test_import_essay_21() { public function test_export_essay() { $qdata = new stdClass(); $qdata->id = 123; - $qdata->contextid = 0; + $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'essay'; $qdata->name = 'An essay'; $qdata->questiontext = 'Write something.'; @@ -636,7 +638,7 @@ public function test_import_match_19() { public function test_export_match() { $qdata = new stdClass(); $qdata->id = 123; - $qdata->contextid = 0; + $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'match'; $qdata->name = 'Matching question'; $qdata->questiontext = 'Match the upper and lower case letters.'; @@ -867,7 +869,7 @@ public function test_import_multichoice_19() { public function test_export_multichoice() { $qdata = new stdClass(); $qdata->id = 123; - $qdata->contextid = 0; + $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'multichoice'; $qdata->name = 'Multiple choice question'; $qdata->questiontext = 'Which are the even numbers?'; @@ -1040,7 +1042,7 @@ public function test_export_numerical() { $qdata = new stdClass(); $qdata->id = 123; - $qdata->contextid = 0; + $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'numerical'; $qdata->name = 'Numerical question'; $qdata->questiontext = 'What is the answer?'; @@ -1170,7 +1172,7 @@ public function test_import_shortanswer_19() { public function test_export_shortanswer() { $qdata = new stdClass(); $qdata->id = 123; - $qdata->contextid = 0; + $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'shortanswer'; $qdata->name = 'Short answer question'; $qdata->questiontext = 'Fill in the gap in this sequence: Alpha, ________, Gamma.'; @@ -1291,7 +1293,7 @@ public function test_import_truefalse_19() { public function test_export_truefalse() { $qdata = new stdClass(); $qdata->id = 12; - $qdata->contextid = 0; + $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'truefalse'; $qdata->name = 'True false question'; $qdata->questiontext = 'The answer is true.'; @@ -1455,7 +1457,7 @@ public function test_import_multianswer() { public function test_export_multianswer() { $qdata = test_question_maker::get_question_data('multianswer', 'twosubq'); - + $qdata->contextid = \context_system::instance()->id; $exporter = new qformat_xml(); $xml = $exporter->writequestion($qdata); @@ -1486,7 +1488,7 @@ public function test_export_multianswer() { public function test_export_multianswer_withdollars() { $qdata = test_question_maker::get_question_data('multianswer', 'dollarsigns'); - + $qdata->contextid = \context_system::instance()->id; $exporter = new qformat_xml(); $xml = $exporter->writequestion($qdata); diff --git a/question/type/ddwtos/tests/questiontype_test.php b/question/type/ddwtos/tests/questiontype_test.php index 2e8d8ad48650b..747c87f1f968b 100644 --- a/question/type/ddwtos/tests/questiontype_test.php +++ b/question/type/ddwtos/tests/questiontype_test.php @@ -439,7 +439,7 @@ public function test_xml_import_legacy() { public function test_xml_export() { $qdata = new stdClass(); $qdata->id = 123; - $qdata->contextid = 0; + $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'ddwtos'; $qdata->name = 'A drag-and-drop question'; $qdata->questiontext = 'Put these in order: [[1]], [[2]], [[3]].'; diff --git a/question/type/gapselect/tests/questiontype_test.php b/question/type/gapselect/tests/questiontype_test.php index 12a5e0a9c5922..0a85673b8f411 100644 --- a/question/type/gapselect/tests/questiontype_test.php +++ b/question/type/gapselect/tests/questiontype_test.php @@ -242,7 +242,7 @@ public function test_xml_import() { public function test_xml_export() { $qdata = new stdClass(); $qdata->id = 123; - $qdata->contextid = 0; + $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'gapselect'; $qdata->name = 'A select missing words question'; $qdata->questiontext = 'Put these in order: [[1]], [[2]], [[3]].';