diff --git a/question/format/xml/format.php b/question/format/xml/format.php
index 8a0a7b1dd38..7c6dbda2436 100644
--- a/question/format/xml/format.php
+++ b/question/format/xml/format.php
@@ -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 - 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 .= " " . $question->options->responseformat .
+ "\n";
+ $expout .= " " . $question->options->responsefieldlines .
+ "\n";
+ $expout .= " " . $question->options->attachments .
+ "\n";
+ $expout .= " format($question->options->graderinfoformat) . ">\n";
+ $expout .= $this->writetext($question->options->graderinfo, 3);
+ $expout .= " \n";
break;
case 'calculated':
diff --git a/question/format/xml/simpletest/testxmlformat.php b/question/format/xml/simpletest/testxmlformat.php
index 0fe0f0357b4..9ab295fac37 100644
--- a/question/format/xml/simpletest/testxmlformat.php
+++ b/question/format/xml/simpletest/testxmlformat.php
@@ -272,7 +272,7 @@ END;
$this->assert_same_xml($expectedxml, $xml);
}
- public function test_import_essay() {
+ public function test_import_essay_20() {
$xml = '
An essay
@@ -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 = '
+
+ An essay
+
+
+ Write something.
+
+
+ I hope you wrote something interesting.
+
+ 1
+ 0
+ 0
+ monospaced
+ 42
+ -1
+
+ Grade generously!
]]>
+
+ ';
+ $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'] = 'Grade generously!
';
+ $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 = 'Grade generously!
';
+ $qdata->options->graderinfoformat = FORMAT_HTML;
$exporter = new qformat_xml();
$xml = $exporter->writequestion($qdata);
@@ -337,6 +393,12 @@ END;
1
0
0
+ monospaced
+ 42
+ -1
+
+ Grade generously!]]>
+
';