. /** * Unit tests for the HTMLPurifier integration * * @package core * @subpackage simpletest * @copyright 2011 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); class purifier_test extends UnitTestCase { public static $includecoverage = array('lib/htmlpurifier/HTMLPurifier.php'); private $cachetext = null; function setUp() { global $CFG; $this->cachetext = $CFG->cachetext; $CFG->cachetext = 0; } function tearDown() { global $CFG; $CFG->cachetext = $this->cachetext; } /** * Verify _blank target is allowed * @return void */ public function test_allow_blank_target() { $text = 'Some link'; $result = format_text($text, FORMAT_HTML); $this->assertIdentical($text, $result); $result = format_text('Some link', FORMAT_HTML); $this->assertIdentical('Some link', $result); } /** * Verify our nolink tag accepted * @return void */ public function test_nolink() { // we can not use format text because nolink changes result $text = '
no filters
'; $result = purify_html($text, array()); $this->assertIdentical($text, $result); } /** * Verify our tex tag accepted * @return void */ public function test_tex() { $text = 'a+b=c'; $result = purify_html($text, array()); $this->assertIdentical($text, $result); } /** * Verify our algebra tag accepted * @return void */ public function test_algebra() { $text = 'a+b=c'; $result = purify_html($text, array()); $this->assertIdentical($text, $result); } /** * Verify our hacky multilang works * @return void */ public function test_multilang() { $text = 'hmmmhm'; $result = purify_html($text, array()); $this->assertIdentical($text, $result); $text = 'hmmmhm'; $result = purify_html($text, array()); $this->assertIdentical($text, $result); $text = 'hmmm'; $result = purify_html($text, array()); $this->assertNotIdentical($text, $result); } /** * Tests the 'allowid' option for format_text. */ public function test_format_text_allowid() { // Start off by not allowing ids (default) $options = array( 'nocache' => true ); $result = format_text('
Frog
', FORMAT_HTML, $options); $this->assertIdentical('
Frog
', $result); // Now allow ids $options['allowid'] = true; $result = format_text('
Frog
', FORMAT_HTML, $options); $this->assertIdentical('
Frog
', $result); } //TODO: add XSS smoke tests here }