mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
Merge branch 'MDL-50642' of https://github.com/ecampbell/moodle
This commit is contained in:
commit
30deee105c
@ -198,7 +198,7 @@ class qformat_xml extends qformat_default {
|
||||
* @return object question object
|
||||
*/
|
||||
public function import_headers($question) {
|
||||
global $CFG, $USER;
|
||||
global $USER;
|
||||
|
||||
// This routine initialises the question object.
|
||||
$qo = $this->defaultquestion();
|
||||
@ -255,14 +255,7 @@ class qformat_xml extends qformat_default {
|
||||
}
|
||||
|
||||
// Read the question tags.
|
||||
if (!empty($CFG->usetags) && array_key_exists('tags', $question['#'])
|
||||
&& !empty($question['#']['tags'][0]['#']['tag'])) {
|
||||
require_once($CFG->dirroot.'/tag/lib.php');
|
||||
$qo->tags = array();
|
||||
foreach ($question['#']['tags'][0]['#']['tag'] as $tagdata) {
|
||||
$qo->tags[] = $this->getpath($tagdata, array('#', 'text', 0, '#'), '', true);
|
||||
}
|
||||
}
|
||||
$this->import_question_tags($qo, $question);
|
||||
|
||||
return $qo;
|
||||
}
|
||||
@ -380,6 +373,26 @@ class qformat_xml extends qformat_default {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Import all the question tags
|
||||
*
|
||||
* @param object $qo the question data that is being constructed.
|
||||
* @param array $questionxml The xml representing the question.
|
||||
* @return array of objects representing the tags in the file.
|
||||
*/
|
||||
public function import_question_tags($qo, $questionxml) {
|
||||
global $CFG;
|
||||
|
||||
if (!empty($CFG->usetags) && array_key_exists('tags', $questionxml['#'])
|
||||
&& !empty($questionxml['#']['tags'][0]['#']['tag'])) {
|
||||
require_once($CFG->dirroot.'/tag/lib.php');
|
||||
$qo->tags = array();
|
||||
foreach ($questionxml['#']['tags'][0]['#']['tag'] as $tagdata) {
|
||||
$qo->tags[] = $this->getpath($tagdata, array('#', 'text', 0, '#'), '', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Import files from a node in the XML.
|
||||
* @param array $xml an array of <file> nodes from the the parsed XML.
|
||||
@ -505,6 +518,7 @@ class qformat_xml extends qformat_default {
|
||||
}
|
||||
|
||||
$this->import_hints($qo, $question, true, false, $this->get_format($qo->questiontextformat));
|
||||
$this->import_question_tags($qo, $question);
|
||||
|
||||
return $qo;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ global $CFG;
|
||||
require_once($CFG->libdir . '/questionlib.php');
|
||||
require_once($CFG->dirroot . '/question/format/xml/format.php');
|
||||
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
|
||||
require_once($CFG->dirroot . '/tag/lib.php');
|
||||
|
||||
|
||||
/**
|
||||
@ -302,6 +303,10 @@ END;
|
||||
<defaultgrade>0</defaultgrade>
|
||||
<penalty>0</penalty>
|
||||
<hidden>0</hidden>
|
||||
<tags>
|
||||
<tag><text>tagDescription</text></tag>
|
||||
<tag><text>tagTest</text></tag>
|
||||
</tags>
|
||||
</question>';
|
||||
$xmldata = xmlize($xml);
|
||||
|
||||
@ -317,6 +322,7 @@ END;
|
||||
$expectedq->defaultmark = 0;
|
||||
$expectedq->length = 0;
|
||||
$expectedq->penalty = 0;
|
||||
$expectedq->tags = array('tagDescription', 'tagTest');
|
||||
|
||||
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
|
||||
}
|
||||
@ -373,6 +379,11 @@ END;
|
||||
<defaultgrade>1</defaultgrade>
|
||||
<penalty>0</penalty>
|
||||
<hidden>0</hidden>
|
||||
<tags>
|
||||
<tag><text>tagEssay</text></tag>
|
||||
<tag><text>tagEssay20</text></tag>
|
||||
<tag><text>tagTest</text></tag>
|
||||
</tags>
|
||||
</question>';
|
||||
$xmldata = xmlize($xml);
|
||||
|
||||
@ -397,6 +408,7 @@ END;
|
||||
$expectedq->graderinfo['format'] = FORMAT_MOODLE;
|
||||
$expectedq->responsetemplate['text'] = '';
|
||||
$expectedq->responsetemplate['format'] = FORMAT_MOODLE;
|
||||
$expectedq->tags = array('tagEssay', 'tagEssay20', 'tagTest');
|
||||
|
||||
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
|
||||
}
|
||||
@ -426,6 +438,11 @@ END;
|
||||
<responsetemplate format="html">
|
||||
<text><![CDATA[<p>Here is something <b>really</b> interesting.</p>]]></text>
|
||||
</responsetemplate>
|
||||
<tags>
|
||||
<tag><text>tagEssay</text></tag>
|
||||
<tag><text>tagEssay21</text></tag>
|
||||
<tag><text>tagTest</text></tag>
|
||||
</tags>
|
||||
</question>';
|
||||
$xmldata = xmlize($xml);
|
||||
|
||||
@ -450,6 +467,7 @@ END;
|
||||
$expectedq->graderinfo['format'] = FORMAT_HTML;
|
||||
$expectedq->responsetemplate['text'] = '<p>Here is something <b>really</b> interesting.</p>';
|
||||
$expectedq->responsetemplate['format'] = FORMAT_HTML;
|
||||
$expectedq->tags = array('tagEssay', 'tagEssay21', 'tagTest');
|
||||
|
||||
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
|
||||
}
|
||||
@ -571,6 +589,10 @@ END;
|
||||
<shownumcorrect />
|
||||
<clearwrong />
|
||||
</hint>
|
||||
<tags>
|
||||
<tag><text>tagMatching</text></tag>
|
||||
<tag><text>tagTest</text></tag>
|
||||
</tags>
|
||||
</question>';
|
||||
$xmldata = xmlize($xml);
|
||||
|
||||
@ -607,6 +629,7 @@ END;
|
||||
);
|
||||
$expectedq->hintshownumcorrect = array(true, true);
|
||||
$expectedq->hintclearwrong = array(false, true);
|
||||
$expectedq->tags = array('tagMatching', 'tagTest');
|
||||
|
||||
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
|
||||
}
|
||||
@ -1343,6 +1366,10 @@ END;
|
||||
<hint format="html">
|
||||
<text>Hint 2</text>
|
||||
</hint>
|
||||
<tags>
|
||||
<tag><text>tagCloze</text></tag>
|
||||
<tag><text>tagTest</text></tag>
|
||||
</tags>
|
||||
</question>
|
||||
';
|
||||
$xmldata = xmlize($xml);
|
||||
@ -1419,6 +1446,7 @@ END;
|
||||
1 => $sa,
|
||||
2 => $mc,
|
||||
);
|
||||
$expectedqa->tags = array('tagCloze', 'tagTest');
|
||||
|
||||
$this->assertEquals($expectedqa->hint, $q->hint);
|
||||
$this->assertEquals($expectedqa->options->questions[1], $q->options->questions[1]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user