Skip to content

Commit

Permalink
MDL-61410 question: fix unit tests failures
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Mar 19, 2018
1 parent 1359686 commit 1796eb1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
7 changes: 3 additions & 4 deletions question/format/xml/format.php
Expand Up @@ -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.
Expand Down
20 changes: 11 additions & 9 deletions question/format/xml/tests/xmlformat_test.php
Expand Up @@ -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.';
Expand Down Expand Up @@ -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.';
Expand Down Expand Up @@ -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.';
Expand Down Expand Up @@ -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.';
Expand Down Expand Up @@ -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.';
Expand Down Expand Up @@ -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?';
Expand Down Expand Up @@ -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?';
Expand Down Expand Up @@ -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.';
Expand Down Expand Up @@ -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.';
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion question/type/ddwtos/tests/questiontype_test.php
Expand Up @@ -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]].';
Expand Down
2 changes: 1 addition & 1 deletion question/type/gapselect/tests/questiontype_test.php
Expand Up @@ -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]].';
Expand Down

0 comments on commit 1796eb1

Please sign in to comment.