Fix autoparagraph bug with non-inline elements.
[htmlpurifier.git] / tests / HTMLPurifier / Strategy / RemoveForeignElementsTest.php
blob3b9a6449efc5ccc3a28f7e08c00e4ee2c806132c
1 <?php
3 class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_StrategyHarness
6 function setUp() {
7 parent::setUp();
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() {
20 $this->assertResult(
21 '<asdf>Bling</asdf><d href="bang">Bong</d><foobar />',
22 'BlingBong'
26 function testRemoveScriptAndContents() {
27 $this->assertResult(
28 '<script>alert();</script>',
33 function testRemoveStyleAndContents() {
34 $this->assertResult(
35 '<style>.foo {blink;}</style>',
40 function testRemoveOnlyScriptTagsLegacy() {
41 $this->config->set('Core.RemoveScriptContents', false);
42 $this->assertResult(
43 '<script>alert();</script>',
44 'alert();'
48 function testRemoveOnlyScriptTags() {
49 $this->config->set('Core.HiddenElements', array());
50 $this->assertResult(
51 '<script>alert();</script>',
52 'alert();'
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
72 $this->assertResult(
73 '<script type="text/javascript"><!--
74 alert(<b>bold</b>);
75 // --></script>',
76 '<script type="text/javascript">
77 alert(&lt;b&gt;bold&lt;/b&gt;);
78 // </script>'
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 -->');
108 // vim: et sw=4 sts=4