mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
MDL-69101 Essay/Moodle XML: recent new settings not imported/exported
This commit is contained in:
parent
9dabd071fe
commit
99778a61a3
@ -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 {
|
||||
"</responserequired>\n";
|
||||
$expout .= " <responsefieldlines>" . $question->options->responsefieldlines .
|
||||
"</responsefieldlines>\n";
|
||||
$expout .= " <minwordlimit>" . $question->options->minwordlimit .
|
||||
"</minwordlimit>\n";
|
||||
$expout .= " <maxwordlimit>" . $question->options->maxwordlimit .
|
||||
"</maxwordlimit>\n";
|
||||
$expout .= " <attachments>" . $question->options->attachments .
|
||||
"</attachments>\n";
|
||||
$expout .= " <attachmentsrequired>" . $question->options->attachmentsrequired .
|
||||
"</attachmentsrequired>\n";
|
||||
$expout .= " <maxbytes>" . $question->options->maxbytes .
|
||||
"</maxbytes>\n";
|
||||
$expout .= " <filetypeslist>" . $question->options->filetypeslist .
|
||||
"</filetypeslist>\n";
|
||||
$expout .= " <graderinfo " .
|
||||
$this->format($question->options->graderinfoformat) . ">\n";
|
||||
$expout .= $this->writetext($question->options->graderinfo, 3);
|
||||
|
@ -69,8 +69,12 @@
|
||||
<responseformat>editor</responseformat>
|
||||
<responserequired>1</responserequired>
|
||||
<responsefieldlines>10</responsefieldlines>
|
||||
<minwordlimit></minwordlimit>
|
||||
<maxwordlimit></maxwordlimit>
|
||||
<attachments>0</attachments>
|
||||
<attachmentsrequired>0</attachmentsrequired>
|
||||
<maxbytes>0</maxbytes>
|
||||
<filetypeslist></filetypeslist>
|
||||
<graderinfo format="html">
|
||||
<text></text>
|
||||
</graderinfo>
|
||||
|
@ -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'] = '<p>Grade <b>generously</b>!</p>';
|
||||
$expectedq->graderinfo['format'] = FORMAT_HTML;
|
||||
$expectedq->responsetemplate['text'] = '<p>Here is something <b>really</b> interesting.</p>';
|
||||
$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 = ' <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>
|
||||
<responserequired>0</responserequired>
|
||||
<responsefieldlines>42</responsefieldlines>
|
||||
<minwordlimit>10</minwordlimit>
|
||||
<maxwordlimit>20</maxwordlimit>
|
||||
<attachments>-1</attachments>
|
||||
<attachmentsrequired>1</attachmentsrequired>
|
||||
<maxbytes>52428800</maxbytes>
|
||||
<filetypeslist>.pdf,.zip.,.docx</filetypeslist>
|
||||
<graderinfo format="html">
|
||||
<text><![CDATA[<p>Grade <b>generously</b>!</p>]]></text>
|
||||
</graderinfo>
|
||||
<responsetemplate format="html">
|
||||
<text><![CDATA[<p>Here is something <b>really</b> interesting.</p>]]></text>
|
||||
</responsetemplate>
|
||||
<tags>
|
||||
<tag><text>tagEssay</text></tag>
|
||||
<tag><text>tagEssay21</text></tag>
|
||||
<tag><text>tagTest</text></tag>
|
||||
</tags>
|
||||
</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->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'] = '<p>Grade <b>generously</b>!</p>';
|
||||
$expectedq->graderinfo['format'] = FORMAT_HTML;
|
||||
$expectedq->responsetemplate['text'] = '<p>Here is something <b>really</b> interesting.</p>';
|
||||
@ -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 = '<p>Grade <b>generously</b>!</p>';
|
||||
$qdata->options->graderinfoformat = FORMAT_HTML;
|
||||
$qdata->options->responsetemplate = '<p>Here is something <b>really</b> interesting.</p>';
|
||||
$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;
|
||||
<responseformat>monospaced</responseformat>
|
||||
<responserequired>0</responserequired>
|
||||
<responsefieldlines>42</responsefieldlines>
|
||||
<minwordlimit>10</minwordlimit>
|
||||
<maxwordlimit>20</maxwordlimit>
|
||||
<attachments>-1</attachments>
|
||||
<attachmentsrequired>1</attachmentsrequired>
|
||||
<maxbytes>52428800</maxbytes>
|
||||
<filetypeslist>.pdf,.zip.,.docx</filetypeslist>
|
||||
<graderinfo format="html">
|
||||
<text><![CDATA[<p>Grade <b>generously</b>!</p>]]></text>
|
||||
</graderinfo>
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -25,10 +25,11 @@
|
||||
<responseformat>editor</responseformat>
|
||||
<responserequired>1</responserequired>
|
||||
<responsefieldlines>15</responsefieldlines>
|
||||
<minwordlimit>0</minwordlimit>
|
||||
<maxwordlimit>0</maxwordlimit>
|
||||
<minwordlimit></minwordlimit>
|
||||
<maxwordlimit></maxwordlimit>
|
||||
<attachments>0</attachments>
|
||||
<attachmentsrequired>0</attachmentsrequired>
|
||||
<maxbytes>0</maxbytes>
|
||||
<filetypeslist></filetypeslist>
|
||||
<graderinfo format="html">
|
||||
<text></text>
|
||||
|
@ -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 = ''; // Although once saved in the DB, this becomes null, the form returns '' here.
|
||||
$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 = ''; // Although once saved in the DB, this becomes null, the form returns '' here.
|
||||
$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 = ''; // Although once saved in the DB, this becomes null, the form returns '' here.
|
||||
$fromform->graderinfo = array('text' => '', 'format' => FORMAT_HTML);
|
||||
$fromform->responsetemplate = array('text' => '', 'format' => FORMAT_HTML);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user