2007-06-24 21:35:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class HTMLPurifier_Injector_AutoParagraphTest extends HTMLPurifier_InjectorHarness
|
|
|
|
{
|
|
|
|
|
|
|
|
function setup() {
|
|
|
|
parent::setup();
|
2007-08-08 05:38:52 +00:00
|
|
|
$this->config->set('AutoFormat', 'AutoParagraph', true);
|
2007-06-24 21:35:34 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 05:38:52 +00:00
|
|
|
function testSingleParagraph() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'Foobar',
|
|
|
|
'<p>Foobar</p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testSingleMultiLineParagraph() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'Par 1
|
|
|
|
Par 1 still',
|
|
|
|
'<p>Par 1
|
|
|
|
Par 1 still</p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testTwoParagraphs() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'Par1
|
|
|
|
|
|
|
|
Par2',
|
|
|
|
'<p>Par1</p><p>Par2</p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testTwoParagraphsWithLotsOfSpace() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'Par1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Par2',
|
|
|
|
'<p>Par1</p><p>Par2</p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testTwoParagraphsWithInlineElements() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<b>Par1</b>
|
|
|
|
|
|
|
|
<i>Par2</i>',
|
|
|
|
'<p><b>Par1</b></p><p><i>Par2</i></p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testSingleParagraphThatLooksLikeTwo() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<b>Par1
|
|
|
|
|
|
|
|
Par2</b>',
|
|
|
|
'<p><b>Par1
|
|
|
|
|
|
|
|
Par2</b></p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testAddParagraphAdjacentToParagraph() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'Par1<p>Par2</p>',
|
|
|
|
'<p>Par1</p><p>Par2</p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testParagraphUnclosedInlineElement() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<b>Par1',
|
|
|
|
'<p><b>Par1</b></p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testPreservePreTags() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<pre>Par1
|
|
|
|
|
|
|
|
Par1</pre>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testIgnoreTrailingWhitespace() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'Par1
|
|
|
|
|
|
|
|
',
|
|
|
|
'<p>Par1</p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testDoNotParagraphBlockElements() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'Par1
|
|
|
|
|
|
|
|
<div>Par2</div>
|
|
|
|
|
|
|
|
Par3',
|
|
|
|
'<p>Par1</p><div>Par2</div><p>Par3</p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testParagraphTextAndInlineNodes() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'Par<b>1</b>',
|
|
|
|
'<p>Par<b>1</b></p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testIgnoreLeadingWhitespace() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'
|
|
|
|
|
|
|
|
Par',
|
|
|
|
'<p>Par</p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testIgnoreSurroundingWhitespace() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'
|
|
|
|
|
|
|
|
Par
|
|
|
|
|
|
|
|
',
|
|
|
|
'<p>Par</p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testParagraphInsideBlockNode() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div>Par1
|
|
|
|
|
|
|
|
Par2</div>',
|
|
|
|
'<div><p>Par1</p><p>Par2</p></div>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testParagraphInlineNodeInsideBlockNode() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div><b>Par1</b>
|
|
|
|
|
|
|
|
Par2</div>',
|
|
|
|
'<div><p><b>Par1</b></p><p>Par2</p></div>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testNoParagraphWhenOnlyOneInsideBlockNode() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult('<div>Par1</div>');
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testParagraphTwoInlineNodesInsideBlockNode() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div><b>Par1</b>
|
|
|
|
|
|
|
|
<i>Par2</i></div>',
|
|
|
|
'<div><p><b>Par1</b></p><p><i>Par2</i></p></div>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testPreserveInlineNodesInPreTag() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<pre><b>Par1</b>
|
|
|
|
|
2007-08-08 05:38:52 +00:00
|
|
|
<i>Par2</i></pre>'
|
2007-06-24 21:35:34 +00:00
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testSplitUpInternalsOfPTagInBlockNode() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div><p>Foo
|
|
|
|
|
|
|
|
Bar</p></div>',
|
|
|
|
'<div><p>Foo</p><p>Bar</p></div>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testSplitUpInlineNodesInPTagInBlockNode() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div><p><b>Foo</b>
|
|
|
|
|
|
|
|
<i>Bar</i></p></div>',
|
|
|
|
'<div><p><b>Foo</b></p><p><i>Bar</i></p></div>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testNoParagraphSingleInlineNodeInBlockNode() {
|
2007-09-27 00:39:05 +00:00
|
|
|
$this->assertResult( '<div><b>Foo</b></div>' );
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testParagraphInBlockquote() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<blockquote>Par1
|
|
|
|
|
|
|
|
Par2</blockquote>',
|
|
|
|
'<blockquote><p>Par1</p><p>Par2</p></blockquote>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testNoParagraphBetweenListItem() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<ul><li>Foo</li>
|
|
|
|
|
2007-08-08 05:38:52 +00:00
|
|
|
<li>Bar</li></ul>'
|
2007-06-24 21:35:34 +00:00
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testParagraphSingleElementWithSurroundingSpace() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div>
|
|
|
|
|
|
|
|
Bar
|
|
|
|
|
|
|
|
</div>',
|
|
|
|
'<div><p>Bar</p></div>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testIgnoreExtraSpaceWithLeadingInlineNode() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<b>Par1</b>a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Par2',
|
|
|
|
'<p><b>Par1</b>a</p><p>Par2</p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testAbsorbExtraEndingPTag() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'Par1
|
|
|
|
|
|
|
|
Par2</p>',
|
|
|
|
'<p>Par1</p><p>Par2</p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testAbsorbExtraEndingDivTag() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'Par1
|
|
|
|
|
|
|
|
Par2</div>',
|
|
|
|
'<p>Par1</p><p>Par2</p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testDoNotParagraphSingleSurroundingSpaceInBlockNode() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div>
|
|
|
|
Par1
|
2007-08-08 05:38:52 +00:00
|
|
|
</div>'
|
2007-06-24 21:35:34 +00:00
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testBlockNodeTextDelimeterInBlockNode() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div>Par1
|
|
|
|
|
|
|
|
<div>Par2</div></div>',
|
|
|
|
'<div><p>Par1</p><div>Par2</div></div>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testBlockNodeTextDelimeterWithoutDoublespaceInBlockNode() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div>Par1
|
2007-09-27 00:39:05 +00:00
|
|
|
<div>Par2</div></div>'
|
2007-06-24 21:35:34 +00:00
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testBlockNodeTextDelimeterWithoutDoublespace() {
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'Par1
|
|
|
|
<div>Par2</div>',
|
|
|
|
'<p>Par1
|
|
|
|
</p><div>Par2</div>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testTwoParagraphsOfTextAndInlineNode() {
|
2007-06-26 15:07:07 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'Par1
|
|
|
|
|
|
|
|
<b>Par2</b>',
|
|
|
|
'<p>Par1</p><p><b>Par2</b></p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testLeadingInlineNodeParagraph() {
|
2007-06-29 00:24:59 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<img /> Foo',
|
|
|
|
'<p><img /> Foo</p>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testTrailingInlineNodeParagraph() {
|
2007-06-29 03:57:14 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<li>Foo <a>bar</a></li>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testTwoInlineNodeParagraph() {
|
2007-06-29 03:57:14 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<li><b>baz</b><a>bar</a></li>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testNoParagraphTrailingBlockNodeInBlockNode() {
|
2007-06-29 03:57:14 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div><div>asdf</div><b>asdf</b></div>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testParagraphTrailingBlockNodeWithDoublespaceInBlockNode() {
|
2007-06-29 03:57:14 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<div><div>asdf</div>
|
|
|
|
|
|
|
|
<b>asdf</b></div>',
|
|
|
|
'<div><div>asdf</div><p><b>asdf</b></p></div>'
|
|
|
|
);
|
2007-08-08 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testParagraphTwoInlineNodesAndWhitespaceNode() {
|
2007-06-29 17:48:56 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'<b>One</b> <i>Two</i>',
|
|
|
|
'<p><b>One</b> <i>Two</i></p>'
|
|
|
|
);
|
2007-06-24 21:35:34 +00:00
|
|
|
}
|
|
|
|
|
2007-08-08 05:38:52 +00:00
|
|
|
function testNoParagraphWithInlineRootNode() {
|
|
|
|
$this->config->set('HTML', 'Parent', 'span');
|
2007-06-24 21:35:34 +00:00
|
|
|
$this->assertResult(
|
|
|
|
'Par
|
|
|
|
|
2007-08-08 05:38:52 +00:00
|
|
|
Par2'
|
2007-06-24 21:35:34 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-09-27 00:39:05 +00:00
|
|
|
function testInlineAndBlockTagInDivNoParagraph() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<div><code>bar</code> mmm <pre>asdf</pre></div>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testInlineAndBlockTagInDivNeedingParagraph() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<div><code>bar</code> mmm
|
|
|
|
|
|
|
|
<pre>asdf</pre></div>',
|
|
|
|
'<div><p><code>bar</code> mmm</p><pre>asdf</pre></div>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testTextInlineNodeTextThenDoubleNewlineNeedsParagraph() {
|
|
|
|
$this->assertResult(
|
|
|
|
'<div>asdf <code>bar</code> mmm
|
|
|
|
|
|
|
|
<pre>asdf</pre></div>',
|
|
|
|
'<div><p>asdf <code>bar</code> mmm</p><pre>asdf</pre></div>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-08-08 05:38:52 +00:00
|
|
|
function testErrorNeeded() {
|
|
|
|
$this->config->set('HTML', 'Allowed', 'b');
|
2007-06-28 13:06:15 +00:00
|
|
|
$this->expectError('Cannot enable AutoParagraph injector because p is not allowed');
|
2007-08-08 05:38:52 +00:00
|
|
|
$this->assertResult('<b>foobar</b>');
|
2007-06-28 13:06:15 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 21:35:34 +00:00
|
|
|
}
|
|
|
|
|