Release 2.1.3, merged in 1404 to HEAD.
[htmlpurifier/bfroehle.git] / tests / HTMLPurifier / Strategy / FixNestingTest.php
blobbf4c374d0cf37adb69e3fb786ee0e512ad182e7b
1 <?php
3 require_once 'HTMLPurifier/StrategyHarness.php';
4 require_once 'HTMLPurifier/Strategy/FixNesting.php';
6 class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
9 function setUp() {
10 parent::setUp();
11 $this->obj = new HTMLPurifier_Strategy_FixNesting();
14 function testPreserveInlineInRoot() {
15 $this->assertResult('<b>Bold text</b>');
18 function testPreserveInlineAndBlockInRoot() {
19 $this->assertResult('<a href="about:blank">Blank</a><div>Block</div>');
22 function testRemoveBlockInInline() {
23 $this->assertResult(
24 '<b><div>Illegal div.</div></b>',
25 '<b>Illegal div.</b>'
29 function testEscapeBlockInInline() {
30 $this->config->set('Core', 'EscapeInvalidChildren', true);
31 $this->assertResult(
32 '<b><div>Illegal div.</div></b>',
33 '<b>&lt;div&gt;Illegal div.&lt;/div&gt;</b>'
37 function testRemoveNodeWithMissingRequiredElements() {
38 $this->assertResult('<ul></ul>', '');
41 function testRemoveIllegalPCDATA() {
42 $this->assertResult(
43 '<ul>Illegal text<li>Legal item</li></ul>',
44 '<ul><li>Legal item</li></ul>'
48 function testCustomTableDefinition() {
49 $this->assertResult('<table><tr><td>Cell 1</td></tr></table>');
52 function testRemoveEmptyTable() {
53 $this->assertResult('<table></table>', '');
56 function testChameleonRemoveBlockInNodeInInline() {
57 $this->assertResult(
58 '<span><ins><div>Not allowed!</div></ins></span>',
59 '<span><ins>Not allowed!</ins></span>'
63 function testChameleonRemoveBlockInBlockNodeWithInlineContent() {
64 $this->assertResult(
65 '<h1><ins><div>Not allowed!</div></ins></h1>',
66 '<h1><ins>Not allowed!</ins></h1>'
70 function testNestedChameleonRemoveBlockInNodeWithInlineContent() {
71 $this->assertResult(
72 '<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
73 '<h1><ins><del>Not allowed!</del></ins></h1>'
77 function testNestedChameleonPreserveBlockInBlock() {
78 $this->assertResult(
79 '<div><ins><del><div>Allowed!</div></del></ins></div>'
83 function testChameleonEscapeInvalidBlockInInline() {
84 $this->config->set('Core', 'EscapeInvalidChildren', true);
85 $this->assertResult( // alt config
86 '<span><ins><div>Not allowed!</div></ins></span>',
87 '<span><ins>&lt;div&gt;Not allowed!&lt;/div&gt;</ins></span>'
91 function testExclusionsIntegration() {
92 // test exclusions
93 $this->assertResult(
94 '<a><span><a>Not allowed</a></span></a>',
95 '<a><span></span></a>'
99 function testPreserveInlineNodeInInlineRootNode() {
100 $this->config->set('HTML', 'Parent', 'span');
101 $this->assertResult('<b>Bold</b>');
104 function testRemoveBlockNodeInInlineRootNode() {
105 $this->config->set('HTML', 'Parent', 'span');
106 $this->assertResult('<div>Reject</div>', 'Reject');
109 function testInvalidParentError() {
110 // test fallback to div
111 $this->config->set('HTML', 'Parent', 'obviously-impossible');
112 // $this->expectError('Cannot use unrecognized element as parent');
113 $this->assertResult('<div>Accept</div>');
114 $this->swallowErrors();
117 function testCascadingRemovalOfNodesMissingRequiredChildren() {
118 $this->assertResult('<table><tr></tr></table>', '');
121 function testCascadingRemovalSpecialCaseCannotScrollOneBack() {
122 $this->assertResult('<table><tr></tr><tr></tr></table>', '');
125 function testLotsOfCascadingRemovalOfNodes() {
126 $this->assertResult('<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>', '');
129 function testAdjacentRemovalOfNodeMissingRequiredChildren() {
130 $this->assertResult('<table></table><table></table>', '');
133 function testStrictBlockquoteInHTML401() {
134 $this->config->set('HTML', 'Doctype', 'HTML 4.01 Strict');
135 $this->assertResult('<blockquote>text</blockquote>', '<blockquote><p>text</p></blockquote>');