mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 03:10:09 +02:00
[2.1.2?] Final migration for Injectors, deprecate the config and context parameters in assertResult
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1378 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -8,29 +8,35 @@ class HTMLPurifier_Injector_AutoParagraphTest extends HTMLPurifier_InjectorHarne
|
||||
|
||||
function setup() {
|
||||
parent::setup();
|
||||
$this->config = array('AutoFormat.AutoParagraph' => true);
|
||||
$this->config->set('AutoFormat', 'AutoParagraph', true);
|
||||
}
|
||||
|
||||
function test() {
|
||||
function testSingleParagraph() {
|
||||
$this->assertResult(
|
||||
'Foobar',
|
||||
'<p>Foobar</p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testSingleMultiLineParagraph() {
|
||||
$this->assertResult(
|
||||
'Par 1
|
||||
Par 1 still',
|
||||
'<p>Par 1
|
||||
Par 1 still</p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testTwoParagraphs() {
|
||||
$this->assertResult(
|
||||
'Par1
|
||||
|
||||
Par2',
|
||||
'<p>Par1</p><p>Par2</p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testTwoParagraphsWithLotsOfSpace() {
|
||||
$this->assertResult(
|
||||
'Par1
|
||||
|
||||
@@ -39,15 +45,18 @@ Par2',
|
||||
Par2',
|
||||
'<p>Par1</p><p>Par2</p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testTwoParagraphsWithInlineElements() {
|
||||
$this->assertResult(
|
||||
'<b>Par1</b>
|
||||
|
||||
<i>Par2</i>',
|
||||
'<p><b>Par1</b></p><p><i>Par2</i></p>'
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testSingleParagraphThatLooksLikeTwo() {
|
||||
$this->assertResult(
|
||||
'<b>Par1
|
||||
|
||||
@@ -56,29 +65,40 @@ Par2</b>',
|
||||
|
||||
Par2</b></p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testAddParagraphAdjacentToParagraph() {
|
||||
$this->assertResult(
|
||||
'Par1<p>Par2</p>',
|
||||
'<p>Par1</p><p>Par2</p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testParagraphUnclosedInlineElement() {
|
||||
$this->assertResult(
|
||||
'<b>Par1',
|
||||
'<p><b>Par1</b></p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testPreservePreTags() {
|
||||
$this->assertResult(
|
||||
'<pre>Par1
|
||||
|
||||
Par1</pre>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testIgnoreTrailingWhitespace() {
|
||||
$this->assertResult(
|
||||
'Par1
|
||||
|
||||
',
|
||||
'<p>Par1</p>'
|
||||
);
|
||||
}
|
||||
|
||||
function testDoNotParagraphBlockElements() {
|
||||
$this->assertResult(
|
||||
'Par1
|
||||
|
||||
@@ -87,19 +107,25 @@ Par1</pre>'
|
||||
Par3',
|
||||
'<p>Par1</p><div>Par2</div><p>Par3</p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testParagraphTextAndInlineNodes() {
|
||||
$this->assertResult(
|
||||
'Par<b>1</b>',
|
||||
'<p>Par<b>1</b></p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testIgnoreLeadingWhitespace() {
|
||||
$this->assertResult(
|
||||
'
|
||||
|
||||
Par',
|
||||
'<p>Par</p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testIgnoreSurroundingWhitespace() {
|
||||
$this->assertResult(
|
||||
'
|
||||
|
||||
@@ -108,69 +134,90 @@ Par
|
||||
',
|
||||
'<p>Par</p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testParagraphInsideBlockNode() {
|
||||
$this->assertResult(
|
||||
'<div>Par1
|
||||
|
||||
Par2</div>',
|
||||
'<div><p>Par1</p><p>Par2</p></div>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testParagraphInlineNodeInsideBlockNode() {
|
||||
$this->assertResult(
|
||||
'<div><b>Par1</b>
|
||||
|
||||
Par2</div>',
|
||||
'<div><p><b>Par1</b></p><p>Par2</p></div>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testNoParagraphWhenOnlyOneInsideBlockNode() {
|
||||
$this->assertResult('<div>Par1</div>');
|
||||
|
||||
}
|
||||
|
||||
function testParagraphTwoInlineNodesInsideBlockNode() {
|
||||
$this->assertResult(
|
||||
'<div><b>Par1</b>
|
||||
|
||||
<i>Par2</i></div>',
|
||||
'<div><p><b>Par1</b></p><p><i>Par2</i></p></div>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testPreserveInlineNodesInPreTag() {
|
||||
$this->assertResult(
|
||||
'<pre><b>Par1</b>
|
||||
|
||||
<i>Par2</i></pre>',
|
||||
true
|
||||
<i>Par2</i></pre>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testSplitUpInternalsOfPTagInBlockNode() {
|
||||
$this->assertResult(
|
||||
'<div><p>Foo
|
||||
|
||||
Bar</p></div>',
|
||||
'<div><p>Foo</p><p>Bar</p></div>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testSplitUpInlineNodesInPTagInBlockNode() {
|
||||
$this->assertResult(
|
||||
'<div><p><b>Foo</b>
|
||||
|
||||
<i>Bar</i></p></div>',
|
||||
'<div><p><b>Foo</b></p><p><i>Bar</i></p></div>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testNoParagraphSingleInlineNodeInBlockNode() {
|
||||
$this->assertResult(
|
||||
'<div><b>Foo</b></div>',
|
||||
'<div><b>Foo</b></div>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testParagraphInBlockquote() {
|
||||
$this->assertResult(
|
||||
'<blockquote>Par1
|
||||
|
||||
Par2</blockquote>',
|
||||
'<blockquote><p>Par1</p><p>Par2</p></blockquote>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testNoParagraphBetweenListItem() {
|
||||
$this->assertResult(
|
||||
'<ul><li>Foo</li>
|
||||
|
||||
<li>Bar</li></ul>', true
|
||||
<li>Bar</li></ul>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testParagraphSingleElementWithSurroundingSpace() {
|
||||
$this->assertResult(
|
||||
'<div>
|
||||
|
||||
@@ -179,7 +226,9 @@ Bar
|
||||
</div>',
|
||||
'<div><p>Bar</p></div>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testIgnoreExtraSpaceWithLeadingInlineNode() {
|
||||
$this->assertResult(
|
||||
'<b>Par1</b>a
|
||||
|
||||
@@ -188,99 +237,124 @@ Bar
|
||||
Par2',
|
||||
'<p><b>Par1</b>a</p><p>Par2</p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testAbsorbExtraEndingPTag() {
|
||||
$this->assertResult(
|
||||
'Par1
|
||||
|
||||
Par2</p>',
|
||||
'<p>Par1</p><p>Par2</p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testAbsorbExtraEndingDivTag() {
|
||||
$this->assertResult(
|
||||
'Par1
|
||||
|
||||
Par2</div>',
|
||||
'<p>Par1</p><p>Par2</p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testDoNotParagraphSingleSurroundingSpaceInBlockNode() {
|
||||
$this->assertResult(
|
||||
'<div>
|
||||
Par1
|
||||
</div>', true
|
||||
</div>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testBlockNodeTextDelimeterInBlockNode() {
|
||||
$this->assertResult(
|
||||
'<div>Par1
|
||||
|
||||
<div>Par2</div></div>',
|
||||
'<div><p>Par1</p><div>Par2</div></div>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testBlockNodeTextDelimeterWithoutDoublespaceInBlockNode() {
|
||||
$this->assertResult(
|
||||
'<div>Par1
|
||||
<div>Par2</div></div>',
|
||||
'<div><p>Par1
|
||||
</p><div>Par2</div></div>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testBlockNodeTextDelimeterWithoutDoublespace() {
|
||||
$this->assertResult(
|
||||
'Par1
|
||||
<div>Par2</div>',
|
||||
'<p>Par1
|
||||
</p><div>Par2</div>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testTwoParagraphsOfTextAndInlineNode() {
|
||||
$this->assertResult(
|
||||
'Par1
|
||||
|
||||
<b>Par2</b>',
|
||||
'<p>Par1</p><p><b>Par2</b></p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testLeadingInlineNodeParagraph() {
|
||||
$this->assertResult(
|
||||
'<img /> Foo',
|
||||
'<p><img /> Foo</p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testTrailingInlineNodeParagraph() {
|
||||
$this->assertResult(
|
||||
'<li>Foo <a>bar</a></li>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testTwoInlineNodeParagraph() {
|
||||
$this->assertResult(
|
||||
'<li><b>baz</b><a>bar</a></li>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testNoParagraphTrailingBlockNodeInBlockNode() {
|
||||
$this->assertResult(
|
||||
'<div><div>asdf</div><b>asdf</b></div>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testParagraphTrailingBlockNodeWithDoublespaceInBlockNode() {
|
||||
$this->assertResult(
|
||||
'<div><div>asdf</div>
|
||||
|
||||
<b>asdf</b></div>',
|
||||
'<div><div>asdf</div><p><b>asdf</b></p></div>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testParagraphTwoInlineNodesAndWhitespaceNode() {
|
||||
$this->assertResult(
|
||||
'<b>One</b> <i>Two</i>',
|
||||
'<p><b>One</b> <i>Two</i></p>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testInlineRootNode() {
|
||||
function testNoParagraphWithInlineRootNode() {
|
||||
$this->config->set('HTML', 'Parent', 'span');
|
||||
$this->assertResult(
|
||||
'Par
|
||||
|
||||
Par2',
|
||||
true,
|
||||
array('AutoFormat.AutoParagraph' => true, 'HTML.Parent' => 'span')
|
||||
Par2'
|
||||
);
|
||||
}
|
||||
|
||||
function testNeeded() {
|
||||
function testErrorNeeded() {
|
||||
$this->config->set('HTML', 'Allowed', 'b');
|
||||
$this->expectError('Cannot enable AutoParagraph injector because p is not allowed');
|
||||
$this->assertResult('<b>foobar</b>', true, array('AutoFormat.AutoParagraph' => true, 'HTML.Allowed' => 'b'));
|
||||
$this->assertResult('<b>foobar</b>');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -8,35 +8,40 @@ class HTMLPurifier_Injector_LinkifyTest extends HTMLPurifier_InjectorHarness
|
||||
|
||||
function setup() {
|
||||
parent::setup();
|
||||
$this->config = array('AutoFormat.Linkify' => true);
|
||||
$this->config->set('AutoFormat', 'Linkify', true);
|
||||
}
|
||||
|
||||
function testLinkify() {
|
||||
|
||||
function testLinkifyURLInRootNode() {
|
||||
$this->assertResult(
|
||||
'http://example.com',
|
||||
'<a href="http://example.com">http://example.com</a>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testLinkifyURLInInlineNode() {
|
||||
$this->assertResult(
|
||||
'<b>http://example.com</b>',
|
||||
'<b><a href="http://example.com">http://example.com</a></b>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testBasicUsageCase() {
|
||||
$this->assertResult(
|
||||
'This URL http://example.com is what you need',
|
||||
'This URL <a href="http://example.com">http://example.com</a> is what you need'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testIgnoreURLInATag() {
|
||||
$this->assertResult(
|
||||
'<a>http://example.com/</a>'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testNeeded() {
|
||||
$this->config->set('HTML', 'Allowed', 'b');
|
||||
$this->expectError('Cannot enable Linkify injector because a is not allowed');
|
||||
$this->assertResult('http://example.com/', true, array('AutoFormat.Linkify' => true, 'HTML.Allowed' => 'b'));
|
||||
$this->assertResult('http://example.com/');
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -8,39 +8,53 @@ class HTMLPurifier_Injector_PurifierLinkifyTest extends HTMLPurifier_InjectorHar
|
||||
|
||||
function setup() {
|
||||
parent::setup();
|
||||
$this->config = array(
|
||||
'AutoFormat.PurifierLinkify' => true,
|
||||
'AutoFormatParam.PurifierLinkifyDocURL' => '#%s'
|
||||
);
|
||||
$this->config->set('AutoFormat', 'PurifierLinkify', true);
|
||||
$this->config->set('AutoFormatParam', 'PurifierLinkifyDocURL', '#%s');
|
||||
}
|
||||
|
||||
function testLinkify() {
|
||||
|
||||
function testNoTriggerCharacer() {
|
||||
$this->assertResult('Foobar');
|
||||
}
|
||||
|
||||
function testTriggerCharacterInIrrelevantContext() {
|
||||
$this->assertResult('20% off!');
|
||||
}
|
||||
|
||||
function testPreserveNamespace() {
|
||||
$this->assertResult('%Core namespace (not recognized)');
|
||||
}
|
||||
|
||||
function testLinkifyBasic() {
|
||||
$this->assertResult(
|
||||
'%Namespace.Directive',
|
||||
'<a href="#Namespace.Directive">%Namespace.Directive</a>'
|
||||
);
|
||||
}
|
||||
|
||||
function testLinkifyWithAdjacentTextNodes() {
|
||||
$this->assertResult(
|
||||
'This %Namespace.Directive thing',
|
||||
'This <a href="#Namespace.Directive">%Namespace.Directive</a> thing'
|
||||
);
|
||||
}
|
||||
|
||||
function testLinkifyInBlock() {
|
||||
$this->assertResult(
|
||||
'<div>This %Namespace.Directive thing</div>',
|
||||
'<div>This <a href="#Namespace.Directive">%Namespace.Directive</a> thing</div>'
|
||||
);
|
||||
}
|
||||
|
||||
function testPreserveInATag() {
|
||||
$this->assertResult(
|
||||
'<a>%Namespace.Directive</a>'
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testNeeded() {
|
||||
$this->config->set('HTML', 'Allowed', 'b');
|
||||
$this->expectError('Cannot enable PurifierLinkify injector because a is not allowed');
|
||||
$this->assertResult('%Namespace.Directive', true, array('AutoFormat.PurifierLinkify' => true, 'HTML.Allowed' => 'b'));
|
||||
$this->assertResult('%Namespace.Directive');
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user