obj = null;
$this->func = 'validateChildren';
$this->to_tokens = true;
$this->to_html = true;
}
function test_custom() {
$this->obj = new HTMLPurifier_ChildDef_Custom('(a,b?,c*,d+,(a,b)*)');
$this->assertResult('', false);
$this->assertResult('', false);
$this->assertResult('');
$this->assertResult('Dobfoo'.
'foo');
}
function test_table() {
// the table definition
$this->obj = new HTMLPurifier_ChildDef_Table();
$inputs = $expect = $config = array();
$this->assertResult('', false);
// we're using empty tags to compact the tests: under real circumstances
// there would be contents in them
$this->assertResult('
');
$this->assertResult(''.
'asdf |
');
$this->assertResult('
');
// mixed up order
$this->assertResult(
'1
',
'1
');
// duplicates of singles
// - first caption serves
// - trailing tfoots/theads get turned into tbodys
$this->assertResult(
'11',
'11'
);
// errant text dropped (until bubbling is implemented)
$this->assertResult('foo', false);
// whitespace sticks to the previous element, last whitespace is
// stationary
$this->assertResult("\n
\n
\n ");
$this->assertResult(
"\n\t\n\t\t\n\t\t\t",
"\n\t\t\n\t\n\t\t\t"
);
}
function testParsing() {
$def = new HTMLPurifier_ChildDef_Required('foobar | bang |gizmo');
$this->assertEqual($def->elements,
array(
'foobar' => true
,'bang' => true
,'gizmo' => true
));
$def = new HTMLPurifier_ChildDef_Required(array('href', 'src'));
$this->assertEqual($def->elements,
array(
'href' => true
,'src' => true
));
}
function test_required_pcdata_forbidden() {
$this->obj = new HTMLPurifier_ChildDef_Required('dt | dd');
$this->assertResult('', false);
$this->assertResult(
'TermText in an illegal location'.
'DefinitionIllegal tag',
'TermDefinition');
$this->assertResult('How do you do!', false);
// whitespace shouldn't trigger it
$this->assertResult("\nDefinition ");
$this->assertResult(
'Definition ',
'Definition '
);
$this->assertResult("\t ", false);
}
function test_required_pcdata_allowed() {
$this->obj = new HTMLPurifier_ChildDef_Required('#PCDATA | b');
$this->assertResult('Bold text', 'Bold text');
// with child escaping on
$this->assertResult(
'Bold text',
'Bold text<img />',
array(
'Core.EscapeInvalidChildren' => true
)
);
}
function test_optional() {
$this->obj = new HTMLPurifier_ChildDef_Optional('b | i');
$this->assertResult('Bold text', 'Bold text');
$this->assertResult('Not allowed text', '');
}
function test_chameleon() {
$this->obj = new HTMLPurifier_ChildDef_Chameleon(
'b | i', // allowed only when in inline context
'b | i | div' // allowed only when in block context
);
$this->assertResult(
'Allowed.', true,
array(), array('ParentType' => 'inline')
);
$this->assertResult(
'Not allowed.
', '',
array(), array('ParentType' => 'inline')
);
$this->assertResult(
'Allowed.
', true,
array(), array('ParentType' => 'block')
);
}
}
?>