0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-10 07:38:41 +00:00
htmlpurifier/tests/HTMLPurifier/Strategy/FixNestingTest.php
Edward Z. Yang 77d9e05a07 [1.5.0] Massive refactoring for Blockquote and Chameleon to be more extensible and accommodating of XHTMLDefinition.
- Fixed buggy chameleon-support for ins and del
. Removed context variable ParentType, replaced with IsInline, which
  is false when you're not inline and an integer of the parent that
  caused you to become inline when you are (so possibly zero)
. Removed ElementDef->type in favor of ElementDef->descendants_are_inline
  and HTMLDefinition->content_sets
. StrictBlockquote now reports what elements its supposed to allow,
  rather than what it does allow
. Removed HTMLDefinition->info_flow_elements in favor of
  HTMLDefinition->content_sets['Flow']
. Removed redundant "exclusionary" definitions from DTD roster
. StrictBlockquote now requires a construction parameter as if it
  were an Required ChildDef, this is the "real" set of allowed elements

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@710 48356398-32a2-884e-a903-53898d9a118a
2007-02-04 03:53:57 +00:00

114 lines
3.6 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 test() {
// legal inline
$this->assertResult('<b>Bold text</b>');
// legal inline and block
// as the parent element is considered FLOW
$this->assertResult('<a href="about:blank">Blank</a><div>Block</div>');
// illegal block in inline
$this->assertResult(
'<b><div>Illegal div.</div></b>',
'<b>Illegal div.</b>'
);
// same test with different configuration (fragile)
$this->assertResult(
'<b><div>Illegal div.</div></b>',
'<b>&lt;div&gt;Illegal div.&lt;/div&gt;</b>',
array('Core.EscapeInvalidChildren' => true)
);
// test of empty set that's required, resulting in removal of node
$this->assertResult('<ul></ul>', '');
// test illegal text which gets removed
$this->assertResult(
'<ul>Illegal text<li>Legal item</li></ul>',
'<ul><li>Legal item</li></ul>'
);
// 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>', '');
// block in inline ins not allowed
$this->assertResult(
'<span><ins><div>Not allowed!</div></ins></span>',
'<span><ins>Not allowed!</ins></span>'
);
$this->assertResult( // alt config
'<span><ins><div>Not allowed!</div></ins></span>',
'<span><ins>&lt;div&gt;Not allowed!&lt;/div&gt;</ins></span>',
array('Core.EscapeInvalidChildren' => true)
);
// test block element that has inline content
$this->assertResult(
'<h1><ins><div>Not allowed!</div></ins></h1>',
'<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>',
'<h1><ins><del>Not allowed!</del></ins></h1>'
);
// test inline parent
$this->assertResult(
'<b>Bold</b>', true, array('HTML.Parent' => 'span')
);
$this->assertResult(
'<div>Reject</div>', 'Reject', array('HTML.Parent' => 'span')
);
$this->expectError('Cannot use unrecognized element as parent.');
$this->assertResult(
'<div>Accept</div>', true, array('HTML.Parent' => 'script')
);
}
}
?>