Skip to content
Browse files

MDL-38885 form: Fix comments and stricter unit test

  • Loading branch information...
1 parent 9d02feb commit d39925c792789230e628548ecff9ca34d0a74c16 @FMCorz FMCorz committed May 10, 2013
Showing with 9 additions and 8 deletions.
  1. +3 −2 lib/formslib.php
  2. +6 −6 lib/tests/formslib_test.php
View
5 lib/formslib.php
@@ -1520,10 +1520,11 @@ function setTypes($paramtypes) {
* 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) {
@@ -1568,7 +1569,7 @@ public function getCleanedValue($value, $type) {
} 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
12 lib/tests/formslib_test.php
@@ -278,16 +278,16 @@ public function test_type_cleaning() {
'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
),
@@ -305,13 +305,13 @@ public function test_type_cleaning() {
$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);
}
}

0 comments on commit d39925c

Please sign in to comment.
Something went wrong with that request. Please try again.