Release 2.1.0, merged in 1313 to HEAD.
[htmlpurifier.git] / tests / HTMLPurifier / Strategy / FixNestingTest.php
blobac651684644d7746699dfe32abefb1a91b88d225
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 testBlockAndInlineIntegration() {
16 // legal inline
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
23 $this->assertResult(
24 '<b><div>Illegal div.</div></b>',
25 '<b>Illegal div.</b>'
28 // same test with different configuration (fragile)
29 $this->assertResult(
30 '<b><div>Illegal div.</div></b>',
31 '<b>&lt;div&gt;Illegal div.&lt;/div&gt;</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
43 $this->assertResult(
44 '<ul>Illegal text<li>Legal item</li></ul>',
45 '<ul><li>Legal item</li></ul>'
50 function testTableIntegration() {
51 // test custom table definition
52 $this->assertResult(
53 '<table><tr><td>Cell 1</td></tr></table>'
55 $this->assertResult('<table></table>', '');
58 function testChameleonIntegration() {
60 // block in inline ins not allowed
61 $this->assertResult(
62 '<span><ins><div>Not allowed!</div></ins></span>',
63 '<span><ins>Not allowed!</ins></span>'
66 // test block element that has inline content
67 $this->assertResult(
68 '<h1><ins><div>Not allowed!</div></ins></h1>',
69 '<h1><ins>Not allowed!</ins></h1>'
72 // stacked ins/del
73 $this->assertResult(
74 '<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
75 '<h1><ins><del>Not allowed!</del></ins></h1>'
77 $this->assertResult(
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>&lt;div&gt;Not allowed!&lt;/div&gt;</ins></span>',
84 array('Core.EscapeInvalidChildren' => true)
89 function testExclusionsIntegration() {
90 // test exclusions
91 $this->assertResult(
92 '<a><span><a>Not allowed</a></span></a>',
93 '<a><span></span></a>'
97 function testCustomParentIntegration() {
98 // test inline parent
99 $this->assertResult(
100 '<b>Bold</b>', true, array('HTML.Parent' => 'span')
102 $this->assertResult(
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.');
110 $this->assertResult(
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
125 $this->assertResult(
126 '<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>',
130 // rollbacks twice
131 $this->assertResult('<table></table><table></table>', '');