mirror of
https://github.com/moodle/moodle.git
synced 2025-03-18 22:50:19 +01:00
MDL-27854 qformat_xml fix import/export of essay questions to include the new options.
This commit is contained in:
parent
79e25fb456
commit
8a5d05eea8
@ -680,19 +680,16 @@ class qformat_xml extends qformat_default {
|
||||
// header parts particular to essay
|
||||
$qo->qtype = ESSAY;
|
||||
|
||||
$answers = $this->getpath($question, array('#', 'answer'), null);
|
||||
if ($answers) {
|
||||
$answer = array_pop($answers);
|
||||
$answer = $this->import_answer($answer);
|
||||
// get feedback
|
||||
$qo->feedback = $answer->feedback;
|
||||
} else {
|
||||
$qo->feedback = array('text' => '', 'format' => FORMAT_MOODLE, 'files' => array());
|
||||
}
|
||||
|
||||
// get fraction - <fraction> tag is deprecated
|
||||
$qo->fraction = $this->getpath($question, array('@', 'fraction'), 0) / 100;
|
||||
$qo->fraction = $this->getpath($question, array('#', 'fraction', 0, '#'), $qo->fraction);
|
||||
$qo->responseformat = $this->getpath($question,
|
||||
array('#', 'responseformat', 0, '#'), 'editor');
|
||||
$qo->responsefieldlines = $this->getpath($question,
|
||||
array('#', 'responsefieldlines', 0, '#'), 15);
|
||||
$qo->attachments = $this->getpath($question,
|
||||
array('#', 'attachments', 0, '#'), 0);
|
||||
$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'));
|
||||
|
||||
return $qo;
|
||||
}
|
||||
@ -720,7 +717,7 @@ class qformat_xml extends qformat_default {
|
||||
$qo->correctfeedback['text'] = $this->getpath(
|
||||
$question, array('#', 'correctfeedback', 0, '#', 'text', 0, '#'), '', true);
|
||||
$qo->correctfeedback['format'] = $this->trans_format($this->getpath(
|
||||
$question, array('#', 'correctfeedback', 0, '@', 'formath'), 'moodle_auto_format'));
|
||||
$question, array('#', 'correctfeedback', 0, '@', 'format'), 'moodle_auto_format'));
|
||||
$qo->correctfeedback['files'] = $this->import_files($this->getpath(
|
||||
$question, array('#', 'correctfeedback', '0', '#', 'file'), array()));
|
||||
|
||||
@ -1234,7 +1231,16 @@ class qformat_xml extends qformat_default {
|
||||
break;
|
||||
|
||||
case 'essay':
|
||||
// Nothing else to do.
|
||||
$expout .= " <responseformat>" . $question->options->responseformat .
|
||||
"</responseformat>\n";
|
||||
$expout .= " <responsefieldlines>" . $question->options->responsefieldlines .
|
||||
"</responsefieldlines>\n";
|
||||
$expout .= " <attachments>" . $question->options->attachments .
|
||||
"</attachments>\n";
|
||||
$expout .= " <graderinfo " .
|
||||
$this->format($question->options->graderinfoformat) . ">\n";
|
||||
$expout .= $this->writetext($question->options->graderinfo, 3);
|
||||
$expout .= " </graderinfo>\n";
|
||||
break;
|
||||
|
||||
case 'calculated':
|
||||
|
@ -272,7 +272,7 @@ END;
|
||||
$this->assert_same_xml($expectedxml, $xml);
|
||||
}
|
||||
|
||||
public function test_import_essay() {
|
||||
public function test_import_essay_20() {
|
||||
$xml = ' <question type="essay">
|
||||
<name>
|
||||
<text>An essay</text>
|
||||
@ -301,6 +301,55 @@ END;
|
||||
$expectedq->defaultmark = 1;
|
||||
$expectedq->length = 1;
|
||||
$expectedq->penalty = 0;
|
||||
$expectedq->responseformat = 'editor';
|
||||
$expectedq->responsefieldlines = 15;
|
||||
$expectedq->attachments = 0;
|
||||
$expectedq->graderinfo['text'] = '';
|
||||
$expectedq->graderinfo['format'] = FORMAT_MOODLE;
|
||||
|
||||
$this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
|
||||
}
|
||||
|
||||
public function test_import_essay_21() {
|
||||
$xml = ' <question type="essay">
|
||||
<name>
|
||||
<text>An essay</text>
|
||||
</name>
|
||||
<questiontext format="moodle_auto_format">
|
||||
<text>Write something.</text>
|
||||
</questiontext>
|
||||
<generalfeedback>
|
||||
<text>I hope you wrote something interesting.</text>
|
||||
</generalfeedback>
|
||||
<defaultgrade>1</defaultgrade>
|
||||
<penalty>0</penalty>
|
||||
<hidden>0</hidden>
|
||||
<responseformat>monospaced</responseformat>
|
||||
<responsefieldlines>42</responsefieldlines>
|
||||
<attachments>-1</attachments>
|
||||
<graderinfo format="html">
|
||||
<text><![CDATA[<p>Grade <b>generously</b>!</p>]]></text>
|
||||
</graderinfo>
|
||||
</question>';
|
||||
$xmldata = xmlize($xml);
|
||||
|
||||
$importer = new qformat_xml();
|
||||
$q = $importer->import_essay($xmldata['question']);
|
||||
|
||||
$expectedq = new stdClass();
|
||||
$expectedq->qtype = 'essay';
|
||||
$expectedq->name = 'An essay';
|
||||
$expectedq->questiontext = 'Write something.';
|
||||
$expectedq->questiontextformat = FORMAT_MOODLE;
|
||||
$expectedq->generalfeedback = 'I hope you wrote something interesting.';
|
||||
$expectedq->defaultmark = 1;
|
||||
$expectedq->length = 1;
|
||||
$expectedq->penalty = 0;
|
||||
$expectedq->responseformat = 'monospaced';
|
||||
$expectedq->responsefieldlines = 42;
|
||||
$expectedq->attachments = -1;
|
||||
$expectedq->graderinfo['text'] = '<p>Grade <b>generously</b>!</p>';
|
||||
$expectedq->graderinfo['format'] = FORMAT_HTML;
|
||||
|
||||
$this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
|
||||
}
|
||||
@ -319,6 +368,13 @@ END;
|
||||
$qdata->length = 1;
|
||||
$qdata->penalty = 0;
|
||||
$qdata->hidden = 0;
|
||||
$qdata->options->id = 456;
|
||||
$qdata->options->questionid = 123;
|
||||
$qdata->options->responseformat = 'monospaced';
|
||||
$qdata->options->responsefieldlines = 42;
|
||||
$qdata->options->attachments = -1;
|
||||
$qdata->options->graderinfo = '<p>Grade <b>generously</b>!</p>';
|
||||
$qdata->options->graderinfoformat = FORMAT_HTML;
|
||||
|
||||
$exporter = new qformat_xml();
|
||||
$xml = $exporter->writequestion($qdata);
|
||||
@ -337,6 +393,12 @@ END;
|
||||
<defaultgrade>1</defaultgrade>
|
||||
<penalty>0</penalty>
|
||||
<hidden>0</hidden>
|
||||
<responseformat>monospaced</responseformat>
|
||||
<responsefieldlines>42</responsefieldlines>
|
||||
<attachments>-1</attachments>
|
||||
<graderinfo format="html">
|
||||
<text><![CDATA[<p>Grade <b>generously</b>!</p>]]></text>
|
||||
</graderinfo>
|
||||
</question>
|
||||
';
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user