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';
|
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
|
2006-07-24 02:43:53 +00:00
|
|
|
{
|
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->obj = new HTMLPurifier_Strategy_FixNesting();
|
|
|
|
}
|
|
|
|
|
2006-07-24 02:43:53 +00:00
|
|
|
function test() {
|
|
|
|
|
2006-10-01 21:55:13 +00:00
|
|
|
// legal inline
|
|
|
|
$this->assertResult('<b>Bold text</b>');
|
2006-07-24 02:43:53 +00:00
|
|
|
|
|
|
|
// legal inline and block
|
|
|
|
// as the parent element is considered FLOW
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<a href="about:blank">Blank</a><div>Block</div>');
|
2006-07-24 02:43:53 +00:00
|
|
|
|
2006-08-15 23:58:18 +00:00
|
|
|
// illegal block in inline
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<b><div>Illegal div.</div></b>',
|
|
|
|
'<b>Illegal div.</b>'
|
|
|
|
);
|
2006-08-14 02:46:34 +00:00
|
|
|
|
|
|
|
// same test with different configuration (fragile)
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<b><div>Illegal div.</div></b>',
|
|
|
|
'<b><div>Illegal div.</div></b>',
|
|
|
|
array('Core.EscapeInvalidChildren' => true)
|
|
|
|
);
|
2006-07-24 02:43:53 +00:00
|
|
|
|
|
|
|
// test of empty set that's required, resulting in removal of node
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<ul></ul>', '');
|
2006-07-24 02:43:53 +00:00
|
|
|
|
|
|
|
// test illegal text which gets removed
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<ul>Illegal text<li>Legal item</li></ul>',
|
|
|
|
'<ul><li>Legal item</li></ul>'
|
|
|
|
);
|
2006-07-24 02:43:53 +00:00
|
|
|
|
2006-07-31 00:15:01 +00:00
|
|
|
// test custom table definition
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<table><tr><td>Cell 1</td></tr></table>',
|
|
|
|
'<table><tr><td>Cell 1</td></tr></table>'
|
|
|
|
);
|
|
|
|
$this->assertResult('<table></table>', '');
|
2006-07-31 03:04:57 +00:00
|
|
|
|
|
|
|
// breaks without the redundant checking code
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<table><tr></tr></table>', '');
|
2006-07-31 03:04:57 +00:00
|
|
|
|
|
|
|
// special case, prevents scrolling one back to find parent
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<table><tr></tr><tr></tr></table>', '');
|
2006-07-31 03:04:57 +00:00
|
|
|
|
|
|
|
// cascading rollbacks
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>',
|
|
|
|
''
|
|
|
|
);
|
2006-07-31 03:04:57 +00:00
|
|
|
|
|
|
|
// rollbacks twice
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<table></table><table></table>', '');
|
2006-07-31 03:04:57 +00:00
|
|
|
|
2006-08-03 01:03:23 +00:00
|
|
|
// block in inline ins not allowed
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<span><ins><div>Not allowed!</div></ins></span>',
|
|
|
|
'<span><ins>Not allowed!</ins></span>'
|
|
|
|
);
|
2006-08-14 02:46:34 +00:00
|
|
|
|
2007-02-04 03:53:57 +00:00
|
|
|
$this->assertResult( // alt config
|
2006-10-01 21:55:13 +00:00
|
|
|
'<span><ins><div>Not allowed!</div></ins></span>',
|
|
|
|
'<span><ins><div>Not allowed!</div></ins></span>',
|
|
|
|
array('Core.EscapeInvalidChildren' => true)
|
|
|
|
);
|
2006-08-03 01:03:23 +00:00
|
|
|
|
2007-02-04 03:53:57 +00:00
|
|
|
// test block element that has inline content
|
|
|
|
$this->assertResult(
|
|
|
|
'<h1><ins><div>Not allowed!</div></ins></h1>',
|
|
|
|
'<h1><ins>Not allowed!</ins></h1>'
|
|
|
|
);
|
|
|
|
|
2006-08-03 01:18:57 +00:00
|
|
|
// test exclusions
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<a><span><a>Not allowed</a></span></a>',
|
|
|
|
'<a><span></span></a>'
|
|
|
|
);
|
2006-08-14 02:46:34 +00:00
|
|
|
|
2007-02-04 03:53:57 +00:00
|
|
|
// stacked ins/del
|
|
|
|
$this->assertResult(
|
|
|
|
'<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
|
|
|
|
'<h1><ins><del>Not allowed!</del></ins></h1>'
|
|
|
|
);
|
2007-02-04 21:02:35 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div><ins><del><div>Allowed!</div></del></ins></div>'
|
|
|
|
);
|
2007-02-04 03:53:57 +00:00
|
|
|
|
2006-11-23 03:23:35 +00:00
|
|
|
// test inline parent
|
|
|
|
$this->assertResult(
|
|
|
|
'<b>Bold</b>', true, array('HTML.Parent' => 'span')
|
|
|
|
);
|
|
|
|
$this->assertResult(
|
|
|
|
'<div>Reject</div>', 'Reject', array('HTML.Parent' => 'span')
|
|
|
|
);
|
|
|
|
|
2007-01-20 19:22:55 +00:00
|
|
|
$this->expectError('Cannot use unrecognized element as parent.');
|
2006-11-23 03:23:35 +00:00
|
|
|
$this->assertResult(
|
2007-05-15 02:33:19 +00:00
|
|
|
'<div>Accept</div>', true, array('HTML.Parent' => 'fling')
|
2006-11-23 03:23:35 +00:00
|
|
|
);
|
|
|
|
|
2006-07-24 02:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|