Convert all to new configuration get/set format.
[htmlpurifier/darkodev.git] / tests / HTMLPurifier / AttrCollectionsTest.php
blob227bc95359ea09d82f6c6b0d243767efceec1930
1 <?php
3 Mock::generatePartial(
4 'HTMLPurifier_AttrCollections',
5 'HTMLPurifier_AttrCollections_TestForConstruct',
6 array('performInclusions', 'expandIdentifiers')
7 );
9 class HTMLPurifier_AttrCollectionsTest extends HTMLPurifier_Harness
12 function testConstruction() {
14 generate_mock_once('HTMLPurifier_AttrTypes');
16 $collections = new HTMLPurifier_AttrCollections_TestForConstruct();
18 $types = new HTMLPurifier_AttrTypesMock();
20 $modules = array();
22 $modules['Module1'] = new HTMLPurifier_HTMLModule();
23 $modules['Module1']->attr_collections = array(
24 'Core' => array(
25 0 => array('Soup', 'Undefined'),
26 'attribute' => 'Type',
27 'attribute-2' => 'Type2',
29 'Soup' => array(
30 'attribute-3' => 'Type3-old' // overwritten
34 $modules['Module2'] = new HTMLPurifier_HTMLModule();
35 $modules['Module2']->attr_collections = array(
36 'Core' => array(
37 0 => array('Brocolli')
39 'Soup' => array(
40 'attribute-3' => 'Type3'
42 'Brocolli' => array()
45 $collections->__construct($types, $modules);
46 // this is without identifier expansion or inclusions
47 $this->assertIdentical(
48 $collections->info,
49 array(
50 'Core' => array(
51 0 => array('Soup', 'Undefined', 'Brocolli'),
52 'attribute' => 'Type',
53 'attribute-2' => 'Type2'
55 'Soup' => array(
56 'attribute-3' => 'Type3'
58 'Brocolli' => array()
64 function test_performInclusions() {
66 generate_mock_once('HTMLPurifier_AttrTypes');
68 $types = new HTMLPurifier_AttrTypesMock();
69 $collections = new HTMLPurifier_AttrCollections($types, array());
70 $collections->info = array(
71 'Core' => array(0 => array('Inclusion', 'Undefined'), 'attr-original' => 'Type'),
72 'Inclusion' => array(0 => array('SubInclusion'), 'attr' => 'Type'),
73 'SubInclusion' => array('attr2' => 'Type')
76 $collections->performInclusions($collections->info['Core']);
77 $this->assertIdentical(
78 $collections->info['Core'],
79 array(
80 'attr-original' => 'Type',
81 'attr' => 'Type',
82 'attr2' => 'Type'
86 // test recursive
87 $collections->info = array(
88 'One' => array(0 => array('Two'), 'one' => 'Type'),
89 'Two' => array(0 => array('One'), 'two' => 'Type')
91 $collections->performInclusions($collections->info['One']);
92 $this->assertIdentical(
93 $collections->info['One'],
94 array(
95 'one' => 'Type',
96 'two' => 'Type'
102 function test_expandIdentifiers() {
104 generate_mock_once('HTMLPurifier_AttrTypes');
106 $types = new HTMLPurifier_AttrTypesMock();
107 $collections = new HTMLPurifier_AttrCollections($types, array());
109 $attr = array(
110 'attr1' => 'Color',
111 'attr2*' => 'URI'
113 $c_object = new HTMLPurifier_AttrDef_HTML_Color();
114 $u_object = new HTMLPurifier_AttrDef_URI();
116 $types->setReturnValue('get', $c_object, array('Color'));
117 $types->setReturnValue('get', $u_object, array('URI'));
119 $collections->expandIdentifiers($attr, $types);
121 $u_object->required = true;
122 $this->assertIdentical(
123 $attr,
124 array(
125 'attr1' => $c_object,
126 'attr2' => $u_object
134 // vim: et sw=4 sts=4