* @return object question object
*/
public function import_headers($question) {
- global $CFG, $USER;
+ global $USER;
// This routine initialises the question object.
$qo = $this->defaultquestion();
}
// 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;
}
}
}
+ /**
+ * 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.
}
$this->import_hints($qo, $question, true, false, $this->get_format($qo->questiontextformat));
+ $this->import_question_tags($qo, $question);
return $qo;
}
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');
/**
<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);
$expectedq->defaultmark = 0;
$expectedq->length = 0;
$expectedq->penalty = 0;
+ $expectedq->tags = array('tagDescription', 'tagTest');
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}
<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);
$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);
}
<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);
$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);
}
<shownumcorrect />
<clearwrong />
</hint>
+ <tags>
+ <tag><text>tagMatching</text></tag>
+ <tag><text>tagTest</text></tag>
+ </tags>
</question>';
$xmldata = xmlize($xml);
);
$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);
}
<hint format="html">
<text>Hint 2</text>
</hint>
+ <tags>
+ <tag><text>tagCloze</text></tag>
+ <tag><text>tagTest</text></tag>
+ </tags>
</question>
';
$xmldata = xmlize($xml);
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]);