Implement %HTML.AllowedComments and %HTML.AllowedCommentsRegexp
[htmlpurifier.git] / tests / HTMLPurifier / Strategy / RemoveForeignElementsTest.php
blobb3ca1646abf0bd8072a376f57d06f4712a9ea21b
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 $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