Convert all to new configuration get/set format.
[htmlpurifier/darkodev.git] / tests / HTMLPurifier / HTMLModule / TidyTest.php
blobe80aeb16dae5e796341297ca1000521d0887482c
1 <?php
3 Mock::generatePartial(
4 'HTMLPurifier_HTMLModule_Tidy',
5 'HTMLPurifier_HTMLModule_Tidy_TestForConstruct',
6 array('makeFixes', 'makeFixesForLevel', 'populate')
7 );
9 class HTMLPurifier_HTMLModule_TidyTest extends HTMLPurifier_Harness
12 function test_getFixesForLevel() {
14 $module = new HTMLPurifier_HTMLModule_Tidy();
15 $module->fixesForLevel['light'][] = 'light-fix';
16 $module->fixesForLevel['medium'][] = 'medium-fix';
17 $module->fixesForLevel['heavy'][] = 'heavy-fix';
19 $this->assertIdentical(
20 array(),
21 $module->getFixesForLevel('none')
23 $this->assertIdentical(
24 array('light-fix' => true),
25 $module->getFixesForLevel('light')
27 $this->assertIdentical(
28 array('light-fix' => true, 'medium-fix' => true),
29 $module->getFixesForLevel('medium')
31 $this->assertIdentical(
32 array('light-fix' => true, 'medium-fix' => true, 'heavy-fix' => true),
33 $module->getFixesForLevel('heavy')
36 $this->expectError('Tidy level turbo not recognized');
37 $module->getFixesForLevel('turbo');
41 function test_setup() {
43 $i = 0; // counter, helps us isolate expectations
45 // initialize partial mock
46 $module = new HTMLPurifier_HTMLModule_Tidy_TestForConstruct();
47 $module->fixesForLevel['light'] = array('light-fix-1', 'light-fix-2');
48 $module->fixesForLevel['medium'] = array('medium-fix-1', 'medium-fix-2');
49 $module->fixesForLevel['heavy'] = array('heavy-fix-1', 'heavy-fix-2');
51 $j = 0;
52 $fixes = array(
53 'light-fix-1' => $lf1 = $j++,
54 'light-fix-2' => $lf2 = $j++,
55 'medium-fix-1' => $mf1 = $j++,
56 'medium-fix-2' => $mf2 = $j++,
57 'heavy-fix-1' => $hf1 = $j++,
58 'heavy-fix-2' => $hf2 = $j++
60 $module->setReturnValue('makeFixes', $fixes);
62 $config = HTMLPurifier_Config::create(array(
63 'HTML.TidyLevel' => 'none'
64 ));
65 $module->expectAt($i++, 'populate', array(array()));
66 $module->setup($config);
68 // basic levels
70 $config = HTMLPurifier_Config::create(array(
71 'HTML.TidyLevel' => 'light'
72 ));
73 $module->expectAt($i++, 'populate', array(array(
74 'light-fix-1' => $lf1,
75 'light-fix-2' => $lf2
76 )));
77 $module->setup($config);
79 $config = HTMLPurifier_Config::create(array(
80 'HTML.TidyLevel' => 'heavy'
81 ));
82 $module->expectAt($i++, 'populate', array(array(
83 'light-fix-1' => $lf1,
84 'light-fix-2' => $lf2,
85 'medium-fix-1' => $mf1,
86 'medium-fix-2' => $mf2,
87 'heavy-fix-1' => $hf1,
88 'heavy-fix-2' => $hf2
89 )));
90 $module->setup($config);
92 // fine grained tuning
94 $config = HTMLPurifier_Config::create(array(
95 'HTML.TidyLevel' => 'none',
96 'HTML.TidyAdd' => array('light-fix-1', 'medium-fix-1')
97 ));
98 $module->expectAt($i++, 'populate', array(array(
99 'light-fix-1' => $lf1,
100 'medium-fix-1' => $mf1
101 )));
102 $module->setup($config);
104 $config = HTMLPurifier_Config::create(array(
105 'HTML.TidyLevel' => 'medium',
106 'HTML.TidyRemove' => array('light-fix-1', 'medium-fix-1')
108 $module->expectAt($i++, 'populate', array(array(
109 'light-fix-2' => $lf2,
110 'medium-fix-2' => $mf2
111 )));
112 $module->setup($config);
116 function test_makeFixesForLevel() {
118 $module = new HTMLPurifier_HTMLModule_Tidy();
119 $module->defaultLevel = 'heavy';
121 $module->makeFixesForLevel(array(
122 'fix-1' => 0,
123 'fix-2' => 1,
124 'fix-3' => 2
127 $this->assertIdentical($module->fixesForLevel['heavy'], array('fix-1', 'fix-2', 'fix-3'));
128 $this->assertIdentical($module->fixesForLevel['medium'], array());
129 $this->assertIdentical($module->fixesForLevel['light'], array());
132 function test_makeFixesForLevel_undefinedLevel() {
134 $module = new HTMLPurifier_HTMLModule_Tidy();
135 $module->defaultLevel = 'bananas';
137 $this->expectError('Default level bananas does not exist');
139 $module->makeFixesForLevel(array(
140 'fix-1' => 0
145 function test_getFixType() {
147 // syntax needs documenting
149 $module = new HTMLPurifier_HTMLModule_Tidy();
151 $this->assertIdentical(
152 $module->getFixType('a'),
153 array('tag_transform', array('element' => 'a'))
156 $this->assertIdentical(
157 $module->getFixType('a@href'),
158 $reuse = array('attr_transform_pre', array('element' => 'a', 'attr' => 'href'))
161 $this->assertIdentical(
162 $module->getFixType('a@href#pre'),
163 $reuse
166 $this->assertIdentical(
167 $module->getFixType('a@href#post'),
168 array('attr_transform_post', array('element' => 'a', 'attr' => 'href'))
171 $this->assertIdentical(
172 $module->getFixType('xml:foo@xml:bar'),
173 array('attr_transform_pre', array('element' => 'xml:foo', 'attr' => 'xml:bar'))
176 $this->assertIdentical(
177 $module->getFixType('blockquote#child'),
178 array('child', array('element' => 'blockquote'))
181 $this->assertIdentical(
182 $module->getFixType('@lang'),
183 array('attr_transform_pre', array('attr' => 'lang'))
186 $this->assertIdentical(
187 $module->getFixType('@lang#post'),
188 array('attr_transform_post', array('attr' => 'lang'))
193 function test_populate() {
195 $i = 0;
197 $module = new HTMLPurifier_HTMLModule_Tidy();
198 $module->populate(array(
199 'element' => $element = $i++,
200 'element@attr' => $attr = $i++,
201 'element@attr#post' => $attr_post = $i++,
202 'element#child' => $child = $i++,
203 'element#content_model_type' => $content_model_type = $i++,
204 '@attr' => $global_attr = $i++,
205 '@attr#post' => $global_attr_post = $i++
208 $module2 = new HTMLPurifier_HTMLModule_Tidy();
209 $e = $module2->addBlankElement('element');
210 $e->attr_transform_pre['attr'] = $attr;
211 $e->attr_transform_post['attr'] = $attr_post;
212 $e->child = $child;
213 $e->content_model_type = $content_model_type;
214 $module2->info_tag_transform['element'] = $element;
215 $module2->info_attr_transform_pre['attr'] = $global_attr;
216 $module2->info_attr_transform_post['attr'] = $global_attr_post;
218 $this->assertEqual($module, $module2);
224 // vim: et sw=4 sts=4