2006-07-24 02:33:07 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-05 00:30:31 +00:00
|
|
|
require_once 'HTMLPurifier/StrategyHarness.php';
|
2006-07-24 02:33:07 +00:00
|
|
|
require_once 'HTMLPurifier/Strategy/RemoveForeignElements.php';
|
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_StrategyHarness
|
2006-07-24 02:33:07 +00:00
|
|
|
{
|
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->obj = new HTMLPurifier_Strategy_RemoveForeignElements();
|
|
|
|
}
|
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testBlankInput() {
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testPreserveRecognizedElements() {
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('This is <b>bold text</b>.');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testRemoveForeignElements() {
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<asdf>Bling</asdf><d href="bang">Bong</d><foobar />',
|
|
|
|
'BlingBong'
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testRemoveScriptAndContents() {
|
2007-06-16 19:31:45 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<script>alert();</script>',
|
|
|
|
''
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testRemoveStyleAndContents() {
|
2007-07-11 20:42:58 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<style>.foo {blink;}</style>',
|
|
|
|
''
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testRemoveOnlyScriptTagsLegacy() {
|
|
|
|
$this->config->set('Core', 'RemoveScriptContents', false);
|
2007-06-16 19:31:45 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<script>alert();</script>',
|
2007-08-06 06:22:23 +00:00
|
|
|
'alert();'
|
2007-06-16 19:31:45 +00:00
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testRemoveOnlyScriptTags() {
|
|
|
|
$this->config->set('Core', 'HiddenElements', array());
|
2007-07-11 20:42:58 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<script>alert();</script>',
|
2007-08-06 06:22:23 +00:00
|
|
|
'alert();'
|
2006-10-01 21:55:13 +00:00
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testRemoveInvalidImg() {
|
|
|
|
$this->assertResult('<img />', '');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testPreserveValidImg() {
|
2007-06-20 21:39:28 +00:00
|
|
|
$this->assertResult('<img src="foobar.gif" alt="foobar.gif" />');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testPreserveInvalidImgWhenRemovalIsDisabled() {
|
|
|
|
$this->config->set('Core', 'RemoveInvalidImg', false);
|
|
|
|
$this->assertResult('<img />');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testTextifyCommentedScriptContents() {
|
|
|
|
$this->config->set('HTML', 'Trusted', true);
|
|
|
|
$this->config->set('Output', 'CommentScriptContents', false); // simplify output
|
2007-06-21 14:44:26 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<script type="text/javascript"><!--
|
|
|
|
alert(<b>bold</b>);
|
|
|
|
// --></script>',
|
|
|
|
'<script type="text/javascript">
|
|
|
|
alert(<b>bold</b>);
|
2007-08-06 06:22:23 +00:00
|
|
|
// </script>'
|
2007-06-21 14:44:26 +00:00
|
|
|
);
|
2006-07-24 02:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|