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 $this->config
->set('HTML', 'DefinitionID',
84 'HTMLPurifier_Strategy_RemoveForeignElementsTest'.
85 '->testRequiredAttributesTestNotPerformedOnEndTag');
86 $def = $this->config
->getHTMLDefinition(true);
87 $def->addElement('f', 'Block', 'Optional: #PCDATA', false, array('req*' => 'Text'));
88 $this->assertResult('<f req="text">Foo</f> Bar');
91 function testPreserveCommentsWithHTMLTrusted() {
92 $this->config
->set('HTML', 'Trusted', true);
93 $this->assertResult('<!-- foo -->');
96 function testRemoveTrailingHyphensInComment() {
97 $this->config
->set('HTML', 'Trusted', true);
98 $this->assertResult('<!-- foo ----->', '<!-- foo -->');
101 function testCollapseDoubleHyphensInComment() {
102 $this->config
->set('HTML', 'Trusted', true);
103 $this->assertResult('<!-- bo --- asdf--as -->', '<!-- bo - asdf-as -->');