0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-09 15:28:40 +00:00

[2.1.2?] Add missing sub-tests for strategy, fix error message typo.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1376 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2007-08-08 05:08:59 +00:00
parent 24a4dfdf83
commit 4f0d012dfa
5 changed files with 530 additions and 1 deletions

View File

@ -109,7 +109,7 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
function testInvalidParentError() {
// test fallback to div
$this->config->set('HTML', 'Parent', 'obviously-impossible');
$this->expectError('Cannot use unrecognized element as parent.');
$this->expectError('Cannot use unrecognized element as parent');
$this->assertResult('<div>Accept</div>');
}

View File

@ -0,0 +1,65 @@
<?php
require_once 'HTMLPurifier/StrategyHarness.php';
require_once 'HTMLPurifier/Strategy/MakeWellFormed.php';
class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_StrategyHarness
{
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
$this->config->set('AutoFormat', 'AutoParagraph', true);
$this->config->set('AutoFormat', 'Linkify', true);
}
function testOnlyAutoParagraph() {
$this->assertResult(
'Foobar',
'<p>Foobar</p>'
);
}
function testParagraphWrappingOnlyLink() {
$this->assertResult(
'http://example.com',
'<p><a href="http://example.com">http://example.com</a></p>'
);
}
function testParagraphWrappingNodeContainingLink() {
$this->assertResult(
'<b>http://example.com</b>',
'<p><b><a href="http://example.com">http://example.com</a></b></p>'
);
}
function testParagraphWrappingPoorlyFormedNodeContainingLink() {
$this->assertResult(
'<b>http://example.com',
'<p><b><a href="http://example.com">http://example.com</a></b></p>'
);
}
function testTwoParagraphsContainingOnlyOneLink() {
$this->assertResult(
"http://example.com\n\nhttp://dev.example.com",
'<p><a href="http://example.com">http://example.com</a></p><p><a href="http://dev.example.com">http://dev.example.com</a></p>'
);
}
function testParagraphNextToDivWithLinks() {
$this->assertResult(
'http://example.com <div>http://example.com</div>',
'<p><a href="http://example.com">http://example.com</a> </p><div><a href="http://example.com">http://example.com</a></div>'
);
}
function testRealisticLinkInSentence() {
$this->assertResult(
'This URL http://example.com is what you need',
'<p>This URL <a href="http://example.com">http://example.com</a> is what you need</p>'
);
}
}

View File

@ -0,0 +1,46 @@
<?php
require_once 'HTMLPurifier/StrategyHarness.php';
require_once 'HTMLPurifier/Strategy/RemoveForeignElements.php';
class HTMLPurifier_Strategy_RemoveForeignElements_TidyTest
extends HTMLPurifier_StrategyHarness
{
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_RemoveForeignElements();
$this->config->set('HTML', 'TidyLevel', 'heavy');
}
function testCenterTransform() {
$this->assertResult(
'<center>Look I am Centered!</center>',
'<div style="text-align:center;">Look I am Centered!</div>'
);
}
function testFontTransform() {
$this->assertResult(
'<font color="red" face="Arial" size="6">Big Warning!</font>',
'<span style="color:red;font-family:Arial;font-size:xx-large;">Big'.
' Warning!</span>'
);
}
function testTransformToForbiddenElement() {
$this->config->set('HTML', 'Allowed', 'div');
$this->assertResult(
'<font color="red" face="Arial" size="6">Big Warning!</font>',
'Big Warning!'
);
}
function testMenuTransform() {
$this->assertResult(
'<menu><li>Item 1</li></menu>',
'<ul><li>Item 1</li></ul>'
);
}
}

View File

@ -0,0 +1,65 @@
<?php
require_once('HTMLPurifier/StrategyHarness.php');
require_once('HTMLPurifier/Strategy/ValidateAttributes.php');
class HTMLPurifier_Strategy_ValidateAttributes_IDTest extends HTMLPurifier_StrategyHarness
{
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
$this->config->set('HTML', 'EnableAttrID', true);
}
function testPreserveIDWhenEnabled() {
$this->assertResult('<div id="valid">Preserve the ID.</div>');
}
function testRemoveInvalidID() {
$this->assertResult(
'<div id="0invalid">Kill the ID.</div>',
'<div>Kill the ID.</div>'
);
}
function testRemoveDuplicateID() {
$this->assertResult(
'<div id="valid">Valid</div><div id="valid">Invalid</div>',
'<div id="valid">Valid</div><div>Invalid</div>'
);
}
function testAttributeKeyCaseInsensitivity() {
$this->assertResult(
'<div ID="valid">Convert ID to lowercase.</div>',
'<div id="valid">Convert ID to lowercase.</div>'
);
}
function testTrimWhitespace() {
$this->assertResult(
'<div id=" valid ">Trim whitespace.</div>',
'<div id="valid">Trim whitespace.</div>'
);
}
function testIDBlacklist() {
$this->config->set('Attr', 'IDBlacklist', array('invalid'));
$this->assertResult(
'<div id="invalid">Invalid</div>',
'<div>Invalid</div>'
);
}
function testNameConvertedToID() {
$this->config->set('HTML', 'TidyLevel', 'heavy');
$this->assertResult(
'<a name="foobar" />',
'<a id="foobar" />'
);
}
}

View File

@ -0,0 +1,353 @@
<?php
require_once('HTMLPurifier/StrategyHarness.php');
require_once('HTMLPurifier/Strategy/ValidateAttributes.php');
class HTMLPurifier_Strategy_ValidateAttributes_TidyTest extends HTMLPurifier_StrategyHarness
{
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
$this->config->set('HTML', 'TidyLevel', 'heavy');
}
function testConvertCenterAlign() {
$this->assertResult(
'<h1 align="center">Centered Headline</h1>',
'<h1 style="text-align:center;">Centered Headline</h1>'
);
}
function testConvertRightAlign() {
$this->assertResult(
'<h1 align="right">Right-aligned Headline</h1>',
'<h1 style="text-align:right;">Right-aligned Headline</h1>'
);
}
function testConvertLeftAlign() {
$this->assertResult(
'<h1 align="left">Left-aligned Headline</h1>',
'<h1 style="text-align:left;">Left-aligned Headline</h1>'
);
}
function testConvertJustifyAlign() {
$this->assertResult(
'<p align="justify">Justified Paragraph</p>',
'<p style="text-align:justify;">Justified Paragraph</p>'
);
}
function testRemoveInvalidAlign() {
$this->assertResult(
'<h1 align="invalid">Invalid Headline</h1>',
'<h1>Invalid Headline</h1>'
);
}
function testConvertTableLengths() {
$this->assertResult(
'<td width="5%" height="10" /><th width="10" height="5%" /><hr width="10" height="10" />',
'<td style="width:5%;height:10px;" /><th style="width:10px;height:5%;" /><hr style="width:10px;" />'
);
}
function testTdConvertNowrap() {
$this->assertResult(
'<td nowrap />',
'<td style="white-space:nowrap;" />'
);
}
function testCaptionConvertAlignLeft() {
$this->assertResult(
'<caption align="left" />',
'<caption style="text-align:left;" />'
);
}
function testCaptionConvertAlignRight() {
$this->assertResult(
'<caption align="right" />',
'<caption style="text-align:right;" />'
);
}
function testCaptionConvertAlignTop() {
$this->assertResult(
'<caption align="top" />',
'<caption style="caption-side:top;" />'
);
}
function testCaptionConvertAlignBottom() {
$this->assertResult(
'<caption align="bottom" />',
'<caption style="caption-side:bottom;" />'
);
}
function testCaptionRemoveInvalidAlign() {
$this->assertResult(
'<caption align="nonsense" />',
'<caption />'
);
}
function testTableConvertAlignLeft() {
$this->assertResult(
'<table align="left" />',
'<table style="float:left;" />'
);
}
function testTableConvertAlignCenter() {
$this->assertResult(
'<table align="center" />',
'<table style="margin-left:auto;margin-right:auto;" />'
);
}
function testTableConvertAlignRight() {
$this->assertResult(
'<table align="right" />',
'<table style="float:right;" />'
);
}
function testTableRemoveInvalidAlign() {
$this->assertResult(
'<table align="top" />',
'<table />'
);
}
function testImgConvertAlignLeft() {
$this->assertResult(
'<img src="foobar.jpg" alt="foobar" align="left" />',
'<img src="foobar.jpg" alt="foobar" style="float:left;" />'
);
}
function testImgConvertAlignRight() {
$this->assertResult(
'<img src="foobar.jpg" alt="foobar" align="right" />',
'<img src="foobar.jpg" alt="foobar" style="float:right;" />'
);
}
function testImgConvertAlignBottom() {
$this->assertResult(
'<img src="foobar.jpg" alt="foobar" align="bottom" />',
'<img src="foobar.jpg" alt="foobar" style="vertical-align:baseline;" />'
);
}
function testImgConvertAlignMiddle() {
$this->assertResult(
'<img src="foobar.jpg" alt="foobar" align="middle" />',
'<img src="foobar.jpg" alt="foobar" style="vertical-align:middle;" />'
);
}
function testImgConvertAlignTop() {
$this->assertResult(
'<img src="foobar.jpg" alt="foobar" align="top" />',
'<img src="foobar.jpg" alt="foobar" style="vertical-align:top;" />'
);
}
function testImgRemoveInvalidAlign() {
$this->assertResult(
'<img src="foobar.jpg" alt="foobar" align="outerspace" />',
'<img src="foobar.jpg" alt="foobar" />'
);
}
function testBorderConvertHVSpace() {
$this->assertResult(
'<img src="foo" alt="foo" hspace="1" vspace="3" />',
'<img src="foo" alt="foo" style="margin-top:3px;margin-bottom:3px;margin-left:1px;margin-right:1px;" />'
);
}
function testHrConvertSize() {
$this->assertResult(
'<hr size="3" />',
'<hr style="height:3px;" />'
);
}
function testHrConvertNoshade() {
$this->assertResult(
'<hr noshade />',
'<hr style="color:#808080;background-color:#808080;border:0;" />'
);
}
function testHrConvertAlignLeft() {
$this->assertResult(
'<hr align="left" />',
'<hr style="margin-left:0;margin-right:auto;text-align:left;" />'
);
}
function testHrConvertAlignCenter() {
$this->assertResult(
'<hr align="center" />',
'<hr style="margin-left:auto;margin-right:auto;text-align:center;" />'
);
}
function testHrConvertAlignRight() {
$this->assertResult(
'<hr align="right" />',
'<hr style="margin-left:auto;margin-right:0;text-align:right;" />'
);
}
function testHrRemoveInvalidAlign() {
$this->assertResult(
'<hr align="bottom" />',
'<hr />'
);
}
function testBrConvertClearLeft() {
$this->assertResult(
'<br clear="left" />',
'<br style="clear:left;" />'
);
}
function testBrConvertClearRight() {
$this->assertResult(
'<br clear="right" />',
'<br style="clear:right;" />'
);
}
function testBrConvertClearAll() {
$this->assertResult(
'<br clear="all" />',
'<br style="clear:both;" />'
);
}
function testBrConvertClearNone() {
$this->assertResult(
'<br clear="none" />',
'<br style="clear:none;" />'
);
}
function testBrRemoveInvalidClear() {
$this->assertResult(
'<br clear="foo" />',
'<br />'
);
}
function testUlConvertTypeDisc() {
$this->assertResult(
'<ul type="disc" />',
'<ul style="list-style-type:disc;" />'
);
}
function testUlConvertTypeSquare() {
$this->assertResult(
'<ul type="square" />',
'<ul style="list-style-type:square;" />'
);
}
function testUlConvertTypeCircle() {
$this->assertResult(
'<ul type="circle" />',
'<ul style="list-style-type:circle;" />'
);
}
function testUlConvertTypeCaseInsensitive() {
$this->assertResult(
'<ul type="CIRCLE" />',
'<ul style="list-style-type:circle;" />'
);
}
function testUlRemoveInvalidType() {
$this->assertResult(
'<ul type="a" />',
'<ul />'
);
}
function testOlConvertType1() {
$this->assertResult(
'<ol type="1" />',
'<ol style="list-style-type:decimal;" />'
);
}
function testOlConvertTypeLowerI() {
$this->assertResult(
'<ol type="i" />',
'<ol style="list-style-type:lower-roman;" />'
);
}
function testOlConvertTypeUpperI() {
$this->assertResult(
'<ol type="I" />',
'<ol style="list-style-type:upper-roman;" />'
);
}
function testOlConvertTypeLowerA() {
$this->assertResult(
'<ol type="a" />',
'<ol style="list-style-type:lower-alpha;" />'
);
}
function testOlConvertTypeUpperA() {
$this->assertResult(
'<ol type="A" />',
'<ol style="list-style-type:upper-alpha;" />'
);
}
function testOlRemoveInvalidType() {
$this->assertResult(
'<ol type="disc" />',
'<ol />'
);
}
function testLiConvertTypeCircle() {
$this->assertResult(
'<li type="circle" />',
'<li style="list-style-type:circle;" />'
);
}
function testLiConvertTypeA() {
$this->assertResult(
'<li type="A" />',
'<li style="list-style-type:upper-alpha;" />'
);
}
function testLiConvertTypeCaseSensitive() {
$this->assertResult(
'<li type="CIRCLE" />',
'<li />'
);
}
}