2006-07-24 02:43:53 +00:00
|
|
|
<?php
|
|
|
|
|
2006-08-05 00:30:31 +00:00
|
|
|
require_once 'HTMLPurifier/StrategyHarness.php';
|
2006-07-24 02:43:53 +00:00
|
|
|
require_once 'HTMLPurifier/Strategy/FixNesting.php';
|
|
|
|
|
|
|
|
class HTMLPurifier_Strategy_FixNestingTest
|
2006-08-05 00:30:31 +00:00
|
|
|
extends HTMLPurifier_StrategyHarness
|
2006-07-24 02:43:53 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
|
|
|
|
$strategy = new HTMLPurifier_Strategy_FixNesting();
|
|
|
|
|
|
|
|
$inputs = array();
|
|
|
|
$expect = array();
|
|
|
|
|
|
|
|
// next id = 4
|
|
|
|
|
|
|
|
// legal inline nesting
|
|
|
|
$inputs[0] = '<b>Bold text</b>';
|
|
|
|
$expect[0] = $inputs[0];
|
|
|
|
|
|
|
|
// legal inline and block
|
|
|
|
// as the parent element is considered FLOW
|
|
|
|
$inputs[1] = '<a href="about:blank">Blank</a><div>Block</div>';
|
|
|
|
$expect[1] = $inputs[1];
|
|
|
|
|
|
|
|
// illegal block in inline, element -> text
|
|
|
|
$inputs[2] = '<b><div>Illegal div.</div></b>';
|
|
|
|
$expect[2] = '<b><div>Illegal div.</div></b>';
|
|
|
|
|
|
|
|
// test of empty set that's required, resulting in removal of node
|
|
|
|
$inputs[3] = '<ul></ul>';
|
|
|
|
$expect[3] = '';
|
|
|
|
|
|
|
|
// test illegal text which gets removed
|
|
|
|
$inputs[4] = '<ul>Illegal text<li>Legal item</li></ul>';
|
|
|
|
$expect[4] = '<ul><li>Legal item</li></ul>';
|
|
|
|
|
2006-07-31 00:15:01 +00:00
|
|
|
// test custom table definition
|
2006-07-31 03:04:57 +00:00
|
|
|
|
2006-07-31 00:15:01 +00:00
|
|
|
$inputs[5] = '<table><tr><td>Cell 1</td></tr></table>';
|
|
|
|
$expect[5] = '<table><tr><td>Cell 1</td></tr></table>';
|
|
|
|
|
2006-07-31 03:04:57 +00:00
|
|
|
$inputs[6] = '<table></table>';
|
|
|
|
$expect[6] = '';
|
|
|
|
|
|
|
|
// breaks without the redundant checking code
|
|
|
|
$inputs[7] = '<table><tr></tr></table>';
|
|
|
|
$expect[7] = '';
|
|
|
|
|
|
|
|
// special case, prevents scrolling one back to find parent
|
|
|
|
$inputs[8] = '<table><tr></tr><tr></tr></table>';
|
|
|
|
$expect[8] = '';
|
|
|
|
|
|
|
|
// cascading rollbacks
|
|
|
|
$inputs[9] = '<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>';
|
|
|
|
$expect[9] = '';
|
|
|
|
|
|
|
|
// rollbacks twice
|
|
|
|
$inputs[10] = '<table></table><table></table>';
|
|
|
|
$expect[10] = '';
|
|
|
|
|
2006-08-03 01:03:23 +00:00
|
|
|
// block in inline ins not allowed
|
|
|
|
$inputs[11] = '<span><ins><div>Not allowed!</div></ins></span>';
|
|
|
|
$expect[11] = '<span><ins><div>Not allowed!</div></ins></span>';
|
|
|
|
|
2006-08-03 01:18:57 +00:00
|
|
|
// test exclusions
|
|
|
|
$inputs[12] = '<a><span><a>Not allowed</a></span></a>';
|
|
|
|
$expect[12] = '<a><span></span></a>';
|
|
|
|
|
2006-07-29 17:38:28 +00:00
|
|
|
$this->assertStrategyWorks($strategy, $inputs, $expect);
|
2006-07-24 02:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|