Fix #45, errors when ul/ol allowed without li.
[htmlpurifier.git] / tests / HTMLPurifier / Strategy / FixNestingTest.php
blob9e3907456e25d5522723ad0cfa5a5a424ce3e67d
1 <?php
3 class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
6 public function setUp()
8 parent::setUp();
9 $this->obj = new HTMLPurifier_Strategy_FixNesting();
12 public function testPreserveInlineInRoot()
14 $this->assertResult('<b>Bold text</b>');
17 public function testPreserveInlineAndBlockInRoot()
19 $this->assertResult('<a href="about:blank">Blank</a><div>Block</div>');
22 public function testRemoveBlockInInline()
24 $this->assertResult(
25 '<b><div>Illegal div.</div></b>',
26 '<b>Illegal div.</b>'
30 public function testRemoveNodeWithMissingRequiredElements()
32 $this->assertResult('<ul></ul>', '');
35 public function testListHandleIllegalPCDATA()
37 $this->assertResult(
38 '<ul>Illegal text<li>Legal item</li></ul>',
39 '<ul><li>Illegal text</li><li>Legal item</li></ul>'
43 public function testRemoveIllegalPCDATA()
45 $this->assertResult(
46 '<table><tr>Illegal text<td></td></tr></table>',
47 '<table><tr><td></td></tr></table>'
51 public function testCustomTableDefinition()
53 $this->assertResult('<table><tr><td>Cell 1</td></tr></table>');
56 public function testRemoveEmptyTable()
58 $this->assertResult('<table></table>', '');
61 public function testChameleonRemoveBlockInNodeInInline()
63 $this->assertResult(
64 '<span><ins><div>Not allowed!</div></ins></span>',
65 '<span><ins>Not allowed!</ins></span>'
69 public function testChameleonRemoveBlockInBlockNodeWithInlineContent()
71 $this->assertResult(
72 '<h1><ins><div>Not allowed!</div></ins></h1>',
73 '<h1><ins>Not allowed!</ins></h1>'
77 public function testNestedChameleonRemoveBlockInNodeWithInlineContent()
79 $this->assertResult(
80 '<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
81 '<h1><ins><del>Not allowed!</del></ins></h1>'
85 public function testNestedChameleonPreserveBlockInBlock()
87 $this->assertResult(
88 '<div><ins><del><div>Allowed!</div></del></ins></div>'
92 public function testExclusionsIntegration()
94 // test exclusions
95 $this->assertResult(
96 '<a><span><a>Not allowed</a></span></a>',
97 '<a><span></span></a>'
101 public function testPreserveInlineNodeInInlineRootNode()
103 $this->config->set('HTML.Parent', 'span');
104 $this->assertResult('<b>Bold</b>');
107 public function testRemoveBlockNodeInInlineRootNode()
109 $this->config->set('HTML.Parent', 'span');
110 $this->assertResult('<div>Reject</div>', 'Reject');
113 public function testInvalidParentError()
115 // test fallback to div
116 $this->config->set('HTML.Parent', 'obviously-impossible');
117 $this->config->set('Cache.DefinitionImpl', null);
118 $this->expectError('Cannot use unrecognized element as parent');
119 $this->assertResult('<div>Accept</div>');
122 public function testCascadingRemovalOfNodesMissingRequiredChildren()
124 $this->assertResult('<table><tr></tr></table>', '');
127 public function testCascadingRemovalSpecialCaseCannotScrollOneBack()
129 $this->assertResult('<table><tr></tr><tr></tr></table>', '');
132 public function testLotsOfCascadingRemovalOfNodes()
134 $this->assertResult('<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>', '');
137 public function testAdjacentRemovalOfNodeMissingRequiredChildren()
139 $this->assertResult('<table></table><table></table>', '');
142 public function testStrictBlockquoteInHTML401()
144 $this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
145 $this->assertResult('<blockquote>text</blockquote>', '<blockquote><p>text</p></blockquote>');
148 public function testDisabledExcludes()
150 $this->config->set('Core.DisableExcludes', true);
151 $this->assertResult('<pre><font><font></font></font></pre>');
154 public function testDoubleKill()
156 $this->config->set('HTML.Allowed', 'ul');
157 $this->expectError('Cannot allow ul/ol without allowing li');
158 $this->assertResult('<ul>foo</ul>', '');
163 // vim: et sw=4 sts=4