MDL-29739 question import used a bad default for text formats.
The new logic is that the questiontext defaults to HTML if the format is not specified, then all other fields default to the same format of the question text. However, good practice is that the XML file should specify the format for each bit of text content. This code is not 100% backwards-compatible, since some methods have new arguments, however for question types that have not been updated, it will just generate a PHP Warning, which is, I think, and OK way to let qtype developers know that they need to update their question types.
This commit is contained in:
@@ -81,7 +81,8 @@ class qformat_xml extends qformat_default {
|
||||
} else if ($name == 'markdown') {
|
||||
return FORMAT_MARKDOWN;
|
||||
} else {
|
||||
return 0; // or maybe warning required
|
||||
debugging("Unrecognised text format '{$name}' in the import file. Assuming 'html'.");
|
||||
return FORMAT_HTML;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +172,7 @@ class qformat_xml extends qformat_default {
|
||||
$qo->questiontext = $this->getpath($question,
|
||||
array('#', 'questiontext', 0, '#', 'text', 0, '#'), '', true);
|
||||
$qo->questiontextformat = $this->trans_format($this->getpath(
|
||||
$question, array('#', 'questiontext', 0, '@', 'format'), ''));
|
||||
$question, array('#', 'questiontext', 0, '@', 'format'), 'html'));
|
||||
|
||||
$qo->questiontextfiles = $this->import_files($this->getpath($question,
|
||||
array('#', 'questiontext', 0, '#', 'file'), array(), false));
|
||||
@@ -193,7 +194,7 @@ class qformat_xml extends qformat_default {
|
||||
array('#', 'generalfeedback', 0, '#', 'text', 0, '#'), $qo->generalfeedback, true);
|
||||
$qo->generalfeedbackfiles = array();
|
||||
$qo->generalfeedbackformat = $this->trans_format($this->getpath($question,
|
||||
array('#', 'generalfeedback', 0, '@', 'format'), 'moodle_auto_format'));
|
||||
array('#', 'generalfeedback', 0, '@', 'format'), $this->get_format($qo->questiontextformat)));
|
||||
$qo->generalfeedbackfiles = $this->import_files($this->getpath($question,
|
||||
array('#', 'generalfeedback', 0, '#', 'file'), array(), false));
|
||||
|
||||
@@ -223,25 +224,31 @@ class qformat_xml extends qformat_default {
|
||||
/**
|
||||
* Import the common parts of a single answer
|
||||
* @param array answer xml tree for single answer
|
||||
* @param bool $withanswerfiles if true, the answers are HTML (or $defaultformat)
|
||||
* and so may contain files, otherwise the answers are plain text.
|
||||
* @param array Default text format for the feedback, and the answers if $withanswerfiles
|
||||
* is true.
|
||||
* @return object answer object
|
||||
*/
|
||||
public function import_answer($answer, $withanswerfiles = false) {
|
||||
public function import_answer($answer, $withanswerfiles = false, $defaultformat = 'html') {
|
||||
$ans = new stdClass();
|
||||
|
||||
$ans->answer = array();
|
||||
$ans->answer['text'] = $this->getpath($answer, array('#', 'text', 0, '#'), '', true);
|
||||
$ans->answer['format'] = $this->trans_format($this->getpath($answer,
|
||||
array('@', 'format'), 'moodle_auto_format'));
|
||||
array('@', 'format'), $defaultformat));
|
||||
if ($withanswerfiles) {
|
||||
$ans->answer['files'] = $this->import_files($this->getpath($answer,
|
||||
array('#', 'file'), array()));
|
||||
} else {
|
||||
$ans->answer['format'] = FORMAT_PLAIN;
|
||||
}
|
||||
|
||||
$ans->feedback = array();
|
||||
$ans->feedback['text'] = $this->getpath($answer,
|
||||
array('#', 'feedback', 0, '#', 'text', 0, '#'), '', true);
|
||||
$ans->feedback['format'] = $this->trans_format($this->getpath($answer,
|
||||
array('#', 'feedback', 0, '@', 'format'), 'moodle_auto_format'));
|
||||
array('#', 'feedback', 0, '@', 'format'), $defaultformat));
|
||||
$ans->feedback['files'] = $this->import_files($this->getpath($answer,
|
||||
array('#', 'feedback', 0, '#', 'file'), array()));
|
||||
|
||||
@@ -263,7 +270,7 @@ class qformat_xml extends qformat_default {
|
||||
$text['text'] = $this->getpath($questionxml,
|
||||
array('#', $field, 0, '#', 'text', 0, '#'), '', true);
|
||||
$text['format'] = $this->trans_format($this->getpath($questionxml,
|
||||
array('#', $field, 0, '@', 'format'), 'moodle_auto_format'));
|
||||
array('#', $field, 0, '@', 'format'), $this->get_format($qo->questiontextformat)));
|
||||
$text['files'] = $this->import_files($this->getpath($questionxml,
|
||||
array('#', $field, 0, '#', 'file'), array(), false));
|
||||
|
||||
@@ -284,9 +291,10 @@ class qformat_xml extends qformat_default {
|
||||
/**
|
||||
* Import a question hint
|
||||
* @param array $hintxml hint xml fragment.
|
||||
* @param string $defaultformat the text format to assume for hints that do not specify.
|
||||
* @return object hint for storing in the database.
|
||||
*/
|
||||
public function import_hint($hintxml) {
|
||||
public function import_hint($hintxml, $defaultformat) {
|
||||
if (array_key_exists('hintcontent', $hintxml['#'])) {
|
||||
// Backwards compatibility:
|
||||
|
||||
@@ -294,6 +302,8 @@ class qformat_xml extends qformat_default {
|
||||
$hint->hint = array('format' => FORMAT_HTML, 'files' => array());
|
||||
$hint->hint['text'] = $this->getpath($hintxml,
|
||||
array('#', 'hintcontent', 0, '#', 'text', 0, '#'), '', true);
|
||||
$hint->hint['format'] = $this->trans_format($defaultformat);
|
||||
$hint->hint['files'] = array();
|
||||
$hint->shownumcorrect = $this->getpath($hintxml,
|
||||
array('#', 'statenumberofcorrectresponses', 0, '#'), 0);
|
||||
$hint->clearwrong = $this->getpath($hintxml,
|
||||
@@ -308,7 +318,7 @@ class qformat_xml extends qformat_default {
|
||||
$hint->hint['text'] = $this->getpath($hintxml,
|
||||
array('#', 'text', 0, '#'), '', true);
|
||||
$hint->hint['format'] = $this->trans_format($this->getpath($hintxml,
|
||||
array('@', 'format'), 'moodle_auto_format'));
|
||||
array('@', 'format'), $defaultformat));
|
||||
$hint->hint['files'] = $this->import_files($this->getpath($hintxml,
|
||||
array('#', 'file'), array(), false));
|
||||
$hint->shownumcorrect = array_key_exists('shownumcorrect', $hintxml['#']);
|
||||
@@ -322,15 +332,20 @@ class qformat_xml extends qformat_default {
|
||||
* Import all the question hints
|
||||
*
|
||||
* @param object $qo the question data that is being constructed.
|
||||
* @param array $hintsxml hints xml fragment.
|
||||
* @param array $questionxml The xml representing the question.
|
||||
* @param bool $withparts whether the extra fields relating to parts should be imported.
|
||||
* @param bool $withoptions whether the extra options field should be imported.
|
||||
* @param string $defaultformat the text format to assume for hints that do not specify.
|
||||
* @return array of objects representing the hints in the file.
|
||||
*/
|
||||
public function import_hints($qo, $questionxml, $withparts = false, $withoptions = false) {
|
||||
public function import_hints($qo, $questionxml, $withparts = false,
|
||||
$withoptions = false, $defaultformat = 'html') {
|
||||
if (!isset($questionxml['#']['hint'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($questionxml['#']['hint'] as $hintxml) {
|
||||
$hint = $this->import_hint($hintxml);
|
||||
$hint = $this->import_hint($hintxml, $defaultformat);
|
||||
$qo->hint[] = $hint->hint;
|
||||
|
||||
if ($withparts) {
|
||||
@@ -390,7 +405,7 @@ class qformat_xml extends qformat_default {
|
||||
$answers = $question['#']['answer'];
|
||||
$acount = 0;
|
||||
foreach ($answers as $answer) {
|
||||
$ans = $this->import_answer($answer, true);
|
||||
$ans = $this->import_answer($answer, true, $this->get_format($qo->questiontextformat));
|
||||
$qo->answer[$acount] = $ans->answer;
|
||||
$qo->fraction[$acount] = $ans->fraction;
|
||||
$qo->feedback[$acount] = $ans->feedback;
|
||||
@@ -398,7 +413,7 @@ class qformat_xml extends qformat_default {
|
||||
}
|
||||
|
||||
$this->import_combined_feedback($qo, $question, true);
|
||||
$this->import_hints($qo, $question, true);
|
||||
$this->import_hints($qo, $question, true, false, $this->get_format($qo->questiontextformat));
|
||||
|
||||
return $qo;
|
||||
}
|
||||
@@ -412,7 +427,7 @@ class qformat_xml extends qformat_default {
|
||||
question_bank::get_qtype('multianswer');
|
||||
|
||||
$questiontext['text'] = $this->import_text($question['#']['questiontext'][0]['#']['text']);
|
||||
$questiontext['format'] = '1';
|
||||
$questiontext['format'] = FORMAT_HTML;
|
||||
$questiontext['itemid'] = '';
|
||||
$qo = qtype_multianswer_extract_question($questiontext);
|
||||
|
||||
@@ -420,18 +435,20 @@ class qformat_xml extends qformat_default {
|
||||
$qo->qtype = 'multianswer';
|
||||
$qo->course = $this->course;
|
||||
$qo->generalfeedback = '';
|
||||
|
||||
$qo->name = $this->import_text($question['#']['name'][0]['#']['text']);
|
||||
$qo->questiontextformat = $questiontext['format'];
|
||||
$qo->questiontext = $qo->questiontext['text'];
|
||||
$qo->questiontextfiles = array();
|
||||
|
||||
// restore files in generalfeedback
|
||||
$qo->generalfeedback = $this->getpath($question,
|
||||
array('#', 'generalfeedback', 0, '#', 'text', 0, '#'), $qo->generalfeedback, true);
|
||||
$qo->generalfeedbackformat = $this->trans_format($this->getpath($question,
|
||||
array('#', 'generalfeedback', 0, '@', 'format'), 'moodle_auto_format'));
|
||||
array('#', 'generalfeedback', 0, '@', 'format'), $this->get_format($qo->questiontextformat)));
|
||||
$qo->generalfeedbackfiles = $this->import_files($this->getpath($question,
|
||||
array('#', 'generalfeedback', 0, '#', 'file'), array(), false));
|
||||
|
||||
$qo->name = $this->import_text($question['#']['name'][0]['#']['text']);
|
||||
$qo->questiontext = $qo->questiontext['text'];
|
||||
$qo->questiontextformat = '';
|
||||
|
||||
$qo->penalty = $this->getpath($question,
|
||||
array('#', 'penalty', 0, '#'), $this->defaultquestion()->penalty);
|
||||
// Fix problematic rounding from old files:
|
||||
@@ -439,7 +456,7 @@ class qformat_xml extends qformat_default {
|
||||
$qo->penalty = 0.3333333;
|
||||
}
|
||||
|
||||
$this->import_hints($qo, $question);
|
||||
$this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat));
|
||||
|
||||
return $qo;
|
||||
}
|
||||
@@ -469,7 +486,7 @@ class qformat_xml extends qformat_default {
|
||||
$feedback = $this->getpath($answer,
|
||||
array('#', 'feedback', 0, '#', 'text', 0, '#'), '', true);
|
||||
$feedbackformat = $this->getpath($answer,
|
||||
array('#', 'feedback', 0, '@', 'format'), 'moodle_auto_format');
|
||||
array('#', 'feedback', 0, '@', 'format'), $this->get_format($qo->questiontextformat));
|
||||
$feedbackfiles = $this->getpath($answer,
|
||||
array('#', 'feedback', 0, '#', 'file'), array());
|
||||
$files = array();
|
||||
@@ -515,7 +532,7 @@ class qformat_xml extends qformat_default {
|
||||
echo $OUTPUT->notification(get_string('truefalseimporterror', 'qformat_xml', $a));
|
||||
}
|
||||
|
||||
$this->import_hints($qo, $question);
|
||||
$this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat));
|
||||
|
||||
return $qo;
|
||||
}
|
||||
@@ -539,14 +556,14 @@ class qformat_xml extends qformat_default {
|
||||
$answers = $question['#']['answer'];
|
||||
$acount = 0;
|
||||
foreach ($answers as $answer) {
|
||||
$ans = $this->import_answer($answer);
|
||||
$ans = $this->import_answer($answer, false, $this->get_format($qo->questiontextformat));
|
||||
$qo->answer[$acount] = $ans->answer['text'];
|
||||
$qo->fraction[$acount] = $ans->fraction;
|
||||
$qo->feedback[$acount] = $ans->feedback;
|
||||
++$acount;
|
||||
}
|
||||
|
||||
$this->import_hints($qo, $question);
|
||||
$this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat));
|
||||
|
||||
return $qo;
|
||||
}
|
||||
@@ -586,7 +603,7 @@ class qformat_xml extends qformat_default {
|
||||
$qo->tolerance = array();
|
||||
foreach ($answers as $answer) {
|
||||
// answer outside of <text> is deprecated
|
||||
$obj = $this->import_answer($answer);
|
||||
$obj = $this->import_answer($answer, false, $this->get_format($qo->questiontextformat));
|
||||
$qo->answer[] = $obj->answer['text'];
|
||||
if (empty($qo->answer)) {
|
||||
$qo->answer = '*';
|
||||
@@ -622,12 +639,12 @@ class qformat_xml extends qformat_default {
|
||||
$qo->instructions['text'] = $this->getpath($instructions,
|
||||
array('0', '#', 'text', '0', '#'), '', true);
|
||||
$qo->instructions['format'] = $this->trans_format($this->getpath($instructions,
|
||||
array('0', '@', 'format'), 'moodle_auto_format'));
|
||||
array('0', '@', 'format'), $this->get_format($qo->questiontextformat)));
|
||||
$qo->instructions['files'] = $this->import_files($this->getpath(
|
||||
$instructions, array('0', '#', 'file'), array()));
|
||||
}
|
||||
|
||||
$this->import_hints($qo, $question);
|
||||
$this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat));
|
||||
|
||||
return $qo;
|
||||
}
|
||||
@@ -653,7 +670,7 @@ class qformat_xml extends qformat_default {
|
||||
$subquestion = array();
|
||||
$subquestion['text'] = $this->getpath($subqxml, array('#', 'text', 0, '#'), '', true);
|
||||
$subquestion['format'] = $this->trans_format($this->getpath($subqxml,
|
||||
array('@', 'format'), 'moodle_auto_format'));
|
||||
array('@', 'format'), $this->get_format($qo->questiontextformat)));
|
||||
$subquestion['files'] = $this->import_files($this->getpath($subqxml,
|
||||
array('#', 'file'), array()));
|
||||
|
||||
@@ -664,7 +681,7 @@ class qformat_xml extends qformat_default {
|
||||
}
|
||||
|
||||
$this->import_combined_feedback($qo, $question, true);
|
||||
$this->import_hints($qo, $question, true);
|
||||
$this->import_hints($qo, $question, true, false, $this->get_format($qo->questiontextformat));
|
||||
|
||||
return $qo;
|
||||
}
|
||||
@@ -690,7 +707,7 @@ class qformat_xml extends qformat_default {
|
||||
$qo->graderinfo['text'] = $this->getpath($question,
|
||||
array('#', 'graderinfo', 0, '#', 'text', 0, '#'), '', true);
|
||||
$qo->graderinfo['format'] = $this->trans_format($this->getpath($question,
|
||||
array('#', 'graderinfo', 0, '@', 'format'), 'moodle_auto_format'));
|
||||
array('#', 'graderinfo', 0, '@', 'format'), $this->get_format($qo->questiontextformat)));
|
||||
$qo->graderinfo['files'] = $this->import_files($this->getpath($question,
|
||||
array('#', 'graderinfo', '0', '#', 'file'), array()));
|
||||
|
||||
@@ -716,30 +733,7 @@ class qformat_xml extends qformat_default {
|
||||
array('#', 'answernumbering', 0, '#'), 'abc');
|
||||
$qo->shuffleanswers = $this->trans_single($shuffleanswers);
|
||||
|
||||
$qo->correctfeedback = array();
|
||||
$qo->correctfeedback['text'] = $this->getpath(
|
||||
$question, array('#', 'correctfeedback', 0, '#', 'text', 0, '#'), '', true);
|
||||
$qo->correctfeedback['format'] = $this->trans_format($this->getpath(
|
||||
$question, array('#', 'correctfeedback', 0, '@', 'format'), 'moodle_auto_format'));
|
||||
$qo->correctfeedback['files'] = $this->import_files($this->getpath(
|
||||
$question, array('#', 'correctfeedback', '0', '#', 'file'), array()));
|
||||
|
||||
$qo->partiallycorrectfeedback = array();
|
||||
$qo->partiallycorrectfeedback['text'] = $this->getpath($question,
|
||||
array('#', 'partiallycorrectfeedback', 0, '#', 'text', 0, '#'), '', true);
|
||||
$qo->partiallycorrectfeedback['format'] = $this->trans_format(
|
||||
$this->getpath($question, array('#', 'partiallycorrectfeedback', 0, '@', 'format'),
|
||||
'moodle_auto_format'));
|
||||
$qo->partiallycorrectfeedback['files'] = $this->import_files($this->getpath(
|
||||
$question, array('#', 'partiallycorrectfeedback', '0', '#', 'file'), array()));
|
||||
|
||||
$qo->incorrectfeedback = array();
|
||||
$qo->incorrectfeedback['text'] = $this->getpath($question,
|
||||
array('#', 'incorrectfeedback', 0, '#', 'text', 0, '#'), '', true);
|
||||
$qo->incorrectfeedback['format'] = $this->trans_format($this->getpath($question,
|
||||
array('#', 'incorrectfeedback', 0, '@', 'format'), 'moodle_auto_format'));
|
||||
$qo->incorrectfeedback['files'] = $this->import_files($this->getpath($question,
|
||||
array('#', 'incorrectfeedback', '0', '#', 'file'), array()));
|
||||
$this->import_combined_feedback($qo, $question);
|
||||
|
||||
$qo->unitgradingtype = $this->getpath($question,
|
||||
array('#', 'unitgradingtype', 0, '#'), 0);
|
||||
@@ -753,7 +747,7 @@ class qformat_xml extends qformat_default {
|
||||
$qo->instructions['text'] = $this->getpath($instructions,
|
||||
array('0', '#', 'text', '0', '#'), '', true);
|
||||
$qo->instructions['format'] = $this->trans_format($this->getpath($instructions,
|
||||
array('0', '@', 'format'), 'moodle_auto_format'));
|
||||
array('0', '@', 'format'), $this->get_format($qo->questiontextformat)));
|
||||
$qo->instructions['files'] = $this->import_files($this->getpath($instructions,
|
||||
array('0', '#', 'file'), array()));
|
||||
}
|
||||
@@ -769,7 +763,7 @@ class qformat_xml extends qformat_default {
|
||||
$qo->correctanswerlength = array();
|
||||
$qo->feedback = array();
|
||||
foreach ($answers as $answer) {
|
||||
$ans = $this->import_answer($answer, true);
|
||||
$ans = $this->import_answer($answer, true, $this->get_format($qo->questiontextformat));
|
||||
// answer outside of <text> is deprecated
|
||||
if (empty($ans->answer['text'])) {
|
||||
$ans->answer['text'] = '*';
|
||||
@@ -803,7 +797,7 @@ class qformat_xml extends qformat_default {
|
||||
$qo->instructions['text'] = $this->getpath($instructions,
|
||||
array('0', '#', 'text', '0', '#'), '', true);
|
||||
$qo->instructions['format'] = $this->trans_format($this->getpath($instructions,
|
||||
array('0', '@', 'format'), 'moodle_auto_format'));
|
||||
array('0', '@', 'format'), $this->get_format($qo->questiontextformat)));
|
||||
$qo->instructions['files'] = $this->import_files($this->getpath($instructions,
|
||||
array('0', '#', 'file'), array()));
|
||||
}
|
||||
@@ -848,7 +842,7 @@ class qformat_xml extends qformat_default {
|
||||
}
|
||||
}
|
||||
|
||||
$this->import_hints($qo, $question);
|
||||
$this->import_hints($qo, $question, false, false, $this->get_format($qo->questiontextformat));
|
||||
|
||||
return $qo;
|
||||
}
|
||||
@@ -970,7 +964,7 @@ class qformat_xml extends qformat_default {
|
||||
* @param int id internal code
|
||||
* @return string format text
|
||||
*/
|
||||
protected function get_format($id) {
|
||||
public function get_format($id) {
|
||||
switch($id) {
|
||||
case FORMAT_MOODLE:
|
||||
return 'moodle_auto_format';
|
||||
|
||||
@@ -191,13 +191,13 @@ END;
|
||||
$qo = new stdClass();
|
||||
|
||||
$importer = new qformat_xml();
|
||||
$importer->import_hints($qo, $questionxml['question']);
|
||||
$importer->import_hints($qo, $questionxml['question'], false, false, 'html');
|
||||
|
||||
$this->assertEqual(array(
|
||||
array('text' => 'This is the first hint',
|
||||
'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => 'This is the second hint',
|
||||
'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
'format' => FORMAT_HTML, 'files' => array()),
|
||||
), $qo->hint);
|
||||
$this->assertFalse(isset($qo->hintclearwrong));
|
||||
$this->assertFalse(isset($qo->hintshownumcorrect));
|
||||
@@ -221,13 +221,13 @@ END;
|
||||
$qo = new stdClass();
|
||||
|
||||
$importer = new qformat_xml();
|
||||
$importer->import_hints($qo, $questionxml['question'], true, true);
|
||||
$importer->import_hints($qo, $questionxml['question'], true, true, 'html');
|
||||
|
||||
$this->assertEqual(array(
|
||||
array('text' => 'This is the first hint',
|
||||
'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => 'This is the second hint',
|
||||
'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
'format' => FORMAT_HTML, 'files' => array()),
|
||||
), $qo->hint);
|
||||
$this->assertEqual(array(1, 0), $qo->hintclearwrong);
|
||||
$this->assertEqual(array(0, 1), $qo->hintshownumcorrect);
|
||||
@@ -243,7 +243,7 @@ END;
|
||||
$qo = new stdClass();
|
||||
|
||||
$importer = new qformat_xml();
|
||||
$importer->import_hints($qo, $questionxml['question']);
|
||||
$importer->import_hints($qo, $questionxml['question'], 'html');
|
||||
|
||||
$this->assertFalse(isset($qo->hint));
|
||||
}
|
||||
@@ -523,27 +523,27 @@ END;
|
||||
$expectedq->questiontext = 'Match the upper and lower case letters.';
|
||||
$expectedq->questiontextformat = FORMAT_HTML;
|
||||
$expectedq->correctfeedback = array('text' => 'Well done.',
|
||||
'format' => FORMAT_MOODLE, 'files' => array());
|
||||
'format' => FORMAT_HTML, 'files' => array());
|
||||
$expectedq->partiallycorrectfeedback = array('text' => 'Not entirely.',
|
||||
'format' => FORMAT_MOODLE, 'files' => array());
|
||||
'format' => FORMAT_HTML, 'files' => array());
|
||||
$expectedq->shownumcorrect = false;
|
||||
$expectedq->incorrectfeedback = array('text' => 'Completely wrong!',
|
||||
'format' => FORMAT_MOODLE, 'files' => array());
|
||||
'format' => FORMAT_HTML, 'files' => array());
|
||||
$expectedq->generalfeedback = 'The answer is A -> a, B -> b and C -> c.';
|
||||
$expectedq->generalfeedbackformat = FORMAT_MOODLE;
|
||||
$expectedq->generalfeedbackformat = FORMAT_HTML;
|
||||
$expectedq->defaultmark = 1;
|
||||
$expectedq->length = 1;
|
||||
$expectedq->penalty = 0.3333333;
|
||||
$expectedq->shuffleanswers = 0;
|
||||
$expectedq->subquestions = array(
|
||||
array('text' => 'A', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => 'B', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => 'C', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array()));
|
||||
array('text' => 'A', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => 'B', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => 'C', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => '', 'format' => FORMAT_HTML, 'files' => array()));
|
||||
$expectedq->subanswers = array('a', 'b', 'c', 'd');
|
||||
$expectedq->hint = array(
|
||||
array('text' => 'Hint 1', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => 'Hint 1', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => '', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
);
|
||||
$expectedq->hintshownumcorrect = array(true, true);
|
||||
$expectedq->hintclearwrong = array(false, true);
|
||||
@@ -744,17 +744,17 @@ END;
|
||||
$expectedq->questiontextformat = FORMAT_HTML;
|
||||
$expectedq->correctfeedback = array(
|
||||
'text' => '<p>Your answer is correct.</p>',
|
||||
'format' => FORMAT_MOODLE,
|
||||
'format' => FORMAT_HTML,
|
||||
'files' => array());
|
||||
$expectedq->shownumcorrect = false;
|
||||
$expectedq->partiallycorrectfeedback = array(
|
||||
'text' => '<p>Your answer is partially correct.</p>',
|
||||
'format' => FORMAT_MOODLE,
|
||||
'format' => FORMAT_HTML,
|
||||
'files' => array());
|
||||
$expectedq->shownumcorrect = true;
|
||||
$expectedq->incorrectfeedback = array(
|
||||
'text' => '<p>Your answer is incorrect.</p>',
|
||||
'format' => FORMAT_MOODLE,
|
||||
'format' => FORMAT_HTML,
|
||||
'files' => array());
|
||||
$expectedq->generalfeedback = 'The even numbers are 2 and 4.';
|
||||
$expectedq->defaultmark = 2;
|
||||
@@ -764,20 +764,20 @@ END;
|
||||
$expectedq->single = false;
|
||||
|
||||
$expectedq->answer = array(
|
||||
array('text' => '1', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => '2', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => '3', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => '4', 'format' => FORMAT_MOODLE, 'files' => array()));
|
||||
array('text' => '1', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => '2', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => '3', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => '4', 'format' => FORMAT_HTML, 'files' => array()));
|
||||
$expectedq->fraction = array(0, 1, 0, 1);
|
||||
$expectedq->feedback = array(
|
||||
array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array()));
|
||||
array('text' => '', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => '', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => '', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => '', 'format' => FORMAT_HTML, 'files' => array()));
|
||||
|
||||
$expectedq->hint = array(
|
||||
array('text' => 'Hint 1.', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => 'Hint 2.', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => 'Hint 1.', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => 'Hint 2.', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
);
|
||||
$expectedq->hintshownumcorrect = array(false, false);
|
||||
$expectedq->hintclearwrong = array(false, false);
|
||||
@@ -937,7 +937,7 @@ END;
|
||||
$expectedq->questiontext = 'What is the answer?';
|
||||
$expectedq->questiontextformat = FORMAT_HTML;
|
||||
$expectedq->generalfeedback = 'General feedback: Think Hitch-hikers guide to the Galaxy.';
|
||||
$expectedq->generalfeedbackformat = FORMAT_MOODLE;
|
||||
$expectedq->generalfeedbackformat = FORMAT_HTML;
|
||||
$expectedq->defaultmark = 1;
|
||||
$expectedq->length = 1;
|
||||
$expectedq->penalty = 0.1;
|
||||
@@ -946,11 +946,11 @@ END;
|
||||
$expectedq->fraction = array(1, 0, 0);
|
||||
$expectedq->feedback = array(
|
||||
array('text' => 'Well done!',
|
||||
'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => 'What were you thinking?!',
|
||||
'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => 'Completely wrong.',
|
||||
'format' => FORMAT_MOODLE, 'files' => array()));
|
||||
'format' => FORMAT_HTML, 'files' => array()));
|
||||
$expectedq->tolerance = array(0.001, 1, 0);
|
||||
|
||||
$this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
|
||||
@@ -1081,8 +1081,8 @@ END;
|
||||
$expectedq->answer = array('Beta', '*');
|
||||
$expectedq->fraction = array(1, 0);
|
||||
$expectedq->feedback = array(
|
||||
array('text' => 'Well done!', 'format' => FORMAT_MOODLE, 'files' => array()),
|
||||
array('text' => 'Doh!', 'format' => FORMAT_MOODLE, 'files' => array()));
|
||||
array('text' => 'Well done!', 'format' => FORMAT_HTML, 'files' => array()),
|
||||
array('text' => 'Doh!', 'format' => FORMAT_HTML, 'files' => array()));
|
||||
|
||||
$this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
|
||||
}
|
||||
@@ -1199,9 +1199,9 @@ END;
|
||||
$expectedq->penalty = 1;
|
||||
|
||||
$expectedq->feedbacktrue = array('text' => 'Well done!',
|
||||
'format' => FORMAT_MOODLE, 'files' => array());
|
||||
'format' => FORMAT_HTML, 'files' => array());
|
||||
$expectedq->feedbackfalse = array('text' => 'Doh!',
|
||||
'format' => FORMAT_MOODLE, 'files' => array());
|
||||
'format' => FORMAT_HTML, 'files' => array());
|
||||
$expectedq->correctanswer = true;
|
||||
|
||||
$this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
|
||||
|
||||
Reference in New Issue
Block a user