2006-11-22 18:55:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
|
|
|
|
{
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function setUp()
|
|
|
|
{
|
2007-08-06 06:22:23 +00:00
|
|
|
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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public 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
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testDeleteNodeIfOnlyWhitespace()
|
|
|
|
{
|
2006-11-22 18:55:15 +00:00
|
|
|
$this->assertResult("\t ", false);
|
|
|
|
}
|
2008-12-06 07:28:20 +00:00
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function testPCDATAAllowed()
|
|
|
|
{
|
2006-11-22 18:55:15 +00:00
|
|
|
$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>');
|
|
|
|
}
|
2013-10-21 05:18:59 +00:00
|
|
|
public function testPCDATAAllowedJump()
|
2013-07-16 11:56:14 +00:00
|
|
|
{
|
2007-08-06 06:22:23 +00:00
|
|
|
$this->obj = new HTMLPurifier_ChildDef_Required('#PCDATA | b');
|
2013-10-21 05:18:59 +00:00
|
|
|
$this->assertResult('A <i>foo</i>', 'A foo');
|
2006-11-22 18:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-06 09:24:59 +00:00
|
|
|
// vim: et sw=4 sts=4
|