Properly handle nested sublists by folding into previous list item.
[htmlpurifier.git] / tests / HTMLPurifier / Strategy / FixNestingTest.php
blob9394352ec30d6613dc76ec06c5b5ebeb162c692a
1 <?php
3 class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
6 function setUp() {
7 parent::setUp();
8 $this->obj = new HTMLPurifier_Strategy_FixNesting();
11 function testPreserveInlineInRoot() {
12 $this->assertResult('<b>Bold text</b>');
15 function testPreserveInlineAndBlockInRoot() {
16 $this->assertResult('<a href="about:blank">Blank</a><div>Block</div>');
19 function testRemoveBlockInInline() {
20 $this->assertResult(
21 '<b><div>Illegal div.</div></b>',
22 '<b>Illegal div.</b>'
26 function testEscapeBlockInInline() {
27 $this->config->set('Core.EscapeInvalidChildren', true);
28 $this->assertResult(
29 '<b><div>Illegal div.</div></b>',
30 '<b>&lt;div&gt;Illegal div.&lt;/div&gt;</b>'
34 function testRemoveNodeWithMissingRequiredElements() {
35 $this->assertResult('<ul></ul>', '');
38 function testListHandleIllegalPCDATA() {
39 $this->assertResult(
40 '<ul>Illegal text<li>Legal item</li></ul>',
41 '<ul><li>Illegal text</li><li>Legal item</li></ul>'
45 function testRemoveIllegalPCDATA() {
46 $this->assertResult(
47 '<table><tr>Illegal text<td></td></tr></table>',
48 '<table><tr><td></td></tr></table>'
52 function testCustomTableDefinition() {
53 $this->assertResult('<table><tr><td>Cell 1</td></tr></table>');
56 function testRemoveEmptyTable() {
57 $this->assertResult('<table></table>', '');
60 function testChameleonRemoveBlockInNodeInInline() {
61 $this->assertResult(
62 '<span><ins><div>Not allowed!</div></ins></span>',
63 '<span><ins>Not allowed!</ins></span>'
67 function testChameleonRemoveBlockInBlockNodeWithInlineContent() {
68 $this->assertResult(
69 '<h1><ins><div>Not allowed!</div></ins></h1>',
70 '<h1><ins>Not allowed!</ins></h1>'
74 function testNestedChameleonRemoveBlockInNodeWithInlineContent() {
75 $this->assertResult(
76 '<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
77 '<h1><ins><del>Not allowed!</del></ins></h1>'
81 function testNestedChameleonPreserveBlockInBlock() {
82 $this->assertResult(
83 '<div><ins><del><div>Allowed!</div></del></ins></div>'
87 function testChameleonEscapeInvalidBlockInInline() {
88 $this->config->set('Core.EscapeInvalidChildren', true);
89 $this->assertResult( // alt config
90 '<span><ins><div>Not allowed!</div></ins></span>',
91 '<span><ins>&lt;div&gt;Not allowed!&lt;/div&gt;</ins></span>'
95 function testExclusionsIntegration() {
96 // test exclusions
97 $this->assertResult(
98 '<a><span><a>Not allowed</a></span></a>',
99 '<a><span></span></a>'
103 function testPreserveInlineNodeInInlineRootNode() {
104 $this->config->set('HTML.Parent', 'span');
105 $this->assertResult('<b>Bold</b>');
108 function testRemoveBlockNodeInInlineRootNode() {
109 $this->config->set('HTML.Parent', 'span');
110 $this->assertResult('<div>Reject</div>', 'Reject');
113 function testInvalidParentError() {
114 // test fallback to div
115 $this->config->set('HTML.Parent', 'obviously-impossible');
116 $this->config->set('Cache.DefinitionImpl', null);
117 $this->expectError('Cannot use unrecognized element as parent');
118 $this->assertResult('<div>Accept</div>');
121 function testCascadingRemovalOfNodesMissingRequiredChildren() {
122 $this->assertResult('<table><tr></tr></table>', '');
125 function testCascadingRemovalSpecialCaseCannotScrollOneBack() {
126 $this->assertResult('<table><tr></tr><tr></tr></table>', '');
129 function testLotsOfCascadingRemovalOfNodes() {
130 $this->assertResult('<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>', '');
133 function testAdjacentRemovalOfNodeMissingRequiredChildren() {
134 $this->assertResult('<table></table><table></table>', '');
137 function testStrictBlockquoteInHTML401() {
138 $this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
139 $this->assertResult('<blockquote>text</blockquote>', '<blockquote><p>text</p></blockquote>');
144 // vim: et sw=4 sts=4