Support for inline-block.
[htmlpurifier.git] / tests / HTMLPurifier / HTMLModuleTest.php
blob65220f08b056f1fedc5e227b9a5933f07b675546
1 <?php
3 class HTMLPurifier_HTMLModuleTest extends HTMLPurifier_Harness
6 function test_addElementToContentSet() {
8 $module = new HTMLPurifier_HTMLModule();
10 $module->addElementToContentSet('b', 'Inline');
11 $this->assertIdentical($module->content_sets, array('Inline' => 'b'));
13 $module->addElementToContentSet('i', 'Inline');
14 $this->assertIdentical($module->content_sets, array('Inline' => 'b | i'));
18 function test_addElement() {
20 $module = new HTMLPurifier_HTMLModule();
21 $def = $module->addElement(
22 'a', 'Inline', 'Optional: #PCDATA', array('Common'),
23 array(
24 'href' => 'URI'
28 $module2 = new HTMLPurifier_HTMLModule();
29 $def2 = new HTMLPurifier_ElementDef();
30 $def2->content_model = '#PCDATA';
31 $def2->content_model_type = 'optional';
32 $def2->attr = array(
33 'href' => 'URI',
34 0 => array('Common')
36 $module2->info['a'] = $def2;
37 $module2->elements = array('a');
38 $module2->content_sets['Inline'] = 'a';
40 $this->assertIdentical($module, $module2);
41 $this->assertIdentical($def, $def2);
42 $this->assertReference($def, $module->info['a']);
46 function test_parseContents() {
48 $module = new HTMLPurifier_HTMLModule();
50 // pre-defined templates
51 $this->assertIdentical(
52 $module->parseContents('Inline'),
53 array('optional', 'Inline | #PCDATA')
55 $this->assertIdentical(
56 $module->parseContents('Flow'),
57 array('optional', 'Flow | #PCDATA')
59 $this->assertIdentical(
60 $module->parseContents('Empty'),
61 array('empty', '')
64 // normalization procedures
65 $this->assertIdentical(
66 $module->parseContents('optional: a'),
67 array('optional', 'a')
69 $this->assertIdentical(
70 $module->parseContents('OPTIONAL :a'),
71 array('optional', 'a')
73 $this->assertIdentical(
74 $module->parseContents('Optional: a'),
75 array('optional', 'a')
78 // others
79 $this->assertIdentical(
80 $module->parseContents('Optional: a | b | c'),
81 array('optional', 'a | b | c')
84 // object pass-through
85 generate_mock_once('HTMLPurifier_AttrDef');
86 $this->assertIdentical(
87 $module->parseContents(new HTMLPurifier_AttrDefMock()),
88 array(null, null)
93 function test_mergeInAttrIncludes() {
95 $module = new HTMLPurifier_HTMLModule();
97 $attr = array();
98 $module->mergeInAttrIncludes($attr, 'Common');
99 $this->assertIdentical($attr, array(0 => array('Common')));
101 $attr = array('a' => 'b');
102 $module->mergeInAttrIncludes($attr, array('Common', 'Good'));
103 $this->assertIdentical($attr, array('a' => 'b', 0 => array('Common', 'Good')));
107 function test_addBlankElement() {
109 $module = new HTMLPurifier_HTMLModule();
110 $def = $module->addBlankElement('a');
112 $def2 = new HTMLPurifier_ElementDef();
113 $def2->standalone = false;
115 $this->assertReference($module->info['a'], $def);
116 $this->assertIdentical($def, $def2);
120 function test_makeLookup() {
122 $module = new HTMLPurifier_HTMLModule();
124 $this->assertIdentical(
125 $module->makeLookup('foo'),
126 array('foo' => true)
128 $this->assertIdentical(
129 $module->makeLookup(array('foo')),
130 array('foo' => true)
133 $this->assertIdentical(
134 $module->makeLookup('foo', 'two'),
135 array('foo' => true, 'two' => true)
137 $this->assertIdentical(
138 $module->makeLookup(array('foo', 'two')),
139 array('foo' => true, 'two' => true)
146 // vim: et sw=4 sts=4