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

Convert all to new configuration get/set format.

Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
Edward Z. Yang
2009-02-19 19:17:49 -05:00
parent b107eec452
commit 86ca784da3
106 changed files with 504 additions and 815 deletions

View File

@@ -24,7 +24,7 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
}
function testEscapeBlockInInline() {
$this->config->set('Core', 'EscapeInvalidChildren', true);
$this->config->set('Core.EscapeInvalidChildren', true);
$this->assertResult(
'<b><div>Illegal div.</div></b>',
'<b>&lt;div&gt;Illegal div.&lt;/div&gt;</b>'
@@ -78,7 +78,7 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
}
function testChameleonEscapeInvalidBlockInInline() {
$this->config->set('Core', 'EscapeInvalidChildren', true);
$this->config->set('Core.EscapeInvalidChildren', true);
$this->assertResult( // alt config
'<span><ins><div>Not allowed!</div></ins></span>',
'<span><ins>&lt;div&gt;Not allowed!&lt;/div&gt;</ins></span>'
@@ -94,19 +94,19 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
}
function testPreserveInlineNodeInInlineRootNode() {
$this->config->set('HTML', 'Parent', 'span');
$this->config->set('HTML.Parent', 'span');
$this->assertResult('<b>Bold</b>');
}
function testRemoveBlockNodeInInlineRootNode() {
$this->config->set('HTML', 'Parent', 'span');
$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');
$this->config->set('Cache', 'DefinitionImpl', null);
$this->config->set('HTML.Parent', 'obviously-impossible');
$this->config->set('Cache.DefinitionImpl', null);
$this->expectError('Cannot use unrecognized element as parent');
$this->assertResult('<div>Accept</div>');
}
@@ -128,7 +128,7 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
}
function testStrictBlockquoteInHTML401() {
$this->config->set('HTML', 'Doctype', 'HTML 4.01 Strict');
$this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
$this->assertResult('<blockquote>text</blockquote>', '<blockquote><p>text</p></blockquote>');
}

View File

@@ -5,7 +5,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_EndInsertInjectorTest extends HTMLPur
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
$this->config->set('AutoFormat', 'Custom', array(
$this->config->set('AutoFormat.Custom', array(
new HTMLPurifier_Strategy_MakeWellFormed_EndInsertInjector()
));
}

View File

@@ -5,7 +5,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjectorTest extends HTMLPur
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
$this->config->set('AutoFormat', 'Custom', array(
$this->config->set('AutoFormat.Custom', array(
new HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector()
));
}
@@ -22,7 +22,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjectorTest extends HTMLPur
$this->assertResult('<b></b><span>asdf</span><b></b>','<b></b><b></b>');
}
function testDoubled() {
$this->config->set('AutoFormat', 'Custom', array(
$this->config->set('AutoFormat.Custom', array(
new HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector(),
new HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector(),
));

View File

@@ -5,7 +5,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_SkipInjectorTest extends HTMLPurifier
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
$this->config->set('AutoFormat', 'Custom', array(
$this->config->set('AutoFormat.Custom', array(
new HTMLPurifier_Strategy_MakeWellFormed_SkipInjector()
));
}
@@ -16,7 +16,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_SkipInjectorTest extends HTMLPurifier
$this->assertResult('<br />', '<br /><br />');
}
function testMultiplyMultiply() {
$this->config->set('AutoFormat', 'Custom', array(
$this->config->set('AutoFormat.Custom', array(
new HTMLPurifier_Strategy_MakeWellFormed_SkipInjector(),
new HTMLPurifier_Strategy_MakeWellFormed_SkipInjector()
));

View File

@@ -94,7 +94,7 @@ class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarn
}
function testBlockquoteWithInline() {
$this->config->set('HTML', 'Doctype', 'XHTML 1.0 Strict');
$this->config->set('HTML.Doctype', 'XHTML 1.0 Strict');
$this->assertResult(
// This is actually invalid, but will be fixed by
// ChildDef_StrictBlockquote

View File

@@ -14,7 +14,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_ErrorsTest extends HTMLPurifier_Strat
}
function testUnnecessaryEndTagToText() {
$this->config->set('Core', 'EscapeInvalidTags', true);
$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>');
@@ -40,7 +40,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_ErrorsTest extends HTMLPurifier_Strat
}
function testStrayEndTagToText() {
$this->config->set('Core', 'EscapeInvalidTags', true);
$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>');

View File

@@ -6,9 +6,9 @@ class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_Str
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
$this->config->set('AutoFormat', 'AutoParagraph', true);
$this->config->set('AutoFormat', 'Linkify', true);
$this->config->set('AutoFormat', 'RemoveEmpty', true);
$this->config->set('AutoFormat.AutoParagraph', true);
$this->config->set('AutoFormat.Linkify', true);
$this->config->set('AutoFormat.RemoveEmpty', true);
generate_mock_once('HTMLPurifier_Injector');
}
@@ -26,21 +26,21 @@ class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_Str
$mock->expectAt(1, 'handleEnd', array($i));
$mock->expectCallCount('handleEnd', 2);
$mock->setReturnValue('getRewind', false);
$this->config->set('AutoFormat', 'AutoParagraph', false);
$this->config->set('AutoFormat', 'Linkify', false);
$this->config->set('AutoFormat', 'Custom', array($mock));
$this->config->set('AutoFormat.AutoParagraph', false);
$this->config->set('AutoFormat.Linkify', false);
$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->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->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>');
}

View File

@@ -38,7 +38,7 @@ class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_Strat
}
function testRemoveOnlyScriptTagsLegacy() {
$this->config->set('Core', 'RemoveScriptContents', false);
$this->config->set('Core.RemoveScriptContents', false);
$this->assertResult(
'<script>alert();</script>',
'alert();'
@@ -46,7 +46,7 @@ class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_Strat
}
function testRemoveOnlyScriptTags() {
$this->config->set('Core', 'HiddenElements', array());
$this->config->set('Core.HiddenElements', array());
$this->assertResult(
'<script>alert();</script>',
'alert();'
@@ -62,13 +62,13 @@ class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_Strat
}
function testPreserveInvalidImgWhenRemovalIsDisabled() {
$this->config->set('Core', 'RemoveInvalidImg', false);
$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
$this->config->set('HTML.Trusted', true);
$this->config->set('Output.CommentScriptContents', false); // simplify output
$this->assertResult(
'<script type="text/javascript"><!--
alert(<b>bold</b>);
@@ -80,7 +80,7 @@ alert(&lt;b&gt;bold&lt;/b&gt;);
}
function testRequiredAttributesTestNotPerformedOnEndTag() {
$this->config->set('HTML', 'DefinitionID',
$this->config->set('HTML.DefinitionID',
'HTMLPurifier_Strategy_RemoveForeignElementsTest'.
'->testRequiredAttributesTestNotPerformedOnEndTag');
$def = $this->config->getHTMLDefinition(true);
@@ -89,17 +89,17 @@ alert(&lt;b&gt;bold&lt;/b&gt;);
}
function testPreserveCommentsWithHTMLTrusted() {
$this->config->set('HTML', 'Trusted', true);
$this->config->set('HTML.Trusted', true);
$this->assertResult('<!-- foo -->');
}
function testRemoveTrailingHyphensInComment() {
$this->config->set('HTML', 'Trusted', true);
$this->config->set('HTML.Trusted', true);
$this->assertResult('<!-- foo ----->', '<!-- foo -->');
}
function testCollapseDoubleHyphensInComment() {
$this->config->set('HTML', 'Trusted', true);
$this->config->set('HTML.Trusted', true);
$this->assertResult('<!-- bo --- asdf--as -->', '<!-- bo - asdf-as -->');
}

View File

@@ -5,7 +5,7 @@ class HTMLPurifier_Strategy_RemoveForeignElements_ErrorsTest extends HTMLPurifie
public function setup() {
parent::setup();
$this->config->set('HTML', 'TidyLevel', 'heavy');
$this->config->set('HTML.TidyLevel', 'heavy');
}
protected function getStrategy() {
@@ -26,7 +26,7 @@ class HTMLPurifier_Strategy_RemoveForeignElements_ErrorsTest extends HTMLPurifie
}
function testForeignElementToText() {
$this->config->set('Core', 'EscapeInvalidTags', true);
$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>');
@@ -46,14 +46,14 @@ class HTMLPurifier_Strategy_RemoveForeignElements_ErrorsTest extends HTMLPurifie
}
function testTrailingHyphenInCommentRemoved() {
$this->config->set('HTML', 'Trusted', true);
$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->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 -->');

View File

@@ -7,7 +7,7 @@ class HTMLPurifier_Strategy_RemoveForeignElements_TidyTest
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_RemoveForeignElements();
$this->config->set('HTML', 'TidyLevel', 'heavy');
$this->config->set('HTML.TidyLevel', 'heavy');
}
function testCenterTransform() {
@@ -26,7 +26,7 @@ class HTMLPurifier_Strategy_RemoveForeignElements_TidyTest
}
function testTransformToForbiddenElement() {
$this->config->set('HTML', 'Allowed', 'div');
$this->config->set('HTML.Allowed', 'div');
$this->assertResult(
'<font color="red" face="Arial" size="6">Big Warning!</font>',
'Big Warning!'

View File

@@ -52,7 +52,7 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
}
function testOnlyXMLLangInXHTML11() {
$this->config->set('HTML', 'Doctype', 'XHTML 1.1');
$this->config->set('HTML.Doctype', 'XHTML 1.1');
$this->assertResult(
'<b lang="en">asdf</b>',
'<b xml:lang="en">asdf</b>'
@@ -85,7 +85,7 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
}
function testBdoAlternateDefaultDir() {
$this->config->set('Attr', 'DefaultTextDir', 'rtl');
$this->config->set('Attr.DefaultTextDir', 'rtl');
$this->assertResult(
'<bdo>Go right.</bdo>',
'<bdo dir="rtl">Go right.</bdo>'
@@ -127,7 +127,7 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
}
function testImgAddDefaults() {
$this->config->set('Core', 'RemoveInvalidImg', false);
$this->config->set('Core.RemoveInvalidImg', false);
$this->assertResult(
'<img />',
'<img src="" alt="Invalid image" />'
@@ -142,7 +142,7 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
}
function testImgAddDefaultSrc() {
$this->config->set('Core', 'RemoveInvalidImg', false);
$this->config->set('Core.RemoveInvalidImg', false);
$this->assertResult(
'<img alt="pretty picture" />',
'<img alt="pretty picture" src="" />'
@@ -150,7 +150,7 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
}
function testImgRemoveNonRetrievableProtocol() {
$this->config->set('Core', 'RemoveInvalidImg', false);
$this->config->set('Core.RemoveInvalidImg', false);
$this->assertResult(
'<img src="mailto:foo@example.com" />',
'<img alt="mailto:foo@example.com" src="" />'
@@ -158,19 +158,19 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
}
function testPreserveRel() {
$this->config->set('Attr', 'AllowedRel', 'nofollow');
$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->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');
$this->config->set('HTML.Doctype', 'XHTML 1.0 Strict');
$this->config->set('Attr.AllowedFrameTargets', '_top');
$this->assertResult(
'<a href="foo" target="_top" />',
'<a href="foo" />'
@@ -191,7 +191,7 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
}
function testRemoveLargeCSSWidthAndHeightOnImgWithUserConf() {
$this->config->set('CSS', 'MaxImgLength', '1px');
$this->config->set('CSS.MaxImgLength', '1px');
$this->assertResult(
'<img src="" alt="" style="width:1mm;height:1mm;border:1px solid #000;" />',
'<img src="" alt="" style="border:1px solid #000;" />'
@@ -199,14 +199,14 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
}
function testKeepLargeCSSWidthAndHeightOnImgWhenToldTo() {
$this->config->set('CSS', 'MaxImgLength', null);
$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->config->set('CSS.MaxImgLength', null);
$this->assertResult(
'<img src="" alt="" style="width:100%;height:100%;border:1px solid #000;" />'
);

View File

@@ -6,7 +6,7 @@ class HTMLPurifier_Strategy_ValidateAttributes_IDTest extends HTMLPurifier_Strat
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
$this->config->set('Attr', 'EnableID', true);
$this->config->set('Attr.EnableID', true);
}
@@ -43,7 +43,7 @@ class HTMLPurifier_Strategy_ValidateAttributes_IDTest extends HTMLPurifier_Strat
}
function testIDBlacklist() {
$this->config->set('Attr', 'IDBlacklist', array('invalid'));
$this->config->set('Attr.IDBlacklist', array('invalid'));
$this->assertResult(
'<div id="invalid">Invalid</div>',
'<div>Invalid</div>'
@@ -51,7 +51,7 @@ class HTMLPurifier_Strategy_ValidateAttributes_IDTest extends HTMLPurifier_Strat
}
function testNameConvertedToID() {
$this->config->set('HTML', 'TidyLevel', 'heavy');
$this->config->set('HTML.TidyLevel', 'heavy');
$this->assertResult(
'<a name="foobar" />',
'<a id="foobar" />'

View File

@@ -6,7 +6,7 @@ class HTMLPurifier_Strategy_ValidateAttributes_TidyTest extends HTMLPurifier_Str
function setUp() {
parent::setUp();
$this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
$this->config->set('HTML', 'TidyLevel', 'heavy');
$this->config->set('HTML.TidyLevel', 'heavy');
}
function testConvertCenterAlign() {