mirror of
https://github.com/moodle/moodle.git
synced 2025-05-03 06:48:46 +02:00
MDL-39915 cleanup core_htmlpurifier_testcase
This commit is contained in:
parent
c53adcaf46
commit
cd51a94441
@ -37,8 +37,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class core_htmlpurifier_testcase extends basic_testcase {
|
||||
|
||||
/**
|
||||
* Verify _blank target is allowed
|
||||
* @return void
|
||||
* Verify _blank target is allowed.
|
||||
*/
|
||||
public function test_allow_blank_target() {
|
||||
$text = '<a href="http://moodle.org" target="_blank">Some link</a>';
|
||||
@ -50,11 +49,10 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify our nolink tag accepted
|
||||
* @return void
|
||||
* Verify our nolink tag accepted.
|
||||
*/
|
||||
public function test_nolink() {
|
||||
// we can not use format text because nolink changes result
|
||||
// We can not use format text because nolink changes result.
|
||||
$text = '<nolink><div>no filters</div></nolink>';
|
||||
$result = purify_html($text, array());
|
||||
$this->assertSame($text, $result);
|
||||
@ -65,8 +63,7 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify our tex tag accepted
|
||||
* @return void
|
||||
* Verify our tex tag accepted.
|
||||
*/
|
||||
public function test_tex() {
|
||||
$text = '<tex>a+b=c</tex>';
|
||||
@ -75,8 +72,7 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify our algebra tag accepted
|
||||
* @return void
|
||||
* Verify our algebra tag accepted.
|
||||
*/
|
||||
public function test_algebra() {
|
||||
$text = '<algebra>a+b=c</algebra>';
|
||||
@ -85,8 +81,7 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify our hacky multilang works
|
||||
* @return void
|
||||
* Verify our hacky multilang works.
|
||||
*/
|
||||
public function test_multilang() {
|
||||
$text = '<lang lang="en">hmmm</lang><lang lang="anything">hm</lang>';
|
||||
@ -101,7 +96,7 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
$result = purify_html($text, array());
|
||||
$this->assertNotSame($text, $result);
|
||||
|
||||
// keep standard lang tags
|
||||
// Keep standard lang tags.
|
||||
|
||||
$text = '<span lang="de_DU" class="multilang">asas</span>';
|
||||
$result = purify_html($text, array());
|
||||
@ -114,17 +109,16 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
|
||||
/**
|
||||
* Tests the 'allowid' option for format_text.
|
||||
* @return void
|
||||
*/
|
||||
public function test_format_text_allowid() {
|
||||
// Start off by not allowing ids (default)
|
||||
// Start off by not allowing ids (default).
|
||||
$options = array(
|
||||
'nocache' => true
|
||||
);
|
||||
$result = format_text('<div id="example">Frog</div>', FORMAT_HTML, $options);
|
||||
$this->assertSame('<div>Frog</div>', $result);
|
||||
|
||||
// Now allow ids
|
||||
// Now allow ids.
|
||||
$options['allowid'] = true;
|
||||
$result = format_text('<div id="example">Frog</div>', FORMAT_HTML, $options);
|
||||
$this->assertSame('<div id="example">Frog</div>', $result);
|
||||
@ -132,7 +126,6 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
|
||||
/**
|
||||
* Test if linebreaks kept unchanged.
|
||||
* @return void
|
||||
*/
|
||||
public function test_line_breaking() {
|
||||
$text = "\n\raa\rsss\nsss\r";
|
||||
@ -141,7 +134,6 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
|
||||
/**
|
||||
* Test fixing of strict problems.
|
||||
* @return void
|
||||
*/
|
||||
public function test_tidy() {
|
||||
$text = "<p>xx";
|
||||
@ -155,8 +147,7 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test nesting - this used to cause problems in earlier versions
|
||||
* @return void
|
||||
* Test nesting - this used to cause problems in earlier versions.
|
||||
*/
|
||||
public function test_nested_lists() {
|
||||
$text = "<ul><li>One<ul><li>Two</li></ul></li><li>Three</li></ul>";
|
||||
@ -165,7 +156,6 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
|
||||
/**
|
||||
* Test that XSS protection works, complete smoke tests are in htmlpurifier itself.
|
||||
* @return void
|
||||
*/
|
||||
public function test_cleaning_nastiness() {
|
||||
$text = "x<SCRIPT>alert('XSS')</SCRIPT>x";
|
||||
@ -192,10 +182,9 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
|
||||
/**
|
||||
* Test internal function used for clean_text() speedup.
|
||||
* @return void
|
||||
*/
|
||||
public function test_is_purify_html_necessary() {
|
||||
// first our shortcuts
|
||||
// First our shortcuts.
|
||||
$text = "";
|
||||
$this->assertFalse(is_purify_html_necessary($text));
|
||||
$this->assertSame($text, purify_html($text));
|
||||
@ -216,7 +205,7 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
$this->assertFalse(is_purify_html_necessary($text));
|
||||
$this->assertSame($text, purify_html($text));
|
||||
|
||||
// now failures
|
||||
// Now failures.
|
||||
$text = " ";
|
||||
$this->assertTrue(is_purify_html_necessary($text));
|
||||
|
||||
@ -249,7 +238,7 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
}
|
||||
|
||||
public function test_allowed_schemes() {
|
||||
// first standard schemes
|
||||
// First standard schemas.
|
||||
$text = '<a href="http://www.example.com/course/view.php?id=5">link</a>';
|
||||
$this->assertSame($text, purify_html($text));
|
||||
|
||||
@ -268,7 +257,7 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
$text = '<a href="mailto:user@example.com">link</a>';
|
||||
$this->assertSame($text, purify_html($text));
|
||||
|
||||
// extra schemes allowed in moodle
|
||||
// Extra schemes allowed in moodle.
|
||||
$text = '<a href="irc://irc.example.com/3213?pass">link</a>';
|
||||
$this->assertSame($text, purify_html($text));
|
||||
|
||||
@ -284,7 +273,7 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
$text = '<a href="mms://www.example.com/movie.mms">link</a>';
|
||||
$this->assertSame($text, purify_html($text));
|
||||
|
||||
// now some borked or dangerous schemes
|
||||
// Now some borked or dangerous schemes.
|
||||
$text = '<a href="javascript://www.example.com">link</a>';
|
||||
$this->assertSame('<a>link</a>', purify_html($text));
|
||||
|
||||
@ -292,4 +281,3 @@ class core_htmlpurifier_testcase extends basic_testcase {
|
||||
$this->assertSame('<a>link</a>', purify_html($text));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user