mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-10 07:38:41 +00:00
bb08f679f0
- Work around unnecessary DOMElement type-cast in PH5P that caused errors in PHP 5.1 - Work around PHP 4 SimpleTest lack-of-error complaining for one-time-only HTMLDefinition errors, this may indicate problems with error-collecting facilities in PHP 5 - Make ErrorCollectorEMock work in both PHP 4 and PHP 5 . tests/multitest.php allows you to test multiple versions by running tests/index.php through multiple interpreters using `phpv` shell script (you must provide this script!) . Minor cosmetic change to flush-definition-cache.php: trailing newline is outputted . Maintenance script for generating PH5P patch added, original PH5P source file also added under version control . Full unit test runner script title made more descriptive with PHP version git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1440 48356398-32a2-884e-a903-53898d9a118a
140 lines
4.3 KiB
PHP
140 lines
4.3 KiB
PHP
<?php
|
|
|
|
require_once 'HTMLPurifier/StrategyHarness.php';
|
|
require_once 'HTMLPurifier/Strategy/FixNesting.php';
|
|
|
|
class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
|
|
{
|
|
|
|
function setUp() {
|
|
parent::setUp();
|
|
$this->obj = new HTMLPurifier_Strategy_FixNesting();
|
|
}
|
|
|
|
function testPreserveInlineInRoot() {
|
|
$this->assertResult('<b>Bold text</b>');
|
|
}
|
|
|
|
function testPreserveInlineAndBlockInRoot() {
|
|
$this->assertResult('<a href="about:blank">Blank</a><div>Block</div>');
|
|
}
|
|
|
|
function testRemoveBlockInInline() {
|
|
$this->assertResult(
|
|
'<b><div>Illegal div.</div></b>',
|
|
'<b>Illegal div.</b>'
|
|
);
|
|
}
|
|
|
|
function testEscapeBlockInInline() {
|
|
$this->config->set('Core', 'EscapeInvalidChildren', true);
|
|
$this->assertResult(
|
|
'<b><div>Illegal div.</div></b>',
|
|
'<b><div>Illegal div.</div></b>'
|
|
);
|
|
}
|
|
|
|
function testRemoveNodeWithMissingRequiredElements() {
|
|
$this->assertResult('<ul></ul>', '');
|
|
}
|
|
|
|
function testRemoveIllegalPCDATA() {
|
|
$this->assertResult(
|
|
'<ul>Illegal text<li>Legal item</li></ul>',
|
|
'<ul><li>Legal item</li></ul>'
|
|
);
|
|
}
|
|
|
|
function testCustomTableDefinition() {
|
|
$this->assertResult('<table><tr><td>Cell 1</td></tr></table>');
|
|
}
|
|
|
|
function testRemoveEmptyTable() {
|
|
$this->assertResult('<table></table>', '');
|
|
}
|
|
|
|
function testChameleonRemoveBlockInNodeInInline() {
|
|
$this->assertResult(
|
|
'<span><ins><div>Not allowed!</div></ins></span>',
|
|
'<span><ins>Not allowed!</ins></span>'
|
|
);
|
|
}
|
|
|
|
function testChameleonRemoveBlockInBlockNodeWithInlineContent() {
|
|
$this->assertResult(
|
|
'<h1><ins><div>Not allowed!</div></ins></h1>',
|
|
'<h1><ins>Not allowed!</ins></h1>'
|
|
);
|
|
}
|
|
|
|
function testNestedChameleonRemoveBlockInNodeWithInlineContent() {
|
|
$this->assertResult(
|
|
'<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
|
|
'<h1><ins><del>Not allowed!</del></ins></h1>'
|
|
);
|
|
}
|
|
|
|
function testNestedChameleonPreserveBlockInBlock() {
|
|
$this->assertResult(
|
|
'<div><ins><del><div>Allowed!</div></del></ins></div>'
|
|
);
|
|
}
|
|
|
|
function testChameleonEscapeInvalidBlockInInline() {
|
|
$this->config->set('Core', 'EscapeInvalidChildren', true);
|
|
$this->assertResult( // alt config
|
|
'<span><ins><div>Not allowed!</div></ins></span>',
|
|
'<span><ins><div>Not allowed!</div></ins></span>'
|
|
);
|
|
}
|
|
|
|
function testExclusionsIntegration() {
|
|
// test exclusions
|
|
$this->assertResult(
|
|
'<a><span><a>Not allowed</a></span></a>',
|
|
'<a><span></span></a>'
|
|
);
|
|
}
|
|
|
|
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');
|
|
}
|
|
|
|
function testInvalidParentError() {
|
|
// test fallback to div
|
|
$this->config->set('HTML', 'Parent', 'obviously-impossible');
|
|
// $this->expectError('Cannot use unrecognized element as parent');
|
|
$this->assertResult('<div>Accept</div>');
|
|
$this->swallowErrors();
|
|
}
|
|
|
|
function testCascadingRemovalOfNodesMissingRequiredChildren() {
|
|
$this->assertResult('<table><tr></tr></table>', '');
|
|
}
|
|
|
|
function testCascadingRemovalSpecialCaseCannotScrollOneBack() {
|
|
$this->assertResult('<table><tr></tr><tr></tr></table>', '');
|
|
}
|
|
|
|
function testLotsOfCascadingRemovalOfNodes() {
|
|
$this->assertResult('<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>', '');
|
|
}
|
|
|
|
function testAdjacentRemovalOfNodeMissingRequiredChildren() {
|
|
$this->assertResult('<table></table><table></table>', '');
|
|
}
|
|
|
|
function testStrictBlockquoteInHTML401() {
|
|
$this->config->set('HTML', 'Doctype', 'HTML 4.01 Strict');
|
|
$this->assertResult('<blockquote>text</blockquote>', '<blockquote><p>text</p></blockquote>');
|
|
}
|
|
|
|
}
|
|
|