1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-31 03:10:09 +02:00

Minor test-case refactoring.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1100 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2007-05-27 23:12:17 +00:00
parent f758f7c534
commit ee61ffc0d9
5 changed files with 81 additions and 52 deletions

View File

@@ -11,15 +11,12 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
$this->obj = new HTMLPurifier_Strategy_FixNesting();
}
function test() {
$this->config = array('HTML.Doctype' => 'XHTML 1.0 Strict');
function testBlockAndInlineIntegration() {
// legal inline
$this->assertResult('<b>Bold text</b>');
// legal inline and block
// as the parent element is considered FLOW
// legal inline and block (default parent element is FLOW)
$this->assertResult('<a href="about:blank">Blank</a><div>Block</div>');
// illegal block in inline
@@ -35,6 +32,10 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
array('Core.EscapeInvalidChildren' => true)
);
}
function testNodeRemovalIntegration() {
// test of empty set that's required, resulting in removal of node
$this->assertResult('<ul></ul>', '');
@@ -44,27 +45,17 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
'<ul><li>Legal item</li></ul>'
);
}
function testTableIntegration() {
// test custom table definition
$this->assertResult(
'<table><tr><td>Cell 1</td></tr></table>',
'<table><tr><td>Cell 1</td></tr></table>'
);
$this->assertResult('<table></table>', '');
// breaks without the redundant checking code
$this->assertResult('<table><tr></tr></table>', '');
// special case, prevents scrolling one back to find parent
$this->assertResult('<table><tr></tr><tr></tr></table>', '');
// cascading rollbacks
$this->assertResult(
'<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>',
''
);
// rollbacks twice
$this->assertResult('<table></table><table></table>', '');
}
function testChameleonIntegration() {
// block in inline ins not allowed
$this->assertResult(
@@ -84,12 +75,6 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
'<h1><ins>Not allowed!</ins></h1>'
);
// test exclusions
$this->assertResult(
'<a><span><a>Not allowed</a></span></a>',
'<a><span></span></a>'
);
// stacked ins/del
$this->assertResult(
'<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
@@ -99,6 +84,17 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
'<div><ins><del><div>Allowed!</div></del></ins></div>'
);
}
function testExclusionsIntegration() {
// test exclusions
$this->assertResult(
'<a><span><a>Not allowed</a></span></a>',
'<a><span></span></a>'
);
}
function testCustomParentIntegration() {
// test inline parent
$this->assertResult(
'<b>Bold</b>', true, array('HTML.Parent' => 'span')
@@ -107,13 +103,31 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
'<div>Reject</div>', 'Reject', array('HTML.Parent' => 'span')
);
// test fallback to div
$this->expectError('Cannot use unrecognized element as parent.');
$this->assertResult(
'<div>Accept</div>', true, array('HTML.Parent' => 'fling')
'<div>Accept</div>', true, array('HTML.Parent' => 'obviously-impossible')
);
}
function testDoubleCheckIntegration() {
// breaks without the redundant checking code
$this->assertResult('<table><tr></tr></table>', '');
// special case, prevents scrolling one back to find parent
$this->assertResult('<table><tr></tr><tr></tr></table>', '');
// cascading rollbacks
$this->assertResult(
'<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>',
''
);
// rollbacks twice
$this->assertResult('<table></table><table></table>', '');
}
}
?>

View File

@@ -11,13 +11,12 @@ class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarn
$this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
}
function test() {
$this->config = array('HTML.Doctype' => 'XHTML 1.0 Strict');
function testNormalIntegration() {
$this->assertResult('');
$this->assertResult('This is <b>bold text</b>.');
}
function testUnclosedTagIntegration() {
$this->assertResult(
'<b>Unclosed tag, gasp!',
'<b>Unclosed tag, gasp!</b>'
@@ -32,7 +31,9 @@ class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarn
'Unused end tags... recycle!</b>',
'Unused end tags... recycle!'
);
}
function testEmptyTagDetectionIntegration() {
$this->assertResult(
'<br style="clear:both;">',
'<br style="clear:both;" />'
@@ -42,8 +43,10 @@ class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarn
'<div style="clear:both;" />',
'<div style="clear:both;"></div>'
);
// test automatic paragraph closing
}
function testAutoClose() {
// paragraph
$this->assertResult(
'<p>Paragraph 1<p>Paragraph 2',
@@ -55,12 +58,20 @@ class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarn
'<div><p>Paragraphs</p><p>In</p><p>A</p><p>Div</p></div>'
);
// automatic list closing
// list
$this->assertResult(
'<ol><li>Item 1<li>Item 2</ol>',
'<ol><li>Item 1</li><li>Item 2</li></ol>'
);
// colgroup
$this->assertResult(
'<table><colgroup><col /><tr></tr></table>',
'<table><colgroup><col /></colgroup><tr></tr></table>'
);
}
}