3 require_once 'HTMLPurifier/StrategyHarness.php';
4 require_once 'HTMLPurifier/Strategy/FixNesting.php';
6 class HTMLPurifier_Strategy_FixNestingTest
extends HTMLPurifier_StrategyHarness
11 $this->obj
= new HTMLPurifier_Strategy_FixNesting();
14 function testBlockAndInlineIntegration() {
17 $this->assertResult('<b>Bold text</b>');
19 // legal inline and block (default parent element is FLOW)
20 $this->assertResult('<a href="about:blank">Blank</a><div>Block</div>');
22 // illegal block in inline
24 '<b><div>Illegal div.</div></b>',
28 // same test with different configuration (fragile)
30 '<b><div>Illegal div.</div></b>',
31 '<b><div>Illegal div.</div></b>',
32 array('Core.EscapeInvalidChildren' => true)
37 function testNodeRemovalIntegration() {
39 // test of empty set that's required, resulting in removal of node
40 $this->assertResult('<ul></ul>', '');
42 // test illegal text which gets removed
44 '<ul>Illegal text<li>Legal item</li></ul>',
45 '<ul><li>Legal item</li></ul>'
50 function testTableIntegration() {
51 // test custom table definition
53 '<table><tr><td>Cell 1</td></tr></table>'
55 $this->assertResult('<table></table>', '');
58 function testChameleonIntegration() {
60 // block in inline ins not allowed
62 '<span><ins><div>Not allowed!</div></ins></span>',
63 '<span><ins>Not allowed!</ins></span>'
66 // test block element that has inline content
68 '<h1><ins><div>Not allowed!</div></ins></h1>',
69 '<h1><ins>Not allowed!</ins></h1>'
74 '<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
75 '<h1><ins><del>Not allowed!</del></ins></h1>'
78 '<div><ins><del><div>Allowed!</div></del></ins></div>'
81 $this->assertResult( // alt config
82 '<span><ins><div>Not allowed!</div></ins></span>',
83 '<span><ins><div>Not allowed!</div></ins></span>',
84 array('Core.EscapeInvalidChildren' => true)
89 function testExclusionsIntegration() {
92 '<a><span><a>Not allowed</a></span></a>',
93 '<a><span></span></a>'
97 function testCustomParentIntegration() {
100 '<b>Bold</b>', true, array('HTML.Parent' => 'span')
103 '<div>Reject</div>', 'Reject', array('HTML.Parent' => 'span')
107 function testError() {
108 // test fallback to div
109 $this->expectError('Cannot use unrecognized element as parent.');
111 '<div>Accept</div>', true, array('HTML.Parent' => 'obviously-impossible')
113 $this->swallowErrors();
117 function testDoubleCheckIntegration() {
118 // breaks without the redundant checking code
119 $this->assertResult('<table><tr></tr></table>', '');
121 // special case, prevents scrolling one back to find parent
122 $this->assertResult('<table><tr></tr><tr></tr></table>', '');
124 // cascading rollbacks
126 '<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>',
131 $this->assertResult('<table></table><table></table>', '');