diff --git a/question/format/xml/format.php b/question/format/xml/format.php
index 0e63bdf0471..cb6b56cc0ac 100644
--- a/question/format/xml/format.php
+++ b/question/format/xml/format.php
@@ -770,10 +770,18 @@ class qformat_xml extends qformat_default {
array('#', 'responsefieldlines', 0, '#'), 15);
$qo->responserequired = $this->getpath($question,
array('#', 'responserequired', 0, '#'), 1);
+ $qo->minwordlimit = $this->getpath($question,
+ array('#', 'minwordlimit', 0, '#'), null);
+ $qo->maxwordlimit = $this->getpath($question,
+ array('#', 'maxwordlimit', 0, '#'), null);
$qo->attachments = $this->getpath($question,
array('#', 'attachments', 0, '#'), 0);
$qo->attachmentsrequired = $this->getpath($question,
array('#', 'attachmentsrequired', 0, '#'), 0);
+ $qo->filetypeslist = $this->getpath($question,
+ array('#', 'filetypeslist', 0, '#'), null);
+ $qo->maxbytes = $this->getpath($question,
+ array('#', 'maxbytes', 0, '#'), null);
$qo->graderinfo = $this->import_text_with_files($question,
array('#', 'graderinfo', 0), '', $this->get_format($qo->questiontextformat));
$qo->responsetemplate['text'] = $this->getpath($question,
@@ -1168,7 +1176,6 @@ class qformat_xml extends qformat_default {
* @return string xml segment
*/
public function writequestion($question) {
- global $CFG, $OUTPUT;
$invalidquestion = false;
$fs = get_file_storage();
@@ -1348,10 +1355,18 @@ class qformat_xml extends qformat_default {
"\n";
$expout .= " " . $question->options->responsefieldlines .
"\n";
+ $expout .= " " . $question->options->minwordlimit .
+ "\n";
+ $expout .= " " . $question->options->maxwordlimit .
+ "\n";
$expout .= " " . $question->options->attachments .
"\n";
$expout .= " " . $question->options->attachmentsrequired .
"\n";
+ $expout .= " " . $question->options->maxbytes .
+ "\n";
+ $expout .= " " . $question->options->filetypeslist .
+ "\n";
$expout .= " format($question->options->graderinfoformat) . ">\n";
$expout .= $this->writetext($question->options->graderinfo, 3);
diff --git a/question/format/xml/tests/fixtures/nested_categories_with_questions.xml b/question/format/xml/tests/fixtures/nested_categories_with_questions.xml
index 8350c16c4f8..cca8027ec0b 100644
--- a/question/format/xml/tests/fixtures/nested_categories_with_questions.xml
+++ b/question/format/xml/tests/fixtures/nested_categories_with_questions.xml
@@ -69,8 +69,12 @@
editor
1
10
+
+
0
0
+ 0
+
diff --git a/question/format/xml/tests/xmlformat_test.php b/question/format/xml/tests/xmlformat_test.php
index 0889ad55e29..740db03d52b 100644
--- a/question/format/xml/tests/xmlformat_test.php
+++ b/question/format/xml/tests/xmlformat_test.php
@@ -406,8 +406,12 @@ END;
$expectedq->responseformat = 'editor';
$expectedq->responserequired = 1;
$expectedq->responsefieldlines = 15;
+ $expectedq->minwordlimit = null;
+ $expectedq->maxwordlimit = null;
$expectedq->attachments = 0;
$expectedq->attachmentsrequired = 0;
+ $expectedq->maxbytes = 0;
+ $expectedq->filetypeslist = null;
$expectedq->graderinfo['text'] = '';
$expectedq->graderinfo['format'] = FORMAT_MOODLE;
$expectedq->responsetemplate['text'] = '';
@@ -465,8 +469,79 @@ END;
$expectedq->responseformat = 'monospaced';
$expectedq->responserequired = 0;
$expectedq->responsefieldlines = 42;
+ $expectedq->minwordlimit = null;
+ $expectedq->maxwordlimit = null;
$expectedq->attachments = -1;
$expectedq->attachmentsrequired = 1;
+ $expectedq->maxbytes = 0;
+ $expectedq->filetypeslist = null;
+ $expectedq->graderinfo['text'] = 'Grade generously!
';
+ $expectedq->graderinfo['format'] = FORMAT_HTML;
+ $expectedq->responsetemplate['text'] = 'Here is something really interesting.
';
+ $expectedq->responsetemplate['format'] = FORMAT_HTML;
+ $expectedq->tags = array('tagEssay', 'tagEssay21', 'tagTest');
+
+ $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
+ }
+
+ public function test_import_essay_311() {
+ $xml = '
+
+ An essay
+
+
+ Write something.
+
+
+ I hope you wrote something interesting.
+
+ 1
+ 0
+ 0
+ monospaced
+ 0
+ 42
+ 10
+ 20
+ -1
+ 1
+ 52428800
+ .pdf,.zip.,.docx
+
+ Grade generously!
]]>
+
+
+ Here is something really interesting.]]>
+
+
+ tagEssay
+ tagEssay21
+ tagTest
+
+ ';
+ $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->responserequired = 0;
+ $expectedq->responsefieldlines = 42;
+ $expectedq->minwordlimit = 10;
+ $expectedq->maxwordlimit = 20;
+ $expectedq->attachments = -1;
+ $expectedq->attachmentsrequired = 1;
+ $expectedq->maxbytes = 52428800; // 50MB.
+ $expectedq->filetypeslist = '.pdf,.zip.,.docx';
$expectedq->graderinfo['text'] = 'Grade generously!
';
$expectedq->graderinfo['format'] = FORMAT_HTML;
$expectedq->responsetemplate['text'] = 'Here is something really interesting.
';
@@ -497,12 +572,16 @@ END;
$qdata->options->responseformat = 'monospaced';
$qdata->options->responserequired = 0;
$qdata->options->responsefieldlines = 42;
+ $qdata->options->minwordlimit = 10;
+ $qdata->options->maxwordlimit = 20;
$qdata->options->attachments = -1;
$qdata->options->attachmentsrequired = 1;
$qdata->options->graderinfo = 'Grade generously!
';
$qdata->options->graderinfoformat = FORMAT_HTML;
$qdata->options->responsetemplate = 'Here is something really interesting.
';
$qdata->options->responsetemplateformat = FORMAT_HTML;
+ $qdata->options->maxbytes = 52428800; // 50MB.
+ $qdata->options->filetypeslist = '.pdf,.zip.,.docx';
$exporter = new qformat_xml();
$xml = $exporter->writequestion($qdata);
@@ -524,8 +603,12 @@ END;
monospaced
0
42
+ 10
+ 20
-1
1
+ 52428800
+ .pdf,.zip.,.docx
Grade generously!]]>
diff --git a/question/type/essay/questiontype.php b/question/type/essay/questiontype.php
index b39fc3e41e0..44cc125d3a6 100644
--- a/question/type/essay/questiontype.php
+++ b/question/type/essay/questiontype.php
@@ -65,12 +65,12 @@ class qtype_essay extends question_type {
$options->responseformat = $formdata->responseformat;
$options->responserequired = $formdata->responserequired;
$options->responsefieldlines = $formdata->responsefieldlines;
- $options->minwordlimit = isset($formdata->minwordenabled) ? $formdata->minwordlimit : 0;
- $options->maxwordlimit = isset($formdata->maxwordenabled) ? $formdata->maxwordlimit : 0;
+ $options->minwordlimit = isset($formdata->minwordenabled) ? $formdata->minwordlimit : null;
+ $options->maxwordlimit = isset($formdata->maxwordenabled) ? $formdata->maxwordlimit : null;
$options->attachments = $formdata->attachments;
$options->attachmentsrequired = $formdata->attachmentsrequired;
if (!isset($formdata->filetypeslist)) {
- $options->filetypeslist = "";
+ $options->filetypeslist = null;
} else {
$options->filetypeslist = $formdata->filetypeslist;
}
diff --git a/question/type/essay/tests/behat/export.feature b/question/type/essay/tests/behat/export.feature
index ba370a40425..deef3d77558 100644
--- a/question/type/essay/tests/behat/export.feature
+++ b/question/type/essay/tests/behat/export.feature
@@ -29,7 +29,7 @@ Feature: Test exporting Essay questions
When I navigate to "Question bank > Export" in current page administration
And I set the field "id_format_xml" to "1"
And I press "Export questions to file"
- Then following "click here" should download between "2600" and "2850" bytes
+ Then following "click here" should download between "3000" and "3500" bytes
# If the download step is the last in the scenario then we can sometimes run
# into the situation where the download page causes a http redirect but behat
# has already conducted its reset (generating an error). By putting a logout
diff --git a/question/type/essay/tests/fixtures/testquestion.moodle.xml b/question/type/essay/tests/fixtures/testquestion.moodle.xml
index b67846339de..a6fb84bcbea 100644
--- a/question/type/essay/tests/fixtures/testquestion.moodle.xml
+++ b/question/type/essay/tests/fixtures/testquestion.moodle.xml
@@ -25,10 +25,11 @@
editor
1
15
- 0
- 0
+
+
0
0
+ 0
diff --git a/question/type/essay/tests/helper.php b/question/type/essay/tests/helper.php
index 269562f85ab..f1590a39909 100644
--- a/question/type/essay/tests/helper.php
+++ b/question/type/essay/tests/helper.php
@@ -51,11 +51,12 @@ class qtype_essay_test_helper extends question_test_helper {
$q->responseformat = 'editor';
$q->responserequired = 1;
$q->responsefieldlines = 10;
- $q->minwordlimit = 0;
- $q->maxwordlimit = 0;
+ $q->minwordlimit = null;
+ $q->maxwordlimit = null;
$q->attachments = 0;
$q->attachmentsrequired = 0;
- $q->filetypeslist = '';
+ $q->maxbytes = 0;
+ $q->filetypeslist = null;
$q->graderinfo = '';
$q->graderinfoformat = FORMAT_HTML;
$q->qtype = question_bank::get_qtype('essay');
@@ -88,12 +89,10 @@ class qtype_essay_test_helper extends question_test_helper {
$fromform->responseformat = 'editor';
$fromform->responserequired = 1;
$fromform->responsefieldlines = 10;
- $fromform->minwordlimit = 0;
- $fromform->maxwordlimit = 0;
$fromform->attachments = 0;
$fromform->attachmentsrequired = 0;
- $fromform->filetypeslist = '';
$fromform->maxbytes = 0;
+ $fromform->filetypeslist = '';
$fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML);
$fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML);
@@ -142,12 +141,10 @@ class qtype_essay_test_helper extends question_test_helper {
$fromform->responseformat = 'editorfilepicker';
$fromform->responserequired = 1;
$fromform->responsefieldlines = 10;
- $fromform->minwordlimit = 0;
- $fromform->maxwordlimit = 0;
$fromform->attachments = 3;
$fromform->attachmentsrequired = 0;
- $fromform->filetypeslist = '';
$fromform->maxbytes = 0;
+ $fromform->filetypeslist = '';
$fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML);
$fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML);
@@ -181,12 +178,10 @@ class qtype_essay_test_helper extends question_test_helper {
$fromform->responseformat = 'plain';
$fromform->responserequired = 1;
$fromform->responsefieldlines = 10;
- $fromform->minwordlimit = 0;
- $fromform->maxwordlimit = 0;
$fromform->attachments = 0;
$fromform->attachmentsrequired = 0;
- $fromform->filetypeslist = '';
$fromform->maxbytes = 0;
+ $fromform->filetypeslist = '';
$fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML);
$fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML);
diff --git a/question/type/essay/tests/walkthrough_test.php b/question/type/essay/tests/walkthrough_test.php
index 2aa234eb51e..d8261215304 100644
--- a/question/type/essay/tests/walkthrough_test.php
+++ b/question/type/essay/tests/walkthrough_test.php
@@ -519,7 +519,7 @@ class qtype_essay_walkthrough_testcase extends qbehaviour_walkthrough_test_base
// Start attempt at the question.
$q = question_bank::load_question($question->id);
- $q->filetypeslist = ("pdf, docx");
+ $q->filetypeslist = '.pdf,.docx';
$this->start_attempt_at_question($q, 'deferredfeedback', 1);
$this->check_current_state(question_state::$todo);
@@ -578,7 +578,7 @@ class qtype_essay_walkthrough_testcase extends qbehaviour_walkthrough_test_base
// Start attempt at the question.
$q = question_bank::load_question($question->id);
- $q->filetypeslist = ("txt, docx");
+ $q->filetypeslist = '.txt,.docx';
$this->start_attempt_at_question($q, 'deferredfeedback', 1);
$this->check_current_state(question_state::$todo);