2007-05-07 01:51:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/HTMLModule.php';
|
|
|
|
require_once 'HTMLPurifier/AttrDef.php';
|
|
|
|
|
|
|
|
class HTMLPurifier_HTMLModuleTest extends UnitTestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
function test_addElementToContentSet() {
|
|
|
|
|
|
|
|
$module = new HTMLPurifier_HTMLModule();
|
|
|
|
|
|
|
|
$module->addElementToContentSet('b', 'Inline');
|
|
|
|
$this->assertIdentical($module->content_sets, array('Inline' => 'b'));
|
|
|
|
|
|
|
|
$module->addElementToContentSet('i', 'Inline');
|
|
|
|
$this->assertIdentical($module->content_sets, array('Inline' => 'b | i'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_addElement() {
|
|
|
|
|
|
|
|
$module = new HTMLPurifier_HTMLModule();
|
2007-05-12 20:44:47 +00:00
|
|
|
$def =& $module->addElement(
|
2007-05-07 01:51:26 +00:00
|
|
|
'a', true, 'Inline', 'Optional: #PCDATA', array('Common'),
|
|
|
|
array(
|
|
|
|
'href' => 'URI'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$module2 = new HTMLPurifier_HTMLModule();
|
2007-05-12 20:44:47 +00:00
|
|
|
$def2 = new HTMLPurifier_ElementDef();
|
|
|
|
$def2->safe = true;
|
|
|
|
$def2->content_model = '#PCDATA';
|
|
|
|
$def2->content_model_type = 'optional';
|
|
|
|
$def2->attr = array(
|
2007-05-07 01:51:26 +00:00
|
|
|
'href' => 'URI',
|
|
|
|
0 => array('Common')
|
|
|
|
);
|
2007-05-12 20:44:47 +00:00
|
|
|
$module2->info['a'] = $def2;
|
2007-05-07 01:51:26 +00:00
|
|
|
$module2->elements = array('a');
|
|
|
|
$module2->content_sets['Inline'] = 'a';
|
|
|
|
|
|
|
|
$this->assertIdentical($module, $module2);
|
2007-05-12 20:44:47 +00:00
|
|
|
$this->assertIdentical($def, $def2);
|
|
|
|
$this->assertReference($def, $module->info['a']);
|
2007-05-07 01:51:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-05-08 03:28:58 +00:00
|
|
|
function test_parseContents() {
|
|
|
|
|
|
|
|
$module = new HTMLPurifier_HTMLModule();
|
|
|
|
|
|
|
|
// pre-defined templates
|
|
|
|
$this->assertIdentical(
|
|
|
|
$module->parseContents('Inline'),
|
|
|
|
array('optional', 'Inline | #PCDATA')
|
|
|
|
);
|
|
|
|
$this->assertIdentical(
|
|
|
|
$module->parseContents('Flow'),
|
|
|
|
array('optional', 'Flow | #PCDATA')
|
|
|
|
);
|
2007-05-09 22:01:07 +00:00
|
|
|
$this->assertIdentical(
|
|
|
|
$module->parseContents('Empty'),
|
|
|
|
array('empty', '')
|
|
|
|
);
|
2007-05-08 03:28:58 +00:00
|
|
|
|
|
|
|
// normalization procedures
|
|
|
|
$this->assertIdentical(
|
|
|
|
$module->parseContents('optional: a'),
|
|
|
|
array('optional', 'a')
|
|
|
|
);
|
|
|
|
$this->assertIdentical(
|
|
|
|
$module->parseContents('OPTIONAL :a'),
|
|
|
|
array('optional', 'a')
|
|
|
|
);
|
|
|
|
$this->assertIdentical(
|
|
|
|
$module->parseContents('Optional: a'),
|
|
|
|
array('optional', 'a')
|
|
|
|
);
|
|
|
|
|
|
|
|
// others
|
|
|
|
$this->assertIdentical(
|
|
|
|
$module->parseContents('Optional: a | b | c'),
|
|
|
|
array('optional', 'a | b | c')
|
|
|
|
);
|
|
|
|
|
2007-05-12 20:26:26 +00:00
|
|
|
// object pass-through
|
|
|
|
generate_mock_once('HTMLPurifier_AttrDef');
|
|
|
|
$this->assertIdentical(
|
|
|
|
$module->parseContents(new HTMLPurifier_AttrDefMock()),
|
|
|
|
array(null, null)
|
|
|
|
);
|
|
|
|
|
2007-05-08 03:28:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_mergeInAttrIncludes() {
|
|
|
|
|
|
|
|
$module = new HTMLPurifier_HTMLModule();
|
|
|
|
|
|
|
|
$attr = array();
|
|
|
|
$module->mergeInAttrIncludes($attr, 'Common');
|
|
|
|
$this->assertIdentical($attr, array(0 => array('Common')));
|
|
|
|
|
|
|
|
$attr = array('a' => 'b');
|
|
|
|
$module->mergeInAttrIncludes($attr, array('Common', 'Good'));
|
|
|
|
$this->assertIdentical($attr, array('a' => 'b', 0 => array('Common', 'Good')));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-05-12 20:54:55 +00:00
|
|
|
function test_addBlankElement() {
|
|
|
|
|
|
|
|
$module = new HTMLPurifier_HTMLModule();
|
|
|
|
$def =& $module->addBlankElement('a');
|
|
|
|
|
|
|
|
$def2 = new HTMLPurifier_ElementDef();
|
|
|
|
$def2->standalone = false;
|
|
|
|
|
|
|
|
$this->assertReference($module->info['a'], $def);
|
|
|
|
$this->assertIdentical($def, $def2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-05-13 03:42:09 +00:00
|
|
|
function test_makeLookup() {
|
|
|
|
|
|
|
|
$module = new HTMLPurifier_HTMLModule();
|
|
|
|
|
|
|
|
$this->assertIdentical(
|
|
|
|
$module->makeLookup('foo'),
|
|
|
|
array('foo' => true)
|
|
|
|
);
|
|
|
|
$this->assertIdentical(
|
|
|
|
$module->makeLookup(array('foo')),
|
|
|
|
array('foo' => true)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertIdentical(
|
|
|
|
$module->makeLookup('foo', 'two'),
|
|
|
|
array('foo' => true, 'two' => true)
|
|
|
|
);
|
|
|
|
$this->assertIdentical(
|
|
|
|
$module->makeLookup(array('foo', 'two')),
|
|
|
|
array('foo' => true, 'two' => true)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-05-07 01:51:26 +00:00
|
|
|
}
|
|
|
|
|