3 require_once 'HTMLPurifier/HTMLModule.php';
4 require_once 'HTMLPurifier/AttrDef.php';
6 class HTMLPurifier_HTMLModuleTest
extends UnitTestCase
9 function test_addElementToContentSet() {
11 $module = new HTMLPurifier_HTMLModule();
13 $module->addElementToContentSet('b', 'Inline');
14 $this->assertIdentical($module->content_sets
, array('Inline' => 'b'));
16 $module->addElementToContentSet('i', 'Inline');
17 $this->assertIdentical($module->content_sets
, array('Inline' => 'b | i'));
21 function test_addElement() {
23 $module = new HTMLPurifier_HTMLModule();
25 'a', true, 'Inline', 'Optional: #PCDATA', array('Common'),
31 $module2 = new HTMLPurifier_HTMLModule();
32 $def = new HTMLPurifier_ElementDef();
34 $def->content_model
= '#PCDATA';
35 $def->content_model_type
= 'optional';
40 $module2->info
['a'] = $def;
41 $module2->elements
= array('a');
42 $module2->content_sets
['Inline'] = 'a';
44 $this->assertIdentical($module, $module2);
48 function test_parseContents() {
50 $module = new HTMLPurifier_HTMLModule();
52 // pre-defined templates
53 $this->assertIdentical(
54 $module->parseContents('Inline'),
55 array('optional', 'Inline | #PCDATA')
57 $this->assertIdentical(
58 $module->parseContents('Flow'),
59 array('optional', 'Flow | #PCDATA')
61 $this->assertIdentical(
62 $module->parseContents('Empty'),
66 // normalization procedures
67 $this->assertIdentical(
68 $module->parseContents('optional: a'),
69 array('optional', 'a')
71 $this->assertIdentical(
72 $module->parseContents('OPTIONAL :a'),
73 array('optional', 'a')
75 $this->assertIdentical(
76 $module->parseContents('Optional: a'),
77 array('optional', 'a')
81 $this->assertIdentical(
82 $module->parseContents('Optional: a | b | c'),
83 array('optional', 'a | b | c')
88 function test_mergeInAttrIncludes() {
90 $module = new HTMLPurifier_HTMLModule();
93 $module->mergeInAttrIncludes($attr, 'Common');
94 $this->assertIdentical($attr, array(0 => array('Common')));
96 $attr = array('a' => 'b');
97 $module->mergeInAttrIncludes($attr, array('Common', 'Good'));
98 $this->assertIdentical($attr, array('a' => 'b', 0 => array('Common', 'Good')));