mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
MDL-43809 qformat_xml messes up $s in multianswer questions.
This commit is contained in:
parent
9788e26805
commit
5c0b5ba575
@ -1270,7 +1270,7 @@ class qformat_xml extends qformat_default {
|
||||
|
||||
case 'multianswer':
|
||||
foreach ($question->options->questions as $index => $subq) {
|
||||
$expout = preg_replace('~{#' . $index . '}~', $subq->questiontext, $expout);
|
||||
$expout = str_replace('{#' . $index . '}', $subq->questiontext, $expout);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1423,6 +1423,31 @@ END;
|
||||
$this->assert_same_xml($expectedxml, $xml);
|
||||
}
|
||||
|
||||
public function test_export_multianswer_withdollars() {
|
||||
$qdata = test_question_maker::get_question_data('multianswer', 'dollarsigns');
|
||||
|
||||
$exporter = new qformat_xml();
|
||||
$xml = $exporter->writequestion($qdata);
|
||||
|
||||
$expectedxml = '<!-- question: 0 -->
|
||||
<question type="cloze">
|
||||
<name>
|
||||
<text>Multianswer with $s</text>
|
||||
</name>
|
||||
<questiontext format="html">
|
||||
<text>Which is the right order? {1:MULTICHOICE:=y,y,$3~$3,y,y}</text>
|
||||
</questiontext>
|
||||
<generalfeedback format="html">
|
||||
<text></text>
|
||||
</generalfeedback>
|
||||
<penalty>0.3333333</penalty>
|
||||
<hidden>0</hidden>
|
||||
</question>
|
||||
';
|
||||
|
||||
$this->assert_same_xml($expectedxml, $xml);
|
||||
}
|
||||
|
||||
public function test_import_files_as_draft() {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
@ -37,7 +37,7 @@ require_once($CFG->dirroot . '/question/type/multianswer/question.php');
|
||||
*/
|
||||
class qtype_multianswer_test_helper extends question_test_helper {
|
||||
public function get_test_questions() {
|
||||
return array('twosubq', 'fourmc', 'numericalzero');
|
||||
return array('twosubq', 'fourmc', 'numericalzero', 'dollarsigns');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -196,6 +196,63 @@ class qtype_multianswer_test_helper extends question_test_helper {
|
||||
return $qdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a multianswer question onetaining one blank in some text.
|
||||
* This question has no hints.
|
||||
*
|
||||
* @return object the question definition data, as it might be returned from
|
||||
* get_question_options.
|
||||
*/
|
||||
public function get_multianswer_question_data_dollarsigns() {
|
||||
$qdata = new stdClass();
|
||||
test_question_maker::initialise_question_data($qdata);
|
||||
|
||||
$qdata->name = 'Multianswer with $s';
|
||||
$qdata->questiontext =
|
||||
'Which is the right order? {#1}';
|
||||
$qdata->generalfeedback = '';
|
||||
|
||||
$qdata->defaultmark = 1.0;
|
||||
$qdata->qtype = 'multianswer';
|
||||
|
||||
$mc = new stdClass();
|
||||
test_question_maker::initialise_question_data($mc);
|
||||
|
||||
$mc->name = 'Multianswer with $s';
|
||||
$mc->questiontext = '{1:MULTICHOICE:=y,y,$3~$3,y,y}';
|
||||
$mc->generalfeedback = '';
|
||||
$mc->penalty = 0.0;
|
||||
$mc->qtype = 'multichoice';
|
||||
|
||||
$mc->options = new stdClass();
|
||||
$mc->options->layout = 0;
|
||||
$mc->options->single = 1;
|
||||
$mc->options->shuffleanswers = 1;
|
||||
$mc->options->correctfeedback = '';
|
||||
$mc->options->correctfeedbackformat = 1;
|
||||
$mc->options->partiallycorrectfeedback = '';
|
||||
$mc->options->partiallycorrectfeedbackformat = 1;
|
||||
$mc->options->incorrectfeedback = '';
|
||||
$mc->options->incorrectfeedbackformat = 1;
|
||||
$mc->options->answernumbering = 0;
|
||||
$mc->options->shownumcorrect = 0;
|
||||
|
||||
$mc->options->answers = array(
|
||||
23 => new question_answer(23, 'y,y,$3', 0, '', FORMAT_HTML),
|
||||
24 => new question_answer(24, '$3,y,y', 0, '', FORMAT_HTML),
|
||||
);
|
||||
|
||||
$qdata->options = new stdClass();
|
||||
$qdata->options->questions = array(
|
||||
1 => $mc,
|
||||
);
|
||||
|
||||
$qdata->hints = array(
|
||||
);
|
||||
|
||||
return $qdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a multianswer question about completing two blanks in some text.
|
||||
* @return object the question definition data, as it might be returned from
|
||||
|
Loading…
x
Reference in New Issue
Block a user