2006-09-01 17:56:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier.php';
|
|
|
|
|
|
|
|
// integration test
|
|
|
|
|
|
|
|
class HTMLPurifier_Test extends UnitTestCase
|
|
|
|
{
|
|
|
|
var $purifier;
|
|
|
|
|
2006-11-23 23:59:20 +00:00
|
|
|
function setUp() {
|
|
|
|
$this->purifier = new HTMLPurifier();
|
|
|
|
}
|
|
|
|
|
2006-09-04 23:01:47 +00:00
|
|
|
function assertPurification($input, $expect = null) {
|
|
|
|
if ($expect === null) $expect = $input;
|
2006-09-01 17:56:55 +00:00
|
|
|
$result = $this->purifier->purify($input);
|
|
|
|
$this->assertIdentical($expect, $result);
|
|
|
|
}
|
|
|
|
|
2006-11-22 18:17:39 +00:00
|
|
|
function testNull() {
|
|
|
|
$this->assertPurification("Null byte\0", "Null byte");
|
|
|
|
}
|
|
|
|
|
|
|
|
function testStrict() {
|
2006-09-01 17:56:55 +00:00
|
|
|
$config = HTMLPurifier_Config::createDefault();
|
2006-11-22 18:17:39 +00:00
|
|
|
$config->set('HTML', 'Strict', true);
|
2006-09-01 17:56:55 +00:00
|
|
|
$this->purifier = new HTMLPurifier($config);
|
2006-11-22 18:17:39 +00:00
|
|
|
|
|
|
|
$this->assertPurification(
|
|
|
|
'<u>Illegal underline</u>',
|
|
|
|
'Illegal underline'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertPurification(
|
|
|
|
'<blockquote>Illegal contents</blockquote>',
|
2006-11-23 03:23:35 +00:00
|
|
|
'<blockquote><p>Illegal contents</p></blockquote>'
|
2006-11-22 18:17:39 +00:00
|
|
|
);
|
|
|
|
|
2006-09-01 17:56:55 +00:00
|
|
|
}
|
2006-11-22 18:17:39 +00:00
|
|
|
|
2006-11-23 13:51:19 +00:00
|
|
|
function testDifferentAllowedElements() {
|
|
|
|
$config = HTMLPurifier_Config::createDefault();
|
|
|
|
$config->set('HTML', 'AllowedElements', array('b', 'i', 'p', 'a'));
|
|
|
|
$config->set('HTML', 'AllowedAttributes', array('a.href', '*.id'));
|
|
|
|
$this->purifier = new HTMLPurifier($config);
|
|
|
|
|
|
|
|
$this->assertPurification(
|
|
|
|
'<p>Par.</p><p>Para<a href="http://google.com/">gr</a>aph</p>Text<b>Bol<i>d</i></b>'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertPurification(
|
|
|
|
'<span>Not allowed</span><a class="mef" id="foobar">Foobar</a>',
|
|
|
|
'Not allowed<a>Foobar</a>' // no ID!!!
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-11-23 23:59:20 +00:00
|
|
|
function testDisableURI() {
|
|
|
|
|
|
|
|
$config = HTMLPurifier_Config::createDefault();
|
|
|
|
$config->set('Attr', 'DisableURI', true);
|
|
|
|
$this->purifier = new HTMLPurifier($config);
|
|
|
|
|
|
|
|
$this->assertPurification(
|
|
|
|
'<img src="foobar"/>',
|
|
|
|
''
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-09-01 17:56:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|