Release 2.1.0, merged in 1313 to HEAD.
[htmlpurifier.git] / tests / HTMLPurifier / AttrCollectionsTest.php
blob52fc88f1dd6dfdc06d8f5258cc28be533f7bda42
1 <?php
3 require_once 'HTMLPurifier/AttrCollections.php';
5 class HTMLPurifier_AttrCollectionsTest_NoConstructor extends HTMLPurifier_AttrCollections
7 function HTMLPurifier_AttrCollectionsTest_NoConstructor() {}
8 function expandIdentifiers(&$a, $b) {}
9 function performInclusions(&$a) {}
12 class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
15 function testConstruction() {
17 generate_mock_once('HTMLPurifier_AttrTypes');
19 $collections = new HTMLPurifier_AttrCollectionsTest_NoConstructor();
21 $types = new HTMLPurifier_AttrTypesMock();
23 $modules = array();
25 $modules['Module1'] = new HTMLPurifier_HTMLModule();
26 $modules['Module1']->attr_collections = array(
27 'Core' => array(
28 0 => array('Soup', 'Undefined'),
29 'attribute' => 'Type',
30 'attribute-2' => 'Type2',
32 'Soup' => array(
33 'attribute-3' => 'Type3-old' // overwritten
37 $modules['Module2'] = new HTMLPurifier_HTMLModule();
38 $modules['Module2']->attr_collections = array(
39 'Core' => array(
40 0 => array('Brocolli')
42 'Soup' => array(
43 'attribute-3' => 'Type3'
45 'Brocolli' => array()
48 $collections->HTMLPurifier_AttrCollections($types, $modules);
49 // this is without identifier expansion or inclusions
50 $this->assertIdentical(
51 $collections->info,
52 array(
53 'Core' => array(
54 0 => array('Soup', 'Undefined', 'Brocolli'),
55 'attribute' => 'Type',
56 'attribute-2' => 'Type2'
58 'Soup' => array(
59 'attribute-3' => 'Type3'
61 'Brocolli' => array()
67 function test_performInclusions() {
69 generate_mock_once('HTMLPurifier_AttrTypes');
71 $types = new HTMLPurifier_AttrTypesMock();
72 $collections = new HTMLPurifier_AttrCollections($types, array());
73 $collections->info = array(
74 'Core' => array(0 => array('Inclusion', 'Undefined'), 'attr-original' => 'Type'),
75 'Inclusion' => array(0 => array('SubInclusion'), 'attr' => 'Type'),
76 'SubInclusion' => array('attr2' => 'Type')
79 $collections->performInclusions($collections->info['Core']);
80 $this->assertIdentical(
81 $collections->info['Core'],
82 array(
83 'attr-original' => 'Type',
84 'attr' => 'Type',
85 'attr2' => 'Type'
89 // test recursive
90 $collections->info = array(
91 'One' => array(0 => array('Two'), 'one' => 'Type'),
92 'Two' => array(0 => array('One'), 'two' => 'Type')
94 $collections->performInclusions($collections->info['One']);
95 $this->assertIdentical(
96 $collections->info['One'],
97 array(
98 'one' => 'Type',
99 'two' => 'Type'
105 function test_expandIdentifiers() {
107 generate_mock_once('HTMLPurifier_AttrTypes');
109 $types = new HTMLPurifier_AttrTypesMock();
110 $collections = new HTMLPurifier_AttrCollections($types, array());
112 $attr = array(
113 'attr1' => 'Color',
114 'attr2*' => 'URI'
116 $c_object = new HTMLPurifier_AttrDef();
117 $c_object->_name = 'Color'; // for testing purposes only
118 $u_object = new HTMLPurifier_AttrDef();
119 $u_object->_name = 'URL'; // for testing purposes only
121 $types->setReturnValue('get', $c_object, array('Color'));
122 $types->setReturnValue('get', $u_object, array('URI'));
124 $collections->expandIdentifiers($attr, $types);
126 $u_object->required = true;
127 $this->assertIdentical(
128 $attr,
129 array(
130 'attr1' => $c_object,
131 'attr2' => $u_object