Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
Merge branch 'MDL-43809' of git://github.com/timhunt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jan 27, 2014
2 parents 0494226 + 5c0b5ba commit 5e7f4b1
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 2 deletions.
2 changes: 1 addition & 1 deletion question/format/xml/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ public function writequestion($question) {

case 'multianswer':
foreach ($question->options->questions as $index => $subq) {
$expout = preg_replace('~{#' . $index . '}~', $subq->questiontext, $expout);
$expout = str_replace('{#' . $index . '}', $subq->questiontext, $expout);
}
break;

Expand Down
25 changes: 25 additions & 0 deletions question/format/xml/tests/xmlformat_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,31 @@ public function test_export_multianswer() {
$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();
Expand Down
59 changes: 58 additions & 1 deletion question/type/multianswer/tests/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
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');
}

/**
Expand Down Expand Up @@ -196,6 +196,63 @@ public function get_multianswer_question_data_twosubq() {
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
Expand Down

0 comments on commit 5e7f4b1

Please sign in to comment.