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';
|
|
|
|
|
|
|
|
class HTMLPurifier_Strategy_RemoveForeignElementsTest
|
2006-10-01 21:55:13 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2006-07-24 02:33:07 +00:00
|
|
|
function test() {
|
|
|
|
|
2007-05-21 01:36:15 +00:00
|
|
|
$this->config = array('HTML.Doctype' => 'XHTML 1.0 Strict');
|
2006-07-24 02:33:07 +00:00
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('');
|
2006-07-24 02:33:07 +00:00
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('This is <b>bold text</b>.');
|
2006-07-24 02:33:07 +00:00
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<asdf>Bling</asdf><d href="bang">Bong</d><foobar />',
|
|
|
|
'BlingBong'
|
|
|
|
);
|
2006-07-24 02:33:07 +00:00
|
|
|
|
2007-06-16 19:31:45 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<script>alert();</script>',
|
|
|
|
''
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertResult(
|
|
|
|
'<script>alert();</script>',
|
|
|
|
'alert();',
|
|
|
|
array('Core.RemoveScriptContents' => false)
|
|
|
|
);
|
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<menu><li>Item 1</li></menu>',
|
|
|
|
'<ul><li>Item 1</li></ul>'
|
|
|
|
);
|
2006-08-02 02:24:03 +00:00
|
|
|
|
|
|
|
// test center transform
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<center>Look I am Centered!</center>',
|
|
|
|
'<div style="text-align:center;">Look I am Centered!</div>'
|
|
|
|
);
|
2006-08-02 02:24:03 +00:00
|
|
|
|
2006-08-03 00:14:10 +00:00
|
|
|
// test font transform
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<font color="red" face="Arial" size="6">Big Warning!</font>',
|
|
|
|
'<span style="color:red;font-family:Arial;font-size:xx-large;">Big'.
|
|
|
|
' Warning!</span>'
|
|
|
|
);
|
2006-08-03 00:14:10 +00:00
|
|
|
|
2006-12-06 22:12:44 +00:00
|
|
|
// test removal of invalid img tag
|
2006-11-23 23:59:20 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<img />',
|
|
|
|
''
|
|
|
|
);
|
|
|
|
|
2006-12-06 22:12:44 +00:00
|
|
|
// test preservation of valid img tag
|
2007-06-20 21:39:28 +00:00
|
|
|
$this->assertResult('<img src="foobar.gif" alt="foobar.gif" />');
|
2006-12-06 22:12:44 +00:00
|
|
|
|
2007-04-30 00:53:13 +00:00
|
|
|
// test preservation of invalid img tag when removal is disabled
|
|
|
|
$this->assertResult(
|
|
|
|
'<img />',
|
|
|
|
true,
|
|
|
|
array(
|
|
|
|
'Core.RemoveInvalidImg' => false
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2007-06-19 22:10:39 +00:00
|
|
|
// test transform to unallowed element
|
|
|
|
$this->assertResult(
|
|
|
|
'<font color="red" face="Arial" size="6">Big Warning!</font>',
|
|
|
|
'Big Warning!',
|
|
|
|
array('HTML.Allowed' => 'div')
|
|
|
|
);
|
|
|
|
|
2007-06-21 14:44:26 +00:00
|
|
|
// text-ify commented script contents ( the trailing comment gets
|
|
|
|
// removed during generation )
|
|
|
|
$this->assertResult(
|
|
|
|
'<script type="text/javascript"><!--
|
|
|
|
alert(<b>bold</b>);
|
|
|
|
// --></script>',
|
|
|
|
'<script type="text/javascript">
|
|
|
|
alert(<b>bold</b>);
|
|
|
|
// </script>',
|
|
|
|
array('HTML.Trusted' => true, 'Output.CommentScriptContents' => false)
|
|
|
|
);
|
|
|
|
|
2006-07-24 02:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|