diff --git a/question/type/multianswer/questiontype.php b/question/type/multianswer/questiontype.php
index a1f01f5554f..325aff85da0 100644
--- a/question/type/multianswer/questiontype.php
+++ b/question/type/multianswer/questiontype.php
@@ -257,7 +257,7 @@ class qtype_multianswer extends question_type {
// ANSWER_ALTERNATIVE regexes.
define('ANSWER_ALTERNATIVE_FRACTION_REGEX',
- '=|%(-?[0-9]+)%');
+ '=|%(-?[0-9]+(?:[.,][0-9]*)?)%');
// For the syntax '(?fraction["{$answerindex}"] = '1';
} else if ($percentile = $altregs[ANSWER_ALTERNATIVE_REGEX_PERCENTILE_FRACTION]) {
- $wrapped->fraction["{$answerindex}"] = .01 * $percentile;
+ // Accept either decimal place character.
+ $wrapped->fraction["{$answerindex}"] = .01 * str_replace(',', '.', $percentile);
$hasspecificfraction = true;
} else {
$wrapped->fraction["{$answerindex}"] = '0';
diff --git a/question/type/multianswer/tests/questiontype_test.php b/question/type/multianswer/tests/questiontype_test.php
index c1d46a5fe91..e06c2e9f336 100644
--- a/question/type/multianswer/tests/questiontype_test.php
+++ b/question/type/multianswer/tests/questiontype_test.php
@@ -298,11 +298,10 @@ class qtype_multianswer_test extends advanced_testcase {
}
}
}
+
/**
* Verify that the multiplechoice variants parameters are correctly interpreted from
* the question text
- *
- *
*/
public function test_questiontext_extraction_of_multiplechoice_subquestions_variants() {
$questiontext = array();
@@ -310,18 +309,18 @@ class qtype_multianswer_test extends advanced_testcase {
$questiontext['itemid'] = '';
$questiontext['text'] = '
Match the following cities with the correct state:
- - 1 San Francisco:{1:MULTICHOICE:=California#OK~Arizona#Wrong}
- - 2 Tucson:{1:MC:%0%California#Wrong~=Arizona#OK}
- - 3 Los Angeles:{1:MULTICHOICE_S:=California#OK~Arizona#Wrong}
- - 4 Phoenix:{1:MCS:%0%California#Wrong~=Arizona#OK}
- - 5 San Francisco:{1:MULTICHOICE_H:=California#OK~Arizona#Wrong}
- - 6 Tucson:{1:MCH:%0%California#Wrong~=Arizona#OK}
- - 7 Los Angeles:{1:MULTICHOICE_HS:=California#OK~Arizona#Wrong}
- - 8 Phoenix:{1:MCHS:%0%California#Wrong~=Arizona#OK}
- - 9 San Francisco:{1:MULTICHOICE_V:=California#OK~Arizona#Wrong}
- - 10 Tucson:{1:MCV:%0%California#Wrong~=Arizona#OK}
- - 11 Los Angeles:{1:MULTICHOICE_VS:=California#OK~Arizona#Wrong}
- - 12 Phoenix:{1:MCVS:%0%California#Wrong~=Arizona#OK}
+ - 1 San Francisco:{1:MULTICHOICE:=California#OK~%33.33333%Ohio#Not really~Arizona#Wrong}
+ - 2 Tucson:{1:MC:%0%California#Wrong~%33,33333%Ohio#Not really~=Arizona#OK}
+ - 3 Los Angeles:{1:MULTICHOICE_S:=California#OK~%33.33333%Ohio#Not really~Arizona#Wrong}
+ - 4 Phoenix:{1:MCS:%0%California#Wrong~%33,33333%Ohio#Not really~=Arizona#OK}
+ - 5 San Francisco:{1:MULTICHOICE_H:=California#OK~%33.33333%Ohio#Not really~Arizona#Wrong}
+ - 6 Tucson:{1:MCH:%0%California#Wrong~%33,33333%Ohio#Not really~=Arizona#OK}
+ - 7 Los Angeles:{1:MULTICHOICE_HS:=California#OK~%33.33333%Ohio#Not really~Arizona#Wrong}
+ - 8 Phoenix:{1:MCHS:%0%California#Wrong~%33,33333%Ohio#Not really~=Arizona#OK}
+ - 9 San Francisco:{1:MULTICHOICE_V:=California#OK~%33.33333%Ohio#Not really~Arizona#Wrong}
+ - 10 Tucson:{1:MCV:%0%California#Wrong~%33,33333%Ohio#Not really~=Arizona#OK}
+ - 11 Los Angeles:{1:MULTICHOICE_VS:=California#OK~%33.33333%Ohio#Not really~Arizona#Wrong}
+ - 12 Phoenix:{1:MCVS:%0%California#Wrong~%33,33333%Ohio#Not really~=Arizona#OK}
';
$q = qtype_multianswer_extract_question($questiontext);
@@ -339,6 +338,16 @@ class qtype_multianswer_test extends advanced_testcase {
} else if ($key == 9 || $key == 10 || $key == 11 || $key == 12) {
$this->assertSame($sub->layout, qtype_multichoice_base::LAYOUT_VERTICAL);
}
+ foreach ($sub->feedback as $key => $feedback) {
+ if ($feedback['text'] === 'OK') {
+ $this->assertEquals(1, $sub->fraction[$key]);
+ } else if ($feedback['text'] === 'Wrong') {
+ $this->assertEquals(0, $sub->fraction[$key]);
+ } else {
+ $this->assertEquals('Not really', $feedback['text']);
+ $this->assertEquals(0.3333333, $sub->fraction[$key]);
+ }
+ }
}
}
}