mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
Merge branch 'MDL-38885-master-int' of git://github.com/FMCorz/moodle
This commit is contained in:
commit
da2cff35c5
2 changed files with 407 additions and 31 deletions
|
@ -209,9 +209,20 @@ class formslib_testcase extends advanced_testcase {
|
|||
$mform->display();
|
||||
}
|
||||
|
||||
public function test_settype_debugging_url() {
|
||||
$this->resetAfterTest(true);
|
||||
$this->setAdminUser();
|
||||
$mform = new formslib_settype_debugging_url();
|
||||
$this->assertDebuggingCalled("Did you remember to call setType() for 'urltest'? Defaulting to PARAM_RAW cleaning.");
|
||||
|
||||
// Check form still there though
|
||||
$this->expectOutputRegex('/<input[^>]*name="urltest"[^>]*type="text/');
|
||||
$mform->display();
|
||||
}
|
||||
|
||||
public function test_settype_debugging_repeat() {
|
||||
$mform = new formslib_settype_debugging_repeat();
|
||||
$this->assertDebuggingCalled("Did you remember to call setType() for 'repeattest'? Defaulting to PARAM_RAW cleaning.");
|
||||
$this->assertDebuggingCalled("Did you remember to call setType() for 'repeattest[0]'? Defaulting to PARAM_RAW cleaning.");
|
||||
|
||||
// Check form still there though
|
||||
$this->expectOutputRegex('/<input[^>]*name="repeattest[^>]*type="text/');
|
||||
|
@ -225,6 +236,161 @@ class formslib_testcase extends advanced_testcase {
|
|||
$this->expectOutputRegex('/<input[^>]*name="repeattest[^>]*type="text/');
|
||||
$mform->display();
|
||||
}
|
||||
|
||||
public function test_settype_debugging_group() {
|
||||
$mform = new formslib_settype_debugging_group();
|
||||
$this->assertDebuggingCalled("Did you remember to call setType() for 'groupel1'? Defaulting to PARAM_RAW cleaning.");
|
||||
$this->expectOutputRegex('/<input[^>]*name="groupel1"[^>]*type="text/');
|
||||
$this->expectOutputRegex('/<input[^>]*name="groupel2"[^>]*type="text/');
|
||||
$mform->display();
|
||||
}
|
||||
|
||||
public function test_settype_debugging_namedgroup() {
|
||||
$mform = new formslib_settype_debugging_namedgroup();
|
||||
$this->assertDebuggingCalled("Did you remember to call setType() for 'namedgroup[groupel1]'? Defaulting to PARAM_RAW cleaning.");
|
||||
$this->expectOutputRegex('/<input[^>]*name="namedgroup\[groupel1\]"[^>]*type="text/');
|
||||
$this->expectOutputRegex('/<input[^>]*name="namedgroup\[groupel2\]"[^>]*type="text/');
|
||||
$mform->display();
|
||||
}
|
||||
|
||||
public function test_settype_debugging_funky_name() {
|
||||
$mform = new formslib_settype_debugging_funky_name();
|
||||
$this->assertDebuggingCalled("Did you remember to call setType() for 'blah[foo][bar][1]'? Defaulting to PARAM_RAW cleaning.");
|
||||
$this->expectOutputRegex('/<input[^>]*name="blah\[foo\]\[bar\]\[0\]"[^>]*type="text/');
|
||||
$this->expectOutputRegex('/<input[^>]*name="blah\[foo\]\[bar\]\[1\]"[^>]*type="text/');
|
||||
$mform->display();
|
||||
}
|
||||
|
||||
public function test_settype_debugging_type_inheritance() {
|
||||
$mform = new formslib_settype_debugging_type_inheritance();
|
||||
$this->expectOutputRegex('/<input[^>]*name="blah\[foo\]\[bar\]\[0\]"[^>]*type="text/');
|
||||
$this->expectOutputRegex('/<input[^>]*name="blah\[bar\]\[foo\]\[1\]"[^>]*type="text/');
|
||||
$this->expectOutputRegex('/<input[^>]*name="blah\[any\]\[other\]\[2\]"[^>]*type="text/');
|
||||
$mform->display();
|
||||
}
|
||||
|
||||
public function test_type_cleaning() {
|
||||
$expectedtypes = array(
|
||||
'simpleel' => PARAM_INT,
|
||||
'groupel1' => PARAM_INT,
|
||||
'groupel2' => PARAM_FLOAT,
|
||||
'groupel3' => PARAM_INT,
|
||||
'namedgroup' => array(
|
||||
'sndgroupel1' => PARAM_INT,
|
||||
'sndgroupel2' => PARAM_FLOAT,
|
||||
'sndgroupel3' => PARAM_INT
|
||||
),
|
||||
'namedgroupinherit' => array(
|
||||
'thdgroupel1' => PARAM_INT,
|
||||
'thdgroupel2' => PARAM_INT
|
||||
),
|
||||
'repeatedel' => array(
|
||||
0 => PARAM_INT,
|
||||
1 => PARAM_INT
|
||||
),
|
||||
'repeatedelinherit' => array(
|
||||
0 => PARAM_INT,
|
||||
1 => PARAM_INT
|
||||
),
|
||||
'squaretest' => array(
|
||||
0 => PARAM_INT
|
||||
),
|
||||
'nested' => array(
|
||||
0 => array(
|
||||
'bob' => array(
|
||||
123 => PARAM_INT,
|
||||
'foo' => PARAM_FLOAT
|
||||
),
|
||||
'xyz' => PARAM_RAW
|
||||
),
|
||||
1 => PARAM_INT
|
||||
)
|
||||
);
|
||||
$valuessubmitted = array(
|
||||
'simpleel' => '11.01',
|
||||
'groupel1' => '11.01',
|
||||
'groupel2' => '11.01',
|
||||
'groupel3' => '11.01',
|
||||
'namedgroup' => array(
|
||||
'sndgroupel1' => '11.01',
|
||||
'sndgroupel2' => '11.01',
|
||||
'sndgroupel3' => '11.01'
|
||||
),
|
||||
'namedgroupinherit' => array(
|
||||
'thdgroupel1' => '11.01',
|
||||
'thdgroupel2' => '11.01'
|
||||
),
|
||||
'repeatedel' => array(
|
||||
0 => '11.01',
|
||||
1 => '11.01'
|
||||
),
|
||||
'repeatedelinherit' => array(
|
||||
0 => '11.01',
|
||||
1 => '11.01'
|
||||
),
|
||||
'squaretest' => array(
|
||||
0 => '11.01'
|
||||
),
|
||||
'nested' => array(
|
||||
0 => array(
|
||||
'bob' => array(
|
||||
123 => '11.01',
|
||||
'foo' => '11.01'
|
||||
),
|
||||
'xyz' => '11.01'
|
||||
),
|
||||
1 => '11.01'
|
||||
)
|
||||
);
|
||||
$expectedvalues = array(
|
||||
'simpleel' => 11,
|
||||
'groupel1' => 11,
|
||||
'groupel2' => 11.01,
|
||||
'groupel3' => 11,
|
||||
'namedgroup' => array(
|
||||
'sndgroupel1' => 11,
|
||||
'sndgroupel2' => 11.01,
|
||||
'sndgroupel3' => 11
|
||||
),
|
||||
'namedgroupinherit' => array(
|
||||
'thdgroupel1' => 11,
|
||||
'thdgroupel2' => 11
|
||||
),
|
||||
'repeatable' => 2,
|
||||
'repeatedel' => array(
|
||||
0 => 11,
|
||||
1 => 11
|
||||
),
|
||||
'repeatableinherit' => 2,
|
||||
'repeatedelinherit' => array(
|
||||
0 => 11,
|
||||
1 => 11
|
||||
),
|
||||
'squaretest' => array(
|
||||
0 => 11
|
||||
),
|
||||
'nested' => array(
|
||||
0 => array(
|
||||
'bob' => array(
|
||||
123 => 11,
|
||||
'foo' => 11.01
|
||||
),
|
||||
'xyz' => '11.01'
|
||||
),
|
||||
1 => 11
|
||||
)
|
||||
);
|
||||
|
||||
$mform = new formslib_clean_value();
|
||||
$mform->get_form()->updateSubmission($valuessubmitted, null);
|
||||
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->assertSame($expectedvalues, (array) $data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -277,6 +443,15 @@ class formslib_settype_debugging_hidden extends moodleform {
|
|||
}
|
||||
}
|
||||
|
||||
// Used to test debugging is called when hidden added without setType.
|
||||
class formslib_settype_debugging_url extends moodleform {
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
|
||||
$mform->addElement('url', 'urltest', 'urltest');
|
||||
}
|
||||
}
|
||||
|
||||
// Used to test debugging is called when repeated text added without setType.
|
||||
class formslib_settype_debugging_repeat extends moodleform {
|
||||
public function definition() {
|
||||
|
@ -302,3 +477,120 @@ class formslib_settype_debugging_repeat_ok extends moodleform {
|
|||
$this->repeat_elements($repeatels, 2, array('repeattest' => array('type' => PARAM_RAW)), 'numtexts', 'addtexts');
|
||||
}
|
||||
}
|
||||
|
||||
// Used to test if debugging is called when a group contains elements without type.
|
||||
class formslib_settype_debugging_group extends moodleform {
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
$group = array(
|
||||
$mform->createElement('text', 'groupel1', 'groupel1'),
|
||||
$mform->createElement('text', 'groupel2', 'groupel2')
|
||||
);
|
||||
$mform->addGroup($group);
|
||||
$mform->setType('groupel2', PARAM_INT);
|
||||
}
|
||||
}
|
||||
|
||||
// Used to test if debugging is called when a named group contains elements without type.
|
||||
class formslib_settype_debugging_namedgroup extends moodleform {
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
$group = array(
|
||||
$mform->createElement('text', 'groupel1', 'groupel1'),
|
||||
$mform->createElement('text', 'groupel2', 'groupel2')
|
||||
);
|
||||
$mform->addGroup($group, 'namedgroup');
|
||||
$mform->setType('namedgroup[groupel2]', PARAM_INT);
|
||||
}
|
||||
}
|
||||
|
||||
// Used to test if debugging is called when has a funky name.
|
||||
class formslib_settype_debugging_funky_name extends moodleform {
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
$mform->addElement('text', 'blah[foo][bar][0]', 'test', 'test');
|
||||
$mform->addElement('text', 'blah[foo][bar][1]', 'test', 'test');
|
||||
$mform->setType('blah[foo][bar][0]', PARAM_INT);
|
||||
}
|
||||
}
|
||||
|
||||
// Used to test that debugging is not called with type inheritance.
|
||||
class formslib_settype_debugging_type_inheritance extends moodleform {
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
$mform->addElement('text', 'blah[foo][bar][0]', 'test1', 'test');
|
||||
$mform->addElement('text', 'blah[bar][foo][1]', 'test2', 'test');
|
||||
$mform->addElement('text', 'blah[any][other][2]', 'test3', 'test');
|
||||
$mform->setType('blah[foo][bar]', PARAM_INT);
|
||||
$mform->setType('blah[bar]', PARAM_FLOAT);
|
||||
$mform->setType('blah', PARAM_TEXT);
|
||||
}
|
||||
}
|
||||
|
||||
class formslib_clean_value extends moodleform {
|
||||
public function get_form() {
|
||||
return $this->_form;
|
||||
}
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
|
||||
// Add a simple int.
|
||||
$mform->addElement('text', 'simpleel', 'simpleel');
|
||||
$mform->setType('simpleel', PARAM_INT);
|
||||
|
||||
// Add a non-named group.
|
||||
$group = array(
|
||||
$mform->createElement('text', 'groupel1', 'groupel1'),
|
||||
$mform->createElement('text', 'groupel2', 'groupel2'),
|
||||
$mform->createElement('text', 'groupel3', 'groupel3')
|
||||
);
|
||||
$mform->setType('groupel1', PARAM_INT);
|
||||
$mform->setType('groupel2', PARAM_FLOAT);
|
||||
$mform->setType('groupel3', PARAM_INT);
|
||||
$mform->addGroup($group);
|
||||
|
||||
// Add a named group.
|
||||
$group = array(
|
||||
$mform->createElement('text', 'sndgroupel1', 'sndgroupel1'),
|
||||
$mform->createElement('text', 'sndgroupel2', 'sndgroupel2'),
|
||||
$mform->createElement('text', 'sndgroupel3', 'sndgroupel3')
|
||||
);
|
||||
$mform->addGroup($group, 'namedgroup');
|
||||
$mform->setType('namedgroup[sndgroupel1]', PARAM_INT);
|
||||
$mform->setType('namedgroup[sndgroupel2]', PARAM_FLOAT);
|
||||
$mform->setType('namedgroup[sndgroupel3]', PARAM_INT);
|
||||
|
||||
// Add a named group, with inheritance.
|
||||
$group = array(
|
||||
$mform->createElement('text', 'thdgroupel1', 'thdgroupel1'),
|
||||
$mform->createElement('text', 'thdgroupel2', 'thdgroupel2')
|
||||
);
|
||||
$mform->addGroup($group, 'namedgroupinherit');
|
||||
$mform->setType('namedgroupinherit', PARAM_INT);
|
||||
|
||||
// Add a repetition.
|
||||
$repeat = $mform->createElement('text', 'repeatedel', 'repeatedel');
|
||||
$this->repeat_elements(array($repeat), 2, array('repeatedel' => array('type' => PARAM_INT)), 'repeatable', 'add', 0);
|
||||
|
||||
// Add a repetition, with inheritance.
|
||||
$repeat = $mform->createElement('text', 'repeatedelinherit', 'repeatedelinherit');
|
||||
$this->repeat_elements(array($repeat), 2, array(), 'repeatableinherit', 'add', 0);
|
||||
$mform->setType('repeatedelinherit', PARAM_INT);
|
||||
|
||||
// Add an arbitrary named element.
|
||||
$mform->addElement('text', 'squaretest[0]', 'squaretest[0]');
|
||||
$mform->setType('squaretest[0]', PARAM_INT);
|
||||
|
||||
// Add an arbitrary nested array named element.
|
||||
$mform->addElement('text', 'nested[0][bob][123]', 'nested[0][bob][123]');
|
||||
$mform->setType('nested[0][bob][123]', PARAM_INT);
|
||||
|
||||
// Add inheritance test cases.
|
||||
$mform->setType('nested', PARAM_INT);
|
||||
$mform->setType('nested[0]', PARAM_RAW);
|
||||
$mform->setType('nested[0][bob]', PARAM_FLOAT);
|
||||
$mform->addElement('text', 'nested[1]', 'nested[1]');
|
||||
$mform->addElement('text', 'nested[0][xyz]', 'nested[0][xyz]');
|
||||
$mform->addElement('text', 'nested[0][bob][foo]', 'nested[0][bob][foo]');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue