mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-03-23 14:27:02 +00: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:
parent
71301b36eb
commit
8f58c7f49e
3
NEWS
3
NEWS
@ -13,6 +13,9 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
! Implemented Object module for trusted users
|
! Implemented Object module for trusted users
|
||||||
- Fix non-visible parsing error in DirectLex with empty tags that have
|
- Fix non-visible parsing error in DirectLex with empty tags that have
|
||||||
slashes inside attribute values.
|
slashes inside attribute values.
|
||||||
|
. Unit test refactoring for one logical test per test function
|
||||||
|
. Config and context parameters in ComplexHarness deprecated: instead, edit
|
||||||
|
the $config and $context member variables
|
||||||
|
|
||||||
2.1.1, released 2007-08-04
|
2.1.1, released 2007-08-04
|
||||||
- Fix show-stopper bug in %URI.MakeAbsolute functionality
|
- Fix show-stopper bug in %URI.MakeAbsolute functionality
|
||||||
|
@ -67,41 +67,20 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
|
|||||||
* @param $context_array Context array in form of Key => Value or an actual
|
* @param $context_array Context array in form of Key => Value or an actual
|
||||||
* context object.
|
* context object.
|
||||||
*/
|
*/
|
||||||
function assertResult($input, $expect = true,
|
function assertResult($input, $expect = true) {
|
||||||
$config_array = array(), $context_array = array()
|
|
||||||
) {
|
|
||||||
|
|
||||||
// setup config
|
|
||||||
if ($this->config) {
|
|
||||||
$config = HTMLPurifier_Config::create($this->config);
|
|
||||||
$config->autoFinalize = false;
|
|
||||||
$config->loadArray($config_array);
|
|
||||||
} else {
|
|
||||||
$config = HTMLPurifier_Config::create($config_array);
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup context object. Note that we are operating on a copy of it!
|
|
||||||
// When necessary, extend the test harness to allow post-tests
|
|
||||||
// on the context object
|
|
||||||
if (empty($this->context)) {
|
|
||||||
$context = new HTMLPurifier_Context();
|
|
||||||
$context->loadArray($context_array);
|
|
||||||
} else {
|
|
||||||
$context =& $this->context;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->to_tokens && is_string($input)) {
|
if ($this->to_tokens && is_string($input)) {
|
||||||
// $func may cause $input to change, so "clone" another copy
|
// $func may cause $input to change, so "clone" another copy
|
||||||
// to sacrifice
|
// to sacrifice
|
||||||
$input = $this->lexer->tokenizeHTML($s = $input, $config, $context);
|
$input = $this->tokenize($temp = $input);
|
||||||
$input_c = $this->lexer->tokenizeHTML($s, $config, $context);
|
$input_c = $this->tokenize($temp);
|
||||||
} else {
|
} else {
|
||||||
$input_c = $input;
|
$input_c = $input;
|
||||||
}
|
}
|
||||||
|
|
||||||
// call the function
|
// call the function
|
||||||
$func = $this->func;
|
$func = $this->func;
|
||||||
$result = $this->obj->$func($input_c, $config, $context);
|
$result = $this->obj->$func($input_c, $this->config, $this->context);
|
||||||
|
|
||||||
// test a bool result
|
// test a bool result
|
||||||
if (is_bool($result)) {
|
if (is_bool($result)) {
|
||||||
@ -112,11 +91,9 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->to_html) {
|
if ($this->to_html) {
|
||||||
$result = $this->generator->
|
$result = $this->generate($result);
|
||||||
generateFromTokens($result, $config, $context);
|
|
||||||
if (is_array($expect)) {
|
if (is_array($expect)) {
|
||||||
$expect = $this->generator->
|
$expect = $this->generate($expect);
|
||||||
generateFromTokens($expect, $config, $context);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +101,20 @@ class HTMLPurifier_ComplexHarness extends HTMLPurifier_Harness
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tokenize HTML into tokens, uses member variables for common variables
|
||||||
|
*/
|
||||||
|
function tokenize($html) {
|
||||||
|
return $this->lexer->tokenizeHTML($html, $this->config, $this->context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate textual HTML from tokens
|
||||||
|
*/
|
||||||
|
function generate($tokens) {
|
||||||
|
return $this->generator->generateFromTokens($tokens, $this->config, $this->context);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,29 +8,35 @@ class HTMLPurifier_Injector_AutoParagraphTest extends HTMLPurifier_InjectorHarne
|
|||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
parent::setup();
|
parent::setup();
|
||||||
$this->config = array('AutoFormat.AutoParagraph' => true);
|
$this->config->set('AutoFormat', 'AutoParagraph', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function test() {
|
function testSingleParagraph() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'Foobar',
|
'Foobar',
|
||||||
'<p>Foobar</p>'
|
'<p>Foobar</p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSingleMultiLineParagraph() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'Par 1
|
'Par 1
|
||||||
Par 1 still',
|
Par 1 still',
|
||||||
'<p>Par 1
|
'<p>Par 1
|
||||||
Par 1 still</p>'
|
Par 1 still</p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testTwoParagraphs() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'Par1
|
'Par1
|
||||||
|
|
||||||
Par2',
|
Par2',
|
||||||
'<p>Par1</p><p>Par2</p>'
|
'<p>Par1</p><p>Par2</p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testTwoParagraphsWithLotsOfSpace() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'Par1
|
'Par1
|
||||||
|
|
||||||
@ -39,15 +45,18 @@ Par2',
|
|||||||
Par2',
|
Par2',
|
||||||
'<p>Par1</p><p>Par2</p>'
|
'<p>Par1</p><p>Par2</p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testTwoParagraphsWithInlineElements() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<b>Par1</b>
|
'<b>Par1</b>
|
||||||
|
|
||||||
<i>Par2</i>',
|
<i>Par2</i>',
|
||||||
'<p><b>Par1</b></p><p><i>Par2</i></p>'
|
'<p><b>Par1</b></p><p><i>Par2</i></p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSingleParagraphThatLooksLikeTwo() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<b>Par1
|
'<b>Par1
|
||||||
|
|
||||||
@ -56,29 +65,40 @@ Par2</b>',
|
|||||||
|
|
||||||
Par2</b></p>'
|
Par2</b></p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testAddParagraphAdjacentToParagraph() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'Par1<p>Par2</p>',
|
'Par1<p>Par2</p>',
|
||||||
'<p>Par1</p><p>Par2</p>'
|
'<p>Par1</p><p>Par2</p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testParagraphUnclosedInlineElement() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<b>Par1',
|
'<b>Par1',
|
||||||
'<p><b>Par1</b></p>'
|
'<p><b>Par1</b></p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testPreservePreTags() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<pre>Par1
|
'<pre>Par1
|
||||||
|
|
||||||
Par1</pre>'
|
Par1</pre>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testIgnoreTrailingWhitespace() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'Par1
|
'Par1
|
||||||
|
|
||||||
',
|
',
|
||||||
'<p>Par1</p>'
|
'<p>Par1</p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testDoNotParagraphBlockElements() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'Par1
|
'Par1
|
||||||
|
|
||||||
@ -87,19 +107,25 @@ Par1</pre>'
|
|||||||
Par3',
|
Par3',
|
||||||
'<p>Par1</p><div>Par2</div><p>Par3</p>'
|
'<p>Par1</p><div>Par2</div><p>Par3</p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testParagraphTextAndInlineNodes() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'Par<b>1</b>',
|
'Par<b>1</b>',
|
||||||
'<p>Par<b>1</b></p>'
|
'<p>Par<b>1</b></p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testIgnoreLeadingWhitespace() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'
|
'
|
||||||
|
|
||||||
Par',
|
Par',
|
||||||
'<p>Par</p>'
|
'<p>Par</p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testIgnoreSurroundingWhitespace() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'
|
'
|
||||||
|
|
||||||
@ -108,69 +134,90 @@ Par
|
|||||||
',
|
',
|
||||||
'<p>Par</p>'
|
'<p>Par</p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testParagraphInsideBlockNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div>Par1
|
'<div>Par1
|
||||||
|
|
||||||
Par2</div>',
|
Par2</div>',
|
||||||
'<div><p>Par1</p><p>Par2</p></div>'
|
'<div><p>Par1</p><p>Par2</p></div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testParagraphInlineNodeInsideBlockNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div><b>Par1</b>
|
'<div><b>Par1</b>
|
||||||
|
|
||||||
Par2</div>',
|
Par2</div>',
|
||||||
'<div><p><b>Par1</b></p><p>Par2</p></div>'
|
'<div><p><b>Par1</b></p><p>Par2</p></div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testNoParagraphWhenOnlyOneInsideBlockNode() {
|
||||||
$this->assertResult('<div>Par1</div>');
|
$this->assertResult('<div>Par1</div>');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testParagraphTwoInlineNodesInsideBlockNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div><b>Par1</b>
|
'<div><b>Par1</b>
|
||||||
|
|
||||||
<i>Par2</i></div>',
|
<i>Par2</i></div>',
|
||||||
'<div><p><b>Par1</b></p><p><i>Par2</i></p></div>'
|
'<div><p><b>Par1</b></p><p><i>Par2</i></p></div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testPreserveInlineNodesInPreTag() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<pre><b>Par1</b>
|
'<pre><b>Par1</b>
|
||||||
|
|
||||||
<i>Par2</i></pre>',
|
<i>Par2</i></pre>'
|
||||||
true
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSplitUpInternalsOfPTagInBlockNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div><p>Foo
|
'<div><p>Foo
|
||||||
|
|
||||||
Bar</p></div>',
|
Bar</p></div>',
|
||||||
'<div><p>Foo</p><p>Bar</p></div>'
|
'<div><p>Foo</p><p>Bar</p></div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSplitUpInlineNodesInPTagInBlockNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div><p><b>Foo</b>
|
'<div><p><b>Foo</b>
|
||||||
|
|
||||||
<i>Bar</i></p></div>',
|
<i>Bar</i></p></div>',
|
||||||
'<div><p><b>Foo</b></p><p><i>Bar</i></p></div>'
|
'<div><p><b>Foo</b></p><p><i>Bar</i></p></div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testNoParagraphSingleInlineNodeInBlockNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div><b>Foo</b></div>',
|
'<div><b>Foo</b></div>',
|
||||||
'<div><b>Foo</b></div>'
|
'<div><b>Foo</b></div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testParagraphInBlockquote() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<blockquote>Par1
|
'<blockquote>Par1
|
||||||
|
|
||||||
Par2</blockquote>',
|
Par2</blockquote>',
|
||||||
'<blockquote><p>Par1</p><p>Par2</p></blockquote>'
|
'<blockquote><p>Par1</p><p>Par2</p></blockquote>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testNoParagraphBetweenListItem() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<ul><li>Foo</li>
|
'<ul><li>Foo</li>
|
||||||
|
|
||||||
<li>Bar</li></ul>', true
|
<li>Bar</li></ul>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testParagraphSingleElementWithSurroundingSpace() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div>
|
'<div>
|
||||||
|
|
||||||
@ -179,7 +226,9 @@ Bar
|
|||||||
</div>',
|
</div>',
|
||||||
'<div><p>Bar</p></div>'
|
'<div><p>Bar</p></div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testIgnoreExtraSpaceWithLeadingInlineNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<b>Par1</b>a
|
'<b>Par1</b>a
|
||||||
|
|
||||||
@ -188,99 +237,124 @@ Bar
|
|||||||
Par2',
|
Par2',
|
||||||
'<p><b>Par1</b>a</p><p>Par2</p>'
|
'<p><b>Par1</b>a</p><p>Par2</p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testAbsorbExtraEndingPTag() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'Par1
|
'Par1
|
||||||
|
|
||||||
Par2</p>',
|
Par2</p>',
|
||||||
'<p>Par1</p><p>Par2</p>'
|
'<p>Par1</p><p>Par2</p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testAbsorbExtraEndingDivTag() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'Par1
|
'Par1
|
||||||
|
|
||||||
Par2</div>',
|
Par2</div>',
|
||||||
'<p>Par1</p><p>Par2</p>'
|
'<p>Par1</p><p>Par2</p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testDoNotParagraphSingleSurroundingSpaceInBlockNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div>
|
'<div>
|
||||||
Par1
|
Par1
|
||||||
</div>', true
|
</div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testBlockNodeTextDelimeterInBlockNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div>Par1
|
'<div>Par1
|
||||||
|
|
||||||
<div>Par2</div></div>',
|
<div>Par2</div></div>',
|
||||||
'<div><p>Par1</p><div>Par2</div></div>'
|
'<div><p>Par1</p><div>Par2</div></div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testBlockNodeTextDelimeterWithoutDoublespaceInBlockNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div>Par1
|
'<div>Par1
|
||||||
<div>Par2</div></div>',
|
<div>Par2</div></div>',
|
||||||
'<div><p>Par1
|
'<div><p>Par1
|
||||||
</p><div>Par2</div></div>'
|
</p><div>Par2</div></div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testBlockNodeTextDelimeterWithoutDoublespace() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'Par1
|
'Par1
|
||||||
<div>Par2</div>',
|
<div>Par2</div>',
|
||||||
'<p>Par1
|
'<p>Par1
|
||||||
</p><div>Par2</div>'
|
</p><div>Par2</div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testTwoParagraphsOfTextAndInlineNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'Par1
|
'Par1
|
||||||
|
|
||||||
<b>Par2</b>',
|
<b>Par2</b>',
|
||||||
'<p>Par1</p><p><b>Par2</b></p>'
|
'<p>Par1</p><p><b>Par2</b></p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLeadingInlineNodeParagraph() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<img /> Foo',
|
'<img /> Foo',
|
||||||
'<p><img /> Foo</p>'
|
'<p><img /> Foo</p>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testTrailingInlineNodeParagraph() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<li>Foo <a>bar</a></li>'
|
'<li>Foo <a>bar</a></li>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testTwoInlineNodeParagraph() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<li><b>baz</b><a>bar</a></li>'
|
'<li><b>baz</b><a>bar</a></li>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testNoParagraphTrailingBlockNodeInBlockNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div><div>asdf</div><b>asdf</b></div>'
|
'<div><div>asdf</div><b>asdf</b></div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testParagraphTrailingBlockNodeWithDoublespaceInBlockNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div><div>asdf</div>
|
'<div><div>asdf</div>
|
||||||
|
|
||||||
<b>asdf</b></div>',
|
<b>asdf</b></div>',
|
||||||
'<div><div>asdf</div><p><b>asdf</b></p></div>'
|
'<div><div>asdf</div><p><b>asdf</b></p></div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testParagraphTwoInlineNodesAndWhitespaceNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<b>One</b> <i>Two</i>',
|
'<b>One</b> <i>Two</i>',
|
||||||
'<p><b>One</b> <i>Two</i></p>'
|
'<p><b>One</b> <i>Two</i></p>'
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testInlineRootNode() {
|
function testNoParagraphWithInlineRootNode() {
|
||||||
|
$this->config->set('HTML', 'Parent', 'span');
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'Par
|
'Par
|
||||||
|
|
||||||
Par2',
|
Par2'
|
||||||
true,
|
|
||||||
array('AutoFormat.AutoParagraph' => true, 'HTML.Parent' => 'span')
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testNeeded() {
|
function testErrorNeeded() {
|
||||||
|
$this->config->set('HTML', 'Allowed', 'b');
|
||||||
$this->expectError('Cannot enable AutoParagraph injector because p is not allowed');
|
$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() {
|
function setup() {
|
||||||
parent::setup();
|
parent::setup();
|
||||||
$this->config = array('AutoFormat.Linkify' => true);
|
$this->config->set('AutoFormat', 'Linkify', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testLinkify() {
|
function testLinkifyURLInRootNode() {
|
||||||
|
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'http://example.com',
|
'http://example.com',
|
||||||
'<a href="http://example.com">http://example.com</a>'
|
'<a href="http://example.com">http://example.com</a>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLinkifyURLInInlineNode() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<b>http://example.com</b>',
|
'<b>http://example.com</b>',
|
||||||
'<b><a href="http://example.com">http://example.com</a></b>'
|
'<b><a href="http://example.com">http://example.com</a></b>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testBasicUsageCase() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'This URL http://example.com is what you need',
|
'This URL http://example.com is what you need',
|
||||||
'This URL <a href="http://example.com">http://example.com</a> is what you need'
|
'This URL <a href="http://example.com">http://example.com</a> is what you need'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testIgnoreURLInATag() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<a>http://example.com/</a>'
|
'<a>http://example.com/</a>'
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testNeeded() {
|
function testNeeded() {
|
||||||
|
$this->config->set('HTML', 'Allowed', 'b');
|
||||||
$this->expectError('Cannot enable Linkify injector because a is not allowed');
|
$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() {
|
function setup() {
|
||||||
parent::setup();
|
parent::setup();
|
||||||
$this->config = array(
|
$this->config->set('AutoFormat', 'PurifierLinkify', true);
|
||||||
'AutoFormat.PurifierLinkify' => true,
|
$this->config->set('AutoFormatParam', 'PurifierLinkifyDocURL', '#%s');
|
||||||
'AutoFormatParam.PurifierLinkifyDocURL' => '#%s'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testLinkify() {
|
function testNoTriggerCharacer() {
|
||||||
|
|
||||||
$this->assertResult('Foobar');
|
$this->assertResult('Foobar');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testTriggerCharacterInIrrelevantContext() {
|
||||||
$this->assertResult('20% off!');
|
$this->assertResult('20% off!');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testPreserveNamespace() {
|
||||||
$this->assertResult('%Core namespace (not recognized)');
|
$this->assertResult('%Core namespace (not recognized)');
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLinkifyBasic() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'%Namespace.Directive',
|
'%Namespace.Directive',
|
||||||
'<a href="#Namespace.Directive">%Namespace.Directive</a>'
|
'<a href="#Namespace.Directive">%Namespace.Directive</a>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLinkifyWithAdjacentTextNodes() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'This %Namespace.Directive thing',
|
'This %Namespace.Directive thing',
|
||||||
'This <a href="#Namespace.Directive">%Namespace.Directive</a> thing'
|
'This <a href="#Namespace.Directive">%Namespace.Directive</a> thing'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLinkifyInBlock() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<div>This %Namespace.Directive thing</div>',
|
'<div>This %Namespace.Directive thing</div>',
|
||||||
'<div>This <a href="#Namespace.Directive">%Namespace.Directive</a> thing</div>'
|
'<div>This <a href="#Namespace.Directive">%Namespace.Directive</a> thing</div>'
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testPreserveInATag() {
|
||||||
$this->assertResult(
|
$this->assertResult(
|
||||||
'<a>%Namespace.Directive</a>'
|
'<a>%Namespace.Directive</a>'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testNeeded() {
|
function testNeeded() {
|
||||||
|
$this->config->set('HTML', 'Allowed', 'b');
|
||||||
$this->expectError('Cannot enable PurifierLinkify injector because a is not allowed');
|
$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');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user