3 class HTMLPurifier_HTMLDefinitionTest
extends HTMLPurifier_Harness
6 function test_parseTinyMCEAllowedList() {
8 $def = new HTMLPurifier_HTMLDefinition();
10 // note: this is case-sensitive, but its config schema
11 // counterpart is not. This is generally a good thing for users,
12 // but it's a slight internal inconsistency
15 $def->parseTinyMCEAllowedList(''),
16 array(array(), array())
20 $def->parseTinyMCEAllowedList('a,b,c'),
21 array(array('a' => true, 'b' => true, 'c' => true), array())
25 $def->parseTinyMCEAllowedList('a[x|y|z]'),
26 array(array('a' => true), array('a.x' => true, 'a.y' => true, 'a.z' => true))
30 $def->parseTinyMCEAllowedList('*[id]'),
31 array(array(), array('*.id' => true))
35 $def->parseTinyMCEAllowedList('a[*]'),
36 array(array('a' => true), array('a.*' => true))
40 $def->parseTinyMCEAllowedList('span[style],strong,a[href|title]'),
41 array(array('span' => true, 'strong' => true, 'a' => true),
42 array('span.style' => true, 'a.href' => true, 'a.title' => true))
47 $def->parseTinyMCEAllowedList(
52 array(array('span' => true, 'strong' => true, 'a' => true),
53 array('span.style' => true, 'a.href' => true, 'a.title' => true))
58 function test_Allowed() {
60 $config1 = HTMLPurifier_Config
::create(array(
61 'HTML.AllowedElements' => array('b', 'i', 'p', 'a'),
62 'HTML.AllowedAttributes' => array('a.href', '*.id')
65 $config2 = HTMLPurifier_Config
::create(array(
66 'HTML.Allowed' => 'b,i,p,a[href],*[id]'
69 $this->assertEqual($config1->getHTMLDefinition(), $config2->getHTMLDefinition());
73 function test_addAttribute() {
75 $config = HTMLPurifier_Config
::create(array(
76 'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addAttribute'
78 $def =& $config->getHTMLDefinition(true);
79 $def->addAttribute('span', 'custom', 'Enum#attribute');
81 $purifier = new HTMLPurifier($config);
82 $input = '<span custom="attribute">Custom!</span>';
83 $output = $purifier->purify($input);
84 $this->assertIdentical($input, $output);
88 function test_addAttribute_multiple() {
90 $config = HTMLPurifier_Config
::create(array(
91 'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addAttribute_multiple'
93 $def =& $config->getHTMLDefinition(true);
94 $def->addAttribute('span', 'custom', 'Enum#attribute');
95 $def->addAttribute('span', 'foo', 'Text');
97 $purifier = new HTMLPurifier($config);
98 $input = '<span custom="attribute" foo="asdf">Custom!</span>';
99 $output = $purifier->purify($input);
100 $this->assertIdentical($input, $output);
104 function test_addElement() {
106 $config = HTMLPurifier_Config
::create(array(
107 'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addElement'
109 $def =& $config->getHTMLDefinition(true);
110 $def->addElement('marquee', 'Inline', 'Inline', 'Common', array('width' => 'Length'));
112 $purifier = new HTMLPurifier($config);
113 $input = '<span><marquee width="50">Foobar</marquee></span>';
114 $output = $purifier->purify($input);
115 $this->assertIdentical($input, $output);