diff --git a/question/format/xml/format.php b/question/format/xml/format.php index 69e9695f6f4..c9e0d4b3d36 100644 --- a/question/format/xml/format.php +++ b/question/format/xml/format.php @@ -1271,7 +1271,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; diff --git a/question/format/xml/tests/xmlformat_test.php b/question/format/xml/tests/xmlformat_test.php index 78bfcf35ec3..a5b036bbf3c 100644 --- a/question/format/xml/tests/xmlformat_test.php +++ b/question/format/xml/tests/xmlformat_test.php @@ -1413,6 +1413,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 = ' + + + Multianswer with $s + + + Which is the right order? {1:MULTICHOICE:=y,y,$3~$3,y,y} + + + + + 0.3333333 + 0 + +'; + + $this->assert_same_xml($expectedxml, $xml); + } + public function test_import_files_as_draft() { $this->resetAfterTest(); $this->setAdminUser(); diff --git a/question/type/multianswer/tests/helper.php b/question/type/multianswer/tests/helper.php index 743058e7789..24646c94d38 100644 --- a/question/type/multianswer/tests/helper.php +++ b/question/type/multianswer/tests/helper.php @@ -38,7 +38,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'); } /** @@ -197,6 +197,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