2006-07-24 02:43:53 +00:00
|
|
|
<?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();
|
|
|
|
}
|
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testPreserveInlineInRoot() {
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<b>Bold text</b>');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testPreserveInlineAndBlockInRoot() {
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<a href="about:blank">Blank</a><div>Block</div>');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testRemoveBlockInInline() {
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<b><div>Illegal div.</div></b>',
|
|
|
|
'<b>Illegal div.</b>'
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testEscapeBlockInInline() {
|
|
|
|
$this->config->set('Core', 'EscapeInvalidChildren', true);
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<b><div>Illegal div.</div></b>',
|
2007-08-06 06:22:23 +00:00
|
|
|
'<b><div>Illegal div.</div></b>'
|
2006-10-01 21:55:13 +00:00
|
|
|
);
|
2007-05-27 23:12:17 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testRemoveNodeWithMissingRequiredElements() {
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<ul></ul>', '');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testRemoveIllegalPCDATA() {
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<ul>Illegal text<li>Legal item</li></ul>',
|
|
|
|
'<ul><li>Legal item</li></ul>'
|
|
|
|
);
|
2007-05-27 23:12:17 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testCustomTableDefinition() {
|
|
|
|
$this->assertResult('<table><tr><td>Cell 1</td></tr></table>');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testRemoveEmptyTable() {
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult('<table></table>', '');
|
2007-05-27 23:12:17 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testChameleonRemoveBlockInNodeInInline() {
|
2006-10-01 21:55:13 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<span><ins><div>Not allowed!</div></ins></span>',
|
|
|
|
'<span><ins>Not allowed!</ins></span>'
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testChameleonRemoveBlockInBlockNodeWithInlineContent() {
|
2007-02-04 03:53:57 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<h1><ins><div>Not allowed!</div></ins></h1>',
|
|
|
|
'<h1><ins>Not allowed!</ins></h1>'
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testNestedChameleonRemoveBlockInNodeWithInlineContent() {
|
2007-02-04 03:53:57 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
|
|
|
|
'<h1><ins><del>Not allowed!</del></ins></h1>'
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testNestedChameleonPreserveBlockInBlock() {
|
2007-02-04 21:02:35 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div><ins><del><div>Allowed!</div></del></ins></div>'
|
|
|
|
);
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testChameleonEscapeInvalidBlockInInline() {
|
|
|
|
$this->config->set('Core', 'EscapeInvalidChildren', true);
|
2007-08-02 22:44:42 +00:00
|
|
|
$this->assertResult( // alt config
|
|
|
|
'<span><ins><div>Not allowed!</div></ins></span>',
|
2007-08-06 06:22:23 +00:00
|
|
|
'<span><ins><div>Not allowed!</div></ins></span>'
|
2007-08-02 22:44:42 +00:00
|
|
|
);
|
2007-05-27 23:12:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testExclusionsIntegration() {
|
|
|
|
// test exclusions
|
|
|
|
$this->assertResult(
|
|
|
|
'<a><span><a>Not allowed</a></span></a>',
|
|
|
|
'<a><span></span></a>'
|
|
|
|
);
|
|
|
|
}
|
2007-08-06 06:22:23 +00:00
|
|
|
|
|
|
|
function testPreserveInlineNodeInInlineRootNode() {
|
|
|
|
$this->config->set('HTML', 'Parent', 'span');
|
|
|
|
$this->assertResult('<b>Bold</b>');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testRemoveBlockNodeInInlineRootNode() {
|
|
|
|
$this->config->set('HTML', 'Parent', 'span');
|
|
|
|
$this->assertResult('<div>Reject</div>', 'Reject');
|
2007-06-21 15:15:02 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testInvalidParentError() {
|
2007-05-27 23:12:17 +00:00
|
|
|
// test fallback to div
|
2007-08-06 06:22:23 +00:00
|
|
|
$this->config->set('HTML', 'Parent', 'obviously-impossible');
|
2008-04-15 03:33:09 +00:00
|
|
|
$this->config->set('Cache', 'DefinitionImpl', null);
|
|
|
|
$this->expectError('Cannot use unrecognized element as parent');
|
2007-08-06 06:22:23 +00:00
|
|
|
$this->assertResult('<div>Accept</div>');
|
2007-05-27 23:12:17 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 06:22:23 +00:00
|
|
|
function testCascadingRemovalOfNodesMissingRequiredChildren() {
|
2007-05-27 23:12:17 +00:00
|
|
|
$this->assertResult('<table><tr></tr></table>', '');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testCascadingRemovalSpecialCaseCannotScrollOneBack() {
|
2007-05-27 23:12:17 +00:00
|
|
|
$this->assertResult('<table><tr></tr><tr></tr></table>', '');
|
2007-08-06 06:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testLotsOfCascadingRemovalOfNodes() {
|
|
|
|
$this->assertResult('<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>', '');
|
|
|
|
}
|
|
|
|
|
|
|
|
function testAdjacentRemovalOfNodeMissingRequiredChildren() {
|
2007-05-27 23:12:17 +00:00
|
|
|
$this->assertResult('<table></table><table></table>', '');
|
2006-07-24 02:43:53 +00:00
|
|
|
}
|
|
|
|
|
2007-09-09 01:46:59 +00:00
|
|
|
function testStrictBlockquoteInHTML401() {
|
|
|
|
$this->config->set('HTML', 'Doctype', 'HTML 4.01 Strict');
|
|
|
|
$this->assertResult('<blockquote>text</blockquote>', '<blockquote><p>text</p></blockquote>');
|
|
|
|
}
|
|
|
|
|
2006-07-24 02:43:53 +00:00
|
|
|
}
|
|
|
|
|