2008-06-10 00:13:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This test is kinda weird, because it doesn't test the full safe object
|
|
|
|
* functionality, just a small section of it. Or maybe it's actually the right
|
|
|
|
* way.
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_Injector_SafeObjectTest extends HTMLPurifier_InjectorHarness
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-10 00:13:44 +00:00
|
|
|
function setup() {
|
|
|
|
parent::setup();
|
2008-06-27 20:09:14 +00:00
|
|
|
// there is no AutoFormat.SafeObject directive
|
2008-06-10 00:13:44 +00:00
|
|
|
$this->config->set('AutoFormat', 'Custom', array(new HTMLPurifier_Injector_SafeObject()));
|
|
|
|
$this->config->set('HTML', 'Trusted', true);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-10 00:13:44 +00:00
|
|
|
function testPreserve() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<b>asdf</b>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-10 00:13:44 +00:00
|
|
|
function testRemoveStrayParam() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<param />',
|
|
|
|
''
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-10 00:13:44 +00:00
|
|
|
function testEditObjectParam() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<object></object>',
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-10 00:13:44 +00:00
|
|
|
function testIgnoreStrayParam() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<object><param /></object>',
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-10 00:13:44 +00:00
|
|
|
function testIgnoreDuplicates() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-10 00:13:44 +00:00
|
|
|
function testIgnoreBogusData() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<object><param name="allowScriptAccess" value="always" /><param name="allowNetworking" value="always" /></object>',
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-10 00:13:44 +00:00
|
|
|
function testIgnoreInvalidData() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<object><param name="foo" value="bar" /></object>',
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-10 00:13:44 +00:00
|
|
|
function testKeepValidData() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<object><param name="movie" value="bar" /></object>',
|
2008-06-12 03:12:39 +00:00
|
|
|
'<object data="bar"><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><param name="movie" value="bar" /></object>'
|
2008-06-10 00:13:44 +00:00
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-10 00:13:44 +00:00
|
|
|
function testNested() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><object></object></object>',
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></object></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-10 00:13:44 +00:00
|
|
|
function testNotActuallyNested() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<object><p><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /></p></object>',
|
|
|
|
'<object><param name="allowScriptAccess" value="never" /><param name="allowNetworking" value="internal" /><p></p></object>'
|
|
|
|
);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2008-06-10 00:13:44 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|