Fix autoparagraph bug with non-inline elements.
[htmlpurifier.git] / tests / HTMLPurifier / Strategy / FixNestingTest.php
blob7bbc53a5230b230320ed602f9fec0b6dc5104700
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 testRemoveIllegalPCDATA() {
39 $this->assertResult(
40 '<ul>Illegal text<li>Legal item</li></ul>',
41 '<ul><li>Legal item</li></ul>'
45 function testCustomTableDefinition() {
46 $this->assertResult('<table><tr><td>Cell 1</td></tr></table>');
49 function testRemoveEmptyTable() {
50 $this->assertResult('<table></table>', '');
53 function testChameleonRemoveBlockInNodeInInline() {
54 $this->assertResult(
55 '<span><ins><div>Not allowed!</div></ins></span>',
56 '<span><ins>Not allowed!</ins></span>'
60 function testChameleonRemoveBlockInBlockNodeWithInlineContent() {
61 $this->assertResult(
62 '<h1><ins><div>Not allowed!</div></ins></h1>',
63 '<h1><ins>Not allowed!</ins></h1>'
67 function testNestedChameleonRemoveBlockInNodeWithInlineContent() {
68 $this->assertResult(
69 '<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
70 '<h1><ins><del>Not allowed!</del></ins></h1>'
74 function testNestedChameleonPreserveBlockInBlock() {
75 $this->assertResult(
76 '<div><ins><del><div>Allowed!</div></del></ins></div>'
80 function testChameleonEscapeInvalidBlockInInline() {
81 $this->config->set('Core.EscapeInvalidChildren', true);
82 $this->assertResult( // alt config
83 '<span><ins><div>Not allowed!</div></ins></span>',
84 '<span><ins>&lt;div&gt;Not allowed!&lt;/div&gt;</ins></span>'
88 function testExclusionsIntegration() {
89 // test exclusions
90 $this->assertResult(
91 '<a><span><a>Not allowed</a></span></a>',
92 '<a><span></span></a>'
96 function testPreserveInlineNodeInInlineRootNode() {
97 $this->config->set('HTML.Parent', 'span');
98 $this->assertResult('<b>Bold</b>');
101 function testRemoveBlockNodeInInlineRootNode() {
102 $this->config->set('HTML.Parent', 'span');
103 $this->assertResult('<div>Reject</div>', 'Reject');
106 function testInvalidParentError() {
107 // test fallback to div
108 $this->config->set('HTML.Parent', 'obviously-impossible');
109 $this->config->set('Cache.DefinitionImpl', null);
110 $this->expectError('Cannot use unrecognized element as parent');
111 $this->assertResult('<div>Accept</div>');
114 function testCascadingRemovalOfNodesMissingRequiredChildren() {
115 $this->assertResult('<table><tr></tr></table>', '');
118 function testCascadingRemovalSpecialCaseCannotScrollOneBack() {
119 $this->assertResult('<table><tr></tr><tr></tr></table>', '');
122 function testLotsOfCascadingRemovalOfNodes() {
123 $this->assertResult('<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>', '');
126 function testAdjacentRemovalOfNodeMissingRequiredChildren() {
127 $this->assertResult('<table></table><table></table>', '');
130 function testStrictBlockquoteInHTML401() {
131 $this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
132 $this->assertResult('<blockquote>text</blockquote>', '<blockquote><p>text</p></blockquote>');
137 // vim: et sw=4 sts=4