1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-06 06:07:26 +02:00

Remove trailing whitespace.

Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
Edward Z. Yang
2008-12-06 02:28:20 -05:00
parent 3a6b63dff1
commit 2c955af135
476 changed files with 5595 additions and 5547 deletions

View File

@@ -3,63 +3,63 @@
class HTMLPurifier_Strategy_Composite_Test
extends HTMLPurifier_Strategy_Composite
{
public function __construct(&$strategies) {
$this->strategies =& $strategies;
}
}
// doesn't use Strategy harness
class HTMLPurifier_Strategy_CompositeTest extends HTMLPurifier_Harness
{
function test() {
generate_mock_once('HTMLPurifier_Strategy');
generate_mock_once('HTMLPurifier_Config');
generate_mock_once('HTMLPurifier_Context');
// setup a bunch of mock strategies to inject into our composite test
$mock_1 = new HTMLPurifier_StrategyMock();
$mock_2 = new HTMLPurifier_StrategyMock();
$mock_3 = new HTMLPurifier_StrategyMock();
// setup the object
$strategies = array(&$mock_1, &$mock_2, &$mock_3);
$composite = new HTMLPurifier_Strategy_Composite_Test($strategies);
// setup expectations
$input_1 = 'This is raw data';
$input_2 = 'Processed by 1';
$input_3 = 'Processed by 1 and 2';
$input_4 = 'Processed by 1, 2 and 3'; // expected output
$config = new HTMLPurifier_ConfigMock();
$context = new HTMLPurifier_ContextMock();
$params_1 = array($input_1, $config, $context);
$params_2 = array($input_2, $config, $context);
$params_3 = array($input_3, $config, $context);
$mock_1->expectOnce('execute', $params_1);
$mock_1->setReturnValue('execute', $input_2, $params_1);
$mock_2->expectOnce('execute', $params_2);
$mock_2->setReturnValue('execute', $input_3, $params_2);
$mock_3->expectOnce('execute', $params_3);
$mock_3->setReturnValue('execute', $input_4, $params_3);
// perform test
$output = $composite->execute($input_1, $config, $context);
$this->assertIdentical($input_4, $output);
}
}

View File

@@ -2,43 +2,43 @@
class HTMLPurifier_Strategy_CoreTest extends HTMLPurifier_StrategyHarness
{
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_Core();
}
function testBlankInput() {
$this->assertResult('');
}
function testMakeWellFormed() {
$this->assertResult(
'<b>Make well formed.',
'<b>Make well formed.</b>'
);
}
function testFixNesting() {
$this->assertResult(
'<b><div>Fix nesting.</div></b>',
'<b></b><div>Fix nesting.</div>'
);
}
function testRemoveForeignElements() {
$this->assertResult(
'<asdf>Foreign element removal.</asdf>',
'Foreign element removal.'
);
}
function testFirstThree() {
$this->assertResult(
'<foo><b><div>All three.</div></b>',
'<b></b><div>All three.</div>'
);
}
}

View File

@@ -2,16 +2,16 @@
class HTMLPurifier_Strategy_ErrorsHarness extends HTMLPurifier_ErrorsHarness
{
// needs to be defined
protected function getStrategy() {}
protected function invoke($input) {
$strategy = $this->getStrategy();
$lexer = new HTMLPurifier_Lexer_DirectLex();
$tokens = $lexer->tokenizeHTML($input, $this->config, $this->context);
$strategy->execute($tokens, $this->config, $this->context);
}
}

View File

@@ -2,27 +2,27 @@
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(
@@ -30,53 +30,53 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
'<b>&lt;div&gt;Illegal div.&lt;/div&gt;</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
@@ -84,7 +84,7 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
'<span><ins>&lt;div&gt;Not allowed!&lt;/div&gt;</ins></span>'
);
}
function testExclusionsIntegration() {
// test exclusions
$this->assertResult(
@@ -92,17 +92,17 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
'<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');
@@ -110,27 +110,27 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
$this->expectError('Cannot use unrecognized element as parent');
$this->assertResult('<div>Accept</div>');
}
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>');
}
}

View File

@@ -2,39 +2,39 @@
class HTMLPurifier_Strategy_FixNesting_ErrorsTest extends HTMLPurifier_Strategy_ErrorsHarness
{
protected function getStrategy() {
return new HTMLPurifier_Strategy_FixNesting();
}
function testNodeRemoved() {
$this->expectErrorCollection(E_ERROR, 'Strategy_FixNesting: Node removed');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('ul', array(), 1));
$this->invoke('<ul></ul>');
}
function testNodeExcluded() {
$this->expectErrorCollection(E_ERROR, 'Strategy_FixNesting: Node excluded');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('a', array(), 2));
$this->invoke("<a>\n<a></a></a>");
}
function testNodeReorganized() {
$this->expectErrorCollection(E_WARNING, 'Strategy_FixNesting: Node reorganized');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('span', array(), 1));
$this->invoke("<span>Valid<div>Invalid</div></span>");
}
function testNoNodeReorganizedForEmptyNode() {
$this->expectNoErrorCollection();
$this->invoke("<span></span>");
}
function testNodeContentsRemoved() {
$this->expectErrorCollection(E_ERROR, 'Strategy_FixNesting: Node contents removed');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('span', array(), 1));
$this->invoke("<span><div></div></span>");
}
}

View File

@@ -2,105 +2,105 @@
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>'
);
}
function testBlockquoteWithInline() {
$this->config->set('HTML', 'Doctype', 'XHTML 1.0 Strict');
$this->assertResult(
// This is actually invalid, but will be fixed by
// This is actually invalid, but will be fixed by
// ChildDef_StrictBlockquote
'<blockquote>foo<b>bar</b></blockquote>'
);
}
}

View File

@@ -2,53 +2,53 @@
class HTMLPurifier_Strategy_MakeWellFormed_ErrorsTest extends HTMLPurifier_Strategy_ErrorsHarness
{
protected function getStrategy() {
return new HTMLPurifier_Strategy_MakeWellFormed();
}
function testUnnecessaryEndTagRemoved() {
$this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag removed');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_End('b', array(), 1, 0));
$this->invoke('</b>');
}
function testUnnecessaryEndTagToText() {
$this->config->set('Core', 'EscapeInvalidTags', true);
$this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag to text');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_End('b', array(), 1, 0));
$this->invoke('</b>');
}
function testTagAutoClosed() {
$this->expectErrorCollection(E_NOTICE, 'Strategy_MakeWellFormed: Tag auto closed', new HTMLPurifier_Token_Start('b', array(), 1, 0));
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('div', array(), 1, 6));
$this->invoke('<b>Foo<div>Bar</div>');
}
function testStrayEndTagRemoved() {
$this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag removed');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_End('b', array(), 1, 3));
$this->invoke('<i></b></i>');
}
function testStrayEndTagToText() {
$this->config->set('Core', 'EscapeInvalidTags', true);
$this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag to text');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_End('b', array(), 1, 3));
$this->invoke('<i></b></i>');
}
function testTagClosedByElementEnd() {
$this->expectErrorCollection(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by element end', new HTMLPurifier_Token_Start('b', array(), 1, 3));
$this->expectContext('CurrentToken', new HTMLPurifier_Token_End('i', array(), 1, 12));
$this->invoke('<i><b>Foobar</i>');
}
function testTagClosedByDocumentEnd() {
$this->expectErrorCollection(E_NOTICE, 'Strategy_MakeWellFormed: Tag closed by document end', new HTMLPurifier_Token_Start('b', array(), 1, 0));
$this->invoke('<b>Foobar');
}
}

View File

@@ -2,7 +2,7 @@
class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_StrategyHarness
{
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
@@ -11,7 +11,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_Str
$this->config->set('AutoFormat', 'RemoveEmpty', true);
generate_mock_once('HTMLPurifier_Injector');
}
function testEndHandler() {
$mock = new HTMLPurifier_InjectorMock();
$b = new HTMLPurifier_Token_End('b');
@@ -31,48 +31,48 @@ class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_Str
$this->config->set('AutoFormat', 'Custom', array($mock));
$this->assertResult('<i><b>asdf</b>', '<i><b>asdf</b></i>');
}
function testErrorRequiredElementNotAllowed() {
$this->config->set('HTML', 'Allowed', '');
$this->expectError('Cannot enable AutoParagraph injector because p is not allowed');
$this->expectError('Cannot enable Linkify injector because a is not allowed');
$this->assertResult('Foobar');
}
function testErrorRequiredAttributeNotAllowed() {
$this->config->set('HTML', 'Allowed', 'a,p');
$this->expectError('Cannot enable Linkify injector because a.href is not allowed');
$this->assertResult('<p>http://example.com</p>');
}
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",
@@ -81,7 +81,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_Str
<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>',
@@ -90,14 +90,14 @@ class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_Str
<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>'
);
}
function testParagraphAfterLinkifiedURL() {
$this->assertResult(
"http://google.com
@@ -108,7 +108,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_Str
<p><b>b</b></p>"
);
}
function testEmptyAndParagraph() {
// This is a fairly degenerate case, but it demonstrates that
// the two don't error out together, at least.
@@ -128,7 +128,7 @@ asdf<b></b></p>
"
);
}
function testRewindAndParagraph() {
$this->assertResult(
"bar
@@ -145,5 +145,5 @@ foo",
<p>foo</p>"
);
}
}

View File

@@ -2,41 +2,41 @@
class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_StrategyHarness
{
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_RemoveForeignElements();
}
function testBlankInput() {
$this->assertResult('');
}
function testPreserveRecognizedElements() {
$this->assertResult('This is <b>bold text</b>.');
}
function testRemoveForeignElements() {
$this->assertResult(
'<asdf>Bling</asdf><d href="bang">Bong</d><foobar />',
'BlingBong'
);
}
function testRemoveScriptAndContents() {
$this->assertResult(
'<script>alert();</script>',
''
);
}
function testRemoveStyleAndContents() {
$this->assertResult(
'<style>.foo {blink;}</style>',
''
);
}
function testRemoveOnlyScriptTagsLegacy() {
$this->config->set('Core', 'RemoveScriptContents', false);
$this->assertResult(
@@ -44,7 +44,7 @@ class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_Strat
'alert();'
);
}
function testRemoveOnlyScriptTags() {
$this->config->set('Core', 'HiddenElements', array());
$this->assertResult(
@@ -52,20 +52,20 @@ class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_Strat
'alert();'
);
}
function testRemoveInvalidImg() {
$this->assertResult('<img />', '');
}
function testPreserveValidImg() {
$this->assertResult('<img src="foobar.gif" alt="foobar.gif" />');
}
function testPreserveInvalidImgWhenRemovalIsDisabled() {
$this->config->set('Core', 'RemoveInvalidImg', false);
$this->assertResult('<img />');
}
function testTextifyCommentedScriptContents() {
$this->config->set('HTML', 'Trusted', true);
$this->config->set('Output', 'CommentScriptContents', false); // simplify output
@@ -78,7 +78,7 @@ alert(&lt;b&gt;bold&lt;/b&gt;);
// </script>'
);
}
function testRequiredAttributesTestNotPerformedOnEndTag() {
$this->config->set('HTML', 'DefinitionID',
'HTMLPurifier_Strategy_RemoveForeignElementsTest'.
@@ -87,21 +87,21 @@ alert(&lt;b&gt;bold&lt;/b&gt;);
$def->addElement('f', 'Block', 'Optional: #PCDATA', false, array('req*' => 'Text'));
$this->assertResult('<f req="text">Foo</f> Bar');
}
function testPreserveCommentsWithHTMLTrusted() {
$this->config->set('HTML', 'Trusted', true);
$this->assertResult('<!-- foo -->');
}
function testRemoveTrailingHyphensInComment() {
$this->config->set('HTML', 'Trusted', true);
$this->assertResult('<!-- foo ----->', '<!-- foo -->');
}
function testCollapseDoubleHyphensInComment() {
$this->config->set('HTML', 'Trusted', true);
$this->assertResult('<!-- bo --- asdf--as -->', '<!-- bo - asdf-as -->');
}
}

View File

@@ -2,69 +2,69 @@
class HTMLPurifier_Strategy_RemoveForeignElements_ErrorsTest extends HTMLPurifier_Strategy_ErrorsHarness
{
public function setup() {
parent::setup();
$this->config->set('HTML', 'TidyLevel', 'heavy');
}
protected function getStrategy() {
return new HTMLPurifier_Strategy_RemoveForeignElements();
}
function testTagTransform() {
$this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Tag transform', 'center');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('div', array('style' => 'text-align:center;'), 1));
$this->invoke('<center>');
}
function testMissingRequiredAttr() {
// a little fragile, since img has two required attributes
$this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Missing required attribute', 'alt');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Empty('img', array(), 1));
$this->invoke('<img />');
}
function testForeignElementToText() {
$this->config->set('Core', 'EscapeInvalidTags', true);
$this->expectErrorCollection(E_WARNING, 'Strategy_RemoveForeignElements: Foreign element to text');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('invalid', array(), 1));
$this->invoke('<invalid>');
}
function testForeignElementRemoved() {
// uses $CurrentToken.Serialized
$this->expectErrorCollection(E_ERROR, 'Strategy_RemoveForeignElements: Foreign element removed');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Start('invalid', array(), 1));
$this->invoke('<invalid>');
}
function testCommentRemoved() {
$this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Comment removed');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test ', 1));
$this->invoke('<!-- test -->');
}
function testTrailingHyphenInCommentRemoved() {
$this->config->set('HTML', 'Trusted', true);
$this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Trailing hyphen in comment removed');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test --', 1));
$this->invoke('<!-- test ---->');
}
function testDoubleHyphenInCommentRemoved() {
$this->config->set('HTML', 'Trusted', true);
$this->expectErrorCollection(E_NOTICE, 'Strategy_RemoveForeignElements: Hyphens in comment collapsed');
$this->expectContext('CurrentToken', new HTMLPurifier_Token_Comment(' test --- test -- test ', 1));
$this->invoke('<!-- test --- test -- test -->');
}
function testForeignMetaElementRemoved() {
$this->collector->expectAt(0, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Foreign meta element removed'));
$this->collector->expectContextAt(0, 'CurrentToken', new HTMLPurifier_Token_Start('script', array(), 1));
$this->collector->expectAt(1, 'send', array(E_ERROR, 'Strategy_RemoveForeignElements: Token removed to end', 'script'));
$this->invoke('<script>asdf');
}
}

View File

@@ -3,20 +3,20 @@
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>',
@@ -24,7 +24,7 @@ class HTMLPurifier_Strategy_RemoveForeignElements_TidyTest
' Warning!</span>'
);
}
function testTransformToForbiddenElement() {
$this->config->set('HTML', 'Allowed', 'div');
$this->assertResult(
@@ -32,12 +32,12 @@ class HTMLPurifier_Strategy_RemoveForeignElements_TidyTest
'Big Warning!'
);
}
function testMenuTransform() {
$this->assertResult(
'<menu><li>Item 1</li></menu>',
'<ul><li>Item 1</li></ul>'
);
}
}

View File

@@ -3,54 +3,54 @@
class HTMLPurifier_Strategy_ValidateAttributesTest extends
HTMLPurifier_StrategyHarness
{
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
}
function testEmptyInput() {
$this->assertResult('');
}
function testRemoveIDByDefault() {
$this->assertResult(
'<div id="valid">Kill the ID.</div>',
'<div>Kill the ID.</div>'
);
}
function testRemoveInvalidDir() {
$this->assertResult(
'<span dir="up-to-down">Bad dir.</span>',
'<span>Bad dir.</span>'
);
}
function testPreserveValidClass() {
$this->assertResult('<div class="valid">Valid</div>');
}
function testSelectivelyRemoveInvalidClasses() {
$this->assertResult(
'<div class="valid 0invalid">Keep valid.</div>',
'<div class="valid">Keep valid.</div>'
);
}
function testPreserveTitle() {
$this->assertResult(
'<acronym title="PHP: Hypertext Preprocessor">PHP</acronym>'
);
}
function testAddXMLLang() {
$this->assertResult(
'<span lang="fr">La soupe.</span>',
'<span lang="fr" xml:lang="fr">La soupe.</span>'
);
}
function testOnlyXMLLangInXHTML11() {
$this->config->set('HTML', 'Doctype', 'XHTML 1.1');
$this->assertResult(
@@ -58,32 +58,32 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
'<b xml:lang="en">asdf</b>'
);
}
function testBasicURI() {
$this->assertResult('<a href="http://www.google.com/">Google</a>');
}
function testInvalidURI() {
$this->assertResult(
'<a href="javascript:badstuff();">Google</a>',
'<a>Google</a>'
);
}
function testBdoAddMissingDir() {
$this->assertResult(
'<bdo>Go left.</bdo>',
'<bdo dir="ltr">Go left.</bdo>'
);
}
function testBdoReplaceInvalidDirWithDefault() {
$this->assertResult(
'<bdo dir="blahblah">Invalid value!</bdo>',
'<bdo dir="ltr">Invalid value!</bdo>'
);
}
function testBdoAlternateDefaultDir() {
$this->config->set('Attr', 'DefaultTextDir', 'rtl');
$this->assertResult(
@@ -91,14 +91,14 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
'<bdo dir="rtl">Go right.</bdo>'
);
}
function testRemoveDirWhenNotRequired() {
$this->assertResult(
'<span dir="blahblah">Invalid value!</span>',
'<span>Invalid value!</span>'
);
}
function testTableAttributes() {
$this->assertResult(
'<table frame="above" rules="rows" summary="A test table" border="2" cellpadding="5%" cellspacing="3" width="100%">
@@ -118,14 +118,14 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
</table>'
);
}
function testColSpanIsNonZero() {
$this->assertResult(
'<col span="0" />',
'<col />'
);
}
function testImgAddDefaults() {
$this->config->set('Core', 'RemoveInvalidImg', false);
$this->assertResult(
@@ -133,14 +133,14 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
'<img src="" alt="Invalid image" />'
);
}
function testImgGenerateAlt() {
$this->assertResult(
'<img src="foobar.jpg" />',
'<img src="foobar.jpg" alt="foobar.jpg" />'
);
}
function testImgAddDefaultSrc() {
$this->config->set('Core', 'RemoveInvalidImg', false);
$this->assertResult(
@@ -148,7 +148,7 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
'<img alt="pretty picture" src="" />'
);
}
function testImgRemoveNonRetrievableProtocol() {
$this->config->set('Core', 'RemoveInvalidImg', false);
$this->assertResult(
@@ -156,18 +156,18 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
'<img alt="mailto:foo@example.com" src="" />'
);
}
function testPreserveRel() {
$this->config->set('Attr', 'AllowedRel', 'nofollow');
$this->assertResult('<a href="foo" rel="nofollow" />');
}
function testPreserveTarget() {
$this->config->set('Attr', 'AllowedFrameTargets', '_top');
$this->config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional');
$this->assertResult('<a href="foo" target="_top" />');
}
function testRemoveTargetWhenNotSupported() {
$this->config->set('HTML', 'Doctype', 'XHTML 1.0 Strict');
$this->config->set('Attr', 'AllowedFrameTargets', '_top');
@@ -176,20 +176,20 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
'<a href="foo" />'
);
}
function testKeepAbsoluteCSSWidthAndHeightOnImg() {
$this->assertResult(
'<img src="" alt="" style="width:10px;height:10px;border:1px solid #000;" />'
);
}
function testRemoveLargeCSSWidthAndHeightOnImg() {
$this->assertResult(
'<img src="" alt="" style="width:10000000px;height:10000000px;border:1px solid #000;" />',
'<img src="" alt="" style="border:1px solid #000;" />'
);
}
function testRemoveLargeCSSWidthAndHeightOnImgWithUserConf() {
$this->config->set('CSS', 'MaxImgLength', '1px');
$this->assertResult(
@@ -197,35 +197,35 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
'<img src="" alt="" style="border:1px solid #000;" />'
);
}
function testKeepLargeCSSWidthAndHeightOnImgWhenToldTo() {
$this->config->set('CSS', 'MaxImgLength', null);
$this->assertResult(
'<img src="" alt="" style="width:10000000px;height:10000000px;border:1px solid #000;" />'
);
}
function testKeepPercentCSSWidthAndHeightOnImgWhenToldTo() {
$this->config->set('CSS', 'MaxImgLength', null);
$this->assertResult(
'<img src="" alt="" style="width:100%;height:100%;border:1px solid #000;" />'
);
}
function testRemoveRelativeCSSWidthAndHeightOnImg() {
$this->assertResult(
'<img src="" alt="" style="width:10em;height:10em;border:1px solid #000;" />',
'<img src="" alt="" style="border:1px solid #000;" />'
);
}
function testRemovePercentCSSWidthAndHeightOnImg() {
$this->assertResult(
'<img src="" alt="" style="width:100%;height:100%;border:1px solid #000;" />',
'<img src="" alt="" style="border:1px solid #000;" />'
);
}
}

View File

@@ -2,46 +2,46 @@
class HTMLPurifier_Strategy_ValidateAttributes_IDTest extends HTMLPurifier_StrategyHarness
{
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
$this->config->set('Attr', 'EnableID', 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(
@@ -49,7 +49,7 @@ class HTMLPurifier_Strategy_ValidateAttributes_IDTest extends HTMLPurifier_Strat
'<div>Invalid</div>'
);
}
function testNameConvertedToID() {
$this->config->set('HTML', 'TidyLevel', 'heavy');
$this->assertResult(
@@ -57,6 +57,6 @@ class HTMLPurifier_Strategy_ValidateAttributes_IDTest extends HTMLPurifier_Strat
'<a id="foobar" />'
);
}
}

View File

@@ -2,349 +2,349 @@
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 />'
);
}
}