aboutsummaryrefslogtreecommitdiffstats
path: root/lib/htmlpurifier/tests/HTMLPurifier/HTMLModuleTest.php
blob: 65220f08b056f1fedc5e227b9a5933f07b675546 (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
145
146
<?php

class HTMLPurifier_HTMLModuleTest extends HTMLPurifier_Harness
{

    function test_addElementToContentSet() {

        $module = new HTMLPurifier_HTMLModule();

        $module->addElementToContentSet('b', 'Inline');
        $this->assertIdentical($module->content_sets, array('Inline' => 'b'));

        $module->addElementToContentSet('i', 'Inline');
        $this->assertIdentical($module->content_sets, array('Inline' => 'b | i'));

    }

    function test_addElement() {

        $module = new HTMLPurifier_HTMLModule();
        $def = $module->addElement(
            'a', 'Inline', 'Optional: #PCDATA', array('Common'),
            array(
                'href' => 'URI'
            )
        );

        $module2 = new HTMLPurifier_HTMLModule();
        $def2 = new HTMLPurifier_ElementDef();
        $def2->content_model = '#PCDATA';
        $def2->content_model_type = 'optional';
        $def2->attr = array(
            'href' => 'URI',
            0 => array('Common')
        );
        $module2->info['a'] = $def2;
        $module2->elements = array('a');
        $module2->content_sets['Inline'] = 'a';

        $this->assertIdentical($module, $module2);
        $this->assertIdentical($def, $def2);
        $this->assertReference($def, $module->info['a']);

    }

    function test_parseContents() {

        $module = new HTMLPurifier_HTMLModule();

        // pre-defined templates
        $this->assertIdentical(
            $module->parseContents('Inline'),
            array('optional', 'Inline | #PCDATA')
        );
        $this->assertIdentical(
            $module->parseContents('Flow'),
            array('optional', 'Flow | #PCDATA')
        );
        $this->assertIdentical(
            $module->parseContents('Empty'),
            array('empty', '')
        );

        // normalization procedures
        $this->assertIdentical(
            $module->parseContents('optional: a'),
            array('optional', 'a')
        );
        $this->assertIdentical(
            $module->parseContents('OPTIONAL :a'),
            array('optional', 'a')
        );
        $this->assertIdentical(
            $module->parseContents('Optional: a'),
            array('optional', 'a')
        );

        // others
        $this->assertIdentical(
            $module->parseContents('Optional: a | b | c'),
            array('optional', 'a | b | c')
        );

        // object pass-through
        generate_mock_once('HTMLPurifier_AttrDef');
        $this->assertIdentical(
            $module->parseContents(new HTMLPurifier_AttrDefMock()),
            array(null, null)
        );

    }

    function test_mergeInAttrIncludes() {

        $module = new HTMLPurifier_HTMLModule();

        $attr = array();
        $module->mergeInAttrIncludes($attr, 'Common');
        $this->assertIdentical($attr, array(0 => array('Common')));

        $attr = array('a' => 'b');
        $module->mergeInAttrIncludes($attr, array('Common', 'Good'));
        $this->assertIdentical($attr, array('a' => 'b', 0 => array('Common', 'Good')));

    }

    function test_addBlankElement() {

        $module = new HTMLPurifier_HTMLModule();
        $def = $module->addBlankElement('a');

        $def2 = new HTMLPurifier_ElementDef();
        $def2->standalone = false;

        $this->assertReference($module->info['a'], $def);
        $this->assertIdentical($def, $def2);

    }

    function test_makeLookup() {

        $module = new HTMLPurifier_HTMLModule();

        $this->assertIdentical(
            $module->makeLookup('foo'),
            array('foo' => true)
        );
        $this->assertIdentical(
            $module->makeLookup(array('foo')),
            array('foo' => true)
        );

        $this->assertIdentical(
            $module->makeLookup('foo', 'two'),
            array('foo' => true, 'two' => true)
        );
        $this->assertIdentical(
            $module->makeLookup(array('foo', 'two')),
            array('foo' => true, 'two' => true)
        );

    }

}

// vim: et sw=4 sts=4