X7ROOT File Manager
Current Path:
/home/cbholdings/pasukulu/lib/tests
home
/
cbholdings
/
pasukulu
/
lib
/
tests
/
๐
..
๐
accesslib_has_capability_test.php
(29.72 KB)
๐
accesslib_test.php
(240.86 KB)
๐
adminlib_test.php
(4.29 KB)
๐
admintree_test.php
(18.01 KB)
๐
ajaxlib_test.php
(4.4 KB)
๐
analysers_test.php
(12.79 KB)
๐
analytics
๐
antivirus_test.php
(11.81 KB)
๐
authlib_test.php
(19.04 KB)
๐
behat
๐
behat_lib_test.php
(3.25 KB)
๐
blocklib_test.php
(36.13 KB)
๐
check_test.php
(1.77 KB)
๐
client_test.php
(4.34 KB)
๐
collator_test.php
(12.06 KB)
๐
completionlib_test.php
(84.19 KB)
๐
component_test.php
(44.1 KB)
๐
componentlib_test.php
(6.91 KB)
๐
configonlylib_test.php
(5.93 KB)
๐
content
๐
content_test.php
(4.77 KB)
๐
context
๐
context_block_test.php
(4.14 KB)
๐
context_helper_test.php
(22.27 KB)
๐
context_test.php
(3.38 KB)
๐
core_media_player_native_test.php
(6.4 KB)
๐
core_renderer_template_exploit_test.php
(16.56 KB)
๐
coverage.php
(3.55 KB)
๐
cron_test.php
(6.86 KB)
๐
csslib_test.php
(1.56 KB)
๐
csvclass_test.php
(5.62 KB)
๐
curl_security_helper_test.php
(14.79 KB)
๐
customcontext_test.php
(4.66 KB)
๐
dataformat_test.php
(3.74 KB)
๐
datalib_test.php
(48.36 KB)
๐
datalib_update_with_unique_index_test.php
(6.06 KB)
๐
date_legacy_test.php
(13.62 KB)
๐
date_test.php
(25.77 KB)
๐
db
๐
editorlib_test.php
(1.95 KB)
๐
encryption_test.php
(8.68 KB)
๐
environment_test.php
(8.49 KB)
๐
event
๐
event_course_module_instance_list_viewed.php
(2.54 KB)
๐
event_course_module_viewed.php
(3.14 KB)
๐
exporter_test.php
(11.26 KB)
๐
external
๐
externallib_test.php
(2.02 KB)
๐
filelib_test.php
(77.16 KB)
๐
filestorage_zip_archive_test.php
(2.55 KB)
๐
filetypes_test.php
(10.06 KB)
๐
filter_manager_test.php
(3.31 KB)
๐
filterlib_test.php
(36.76 KB)
๐
fixtures
๐
formslib_test.php
(39.94 KB)
๐
gdlib_test.php
(5.68 KB)
๐
googlelib_test.php
(1.6 KB)
๐
gradelib_test.php
(11.96 KB)
๐
grades_external_test.php
(15.04 KB)
๐
grading_external_test.php
(26.33 KB)
๐
graphlib_test.php
(4.61 KB)
๐
grouplib_test.php
(109.11 KB)
๐
h5p_clean_orphaned_records_task_test.php
(3.16 KB)
๐
html2text_test.php
(7.54 KB)
๐
html_writer_test.php
(9.65 KB)
๐
htmlpurifier_test.php
(23.01 KB)
๐
http_client_test.php
(14.94 KB)
๐
hub
๐
ip_utils_test.php
(14.13 KB)
๐
jquery_test.php
(1.58 KB)
๐
ldaplib_test.php
(17.73 KB)
๐
licenselib_test.php
(11.58 KB)
๐
lock
๐
lock_config_test.php
(3.47 KB)
๐
lock_test.php
(5.3 KB)
๐
markdown_test.php
(2.24 KB)
๐
mathslib_test.php
(13.42 KB)
๐
medialib_test.php
(19.63 KB)
๐
message_test.php
(12.25 KB)
๐
messageinbound_test.php
(5.96 KB)
๐
messagelib_test.php
(56.36 KB)
๐
minify_test.php
(3.12 KB)
๐
modinfolib_test.php
(54.43 KB)
๐
moodle_page_test.php
(31.59 KB)
๐
moodle_url_test.php
(15.64 KB)
๐
moodlelib_current_language_test.php
(7.68 KB)
๐
moodlelib_test.php
(237.46 KB)
๐
moodlenet
๐
myprofilelib_test.php
(12.36 KB)
๐
navigation
๐
navigationlib_test.php
(31.79 KB)
๐
notification_test.php
(4.35 KB)
๐
oauth2
๐
oauth2_test.php
(23.06 KB)
๐
other
๐
output
๐
outputcomponents_test.php
(33.25 KB)
๐
outputfactories_test.php
(6.78 KB)
๐
outputrenderers_test.php
(1.62 KB)
๐
outputrequirementslib_test.php
(16.29 KB)
๐
pdflib_test.php
(3.18 KB)
๐
performance
๐
persistent_test.php
(30.53 KB)
๐
phpxmlrpc_test.php
(2.04 KB)
๐
plugin_manager_test.php
(27.4 KB)
๐
plugininfo
๐
portfoliolib_test.php
(8.4 KB)
๐
progress_display_test.php
(3.75 KB)
๐
progress_test.php
(14.48 KB)
๐
qrcode_test.php
(1.68 KB)
๐
questionlib_test.php
(100.67 KB)
๐
regex_test.php
(1.55 KB)
๐
report_helper_test.php
(2.62 KB)
๐
requirejs_test.php
(2.22 KB)
๐
rsslib_test.php
(7.35 KB)
๐
rtlcss_test.php
(56.86 KB)
๐
sample_questions.ser
(141.76 KB)
๐
sample_questions.xml
(102.62 KB)
๐
sample_questions_with_old_image_tag.ser
(4.85 KB)
๐
sample_questions_with_old_image_tag.xml
(4.08 KB)
๐
sample_questions_wrong.xml
(102.57 KB)
๐
scss_test.php
(4.26 KB)
๐
session_manager_test.php
(34.79 KB)
๐
session_redis_test.php
(13.56 KB)
๐
sessionlib_test.php
(12.32 KB)
๐
setuplib_test.php
(20.17 KB)
๐
statslib_test.php
(26.68 KB)
๐
string_manager_standard_test.php
(10.18 KB)
๐
tablelib_test.php
(25.12 KB)
๐
task
๐
text_test.php
(26.53 KB)
๐
theme_config_test.php
(9.94 KB)
๐
update_api_test.php
(6.62 KB)
๐
update_checker_test.php
(10.82 KB)
๐
update_code_manager_test.php
(8.88 KB)
๐
update_validator_test.php
(18.28 KB)
๐
upgrade_util_test.php
(5.32 KB)
๐
upgradelib_test.php
(69.6 KB)
๐
user_menu_test.php
(3.75 KB)
๐
user_test.php
(34.34 KB)
๐
useragent_test.php
(83.82 KB)
๐
weblib_format_text_test.php
(11.91 KB)
๐
weblib_test.php
(43.44 KB)
๐
xhprof_test.php
(3.14 KB)
๐
xhtml_container_stack_test.php
(4.05 KB)
๐
xmlize_test.php
(2.55 KB)
Editing: weblib_format_text_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/>. namespace core; /** * Unit tests for format_text defined in weblib.php. * * @package core * @category test * @copyright 2015 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU Public License */ class weblib_format_text_test extends \advanced_testcase { public function test_format_text_format_html() { $this->resetAfterTest(); filter_set_global_state('emoticon', TEXTFILTER_ON); $this->assertMatchesRegularExpression('~^<p><img class="icon emoticon" alt="smile" title="smile" ' . 'src="https://www.example.com/moodle/theme/image.php/_s/boost/core/1/s/smiley" /></p>$~', format_text('<p>:-)</p>', FORMAT_HTML)); } public function test_format_text_format_html_no_filters() { $this->resetAfterTest(); filter_set_global_state('emoticon', TEXTFILTER_ON); $this->assertEquals('<p>:-)</p>', format_text('<p>:-)</p>', FORMAT_HTML, array('filter' => false))); } public function test_format_text_format_plain() { // Note FORMAT_PLAIN does not filter ever, no matter we ask for filtering. $this->resetAfterTest(); filter_set_global_state('emoticon', TEXTFILTER_ON); $this->assertEquals(':-)', format_text(':-)', FORMAT_PLAIN)); } public function test_format_text_format_plain_no_filters() { $this->resetAfterTest(); filter_set_global_state('emoticon', TEXTFILTER_ON); $this->assertEquals(':-)', format_text(':-)', FORMAT_PLAIN, array('filter' => false))); } public function test_format_text_format_markdown() { $this->resetAfterTest(); filter_set_global_state('emoticon', TEXTFILTER_ON); $this->assertMatchesRegularExpression('~^<p><em><img class="icon emoticon" alt="smile" title="smile" ' . 'src="https://www.example.com/moodle/theme/image.php/_s/boost/core/1/s/smiley" />' . '</em></p>\n$~', format_text('*:-)*', FORMAT_MARKDOWN)); } public function test_format_text_format_markdown_nofilter() { $this->resetAfterTest(); filter_set_global_state('emoticon', TEXTFILTER_ON); $this->assertEquals("<p><em>:-)</em></p>\n", format_text('*:-)*', FORMAT_MARKDOWN, array('filter' => false))); } public function test_format_text_format_moodle() { $this->resetAfterTest(); filter_set_global_state('emoticon', TEXTFILTER_ON); $this->assertMatchesRegularExpression('~^<div class="text_to_html"><p>' . '<img class="icon emoticon" alt="smile" title="smile" ' . 'src="https://www.example.com/moodle/theme/image.php/_s/boost/core/1/s/smiley" /></p></div>$~', format_text('<p>:-)</p>', FORMAT_MOODLE)); } public function test_format_text_format_moodle_no_filters() { $this->resetAfterTest(); filter_set_global_state('emoticon', TEXTFILTER_ON); $this->assertEquals('<div class="text_to_html"><p>:-)</p></div>', format_text('<p>:-)</p>', FORMAT_MOODLE, array('filter' => false))); } public function test_format_text_overflowdiv() { $this->assertEquals('<div class="no-overflow"><p>Hello world</p></div>', format_text('<p>Hello world</p>', FORMAT_HTML, array('overflowdiv' => true))); } /** * Test adding blank target attribute to links * * @dataProvider format_text_blanktarget_testcases * @param string $link The link to add target="_blank" to * @param string $expected The expected filter value */ public function test_format_text_blanktarget($link, $expected) { $actual = format_text($link, FORMAT_MOODLE, array('blanktarget' => true, 'filter' => false, 'noclean' => true)); $this->assertEquals($expected, $actual); } /** * Data provider for the test_format_text_blanktarget testcase * * @return array of testcases */ public function format_text_blanktarget_testcases() { return [ 'Simple link' => [ '<a href="https://www.youtube.com/watch?v=JeimE8Wz6e4">Hey, that\'s pretty good!</a>', '<div class="text_to_html"><a href="https://www.youtube.com/watch?v=JeimE8Wz6e4" target="_blank"' . ' rel="noreferrer">Hey, that\'s pretty good!</a></div>' ], 'Link with rel' => [ '<a href="https://www.youtube.com/watch?v=JeimE8Wz6e4" rel="nofollow">Hey, that\'s pretty good!</a>', '<div class="text_to_html"><a href="https://www.youtube.com/watch?v=JeimE8Wz6e4" rel="nofollow noreferrer"' . ' target="_blank">Hey, that\'s pretty good!</a></div>' ], 'Link with rel noreferrer' => [ '<a href="https://www.youtube.com/watch?v=JeimE8Wz6e4" rel="noreferrer">Hey, that\'s pretty good!</a>', '<div class="text_to_html"><a href="https://www.youtube.com/watch?v=JeimE8Wz6e4" rel="noreferrer"' . ' target="_blank">Hey, that\'s pretty good!</a></div>' ], 'Link with target' => [ '<a href="https://www.youtube.com/watch?v=JeimE8Wz6e4" target="_self">Hey, that\'s pretty good!</a>', '<div class="text_to_html"><a href="https://www.youtube.com/watch?v=JeimE8Wz6e4" target="_self">' . 'Hey, that\'s pretty good!</a></div>' ], 'Link with target blank' => [ '<a href="https://www.youtube.com/watch?v=JeimE8Wz6e4" target="_blank">Hey, that\'s pretty good!</a>', '<div class="text_to_html"><a href="https://www.youtube.com/watch?v=JeimE8Wz6e4" target="_blank"' . ' rel="noreferrer">Hey, that\'s pretty good!</a></div>' ], 'Link with Frank\'s casket inscription' => [ '<a href="https://en.wikipedia.org/wiki/Franks_Casket">แ แแแณแซแ แแฉแแขแซแชแปแฉแ แฉแพแ แแฑแท แแพแแแฑแแท แนแชแฑแฆแทแชแฌแแฑแแณแทแฑแฉแฑแพแฆแซแฑแปแแฉแพแทแฑแแขแแทแแแนแฉแ แป' . 'แฑแฉแพแซแแแชแพ แแซแทแแ แแแณแซแ แแฉแแขแซแชแปแฉแ แฉแพแ แแฑแท แแพแแแฑแแท แนแชแฑแฆแทแชแฌแแฑแแณแทแฑแฉแฑแพแฆแซแฑแปแแฉแพแทแฑแแขแแทแแแนแฉแ แปแฑแฉแพแซแแแชแพ แแซแทแ</a>', '<div class="text_to_html"><a href="https://en.wikipedia.org/wiki/Franks_Casket" target="_blank" ' . 'rel="noreferrer">แ แแแณแซแ แแฉแแขแซแชแปแฉแ แฉแพแ แแฑแท แแพแแแฑแแท แนแชแฑแฆแทแชแฌแแฑแแณแทแฑแฉแฑแพแฆแซแฑแปแแฉแพแทแฑแแขแแทแแแนแฉแ แปแฑแฉแพแซแแแชแพ แแซแทแแ แแแณแซแ แแฉแแขแซแชแปแฉแ แฉแพแ แแฑแท แแพ' . 'แแแฑแแท แนแชแฑแฆแทแชแฌแแฑแแณแทแฑแฉแฑแพแฆแซแฑแปแแฉแพแทแฑแแขแแทแแแนแฉแ แปแฑแฉแพแซแแแชแพ แแซแทแ</a></div>' ], 'No link' => [ 'Some very boring text written with the Latin script', '<div class="text_to_html">Some very boring text written with the Latin script</div>' ], 'No link with Thror\'s map runes' => [ 'แแแซแพแ แแฃ แฆแ แทแฑแแฃ แแแฉแพแ แปแนแแแ แฆแ แฆแฑแขแแป แพแฉแณแ แซแพแ แฆแ แแแแแแพแท แแขแพ แนแแฆ แฆแ แแซแแ แแแทแปแ แฉแ แแขแฑแแพแ แแซแฃ แนแแแ แแปแแพแ แขแแฉแพ แฆแ แณแแฃแปแฉแแ', '<div class="text_to_html">แแแซแพแ แแฃ แฆแ แทแฑแแฃ แแแฉแพแ แปแนแแแ แฆแ แฆแฑแขแแป แพแฉแณแ แซแพแ แฆแ แแแแแแพแท แแขแพ แนแแฆ แฆแ แแซแแ แแแทแปแ แฉแ แแขแฑแแพแ แแซแฃ แน' . 'แแแ แแปแแพแ แขแแฉแพ แฆแ แณแแฃแปแฉแแ</div>' ] ]; } /** * Test ability to force cleaning of otherwise non-cleaned content. * * @dataProvider format_text_cleaning_testcases * * @param string $input Input text * @param string $nocleaned Expected output of format_text() with noclean=true * @param string $cleaned Expected output of format_text() with noclean=false */ public function test_format_text_cleaning($input, $nocleaned, $cleaned) { global $CFG; $this->resetAfterTest(); $CFG->forceclean = false; $actual = format_text($input, FORMAT_HTML, ['filter' => false, 'noclean' => false]); $this->assertEquals($cleaned, $actual); $CFG->forceclean = true; $actual = format_text($input, FORMAT_HTML, ['filter' => false, 'noclean' => false]); $this->assertEquals($cleaned, $actual); $CFG->forceclean = false; $actual = format_text($input, FORMAT_HTML, ['filter' => false, 'noclean' => true]); $this->assertEquals($nocleaned, $actual); $CFG->forceclean = true; $actual = format_text($input, FORMAT_HTML, ['filter' => false, 'noclean' => true]); $this->assertEquals($cleaned, $actual); } /** * Data provider for the test_format_text_cleaning testcase * * @return array of testcases (string)testcasename => [(string)input, (string)nocleaned, (string)cleaned] */ public function format_text_cleaning_testcases() { return [ 'JavaScript' => [ 'Hello <script type="text/javascript">alert("XSS");</script> world', 'Hello <script type="text/javascript">alert("XSS");</script> world', 'Hello world', ], 'Inline frames' => [ 'Let us go phishing! <iframe src="https://1.2.3.4/google.com"></iframe>', 'Let us go phishing! <iframe src="https://1.2.3.4/google.com"></iframe>', 'Let us go phishing! ', ], 'Malformed A tags' => [ '<a onmouseover="alert(document.cookie)">xxs link</a>', '<a onmouseover="alert(document.cookie)">xxs link</a>', '<a>xxs link</a>', ], 'Malformed IMG tags' => [ '<IMG """><SCRIPT>alert("XSS")</SCRIPT>">', '<IMG """><SCRIPT>alert("XSS")</SCRIPT>">', '">', ], 'On error alert' => [ '<IMG SRC=/ onerror="alert(String.fromCharCode(88,83,83))"></img>', '<IMG SRC=/ onerror="alert(String.fromCharCode(88,83,83))"></img>', '<img src="/" alt="" />', ], 'IMG onerror and javascript alert encode' => [ '<img src=x onerror="javascSS')">', '<img src=x onerror="javascSS')">', '<img src="x" alt="x" />', ], 'DIV background-image' => [ '<DIV STYLE="background-image: url(javascript:alert(\'XSS\'))">', '<DIV STYLE="background-image: url(javascript:alert(\'XSS\'))">', '<div></div>', ], ]; } }
Upload File
Create Folder