|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577 |
- <?php
-
- class HTMLPurifier_Injector_AutoParagraphTest extends HTMLPurifier_InjectorHarness
- {
-
- public function setup()
- {
- parent::setup();
- $this->config->set('AutoFormat.AutoParagraph', true);
- }
-
- public function testSingleParagraph()
- {
- $this->assertResult(
- 'Foobar',
- '<p>Foobar</p>'
- );
- }
-
- public function testSingleMultiLineParagraph()
- {
- $this->assertResult(
- 'Par 1
- Par 1 still',
- '<p>Par 1
- Par 1 still</p>'
- );
- }
-
- public function testTwoParagraphs()
- {
- $this->assertResult(
- 'Par1
-
- Par2',
- "<p>Par1</p>
-
- <p>Par2</p>"
- );
- }
-
- public function testTwoParagraphsWithLotsOfSpace()
- {
- $this->assertResult(
- 'Par1
-
-
-
- Par2',
- '<p>Par1</p>
-
- <p>Par2</p>'
- );
- }
-
- public function testTwoParagraphsWithInlineElements()
- {
- $this->assertResult(
- '<b>Par1</b>
-
- <i>Par2</i>',
- '<p><b>Par1</b></p>
-
- <p><i>Par2</i></p>'
- );
- }
-
- public function testSingleParagraphThatLooksLikeTwo()
- {
- $this->assertResult(
- '<b>Par1
-
- Par2</b>',
- '<p><b>Par1
-
- Par2</b></p>'
- );
- }
-
- public function testAddParagraphAdjacentToParagraph()
- {
- $this->assertResult(
- 'Par1<p>Par2</p>',
- '<p>Par1</p>
-
- <p>Par2</p>'
- );
- }
-
- public function testParagraphUnclosedInlineElement()
- {
- $this->assertResult(
- '<b>Par1',
- '<p><b>Par1</b></p>'
- );
- }
-
- public function testPreservePreTags()
- {
- $this->assertResult(
- '<pre>Par1
-
- Par1</pre>'
- );
- }
-
- public function testIgnoreTrailingWhitespace()
- {
- $this->assertResult(
- 'Par1
-
- ',
- '<p>Par1</p>
-
- '
- );
- }
-
- public function testDoNotParagraphBlockElements()
- {
- $this->assertResult(
- 'Par1
-
- <div>Par2</div>
-
- Par3',
- '<p>Par1</p>
-
- <div>Par2</div>
-
- <p>Par3</p>'
- );
- }
-
- public function testParagraphTextAndInlineNodes()
- {
- $this->assertResult(
- 'Par<b>1</b>',
- '<p>Par<b>1</b></p>'
- );
- }
-
- public function testPreserveLeadingWhitespace()
- {
- $this->assertResult(
- '
-
- Par',
- '
-
- <p>Par</p>'
- );
- }
-
- public function testPreserveSurroundingWhitespace()
- {
- $this->assertResult(
- '
-
- Par
-
- ',
- '
-
- <p>Par</p>
-
- '
- );
- }
-
- public function testParagraphInsideBlockNode()
- {
- $this->assertResult(
- '<div>Par1
-
- Par2</div>',
- '<div><p>Par1</p>
-
- <p>Par2</p></div>'
- );
- }
-
- public function testParagraphInlineNodeInsideBlockNode()
- {
- $this->assertResult(
- '<div><b>Par1</b>
-
- Par2</div>',
- '<div><p><b>Par1</b></p>
-
- <p>Par2</p></div>'
- );
- }
-
- public function testNoParagraphWhenOnlyOneInsideBlockNode()
- {
- $this->assertResult('<div>Par1</div>');
- }
-
- public function testParagraphTwoInlineNodesInsideBlockNode()
- {
- $this->assertResult(
- '<div><b>Par1</b>
-
- <i>Par2</i></div>',
- '<div><p><b>Par1</b></p>
-
- <p><i>Par2</i></p></div>'
- );
- }
-
- public function testPreserveInlineNodesInPreTag()
- {
- $this->assertResult(
- '<pre><b>Par1</b>
-
- <i>Par2</i></pre>'
- );
- }
-
- public function testSplitUpInternalsOfPTagInBlockNode()
- {
- $this->assertResult(
- '<div><p>Foo
-
- Bar</p></div>',
- '<div><p>Foo</p>
-
- <p>Bar</p></div>'
- );
- }
-
- public 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>'
- );
- }
-
- public function testNoParagraphSingleInlineNodeInBlockNode()
- {
- $this->assertResult( '<div><b>Foo</b></div>' );
- }
-
- public function testParagraphInBlockquote()
- {
- $this->assertResult(
- '<blockquote>Par1
-
- Par2</blockquote>',
- '<blockquote><p>Par1</p>
-
- <p>Par2</p></blockquote>'
- );
- }
-
- public function testNoParagraphBetweenListItem()
- {
- $this->assertResult(
- '<ul><li>Foo</li>
-
- <li>Bar</li></ul>'
- );
- }
-
- public function testParagraphSingleElementWithSurroundingSpace()
- {
- $this->assertResult(
- '<div>
-
- Bar
-
- </div>',
- '<div>
-
- <p>Bar</p>
-
- </div>'
- );
- }
-
- public function testIgnoreExtraSpaceWithLeadingInlineNode()
- {
- $this->assertResult(
- '<b>Par1</b>a
-
-
-
- Par2',
- '<p><b>Par1</b>a</p>
-
- <p>Par2</p>'
- );
- }
-
- public function testAbsorbExtraEndingPTag()
- {
- $this->assertResult(
- 'Par1
-
- Par2</p>',
- '<p>Par1</p>
-
- <p>Par2</p>'
- );
- }
-
- public function testAbsorbExtraEndingDivTag()
- {
- $this->assertResult(
- 'Par1
-
- Par2</div>',
- '<p>Par1</p>
-
- <p>Par2</p>'
- );
- }
-
- public function testDoNotParagraphSingleSurroundingSpaceInBlockNode()
- {
- $this->assertResult(
- '<div>
- Par1
- </div>'
- );
- }
-
- public function testBlockNodeTextDelimeterInBlockNode()
- {
- $this->assertResult(
- '<div>Par1
-
- <div>Par2</div></div>',
- '<div><p>Par1</p>
-
- <div>Par2</div></div>'
- );
- }
-
- public function testBlockNodeTextDelimeterWithoutDoublespaceInBlockNode()
- {
- $this->assertResult(
- '<div>Par1
- <div>Par2</div></div>'
- );
- }
-
- public function testBlockNodeTextDelimeterWithoutDoublespace()
- {
- $this->assertResult(
- 'Par1
- <div>Par2</div>',
- '<p>Par1
- </p>
-
- <div>Par2</div>'
- );
- }
-
- public function testTwoParagraphsOfTextAndInlineNode()
- {
- $this->assertResult(
- 'Par1
-
- <b>Par2</b>',
- '<p>Par1</p>
-
- <p><b>Par2</b></p>'
- );
- }
-
- public function testLeadingInlineNodeParagraph()
- {
- $this->assertResult(
- '<img /> Foo',
- '<p><img /> Foo</p>'
- );
- }
-
- public function testTrailingInlineNodeParagraph()
- {
- $this->assertResult(
- '<li>Foo <a>bar</a></li>'
- );
- }
-
- public function testTwoInlineNodeParagraph()
- {
- $this->assertResult(
- '<li><b>baz</b><a>bar</a></li>'
- );
- }
-
- public function testNoParagraphTrailingBlockNodeInBlockNode()
- {
- $this->assertResult(
- '<div><div>asdf</div><b>asdf</b></div>'
- );
- }
-
- public function testParagraphTrailingBlockNodeWithDoublespaceInBlockNode()
- {
- $this->assertResult(
- '<div><div>asdf</div>
-
- <b>asdf</b></div>',
- '<div><div>asdf</div>
-
- <p><b>asdf</b></p></div>'
- );
- }
-
- public function testParagraphTwoInlineNodesAndWhitespaceNode()
- {
- $this->assertResult(
- '<b>One</b> <i>Two</i>',
- '<p><b>One</b> <i>Two</i></p>'
- );
- }
-
- public function testNoParagraphWithInlineRootNode()
- {
- $this->config->set('HTML.Parent', 'span');
- $this->assertResult(
- 'Par
-
- Par2'
- );
- }
-
- public function testInlineAndBlockTagInDivNoParagraph()
- {
- $this->assertResult(
- '<div><code>bar</code> mmm <pre>asdf</pre></div>'
- );
- }
-
- public function testInlineAndBlockTagInDivNeedingParagraph()
- {
- $this->assertResult(
- '<div><code>bar</code> mmm
-
- <pre>asdf</pre></div>',
- '<div><p><code>bar</code> mmm</p>
-
- <pre>asdf</pre></div>'
- );
- }
-
- public 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>'
- );
- }
-
- public function testUpcomingTokenHasNewline()
- {
- $this->assertResult(
- '<div>Test<b>foo</b>bar<b>bing</b>bang
-
- boo</div>',
- '<div><p>Test<b>foo</b>bar<b>bing</b>bang</p>
-
- <p>boo</p></div>'
- );
- }
-
- public function testEmptyTokenAtEndOfDiv()
- {
- $this->assertResult(
- '<div><p>foo</p>
- </div>',
- '<div><p>foo</p>
- </div>'
- );
- }
-
- public function testEmptyDoubleLineTokenAtEndOfDiv()
- {
- $this->assertResult(
- '<div><p>foo</p>
-
- </div>',
- '<div><p>foo</p>
-
- </div>'
- );
- }
-
- public function testTextState11Root()
- {
- $this->assertResult('<div></div> ');
- }
-
- public function testTextState11Element()
- {
- $this->assertResult(
- "<div><div></div>
-
- </div>");
- }
-
- public function testTextStateLikeElementState111NoWhitespace()
- {
- $this->assertResult('<div><p>P</p>Boo</div>', '<div><p>P</p>Boo</div>');
- }
-
- public function testElementState111NoWhitespace()
- {
- $this->assertResult('<div><p>P</p><b>Boo</b></div>', '<div><p>P</p><b>Boo</b></div>');
- }
-
- public function testElementState133()
- {
- $this->assertResult(
- "<div><b>B</b><pre>Ba</pre>
-
- Bar</div>",
- "<div><b>B</b><pre>Ba</pre>
-
- <p>Bar</p></div>"
- );
- }
-
- public function testElementState22()
- {
- $this->assertResult(
- '<ul><li>foo</li></ul>'
- );
- }
-
- public function testElementState311()
- {
- $this->assertResult(
- '<p>Foo</p><b>Bar</b>',
- '<p>Foo</p>
-
- <p><b>Bar</b></p>'
- );
- }
-
- public function testAutoClose()
- {
- $this->assertResult(
- '<p></p>
- <hr />'
- );
- }
-
- public function testErrorNeeded()
- {
- $this->config->set('HTML.Allowed', 'b');
- $this->expectError('Cannot enable AutoParagraph injector because p is not allowed');
- $this->assertResult('<b>foobar</b>');
- }
-
- public function testParentElement()
- {
- $this->config->set('HTML.Allowed', 'p,ul,li');
- $this->assertResult('Foo<ul><li>Bar</li></ul>', "<p>Foo</p>\n\n<ul><li>Bar</li></ul>");
- }
-
- }
-
- // vim: et sw=4 sts=4
|