mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Merge branch 'MDL-50642' of https://github.com/ecampbell/moodle
This commit is contained in:
commit
30deee105c
2 changed files with 51 additions and 9 deletions
|
@ -198,7 +198,7 @@ class qformat_xml extends qformat_default {
|
||||||
* @return object question object
|
* @return object question object
|
||||||
*/
|
*/
|
||||||
public function import_headers($question) {
|
public function import_headers($question) {
|
||||||
global $CFG, $USER;
|
global $USER;
|
||||||
|
|
||||||
// This routine initialises the question object.
|
// This routine initialises the question object.
|
||||||
$qo = $this->defaultquestion();
|
$qo = $this->defaultquestion();
|
||||||
|
@ -255,14 +255,7 @@ class qformat_xml extends qformat_default {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the question tags.
|
// Read the question tags.
|
||||||
if (!empty($CFG->usetags) && array_key_exists('tags', $question['#'])
|
$this->import_question_tags($qo, $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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $qo;
|
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.
|
* Import files from a node in the XML.
|
||||||
* @param array $xml an array of <file> nodes from the the parsed 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_hints($qo, $question, true, false, $this->get_format($qo->questiontextformat));
|
||||||
|
$this->import_question_tags($qo, $question);
|
||||||
|
|
||||||
return $qo;
|
return $qo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ global $CFG;
|
||||||
require_once($CFG->libdir . '/questionlib.php');
|
require_once($CFG->libdir . '/questionlib.php');
|
||||||
require_once($CFG->dirroot . '/question/format/xml/format.php');
|
require_once($CFG->dirroot . '/question/format/xml/format.php');
|
||||||
require_once($CFG->dirroot . '/question/engine/tests/helpers.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>
|
<defaultgrade>0</defaultgrade>
|
||||||
<penalty>0</penalty>
|
<penalty>0</penalty>
|
||||||
<hidden>0</hidden>
|
<hidden>0</hidden>
|
||||||
|
<tags>
|
||||||
|
<tag><text>tagDescription</text></tag>
|
||||||
|
<tag><text>tagTest</text></tag>
|
||||||
|
</tags>
|
||||||
</question>';
|
</question>';
|
||||||
$xmldata = xmlize($xml);
|
$xmldata = xmlize($xml);
|
||||||
|
|
||||||
|
@ -317,6 +322,7 @@ END;
|
||||||
$expectedq->defaultmark = 0;
|
$expectedq->defaultmark = 0;
|
||||||
$expectedq->length = 0;
|
$expectedq->length = 0;
|
||||||
$expectedq->penalty = 0;
|
$expectedq->penalty = 0;
|
||||||
|
$expectedq->tags = array('tagDescription', 'tagTest');
|
||||||
|
|
||||||
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
|
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
|
||||||
}
|
}
|
||||||
|
@ -373,6 +379,11 @@ END;
|
||||||
<defaultgrade>1</defaultgrade>
|
<defaultgrade>1</defaultgrade>
|
||||||
<penalty>0</penalty>
|
<penalty>0</penalty>
|
||||||
<hidden>0</hidden>
|
<hidden>0</hidden>
|
||||||
|
<tags>
|
||||||
|
<tag><text>tagEssay</text></tag>
|
||||||
|
<tag><text>tagEssay20</text></tag>
|
||||||
|
<tag><text>tagTest</text></tag>
|
||||||
|
</tags>
|
||||||
</question>';
|
</question>';
|
||||||
$xmldata = xmlize($xml);
|
$xmldata = xmlize($xml);
|
||||||
|
|
||||||
|
@ -397,6 +408,7 @@ END;
|
||||||
$expectedq->graderinfo['format'] = FORMAT_MOODLE;
|
$expectedq->graderinfo['format'] = FORMAT_MOODLE;
|
||||||
$expectedq->responsetemplate['text'] = '';
|
$expectedq->responsetemplate['text'] = '';
|
||||||
$expectedq->responsetemplate['format'] = FORMAT_MOODLE;
|
$expectedq->responsetemplate['format'] = FORMAT_MOODLE;
|
||||||
|
$expectedq->tags = array('tagEssay', 'tagEssay20', 'tagTest');
|
||||||
|
|
||||||
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
|
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
|
||||||
}
|
}
|
||||||
|
@ -426,6 +438,11 @@ END;
|
||||||
<responsetemplate format="html">
|
<responsetemplate format="html">
|
||||||
<text><![CDATA[<p>Here is something <b>really</b> interesting.</p>]]></text>
|
<text><![CDATA[<p>Here is something <b>really</b> interesting.</p>]]></text>
|
||||||
</responsetemplate>
|
</responsetemplate>
|
||||||
|
<tags>
|
||||||
|
<tag><text>tagEssay</text></tag>
|
||||||
|
<tag><text>tagEssay21</text></tag>
|
||||||
|
<tag><text>tagTest</text></tag>
|
||||||
|
</tags>
|
||||||
</question>';
|
</question>';
|
||||||
$xmldata = xmlize($xml);
|
$xmldata = xmlize($xml);
|
||||||
|
|
||||||
|
@ -450,6 +467,7 @@ END;
|
||||||
$expectedq->graderinfo['format'] = FORMAT_HTML;
|
$expectedq->graderinfo['format'] = FORMAT_HTML;
|
||||||
$expectedq->responsetemplate['text'] = '<p>Here is something <b>really</b> interesting.</p>';
|
$expectedq->responsetemplate['text'] = '<p>Here is something <b>really</b> interesting.</p>';
|
||||||
$expectedq->responsetemplate['format'] = FORMAT_HTML;
|
$expectedq->responsetemplate['format'] = FORMAT_HTML;
|
||||||
|
$expectedq->tags = array('tagEssay', 'tagEssay21', 'tagTest');
|
||||||
|
|
||||||
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
|
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
|
||||||
}
|
}
|
||||||
|
@ -571,6 +589,10 @@ END;
|
||||||
<shownumcorrect />
|
<shownumcorrect />
|
||||||
<clearwrong />
|
<clearwrong />
|
||||||
</hint>
|
</hint>
|
||||||
|
<tags>
|
||||||
|
<tag><text>tagMatching</text></tag>
|
||||||
|
<tag><text>tagTest</text></tag>
|
||||||
|
</tags>
|
||||||
</question>';
|
</question>';
|
||||||
$xmldata = xmlize($xml);
|
$xmldata = xmlize($xml);
|
||||||
|
|
||||||
|
@ -607,6 +629,7 @@ END;
|
||||||
);
|
);
|
||||||
$expectedq->hintshownumcorrect = array(true, true);
|
$expectedq->hintshownumcorrect = array(true, true);
|
||||||
$expectedq->hintclearwrong = array(false, true);
|
$expectedq->hintclearwrong = array(false, true);
|
||||||
|
$expectedq->tags = array('tagMatching', 'tagTest');
|
||||||
|
|
||||||
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
|
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
|
||||||
}
|
}
|
||||||
|
@ -1343,6 +1366,10 @@ END;
|
||||||
<hint format="html">
|
<hint format="html">
|
||||||
<text>Hint 2</text>
|
<text>Hint 2</text>
|
||||||
</hint>
|
</hint>
|
||||||
|
<tags>
|
||||||
|
<tag><text>tagCloze</text></tag>
|
||||||
|
<tag><text>tagTest</text></tag>
|
||||||
|
</tags>
|
||||||
</question>
|
</question>
|
||||||
';
|
';
|
||||||
$xmldata = xmlize($xml);
|
$xmldata = xmlize($xml);
|
||||||
|
@ -1419,6 +1446,7 @@ END;
|
||||||
1 => $sa,
|
1 => $sa,
|
||||||
2 => $mc,
|
2 => $mc,
|
||||||
);
|
);
|
||||||
|
$expectedqa->tags = array('tagCloze', 'tagTest');
|
||||||
|
|
||||||
$this->assertEquals($expectedqa->hint, $q->hint);
|
$this->assertEquals($expectedqa->hint, $q->hint);
|
||||||
$this->assertEquals($expectedqa->options->questions[1], $q->options->questions[1]);
|
$this->assertEquals($expectedqa->options->questions[1], $q->options->questions[1]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue