3 require_once 'HTMLPurifier/HTMLModule/Tidy.php';
6 'HTMLPurifier_HTMLModule_Tidy',
7 'HTMLPurifier_HTMLModule_Tidy_TestForConstruct',
8 array('makeFixes', 'makeFixesForLevel', 'populate')
11 class HTMLPurifier_HTMLModule_TidyTest
extends HTMLPurifier_Harness
14 function test_getFixesForLevel() {
16 $module = new HTMLPurifier_HTMLModule_Tidy();
17 $module->fixesForLevel
['light'][] = 'light-fix';
18 $module->fixesForLevel
['medium'][] = 'medium-fix';
19 $module->fixesForLevel
['heavy'][] = 'heavy-fix';
21 $this->assertIdentical(
23 $module->getFixesForLevel('none')
25 $this->assertIdentical(
26 array('light-fix' => true),
27 $module->getFixesForLevel('light')
29 $this->assertIdentical(
30 array('light-fix' => true, 'medium-fix' => true),
31 $module->getFixesForLevel('medium')
33 $this->assertIdentical(
34 array('light-fix' => true, 'medium-fix' => true, 'heavy-fix' => true),
35 $module->getFixesForLevel('heavy')
38 $this->expectError('Tidy level turbo not recognized');
39 $module->getFixesForLevel('turbo');
43 function test_construct() {
45 $i = 0; // counter, helps us isolate expectations
47 // initialize partial mock
48 $module = new HTMLPurifier_HTMLModule_Tidy_TestForConstruct();
49 $module->fixesForLevel
['light'] = array('light-fix-1', 'light-fix-2');
50 $module->fixesForLevel
['medium'] = array('medium-fix-1', 'medium-fix-2');
51 $module->fixesForLevel
['heavy'] = array('heavy-fix-1', 'heavy-fix-2');
55 'light-fix-1' => $lf1 = $j++
,
56 'light-fix-2' => $lf2 = $j++
,
57 'medium-fix-1' => $mf1 = $j++
,
58 'medium-fix-2' => $mf2 = $j++
,
59 'heavy-fix-1' => $hf1 = $j++
,
60 'heavy-fix-2' => $hf2 = $j++
62 $module->setReturnValue('makeFixes', $fixes);
64 $config = HTMLPurifier_Config
::create(array(
65 'HTML.TidyLevel' => 'none'
67 $module->expectAt($i++
, 'populate', array(array()));
68 $module->construct($config);
72 $config = HTMLPurifier_Config
::create(array(
73 'HTML.TidyLevel' => 'light'
75 $module->expectAt($i++
, 'populate', array(array(
76 'light-fix-1' => $lf1,
79 $module->construct($config);
81 $config = HTMLPurifier_Config
::create(array(
82 'HTML.TidyLevel' => 'heavy'
84 $module->expectAt($i++
, 'populate', array(array(
85 'light-fix-1' => $lf1,
86 'light-fix-2' => $lf2,
87 'medium-fix-1' => $mf1,
88 'medium-fix-2' => $mf2,
89 'heavy-fix-1' => $hf1,
92 $module->construct($config);
94 // fine grained tuning
96 $config = HTMLPurifier_Config
::create(array(
97 'HTML.TidyLevel' => 'none',
98 'HTML.TidyAdd' => array('light-fix-1', 'medium-fix-1')
100 $module->expectAt($i++
, 'populate', array(array(
101 'light-fix-1' => $lf1,
102 'medium-fix-1' => $mf1
104 $module->construct($config);
106 $config = HTMLPurifier_Config
::create(array(
107 'HTML.TidyLevel' => 'medium',
108 'HTML.TidyRemove' => array('light-fix-1', 'medium-fix-1')
110 $module->expectAt($i++
, 'populate', array(array(
111 'light-fix-2' => $lf2,
112 'medium-fix-2' => $mf2
114 $module->construct($config);
122 function test_makeFixesForLevel() {
124 $module = new HTMLPurifier_HTMLModule_Tidy();
125 $module->defaultLevel
= 'heavy';
127 $module->makeFixesForLevel(array(
133 $this->assertIdentical($module->fixesForLevel
['heavy'], array('fix-1', 'fix-2', 'fix-3'));
134 $this->assertIdentical($module->fixesForLevel
['medium'], array());
135 $this->assertIdentical($module->fixesForLevel
['light'], array());
138 function test_makeFixesForLevel_undefinedLevel() {
140 $module = new HTMLPurifier_HTMLModule_Tidy();
141 $module->defaultLevel
= 'bananas';
143 $this->expectError('Default level bananas does not exist');
145 $module->makeFixesForLevel(array(
151 function test_getFixType() {
153 // syntax needs documenting
155 $module = new HTMLPurifier_HTMLModule_Tidy();
157 $this->assertIdentical(
158 $module->getFixType('a'),
159 array('tag_transform', array('element' => 'a'))
162 $this->assertIdentical(
163 $module->getFixType('a@href'),
164 $reuse = array('attr_transform_pre', array('element' => 'a', 'attr' => 'href'))
167 $this->assertIdentical(
168 $module->getFixType('a@href#pre'),
172 $this->assertIdentical(
173 $module->getFixType('a@href#post'),
174 array('attr_transform_post', array('element' => 'a', 'attr' => 'href'))
177 $this->assertIdentical(
178 $module->getFixType('xml:foo@xml:bar'),
179 array('attr_transform_pre', array('element' => 'xml:foo', 'attr' => 'xml:bar'))
182 $this->assertIdentical(
183 $module->getFixType('blockquote#child'),
184 array('child', array('element' => 'blockquote'))
187 $this->assertIdentical(
188 $module->getFixType('@lang'),
189 array('attr_transform_pre', array('attr' => 'lang'))
192 $this->assertIdentical(
193 $module->getFixType('@lang#post'),
194 array('attr_transform_post', array('attr' => 'lang'))
199 function test_populate() {
203 $module = new HTMLPurifier_HTMLModule_Tidy();
204 $module->populate(array(
205 'element' => $element = $i++
,
206 'element@attr' => $attr = $i++
,
207 'element@attr#post' => $attr_post = $i++
,
208 'element#child' => $child = $i++
,
209 'element#content_model_type' => $content_model_type = $i++
,
210 '@attr' => $global_attr = $i++
,
211 '@attr#post' => $global_attr_post = $i++
214 $module2 = new HTMLPurifier_HTMLModule_Tidy();
215 $e =& $module2->addBlankElement('element');
216 $e->attr_transform_pre
['attr'] = $attr;
217 $e->attr_transform_post
['attr'] = $attr_post;
219 $e->content_model_type
= $content_model_type;
220 $module2->info_tag_transform
['element'] = $element;
221 $module2->info_attr_transform_pre
['attr'] = $global_attr;
222 $module2->info_attr_transform_post
['attr'] = $global_attr_post;
224 $this->assertEqual($module, $module2);