| Línea 48... |
Línea 48... |
| 48 |
* @copyright 2011 Sam Hemelryk
|
48 |
* @copyright 2011 Sam Hemelryk
|
| 49 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
49 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 50 |
*/
|
50 |
*/
|
| 51 |
class formslib_test extends \advanced_testcase {
|
51 |
class formslib_test extends \advanced_testcase {
|
| Línea 52... |
Línea 52... |
| 52 |
|
52 |
|
| 53 |
public function test_require_rule() {
|
53 |
public function test_require_rule(): void {
|
| Línea 54... |
Línea 54... |
| 54 |
global $CFG;
|
54 |
global $CFG;
|
| 55 |
|
55 |
|
| 56 |
$strictformsrequired = null;
|
56 |
$strictformsrequired = null;
|
| Línea 139... |
Línea 139... |
| 139 |
if (isset($strictformsrequired)) {
|
139 |
if (isset($strictformsrequired)) {
|
| 140 |
$CFG->strictformsrequired = $strictformsrequired;
|
140 |
$CFG->strictformsrequired = $strictformsrequired;
|
| 141 |
}
|
141 |
}
|
| 142 |
}
|
142 |
}
|
| Línea 143... |
Línea 143... |
| 143 |
|
143 |
|
| 144 |
public function test_range_rule() {
|
144 |
public function test_range_rule(): void {
|
| Línea 145... |
Línea 145... |
| 145 |
global $CFG;
|
145 |
global $CFG;
|
| Línea 146... |
Línea 146... |
| 146 |
|
146 |
|
| Línea 222... |
Línea 222... |
| 222 |
if (isset($strictformsrequired)) {
|
222 |
if (isset($strictformsrequired)) {
|
| 223 |
$CFG->strictformsrequired = $strictformsrequired;
|
223 |
$CFG->strictformsrequired = $strictformsrequired;
|
| 224 |
}
|
224 |
}
|
| 225 |
}
|
225 |
}
|
| Línea 226... |
Línea 226... |
| 226 |
|
226 |
|
| 227 |
public function test_generate_id_select() {
|
227 |
public function test_generate_id_select(): void {
|
| 228 |
$el = new MoodleQuickForm_select('choose_one', 'Choose one',
|
228 |
$el = new MoodleQuickForm_select('choose_one', 'Choose one',
|
| 229 |
array(1 => 'One', '2' => 'Two'));
|
229 |
array(1 => 'One', '2' => 'Two'));
|
| 230 |
$el->_generateId();
|
230 |
$el->_generateId();
|
| 231 |
$this->assertSame('id_choose_one', $el->getAttribute('id'));
|
231 |
$this->assertSame('id_choose_one', $el->getAttribute('id'));
|
| Línea 232... |
Línea 232... |
| 232 |
}
|
232 |
}
|
| 233 |
|
233 |
|
| 234 |
public function test_generate_id_like_repeat() {
|
234 |
public function test_generate_id_like_repeat(): void {
|
| 235 |
$el = new MoodleQuickForm_text('text[7]', 'Type something');
|
235 |
$el = new MoodleQuickForm_text('text[7]', 'Type something');
|
| 236 |
$el->_generateId();
|
236 |
$el->_generateId();
|
| Línea 237... |
Línea 237... |
| 237 |
$this->assertSame('id_text_7', $el->getAttribute('id'));
|
237 |
$this->assertSame('id_text_7', $el->getAttribute('id'));
|
| 238 |
}
|
238 |
}
|
| 239 |
|
239 |
|
| 240 |
public function test_can_manually_set_id() {
|
240 |
public function test_can_manually_set_id(): void {
|
| 241 |
$el = new MoodleQuickForm_text('elementname', 'Type something',
|
241 |
$el = new MoodleQuickForm_text('elementname', 'Type something',
|
| 242 |
array('id' => 'customelementid'));
|
242 |
array('id' => 'customelementid'));
|
| Línea 243... |
Línea 243... |
| 243 |
$el->_generateId();
|
243 |
$el->_generateId();
|
| 244 |
$this->assertSame('customelementid', $el->getAttribute('id'));
|
244 |
$this->assertSame('customelementid', $el->getAttribute('id'));
|
| 245 |
}
|
245 |
}
|
| 246 |
|
246 |
|
| 247 |
public function test_generate_id_radio() {
|
247 |
public function test_generate_id_radio(): void {
|
| Línea 248... |
Línea 248... |
| 248 |
$el = new MoodleQuickForm_radio('radio', 'Label', 'Choice label', 'choice_value');
|
248 |
$el = new MoodleQuickForm_radio('radio', 'Label', 'Choice label', 'choice_value');
|
| 249 |
$el->_generateId();
|
249 |
$el->_generateId();
|
| 250 |
$this->assertSame('id_radio_choice_value', $el->getAttribute('id'));
|
250 |
$this->assertSame('id_radio_choice_value', $el->getAttribute('id'));
|
| 251 |
}
|
251 |
}
|
| 252 |
|
252 |
|
| 253 |
public function test_radio_can_manually_set_id() {
|
253 |
public function test_radio_can_manually_set_id(): void {
|
| Línea 254... |
Línea 254... |
| 254 |
$el = new MoodleQuickForm_radio('radio2', 'Label', 'Choice label', 'choice_value',
|
254 |
$el = new MoodleQuickForm_radio('radio2', 'Label', 'Choice label', 'choice_value',
|
| 255 |
array('id' => 'customelementid2'));
|
255 |
array('id' => 'customelementid2'));
|
| 256 |
$el->_generateId();
|
256 |
$el->_generateId();
|
| 257 |
$this->assertSame('customelementid2', $el->getAttribute('id'));
|
257 |
$this->assertSame('customelementid2', $el->getAttribute('id'));
|
| 258 |
}
|
258 |
}
|
| Línea 259... |
Línea 259... |
| 259 |
|
259 |
|
| 260 |
public function test_generate_id_radio_like_repeat() {
|
260 |
public function test_generate_id_radio_like_repeat(): void {
|
| 261 |
$el = new MoodleQuickForm_radio('repeatradio[2]', 'Label', 'Choice label', 'val');
|
261 |
$el = new MoodleQuickForm_radio('repeatradio[2]', 'Label', 'Choice label', 'val');
|
| 262 |
$el->_generateId();
|
262 |
$el->_generateId();
|
| 263 |
$this->assertSame('id_repeatradio_2_val', $el->getAttribute('id'));
|
263 |
$this->assertSame('id_repeatradio_2_val', $el->getAttribute('id'));
|
| Línea 292... |
Línea 292... |
| 292 |
|
292 |
|
| 293 |
$this->assertTag(array('tag'=>'input', 'id'=>'id_repeatradio_2_2',
|
293 |
$this->assertTag(array('tag'=>'input', 'id'=>'id_repeatradio_2_2',
|
| 294 |
'attributes'=>array('type'=>'radio', 'name'=>'repeatradio[2]', 'value'=>'2')), $html);
|
294 |
'attributes'=>array('type'=>'radio', 'name'=>'repeatradio[2]', 'value'=>'2')), $html);
|
| Línea 295... |
Línea 295... |
| 295 |
}
|
295 |
}
|
| 296 |
|
296 |
|
| 297 |
public function test_settype_debugging_text() {
|
297 |
public function test_settype_debugging_text(): void {
|
| Línea 298... |
Línea 298... |
| 298 |
$mform = new formslib_settype_debugging_text();
|
298 |
$mform = new formslib_settype_debugging_text();
|
| 299 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'texttest'? Defaulting to PARAM_RAW cleaning.");
|
299 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'texttest'? Defaulting to PARAM_RAW cleaning.");
|
| 300 |
|
300 |
|
| 301 |
// Check form still there though.
|
301 |
// Check form still there though.
|
| Línea 302... |
Línea 302... |
| 302 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="texttest/');
|
302 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="texttest/');
|
| 303 |
$mform->display();
|
303 |
$mform->display();
|
| 304 |
}
|
304 |
}
|
| Línea 305... |
Línea 305... |
| 305 |
|
305 |
|
| 306 |
public function test_settype_debugging_hidden() {
|
306 |
public function test_settype_debugging_hidden(): void {
|
| 307 |
$mform = new formslib_settype_debugging_hidden();
|
307 |
$mform = new formslib_settype_debugging_hidden();
|
| 308 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'hiddentest'? Defaulting to PARAM_RAW cleaning.");
|
308 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'hiddentest'? Defaulting to PARAM_RAW cleaning.");
|
| Línea 309... |
Línea 309... |
| 309 |
|
309 |
|
| 310 |
// Check form still there though.
|
310 |
// Check form still there though.
|
| 311 |
$this->expectOutputRegex('/<input[^>]*name="hiddentest[^>]*type="hidden/');
|
311 |
$this->expectOutputRegex('/<input[^>]*name="hiddentest[^>]*type="hidden/');
|
| 312 |
$mform->display();
|
312 |
$mform->display();
|
| 313 |
}
|
313 |
}
|
| Línea 314... |
Línea 314... |
| 314 |
|
314 |
|
| 315 |
public function test_settype_debugging_url() {
|
315 |
public function test_settype_debugging_url(): void {
|
| 316 |
$this->resetAfterTest(true);
|
316 |
$this->resetAfterTest(true);
|
| 317 |
$this->setAdminUser();
|
317 |
$this->setAdminUser();
|
| Línea 318... |
Línea 318... |
| 318 |
$mform = new formslib_settype_debugging_url();
|
318 |
$mform = new formslib_settype_debugging_url();
|
| 319 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'urltest'? Defaulting to PARAM_RAW cleaning.");
|
319 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'urltest'? Defaulting to PARAM_RAW cleaning.");
|
| 320 |
|
320 |
|
| Línea 321... |
Línea 321... |
| 321 |
// Check form still there though.
|
321 |
// Check form still there though.
|
| 322 |
$this->expectOutputRegex('/<input[^>]*type="url[^>]*name="urltest"/');
|
322 |
$this->expectOutputRegex('/<input[^>]*type="url[^>]*name="urltest"/');
|
| 323 |
$mform->display();
|
323 |
$mform->display();
|
| 324 |
}
|
324 |
}
|
| Línea 325... |
Línea 325... |
| 325 |
|
325 |
|
| 326 |
public function test_settype_debugging_repeat() {
|
326 |
public function test_settype_debugging_repeat(): void {
|
| 327 |
$mform = new formslib_settype_debugging_repeat();
|
327 |
$mform = new formslib_settype_debugging_repeat();
|
| Línea 328... |
Línea 328... |
| 328 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'repeattest[0]'? Defaulting to PARAM_RAW cleaning.");
|
328 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'repeattest[0]'? Defaulting to PARAM_RAW cleaning.");
|
| 329 |
|
329 |
|
| 330 |
// Check form still there though.
|
330 |
// Check form still there though.
|
| Línea 331... |
Línea 331... |
| 331 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="repeattest/');
|
331 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="repeattest/');
|
| 332 |
$mform->display();
|
332 |
$mform->display();
|
| 333 |
}
|
333 |
}
|
| 334 |
|
334 |
|
| 335 |
public function test_settype_debugging_repeat_ok() {
|
335 |
public function test_settype_debugging_repeat_ok(): void {
|
| 336 |
$mform = new formslib_settype_debugging_repeat_ok();
|
336 |
$mform = new formslib_settype_debugging_repeat_ok();
|
| 337 |
// No debugging expected here.
|
337 |
// No debugging expected here.
|
| Línea 338... |
Línea 338... |
| 338 |
|
338 |
|
| 339 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="repeattest/');
|
339 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="repeattest/');
|
| 340 |
$mform->display();
|
340 |
$mform->display();
|
| 341 |
}
|
341 |
}
|
| 342 |
|
342 |
|
| 343 |
public function test_settype_debugging_group() {
|
343 |
public function test_settype_debugging_group(): void {
|
| 344 |
$mform = new formslib_settype_debugging_group();
|
344 |
$mform = new formslib_settype_debugging_group();
|
| Línea 345... |
Línea 345... |
| 345 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'groupel1'? Defaulting to PARAM_RAW cleaning.");
|
345 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'groupel1'? Defaulting to PARAM_RAW cleaning.");
|
| 346 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="groupel1"/');
|
346 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="groupel1"/');
|
| 347 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="groupel2"/');
|
347 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="groupel2"/');
|
| 348 |
$mform->display();
|
348 |
$mform->display();
|
| 349 |
}
|
349 |
}
|
| 350 |
|
350 |
|
| 351 |
public function test_settype_debugging_namedgroup() {
|
351 |
public function test_settype_debugging_namedgroup(): void {
|
| Línea 352... |
Línea 352... |
| 352 |
$mform = new formslib_settype_debugging_namedgroup();
|
352 |
$mform = new formslib_settype_debugging_namedgroup();
|
| 353 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'namedgroup[groupel1]'? Defaulting to PARAM_RAW cleaning.");
|
353 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'namedgroup[groupel1]'? Defaulting to PARAM_RAW cleaning.");
|
| 354 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="namedgroup\[groupel1\]"/');
|
354 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="namedgroup\[groupel1\]"/');
|
| 355 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="namedgroup\[groupel2\]"/');
|
355 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="namedgroup\[groupel2\]"/');
|
| 356 |
$mform->display();
|
356 |
$mform->display();
|
| 357 |
}
|
357 |
}
|
| 358 |
|
358 |
|
| Línea 359... |
Línea 359... |
| 359 |
public function test_settype_debugging_funky_name() {
|
359 |
public function test_settype_debugging_funky_name(): void {
|
| 360 |
$mform = new formslib_settype_debugging_funky_name();
|
360 |
$mform = new formslib_settype_debugging_funky_name();
|
| 361 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'blah[foo][bar][1]'? Defaulting to PARAM_RAW cleaning.");
|
361 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'blah[foo][bar][1]'? Defaulting to PARAM_RAW cleaning.");
|
| 362 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[foo\]\[bar\]\[0\]"/');
|
362 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[foo\]\[bar\]\[0\]"/');
|
| 363 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[foo\]\[bar\]\[1\]"/');
|
363 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[foo\]\[bar\]\[1\]"/');
|
| 364 |
$mform->display();
|
364 |
$mform->display();
|
| 365 |
}
|
365 |
}
|
| Línea 366... |
Línea 366... |
| 366 |
|
366 |
|
| 367 |
public function test_settype_debugging_type_inheritance() {
|
367 |
public function test_settype_debugging_type_inheritance(): void {
|
| 368 |
$mform = new formslib_settype_debugging_type_inheritance();
|
368 |
$mform = new formslib_settype_debugging_type_inheritance();
|
| 369 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[foo\]\[bar\]\[0\]"/');
|
369 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[foo\]\[bar\]\[0\]"/');
|
| 370 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[bar\]\[foo\]\[1\]"/');
|
370 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[bar\]\[foo\]\[1\]"/');
|
| 371 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[any\]\[other\]\[2\]"/');
|
371 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[any\]\[other\]\[2\]"/');
|
| 372 |
$mform->display();
|
372 |
$mform->display();
|
| Línea 373... |
Línea 373... |
| 373 |
}
|
373 |
}
|
| 374 |
|
374 |
|
| 375 |
public function test_settype_debugging_type_group_in_repeat() {
|
375 |
public function test_settype_debugging_type_group_in_repeat(): void {
|
| 376 |
$mform = new formslib_settype_debugging_type_group_in_repeat();
|
376 |
$mform = new formslib_settype_debugging_type_group_in_repeat();
|
| 377 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'test2[0]'? Defaulting to PARAM_RAW cleaning.");
|
377 |
$this->assertDebuggingCalled("Did you remember to call setType() for 'test2[0]'? Defaulting to PARAM_RAW cleaning.");
|
| 378 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="test1\[0\]"/');
|
378 |
$this->expectOutputRegex('/<input[^>]*type="text[^>]*name="test1\[0\]"/');
|
| Línea 568... |
Línea 568... |
| 568 |
}
|
568 |
}
|
| Línea 569... |
Línea 569... |
| 569 |
|
569 |
|
| 570 |
/**
|
570 |
/**
|
| 571 |
* MDL-52873
|
571 |
* MDL-52873
|
| 572 |
*/
|
572 |
*/
|
| 573 |
public function test_multiple_modgrade_fields() {
|
573 |
public function test_multiple_modgrade_fields(): void {
|
| 574 |
global $CFG;
|
574 |
global $CFG;
|
| Línea 575... |
Línea 575... |
| 575 |
$this->resetAfterTest(true);
|
575 |
$this->resetAfterTest(true);
|
| 576 |
|
576 |
|
| Línea 597... |
Línea 597... |
| 597 |
}
|
597 |
}
|
| Línea 598... |
Línea 598... |
| 598 |
|
598 |
|
| 599 |
/**
|
599 |
/**
|
| 600 |
* Test persistant freeze elements have different id's.
|
600 |
* Test persistant freeze elements have different id's.
|
| 601 |
*/
|
601 |
*/
|
| 602 |
public function test_persistantrreeze_element() {
|
602 |
public function test_persistantrreeze_element(): void {
|
| 603 |
global $CFG;
|
603 |
global $CFG;
|
| 604 |
$this->resetAfterTest(true);
|
604 |
$this->resetAfterTest(true);
|
| Línea 605... |
Línea 605... |
| 605 |
$CFG->theme = 'classic';
|
605 |
$CFG->theme = 'classic';
|
| Línea 625... |
Línea 625... |
| 625 |
}
|
625 |
}
|
| Línea 626... |
Línea 626... |
| 626 |
|
626 |
|
| 627 |
/**
|
627 |
/**
|
| 628 |
* Ensure a validation can run at least once per object. See MDL-56259.
|
628 |
* Ensure a validation can run at least once per object. See MDL-56259.
|
| 629 |
*/
|
629 |
*/
|
| 630 |
public function test_multiple_validation() {
|
630 |
public function test_multiple_validation(): void {
|
| Línea 631... |
Línea 631... |
| 631 |
$this->resetAfterTest(true);
|
631 |
$this->resetAfterTest(true);
|
| 632 |
|
632 |
|
| 633 |
// It should be valid.
|
633 |
// It should be valid.
|
| Línea 644... |
Línea 644... |
| 644 |
}
|
644 |
}
|
| Línea 645... |
Línea 645... |
| 645 |
|
645 |
|
| 646 |
/**
|
646 |
/**
|
| 647 |
* MDL-56233 - Tests mocking a form inside a namespace.
|
647 |
* MDL-56233 - Tests mocking a form inside a namespace.
|
| 648 |
*/
|
648 |
*/
|
| 649 |
public function test_mock_submit() {
|
649 |
public function test_mock_submit(): void {
|
| 650 |
require_once(__DIR__.'/fixtures/namespaced_form.php');
|
650 |
require_once(__DIR__.'/fixtures/namespaced_form.php');
|
| 651 |
\local_unittests\namespaced_form\exampleform::mock_submit(['title' => 'Mocked Value']);
|
651 |
\local_unittests\namespaced_form\exampleform::mock_submit(['title' => 'Mocked Value']);
|
| Línea 652... |
Línea 652... |
| 652 |
$form = new \local_unittests\namespaced_form\exampleform();
|
652 |
$form = new \local_unittests\namespaced_form\exampleform();
|