aboutsummaryrefslogtreecommitdiffstats
path: root/lib/htmlpurifier/tests/HTMLPurifier/Strategy/FixNestingTest.php
blob: 9394352ec30d6613dc76ec06c5b5ebeb162c692a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php

class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
{

    function setUp() {
        parent::setUp();
        $this->obj = new HTMLPurifier_Strategy_FixNesting();
    }

    function testPreserveInlineInRoot() {
        $this->assertResult('<b>Bold text</b>');
    }

    function testPreserveInlineAndBlockInRoot() {
        $this->assertResult('<a href="about:blank">Blank</a><div>Block</div>');
    }

    function testRemoveBlockInInline() {
        $this->assertResult(
            '<b><div>Illegal div.</div></b>',
            '<b>Illegal div.</b>'
        );
    }

    function testEscapeBlockInInline() {
        $this->config->set('Core.EscapeInvalidChildren', true);
        $this->assertResult(
            '<b><div>Illegal div.</div></b>',
            '<b>&lt;div&gt;Illegal div.&lt;/div&gt;</b>'
        );
    }

    function testRemoveNodeWithMissingRequiredElements() {
        $this->assertResult('<ul></ul>', '');
    }

    function testListHandleIllegalPCDATA() {
        $this->assertResult(
            '<ul>Illegal text<li>Legal item</li></ul>',
            '<ul><li>Illegal text</li><li>Legal item</li></ul>'
        );
    }

    function testRemoveIllegalPCDATA() {
        $this->assertResult(
            '<table><tr>Illegal text<td></td></tr></table>',
            '<table><tr><td></td></tr></table>'
        );
    }

    function testCustomTableDefinition() {
        $this->assertResult('<table><tr><td>Cell 1</td></tr></table>');
    }

    function testRemoveEmptyTable() {
        $this->assertResult('<table></table>', '');
    }

    function testChameleonRemoveBlockInNodeInInline() {
        $this->assertResult(
          '<span><ins><div>Not allowed!</div></ins></span>',
          '<span><ins>Not allowed!</ins></span>'
        );
    }

    function testChameleonRemoveBlockInBlockNodeWithInlineContent() {
        $this->assertResult(
          '<h1><ins><div>Not allowed!</div></ins></h1>',
          '<h1><ins>Not allowed!</ins></h1>'
        );
    }

    function testNestedChameleonRemoveBlockInNodeWithInlineContent() {
        $this->assertResult(
          '<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
          '<h1><ins><del>Not allowed!</del></ins></h1>'
        );
    }

    function testNestedChameleonPreserveBlockInBlock() {
        $this->assertResult(
          '<div><ins><del><div>Allowed!</div></del></ins></div>'
        );
    }

    function testChameleonEscapeInvalidBlockInInline() {
        $this->config->set('Core.EscapeInvalidChildren', true);
        $this->assertResult( // alt config
          '<span><ins><div>Not allowed!</div></ins></span>',
          '<span><ins>&lt;div&gt;Not allowed!&lt;/div&gt;</ins></span>'
        );
    }

    function testExclusionsIntegration() {
        // test exclusions
        $this->assertResult(
          '<a><span><a>Not allowed</a></span></a>',
          '<a><span></span></a>'
        );
    }

    function testPreserveInlineNodeInInlineRootNode() {
        $this->config->set('HTML.Parent', 'span');
        $this->assertResult('<b>Bold</b>');
    }

    function testRemoveBlockNodeInInlineRootNode() {
        $this->config->set('HTML.Parent', 'span');
        $this->assertResult('<div>Reject</div>', 'Reject');
   }

   function testInvalidParentError() {
        // test fallback to div
        $this->config->set('HTML.Parent', 'obviously-impossible');
        $this->config->set('Cache.DefinitionImpl', null);
        $this->expectError('Cannot use unrecognized element as parent');
        $this->assertResult('<div>Accept</div>');
    }

    function testCascadingRemovalOfNodesMissingRequiredChildren() {
        $this->assertResult('<table><tr></tr></table>', '');
    }

    function testCascadingRemovalSpecialCaseCannotScrollOneBack() {
        $this->assertResult('<table><tr></tr><tr></tr></table>', '');
    }

    function testLotsOfCascadingRemovalOfNodes() {
        $this->assertResult('<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>', '');
    }

    function testAdjacentRemovalOfNodeMissingRequiredChildren() {
        $this->assertResult('<table></table><table></table>', '');
    }

    function testStrictBlockquoteInHTML401() {
        $this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
        $this->assertResult('<blockquote>text</blockquote>', '<blockquote><p>text</p></blockquote>');
    }

}

// vim: et sw=4 sts=4