MDL-31594 question manual grading: did not handle comma as decimal.
This commit is contained in:
@@ -884,10 +884,10 @@ class question_attempt {
|
||||
case self::PARAM_MARK:
|
||||
// Special case to work around PARAM_NUMBER converting '' to 0.
|
||||
$mark = $this->get_submitted_var($name, PARAM_RAW_TRIMMED, $postdata);
|
||||
if ($mark === '') {
|
||||
if ($mark === '' || is_null($mark)) {
|
||||
return $mark;
|
||||
} else {
|
||||
return $this->get_submitted_var($name, PARAM_NUMBER, $postdata);
|
||||
return clean_param(str_replace(',', '.', $mark), PARAM_NUMBER);
|
||||
}
|
||||
|
||||
case self::PARAM_FILES:
|
||||
|
||||
@@ -123,6 +123,16 @@ class question_attempt_test extends UnitTestCase {
|
||||
'name', question_attempt::PARAM_MARK, array('name' => '123')));
|
||||
}
|
||||
|
||||
public function test_get_submitted_var_param_mark_number_uk_decimal() {
|
||||
$this->assertIdentical(123.45, $this->qa->get_submitted_var(
|
||||
'name', question_attempt::PARAM_MARK, array('name' => '123.45')));
|
||||
}
|
||||
|
||||
public function test_get_submitted_var_param_mark_number_eu_decimal() {
|
||||
$this->assertIdentical(123.45, $this->qa->get_submitted_var(
|
||||
'name', question_attempt::PARAM_MARK, array('name' => '123,45')));
|
||||
}
|
||||
|
||||
public function test_get_submitted_var_param_mark_invalid() {
|
||||
$this->assertIdentical(0.0, $this->qa->get_submitted_var(
|
||||
'name', question_attempt::PARAM_MARK, array('name' => 'frog')));
|
||||
|
||||
Reference in New Issue
Block a user