2006-11-22 18:55:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testPrepareString() {
|
2006-11-22 18:55:15 +00:00
|
|
|
$def = new HTMLPurifier_ChildDef_Required('foobar | bang |gizmo');
|
2007-05-05 20:17:04 +00:00
|
|
|
$this->assertIdentical($def->elements,
|
2006-11-22 18:55:15 +00:00
|
|
|
array(
|
|
|
|
'foobar' => true
|
|
|
|
,'bang' => true
|
|
|
|
,'gizmo' => true
|
|
|
|
));
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testPrepareArray() {
|
2006-11-22 18:55:15 +00:00
|
|
|
$def = new HTMLPurifier_ChildDef_Required(array('href', 'src'));
|
2007-05-05 20:17:04 +00:00
|
|
|
$this->assertIdentical($def->elements,
|
2006-11-22 18:55:15 +00:00
|
|
|
array(
|
|
|
|
'href' => true
|
|
|
|
,'src' => true
|
|
|
|
));
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
2006-11-22 18:55:15 +00:00
|
|
|
$this->obj = new HTMLPurifier_ChildDef_Required('dt | dd');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testEmptyInput() {
|
2006-11-22 18:55:15 +00:00
|
|
|
$this->assertResult('', false);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testRemoveIllegalTagsAndElements() {
|
2006-11-22 18:55:15 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<dt>Term</dt>Text in an illegal location'.
|
|
|
|
'<dd>Definition</dd><b>Illegal tag</b>',
|
|
|
|
'<dt>Term</dt><dd>Definition</dd>');
|
|
|
|
$this->assertResult('How do you do!', false);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testIgnoreWhitespace() {
|
2006-11-22 18:55:15 +00:00
|
|
|
// whitespace shouldn't trigger it
|
|
|
|
$this->assertResult("\n<dd>Definition</dd> ");
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testPreserveWhitespaceAfterRemoval() {
|
2006-11-22 18:55:15 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<dd>Definition</dd> <b></b> ',
|
|
|
|
'<dd>Definition</dd> '
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testDeleteNodeIfOnlyWhitespace() {
|
2006-11-22 18:55:15 +00:00
|
|
|
$this->assertResult("\t ", false);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2006-11-22 18:55:15 +00:00
|
|
|
function testPCDATAAllowed() {
|
|
|
|
$this->obj = new HTMLPurifier_ChildDef_Required('#PCDATA | b');
|
2007-08-06 06:22:23 +00:00
|
|
|
$this->assertResult('Out <b>Bold text</b><img />', 'Out <b>Bold text</b>');
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testPCDATAAllowedWithEscaping() {
|
|
|
|
$this->obj = new HTMLPurifier_ChildDef_Required('#PCDATA | b');
|
2009-02-20 00:17:49 +00:00
|
|
|
$this->config->set('Core.EscapeInvalidChildren', true);
|
2006-11-22 18:55:15 +00:00
|
|
|
$this->assertResult(
|
2007-08-06 06:22:23 +00:00
|
|
|
'Out <b>Bold text</b><img />',
|
|
|
|
'Out <b>Bold text</b><img />'
|
2006-11-22 18:55:15 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|