MDL-38885 form: Fix comments and stricter unit test

This commit is contained in:
Frederic Massart 2013-05-10 08:34:59 +08:00
parent a85f745d50
commit d5909fd144
2 changed files with 9 additions and 8 deletions

View File

@ -1711,10 +1711,11 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
* Now if you call this method passing 'foo', along with the submitted values of 'foo':
* array(0 => '1.23', 1 => '10'), you will get an array telling you that the key 0 is a
* FLOAT and 1 is an INT. If you had passed 'foo[1]', along with its value '10', you would
* get the default value returned.
* get the default clean type returned (param $default).
*
* @param string $elementname name of the element.
* @param mixed $value value that should be cleaned.
* @param int $default default constant value to be returned (PARAM_...)
* @return string|array constant value or array of constant values (PARAM_...)
*/
public function getCleanType($elementname, $value, $default = PARAM_RAW) {
@ -1759,7 +1760,7 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
} else if (!is_array($type) && is_array($value)) {
$value = clean_param_array($value, $type, true);
} else {
throw new coding_exception('Unexpected type or value received in MoodleQuickForm::cleanValue()');
throw new coding_exception('Unexpected type or value received in MoodleQuickForm::getCleanedValue()');
}
return $value;
}

View File

@ -356,16 +356,16 @@ class formslib_testcase extends advanced_testcase {
'thdgroupel1' => 11,
'thdgroupel2' => 11
),
'repeatable' => 2,
'repeatedel' => array(
0 => 11,
1 => 11
),
'repeatable' => 2,
'repeatableinherit' => 2,
'repeatedelinherit' => array(
0 => 11,
1 => 11
),
'repeatableinherit' => 2,
'squaretest' => array(
0 => 11
),
@ -383,13 +383,13 @@ class formslib_testcase extends advanced_testcase {
$mform = new formslib_clean_value();
$mform->get_form()->updateSubmission($valuessubmitted, null);
foreach ($expectedtypes as $elementname => $type) {
$expected = $mform->get_form()->getCleanType($elementname, $valuessubmitted[$elementname]);
$this->assertEquals($expected, $type, "Failed validating clean type of '$elementname'");
foreach ($expectedtypes as $elementname => $expected) {
$actual = $mform->get_form()->getCleanType($elementname, $valuessubmitted[$elementname]);
$this->assertSame($expected, $actual, "Failed validating clean type of '$elementname'");
}
$data = $mform->get_data();
$this->assertEquals($data, (object) $expectedvalues);
$this->assertSame($expectedvalues, (array) $data);
}
}