From e4e1bd900a2fb73e81d761bf8a5b9d2d162073d6 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Fri, 10 May 2013 08:34:59 +0800 Subject: [PATCH] MDL-38885 form: Fix comments and stricter unit test --- lib/formslib.php | 5 +++-- lib/tests/formslib_test.php | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/formslib.php b/lib/formslib.php index 5a2790a118b..9d46fe6a47c 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -1534,10 +1534,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) { @@ -1582,7 +1583,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; } diff --git a/lib/tests/formslib_test.php b/lib/tests/formslib_test.php index 06efc116c09..eab98a3f72a 100644 --- a/lib/tests/formslib_test.php +++ b/lib/tests/formslib_test.php @@ -278,16 +278,16 @@ class formslib_testcase extends basic_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 ), @@ -305,13 +305,13 @@ class formslib_testcase extends basic_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); } }