Skip to content

Commit

Permalink
Merge branch 'MDL-53938' of git://github.com/timhunt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed May 31, 2016
2 parents d157799 + c76789f commit 0cdef23
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 1 deletion.
2 changes: 1 addition & 1 deletion question/format/gift/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ public function writequestion($question) {
$expout .= $this->write_questiontext($question->questiontext, $question->questiontextformat);
$expout .= "{\n";
foreach ($question->options->answers as $answer) {
if ($answer->fraction == 1) {
if ($answer->fraction == 1 && $question->options->single) {
$answertext = '=';
} else if ($answer->fraction == 0) {
$answertext = '~';
Expand Down
151 changes: 151 additions & 0 deletions question/format/gift/tests/giftformat_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,91 @@ public function test_import_multichoice_multi() {
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}

public function test_import_multichoice_multi_tricky() {
$gift = "
// multiple choice, multiple response with specified feedback for right and wrong answers
::colours:: What's between orange and green in the spectrum?
{
~%100%yellow # right; good!
~%-50%red # wrong
~%-50%blue # wrong
}";
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));

$importer = new qformat_gift();
$q = $importer->readquestion($lines);

$expectedq = (object) array(
'name' => 'colours',
'questiontext' => "What's between orange and green in the spectrum?",
'questiontextformat' => FORMAT_MOODLE,
'generalfeedback' => '',
'generalfeedbackformat' => FORMAT_MOODLE,
'qtype' => 'multichoice',
'defaultmark' => 1,
'penalty' => 0.3333333,
'length' => 1,
'single' => 0,
'shuffleanswers' => '1',
'answernumbering' => 'abc',
'correctfeedback' => array(
'text' => '',
'format' => FORMAT_MOODLE,
'files' => array(),
),
'partiallycorrectfeedback' => array(
'text' => '',
'format' => FORMAT_MOODLE,
'files' => array(),
),
'incorrectfeedback' => array(
'text' => '',
'format' => FORMAT_MOODLE,
'files' => array(),
),
'answer' => array(
0 => array(
'text' => 'yellow',
'format' => FORMAT_MOODLE,
'files' => array(),
),
1 => array(
'text' => 'red',
'format' => FORMAT_MOODLE,
'files' => array(),
),
2 => array(
'text' => 'blue',
'format' => FORMAT_MOODLE,
'files' => array(),
),
),
'fraction' => array(1, -0.5, -0.5),
'feedback' => array(
0 => array(
'text' => 'right; good!',
'format' => FORMAT_MOODLE,
'files' => array(),
),
1 => array(
'text' => "wrong",
'format' => FORMAT_MOODLE,
'files' => array(),
),
2 => array(
'text' => "wrong",
'format' => FORMAT_MOODLE,
'files' => array(),
),
),
);

// Repeated test for better failure messages.
$this->assertEquals($expectedq->answer, $q->answer);
$this->assertEquals($expectedq->feedback, $q->feedback);
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}

public function test_export_multichoice() {
$qdata = (object) array(
'id' => 666 ,
Expand Down Expand Up @@ -509,6 +594,72 @@ public function test_export_multichoice() {
\t~[plain]blue#wrong, it's yellow
}
";

$this->assert_same_gift($expectedgift, $gift);
}

public function test_export_multichoice_multi_tricky() {
$qdata = (object) array(
'id' => 666 ,
'name' => 'Q8',
'questiontext' => "What's between orange and green in the spectrum?",
'questiontextformat' => FORMAT_MOODLE,
'generalfeedback' => '',
'generalfeedbackformat' => FORMAT_MOODLE,
'defaultmark' => 1,
'penalty' => 0.3333333,
'length' => 1,
'qtype' => 'multichoice',
'options' => (object) array(
'single' => 0,
'shuffleanswers' => '1',
'answernumbering' => 'abc',
'correctfeedback' => '',
'correctfeedbackformat' => FORMAT_MOODLE,
'partiallycorrectfeedback' => '',
'partiallycorrectfeedbackformat' => FORMAT_MOODLE,
'incorrectfeedback' => '',
'incorrectfeedbackformat' => FORMAT_MOODLE,
'answers' => array(
123 => (object) array(
'id' => 123,
'answer' => 'yellow',
'answerformat' => FORMAT_MOODLE,
'fraction' => 1,
'feedback' => 'right; good!',
'feedbackformat' => FORMAT_MOODLE,
),
124 => (object) array(
'id' => 124,
'answer' => 'red',
'answerformat' => FORMAT_MOODLE,
'fraction' => -0.5,
'feedback' => "wrong, it's yellow",
'feedbackformat' => FORMAT_MOODLE,
),
125 => (object) array(
'id' => 125,
'answer' => 'blue',
'answerformat' => FORMAT_MOODLE,
'fraction' => -0.5,
'feedback' => "wrong, it's yellow",
'feedbackformat' => FORMAT_MOODLE,
),
),
),
);

$exporter = new qformat_gift();
$gift = $exporter->writequestion($qdata);

$expectedgift = "// question: 666 name: Q8
::Q8::What's between orange and green in the spectrum?{
\t~%100%yellow#right; good!
\t~%-50%red#wrong, it's yellow
\t~%-50%blue#wrong, it's yellow
}
";

$this->assert_same_gift($expectedgift, $gift);
Expand Down

0 comments on commit 0cdef23

Please sign in to comment.