[3.1.0] Fix bug with addAttribute when called multiple times on the same element
[htmlpurifier/rdancer.git] / tests / HTMLPurifier / HTMLDefinitionTest.php
blob64e9e1a38f2c970ad260ac5f136ec858654dcb9b
1 <?php
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
14 $this->assertEqual(
15 $def->parseTinyMCEAllowedList(''),
16 array(array(), array())
19 $this->assertEqual(
20 $def->parseTinyMCEAllowedList('a,b,c'),
21 array(array('a' => true, 'b' => true, 'c' => true), array())
24 $this->assertEqual(
25 $def->parseTinyMCEAllowedList('a[x|y|z]'),
26 array(array('a' => true), array('a.x' => true, 'a.y' => true, 'a.z' => true))
29 $this->assertEqual(
30 $def->parseTinyMCEAllowedList('*[id]'),
31 array(array(), array('*.id' => true))
34 $this->assertEqual(
35 $def->parseTinyMCEAllowedList('a[*]'),
36 array(array('a' => true), array('a.*' => true))
39 $this->assertEqual(
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))
45 $this->assertEqual(
46 // alternate form:
47 $def->parseTinyMCEAllowedList(
48 'span[style]
49 strong
50 a[href|title]
51 '),
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')
63 ));
65 $config2 = HTMLPurifier_Config::create(array(
66 'HTML.Allowed' => 'b,i,p,a[href],*[id]'
67 ));
69 $this->assertEqual($config1->getHTMLDefinition(), $config2->getHTMLDefinition());
73 function test_addAttribute() {
75 $config = HTMLPurifier_Config::create(array(
76 'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addAttribute'
77 ));
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'
92 ));
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);