mirror of
https://github.com/moodle/moodle.git
synced 2025-03-13 04:01:40 +01:00
Merge branch 'MDL-40267-master' of git://github.com/danpoltawski/moodle
This commit is contained in:
commit
792eeb0053
@ -36,7 +36,7 @@ class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule
|
||||
*/
|
||||
function validate($value, $options = null)
|
||||
{
|
||||
$length = strlen($value);
|
||||
$length = core_text::strlen($value);
|
||||
switch ($this->name) {
|
||||
case 'minlength': return ($length >= $options);
|
||||
case 'maxlength': return ($length <= $options);
|
||||
@ -61,4 +61,4 @@ class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule
|
||||
} // end func getValidationScript
|
||||
|
||||
} // end class HTML_QuickForm_Rule_Range
|
||||
?>
|
||||
?>
|
||||
|
@ -20,4 +20,4 @@ Full of our custom hacks, no way to upgrade to latest upstream.
|
||||
Most probably we will stop using this library in the future.
|
||||
|
||||
MDL-20876 - replaced split() with explode() or preg_split() where appropriate
|
||||
|
||||
MDL-40267 - Moodle core_text strlen functions used for range rule rule to be utf8 safe.
|
||||
|
@ -121,6 +121,89 @@ class core_formslib_testcase extends advanced_testcase {
|
||||
}
|
||||
}
|
||||
|
||||
public function test_range_rule() {
|
||||
global $CFG;
|
||||
|
||||
require_once('HTML/QuickForm/Rule/Range.php'); // Requires this pear stuff.
|
||||
|
||||
$strictformsrequired = null;
|
||||
if (isset($CFG->strictformsrequired)) {
|
||||
$strictformsrequired = $CFG->strictformsrequired;
|
||||
}
|
||||
|
||||
$rule = new HTML_QuickForm_Rule_Range();
|
||||
|
||||
// First run the tests with strictformsrequired off.
|
||||
$CFG->strictformsrequired = false;
|
||||
// Passes.
|
||||
$rule->setName('minlength'); // Let's verify some min lengths.
|
||||
$this->assertTrue($rule->validate('12', 2));
|
||||
$this->assertTrue($rule->validate('123', 2));
|
||||
$this->assertTrue($rule->validate('áé', 2));
|
||||
$this->assertTrue($rule->validate('áéí', 2));
|
||||
$rule->setName('maxlength'); // Let's verify some max lengths.
|
||||
$this->assertTrue($rule->validate('1', 2));
|
||||
$this->assertTrue($rule->validate('12', 2));
|
||||
$this->assertTrue($rule->validate('á', 2));
|
||||
$this->assertTrue($rule->validate('áé', 2));
|
||||
$rule->setName('----'); // Let's verify some ranges.
|
||||
$this->assertTrue($rule->validate('', array(0, 2)));
|
||||
$this->assertTrue($rule->validate('1', array(0, 2)));
|
||||
$this->assertTrue($rule->validate('12', array(0, 2)));
|
||||
$this->assertTrue($rule->validate('á', array(0, 2)));
|
||||
$this->assertTrue($rule->validate('áé', array(0, 2)));
|
||||
|
||||
// Fail.
|
||||
$rule->setName('minlength'); // Let's verify some min lengths.
|
||||
$this->assertFalse($rule->validate('', 2));
|
||||
$this->assertFalse($rule->validate('1', 2));
|
||||
$this->assertFalse($rule->validate('á', 2));
|
||||
$rule->setName('maxlength'); // Let's verify some max lengths.
|
||||
$this->assertFalse($rule->validate('123', 2));
|
||||
$this->assertFalse($rule->validate('áéí', 2));
|
||||
$rule->setName('----'); // Let's verify some ranges.
|
||||
$this->assertFalse($rule->validate('', array(1, 2)));
|
||||
$this->assertFalse($rule->validate('123', array(1, 2)));
|
||||
$this->assertFalse($rule->validate('áéí', array(1, 2)));
|
||||
|
||||
// Now run the same tests with it on to make sure things work as expected.
|
||||
$CFG->strictformsrequired = true;
|
||||
// Passes.
|
||||
$rule->setName('minlength'); // Let's verify some min lengths.
|
||||
$this->assertTrue($rule->validate('12', 2));
|
||||
$this->assertTrue($rule->validate('123', 2));
|
||||
$this->assertTrue($rule->validate('áé', 2));
|
||||
$this->assertTrue($rule->validate('áéí', 2));
|
||||
$rule->setName('maxlength'); // Let's verify some min lengths.
|
||||
$this->assertTrue($rule->validate('1', 2));
|
||||
$this->assertTrue($rule->validate('12', 2));
|
||||
$this->assertTrue($rule->validate('á', 2));
|
||||
$this->assertTrue($rule->validate('áé', 2));
|
||||
$rule->setName('----'); // Let's verify some ranges.
|
||||
$this->assertTrue($rule->validate('', array(0, 2)));
|
||||
$this->assertTrue($rule->validate('1', array(0, 2)));
|
||||
$this->assertTrue($rule->validate('12', array(0, 2)));
|
||||
$this->assertTrue($rule->validate('á', array(0, 2)));
|
||||
$this->assertTrue($rule->validate('áé', array(0, 2)));
|
||||
|
||||
// Fail.
|
||||
$rule->setName('minlength'); // Let's verify some min lengths.
|
||||
$this->assertFalse($rule->validate('', 2));
|
||||
$this->assertFalse($rule->validate('1', 2));
|
||||
$this->assertFalse($rule->validate('á', 2));
|
||||
$rule->setName('maxlength'); // Let's verify some min lengths.
|
||||
$this->assertFalse($rule->validate('123', 2));
|
||||
$this->assertFalse($rule->validate('áéí', 2));
|
||||
$rule->setName('----'); // Let's verify some ranges.
|
||||
$this->assertFalse($rule->validate('', array(1, 2)));
|
||||
$this->assertFalse($rule->validate('123', array(1, 2)));
|
||||
$this->assertFalse($rule->validate('áéí', array(1, 2)));
|
||||
|
||||
if (isset($strictformsrequired)) {
|
||||
$CFG->strictformsrequired = $strictformsrequired;
|
||||
}
|
||||
}
|
||||
|
||||
public function test_generate_id_select() {
|
||||
$el = new MoodleQuickForm_select('choose_one', 'Choose one',
|
||||
array(1 => 'One', '2' => 'Two'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user