.
/**
* Unit tests for the HTMLPurifier integration
*
* @package core
* @category phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* HTMLPurifier test case
*
* @package core
* @category phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_htmlpurifier_testcase extends basic_testcase {
/**
* Verify _blank target is allowed.
*/
public function test_allow_blank_target() {
$text = 'Some link';
$result = format_text($text, FORMAT_HTML);
$this->assertSame($text, $result);
$result = format_text('Some link', FORMAT_HTML);
$this->assertSame('Some link', $result);
}
/**
* Verify our nolink tag accepted.
*/
public function test_nolink() {
// We can not use format text because nolink changes result.
$text = '
', $result);
}
public function test_allowobjectembed() {
global $CFG;
$this->assertSame('0', $CFG->allowobjectembed);
$text = 'hmmm';
$result = purify_html($text, array());
$this->assertSame('hmmm', trim($result));
$CFG->allowobjectembed = '1';
$expected = 'hmmm';
$result = purify_html($text, array());
$this->assertSame(str_replace("\n", '', $expected), str_replace("\n", '', $result));
$CFG->allowobjectembed = '0';
$result = purify_html($text, array());
$this->assertSame('hmmm', trim($result));
}
/**
* Test if linebreaks kept unchanged.
*/
public function test_line_breaking() {
$text = "\n\raa\rsss\nsss\r";
$this->assertSame($text, purify_html($text));
}
/**
* Test fixing of strict problems.
*/
public function test_tidy() {
$text = "
xx";
$this->assertSame('
xx
', purify_html($text));
$text = "
xx
";
$this->assertSame('
xx
', purify_html($text));
$text = "xx ";
$this->assertSame('xx ', purify_html($text));
}
/**
* Test nesting - this used to cause problems in earlier versions.
*/
public function test_nested_lists() {
$text = "
One
Two
Three
";
$this->assertSame($text, purify_html($text));
}
/**
* Test that XSS protection works, complete smoke tests are in htmlpurifier itself.
*/
public function test_cleaning_nastiness() {
$text = "xx";
$this->assertSame('xx', purify_html($text));
$text = '
xx
';
$this->assertSame('
xx
', purify_html($text));
$text = '
xx
';
$this->assertSame('
xx
', purify_html($text));
$text = 'xx';
$this->assertSame('xx', purify_html($text));
$text = 'xx';
$this->assertSame('xx', purify_html($text));
$text = 'xx';
$this->assertSame('xx', purify_html($text));
$text = 'xx';
$this->assertSame('xx', purify_html($text));
}
/**
* Test internal function used for clean_text() speedup.
*/
public function test_is_purify_html_necessary() {
// First our shortcuts.
$text = "";
$this->assertFalse(is_purify_html_necessary($text));
$this->assertSame($text, purify_html($text));
$text = "666";
$this->assertFalse(is_purify_html_necessary($text));
$this->assertSame($text, purify_html($text));
$text = "abc\ndef \" ' ";
$this->assertFalse(is_purify_html_necessary($text));
$this->assertSame($text, purify_html($text));
$text = "abc\n