3 class HTMLPurifier_Strategy_RemoveForeignElementsTest
extends HTMLPurifier_StrategyHarness
6 public function setUp()
9 $this->obj
= new HTMLPurifier_Strategy_RemoveForeignElements();
12 public function testBlankInput()
14 $this->assertResult('');
17 public function testPreserveRecognizedElements()
19 $this->assertResult('This is <b>bold text</b>.');
22 public function testRemoveForeignElements()
25 '<asdf>Bling</asdf><d href="bang">Bong</d><foobar />',
30 public function testRemoveScriptAndContents()
33 '<script>alert();</script>',
38 public function testRemoveStyleAndContents()
41 '<style>.foo {blink;}</style>',
46 public function testRemoveOnlyScriptTagsLegacy()
48 $this->config
->set('Core.RemoveScriptContents', false);
50 '<script>alert();</script>',
55 public function testRemoveOnlyScriptTags()
57 $this->config
->set('Core.HiddenElements', array());
59 '<script>alert();</script>',
64 public function testRemoveInvalidImg()
66 $this->assertResult('<img />', '');
69 public function testPreserveValidImg()
71 $this->assertResult('<img src="foobar.gif" alt="foobar.gif" />');
74 public function testPreserveInvalidImgWhenRemovalIsDisabled()
76 $this->config
->set('Core.RemoveInvalidImg', false);
77 $this->assertResult('<img />');
80 public function testTextifyCommentedScriptContents()
82 $this->config
->set('HTML.Trusted', true);
83 $this->config
->set('Output.CommentScriptContents', false); // simplify output
85 '<script type="text/javascript"><!--
88 '<script type="text/javascript">
89 alert(<b>bold</b>);
94 public function testRequiredAttributesTestNotPerformedOnEndTag()
96 $def = $this->config
->getHTMLDefinition(true);
97 $def->addElement('f', 'Block', 'Optional: #PCDATA', false, array('req*' => 'Text'));
98 $this->assertResult('<f req="text">Foo</f> Bar');
101 public function testPreserveCommentsWithHTMLTrusted()
103 $this->config
->set('HTML.Trusted', true);
104 $this->assertResult('<!-- foo -->');
107 public function testRemoveTrailingHyphensInComment()
109 $this->config
->set('HTML.Trusted', true);
110 $this->assertResult('<!-- foo ----->', '<!-- foo -->');
113 public function testCollapseDoubleHyphensInComment()
115 $this->config
->set('HTML.Trusted', true);
116 $this->assertResult('<!-- bo --- asdf--as -->', '<!-- bo - asdf-as -->');
119 public function testPreserveCommentsWithLookup()
121 $this->config
->set('HTML.AllowedComments', array('allowed'));
122 $this->assertResult('<!-- allowed --><!-- not allowed -->', '<!-- allowed -->');
125 public function testPreserveCommentsWithRegexp()
127 $this->config
->set('HTML.AllowedCommentsRegexp', '/^allowed[1-9]$/');
128 $this->assertResult('<!-- allowed1 --><!-- not allowed -->', '<!-- allowed1 -->');
133 // vim: et sw=4 sts=4