3 class HTMLPurifier_Strategy_RemoveForeignElementsTest
extends HTMLPurifier_StrategyHarness
8 $this->obj
= new HTMLPurifier_Strategy_RemoveForeignElements();
11 function testBlankInput() {
12 $this->assertResult('');
15 function testPreserveRecognizedElements() {
16 $this->assertResult('This is <b>bold text</b>.');
19 function testRemoveForeignElements() {
21 '<asdf>Bling</asdf><d href="bang">Bong</d><foobar />',
26 function testRemoveScriptAndContents() {
28 '<script>alert();</script>',
33 function testRemoveStyleAndContents() {
35 '<style>.foo {blink;}</style>',
40 function testRemoveOnlyScriptTagsLegacy() {
41 $this->config
->set('Core.RemoveScriptContents', false);
43 '<script>alert();</script>',
48 function testRemoveOnlyScriptTags() {
49 $this->config
->set('Core.HiddenElements', array());
51 '<script>alert();</script>',
56 function testRemoveInvalidImg() {
57 $this->assertResult('<img />', '');
60 function testPreserveValidImg() {
61 $this->assertResult('<img src="foobar.gif" alt="foobar.gif" />');
64 function testPreserveInvalidImgWhenRemovalIsDisabled() {
65 $this->config
->set('Core.RemoveInvalidImg', false);
66 $this->assertResult('<img />');
69 function testTextifyCommentedScriptContents() {
70 $this->config
->set('HTML.Trusted', true);
71 $this->config
->set('Output.CommentScriptContents', false); // simplify output
73 '<script type="text/javascript"><!--
76 '<script type="text/javascript">
77 alert(<b>bold</b>);
82 function testRequiredAttributesTestNotPerformedOnEndTag() {
83 $def = $this->config
->getHTMLDefinition(true);
84 $def->addElement('f', 'Block', 'Optional: #PCDATA', false, array('req*' => 'Text'));
85 $this->assertResult('<f req="text">Foo</f> Bar');
88 function testPreserveCommentsWithHTMLTrusted() {
89 $this->config
->set('HTML.Trusted', true);
90 $this->assertResult('<!-- foo -->');
93 function testRemoveTrailingHyphensInComment() {
94 $this->config
->set('HTML.Trusted', true);
95 $this->assertResult('<!-- foo ----->', '<!-- foo -->');
98 function testCollapseDoubleHyphensInComment() {
99 $this->config
->set('HTML.Trusted', true);
100 $this->assertResult('<!-- bo --- asdf--as -->', '<!-- bo - asdf-as -->');
103 function testPreserveCommentsWithLookup() {
104 $this->config
->set('HTML.AllowedComments', array('allowed'));
105 $this->assertResult('<!-- allowed --><!-- not allowed -->', '<!-- allowed -->');
108 function testPreserveCommentsWithRegexp() {
109 $this->config
->set('HTML.AllowedCommentsRegexp', '/^allowed[1-9]$/');
110 $this->assertResult('<!-- allowed1 --><!-- not allowed -->', '<!-- allowed1 -->');
115 // vim: et sw=4 sts=4