mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-10 07:38:41 +00:00
965be3bd73
The MakeWellFormed strategy uses metadata from HTMLDefinition in order to determine whether or not tokens need to be converted or tags need to be auto-closed. While this functionality is good to have, it is by no means essential, and MakeWellFormed should not error when this information is not available. Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
98 lines
2.5 KiB
PHP
98 lines
2.5 KiB
PHP
<?php
|
|
|
|
class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarness
|
|
{
|
|
|
|
function setUp() {
|
|
parent::setUp();
|
|
$this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
|
|
}
|
|
|
|
function testEmptyInput() {
|
|
$this->assertResult('');
|
|
}
|
|
|
|
function testWellFormedInput() {
|
|
$this->assertResult('This is <b>bold text</b>.');
|
|
}
|
|
|
|
function testUnclosedTagTerminatedByDocumentEnd() {
|
|
$this->assertResult(
|
|
'<b>Unclosed tag, gasp!',
|
|
'<b>Unclosed tag, gasp!</b>'
|
|
);
|
|
}
|
|
|
|
function testUnclosedTagTerminatedByParentNodeEnd() {
|
|
$this->assertResult(
|
|
'<b><i>Bold and italic?</b>',
|
|
'<b><i>Bold and italic?</i></b>'
|
|
);
|
|
}
|
|
|
|
function testRemoveStrayClosingTag() {
|
|
$this->assertResult(
|
|
'Unused end tags... recycle!</b>',
|
|
'Unused end tags... recycle!'
|
|
);
|
|
}
|
|
|
|
function testConvertStartToEmpty() {
|
|
$this->assertResult(
|
|
'<br style="clear:both;">',
|
|
'<br style="clear:both;" />'
|
|
);
|
|
}
|
|
|
|
function testConvertEmptyToStart() {
|
|
$this->assertResult(
|
|
'<div style="clear:both;" />',
|
|
'<div style="clear:both;"></div>'
|
|
);
|
|
}
|
|
|
|
function testAutoCloseParagraph() {
|
|
$this->assertResult(
|
|
'<p>Paragraph 1<p>Paragraph 2',
|
|
'<p>Paragraph 1</p><p>Paragraph 2</p>'
|
|
);
|
|
}
|
|
|
|
function testAutoCloseParagraphInsideDiv() {
|
|
$this->assertResult(
|
|
'<div><p>Paragraphs<p>In<p>A<p>Div</div>',
|
|
'<div><p>Paragraphs</p><p>In</p><p>A</p><p>Div</p></div>'
|
|
);
|
|
}
|
|
|
|
function testAutoCloseListItem() {
|
|
$this->assertResult(
|
|
'<ol><li>Item 1<li>Item 2</ol>',
|
|
'<ol><li>Item 1</li><li>Item 2</li></ol>'
|
|
);
|
|
}
|
|
|
|
function testAutoCloseColgroup() {
|
|
$this->assertResult(
|
|
'<table><colgroup><col /><tr></tr></table>',
|
|
'<table><colgroup><col /></colgroup><tr></tr></table>'
|
|
);
|
|
}
|
|
|
|
function testAutoCloseMultiple() {
|
|
$this->assertResult(
|
|
'<span><span><div></div>',
|
|
'<span><span></span></span><div></div>'
|
|
);
|
|
}
|
|
|
|
function testUnrecognized() {
|
|
$this->assertResult(
|
|
'<asdf><foobar /><biddles>foo</asdf>',
|
|
'<asdf><foobar /><biddles>foo</biddles></asdf>'
|
|
);
|
|
}
|
|
|
|
}
|
|
|