summaryrefslogtreecommitdiffstats
path: root/vendor/ezyang/htmlpurifier/tests/HTMLPurifier/AttrCollectionsTest.php
blob: d18c036c3d8e00788e867dfb658adc78a90f98ed (plain)
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
<?php

Mock::generatePartial(
    'HTMLPurifier_AttrCollections',
    'HTMLPurifier_AttrCollections_TestForConstruct',
    array('performInclusions', 'expandIdentifiers')
);

class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
{

    public function testConstruction()
    {
        generate_mock_once('HTMLPurifier_AttrTypes');

        $collections = new HTMLPurifier_AttrCollections_TestForConstruct();

        $types = new HTMLPurifier_AttrTypesMock();

        $modules = array();

        $modules['Module1'] = new HTMLPurifier_HTMLModule();
        $modules['Module1']->attr_collections = array(
            'Core' => array(
                0 => array('Soup', 'Undefined'),
                'attribute' => 'Type',
                'attribute-2' => 'Type2',
            ),
            'Soup' => array(
                'attribute-3' => 'Type3-old' // overwritten
            )
        );

        $modules['Module2'] = new HTMLPurifier_HTMLModule();
        $modules['Module2']->attr_collections = array(
            'Core' => array(
                0 => array('Brocolli')
            ),
            'Soup' => array(
                'attribute-3' => 'Type3'
            ),
            'Brocolli' => array()
        );

        $collections->__construct($types, $modules);
        // this is without identifier expansion or inclusions
        $this->assertIdentical(
            $collections->info,
            array(
                'Core' => array(
                    0 => array('Soup', 'Undefined', 'Brocolli'),
                    'attribute' => 'Type',
                    'attribute-2' => 'Type2'
                ),
                'Soup' => array(
                    'attribute-3' => 'Type3'
                ),
                'Brocolli' => array()
            )
        );

    }

    public function test_performInclusions()
    {
        generate_mock_once('HTMLPurifier_AttrTypes');

        $types = new HTMLPurifier_AttrTypesMock();
        $collections = new HTMLPurifier_AttrCollections($types, array());
        $collections->info = array(
            'Core' => array(0 => array('Inclusion', 'Undefined'), 'attr-original' => 'Type'),
            'Inclusion' => array(0 => array('SubInclusion'), 'attr' => 'Type'),
            'SubInclusion' => array('attr2' => 'Type')
        );

        $collections->performInclusions($collections->info['Core']);
        $this->assertIdentical(
            $collections->info['Core'],
            array(
                'attr-original' => 'Type',
                'attr' => 'Type',
                'attr2' => 'Type'
            )
        );

        // test recursive
        $collections->info = array(
            'One' => array(0 => array('Two'), 'one' => 'Type'),
            'Two' => array(0 => array('One'), 'two' => 'Type')
        );
        $collections->performInclusions($collections->info['One']);
        $this->assertIdentical(
            $collections->info['One'],
            array(
                'one' => 'Type',
                'two' => 'Type'
            )
        );

    }

    public function test_expandIdentifiers()
    {
        generate_mock_once('HTMLPurifier_AttrTypes');

        $types = new HTMLPurifier_AttrTypesMock();
        $collections = new HTMLPurifier_AttrCollections($types, array());

        $attr = array(
            'attr1' => 'Color',
            'attr2*' => 'URI'
        );
        $c_object = new HTMLPurifier_AttrDef_HTML_Color();
        $u_object = new HTMLPurifier_AttrDef_URI();

        $types->setReturnValue('get', $c_object, array('Color'));
        $types->setReturnValue('get', $u_object, array('URI'));

        $collections->expandIdentifiers($attr, $types);

        $u_object->required = true;
        $this->assertIdentical(
            $attr,
            array(
                'attr1' => $c_object,
                'attr2' => $u_object
            )
        );

    }

}

// vim: et sw=4 sts=4