Whoops, forgot to edit WHATSNEW
[htmlpurifier.git] / tests / HTMLPurifier / Strategy / RemoveForeignElementsTest.php
blobaea87062eb90bf1c58d227fd3edfbb331fcb9dd6
1 <?php
3 class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_StrategyHarness
6 public function setUp()
8 parent::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()
24 $this->assertResult(
25 '<asdf>Bling</asdf><d href="bang">Bong</d><foobar />',
26 'BlingBong'
30 public function testRemoveScriptAndContents()
32 $this->assertResult(
33 '<script>alert();</script>',
38 public function testRemoveStyleAndContents()
40 $this->assertResult(
41 '<style>.foo {blink;}</style>',
46 public function testRemoveOnlyScriptTagsLegacy()
48 $this->config->set('Core.RemoveScriptContents', false);
49 $this->assertResult(
50 '<script>alert();</script>',
51 'alert();'
55 public function testRemoveOnlyScriptTags()
57 $this->config->set('Core.HiddenElements', array());
58 $this->assertResult(
59 '<script>alert();</script>',
60 'alert();'
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
84 $this->assertResult(
85 '<script type="text/javascript"><!--
86 alert(<b>bold</b>);
87 // --></script>',
88 '<script type="text/javascript">
89 alert(&lt;b&gt;bold&lt;/b&gt;);
90 // </script>'
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