Prepended constants with C_ to avoid reserved words as per https://www.php.net/manual...
[htmlpurifier/darkodev.git] / tests / HTMLPurifier / Injector / AutoParagraphTest.php
blob440b09189f7a1d6ca71a52b067e5e898c1fd6697
1 <?php
3 class HTMLPurifier_Injector_AutoParagraphTest extends HTMLPurifier_InjectorHarness
6 public function setup()
8 parent::setup();
9 $this->config->set('AutoFormat.AutoParagraph', true);
12 public function testSingleParagraph()
14 $this->assertResult(
15 'Foobar',
16 '<p>Foobar</p>'
20 public function testSingleMultiLineParagraph()
22 $this->assertResult(
23 'Par 1
24 Par 1 still',
25 '<p>Par 1
26 Par 1 still</p>'
30 public function testTwoParagraphs()
32 $this->assertResult(
33 'Par1
35 Par2',
36 "<p>Par1</p>
38 <p>Par2</p>"
42 public function testTwoParagraphsWithLotsOfSpace()
44 $this->assertResult(
45 'Par1
49 Par2',
50 '<p>Par1</p>
52 <p>Par2</p>'
56 public function testTwoParagraphsWithInlineElements()
58 $this->assertResult(
59 '<b>Par1</b>
61 <i>Par2</i>',
62 '<p><b>Par1</b></p>
64 <p><i>Par2</i></p>'
68 public function testSingleParagraphThatLooksLikeTwo()
70 $this->assertResult(
71 '<b>Par1
73 Par2</b>',
74 '<p><b>Par1
76 Par2</b></p>'
80 public function testAddParagraphAdjacentToParagraph()
82 $this->assertResult(
83 'Par1<p>Par2</p>',
84 '<p>Par1</p>
86 <p>Par2</p>'
90 public function testParagraphUnclosedInlineElement()
92 $this->assertResult(
93 '<b>Par1',
94 '<p><b>Par1</b></p>'
98 public function testPreservePreTags()
100 $this->assertResult(
101 '<pre>Par1
103 Par1</pre>'
107 public function testIgnoreTrailingWhitespace()
109 $this->assertResult(
110 'Par1
113 '<p>Par1</p>
119 public function testDoNotParagraphBlockElements()
121 $this->assertResult(
122 'Par1
124 <div>Par2</div>
126 Par3',
127 '<p>Par1</p>
129 <div>Par2</div>
131 <p>Par3</p>'
135 public function testParagraphTextAndInlineNodes()
137 $this->assertResult(
138 'Par<b>1</b>',
139 '<p>Par<b>1</b></p>'
143 public function testPreserveLeadingWhitespace()
145 $this->assertResult(
148 Par',
151 <p>Par</p>'
155 public function testPreserveSurroundingWhitespace()
157 $this->assertResult(
165 <p>Par</p>
171 public function testParagraphInsideBlockNode()
173 $this->assertResult(
174 '<div>Par1
176 Par2</div>',
177 '<div><p>Par1</p>
179 <p>Par2</p></div>'
183 public function testParagraphInlineNodeInsideBlockNode()
185 $this->assertResult(
186 '<div><b>Par1</b>
188 Par2</div>',
189 '<div><p><b>Par1</b></p>
191 <p>Par2</p></div>'
195 public function testNoParagraphWhenOnlyOneInsideBlockNode()
197 $this->assertResult('<div>Par1</div>');
200 public function testParagraphTwoInlineNodesInsideBlockNode()
202 $this->assertResult(
203 '<div><b>Par1</b>
205 <i>Par2</i></div>',
206 '<div><p><b>Par1</b></p>
208 <p><i>Par2</i></p></div>'
212 public function testPreserveInlineNodesInPreTag()
214 $this->assertResult(
215 '<pre><b>Par1</b>
217 <i>Par2</i></pre>'
221 public function testSplitUpInternalsOfPTagInBlockNode()
223 $this->assertResult(
224 '<div><p>Foo
226 Bar</p></div>',
227 '<div><p>Foo</p>
229 <p>Bar</p></div>'
233 public function testSplitUpInlineNodesInPTagInBlockNode()
235 $this->assertResult(
236 '<div><p><b>Foo</b>
238 <i>Bar</i></p></div>',
239 '<div><p><b>Foo</b></p>
241 <p><i>Bar</i></p></div>'
245 public function testNoParagraphSingleInlineNodeInBlockNode()
247 $this->assertResult( '<div><b>Foo</b></div>' );
250 public function testParagraphInBlockquote()
252 $this->assertResult(
253 '<blockquote>Par1
255 Par2</blockquote>',
256 '<blockquote><p>Par1</p>
258 <p>Par2</p></blockquote>'
262 public function testNoParagraphBetweenListItem()
264 $this->assertResult(
265 '<ul><li>Foo</li>
267 <li>Bar</li></ul>'
271 public function testParagraphSingleElementWithSurroundingSpace()
273 $this->assertResult(
274 '<div>
278 </div>',
279 '<div>
281 <p>Bar</p>
283 </div>'
287 public function testIgnoreExtraSpaceWithLeadingInlineNode()
289 $this->assertResult(
290 '<b>Par1</b>a
294 Par2',
295 '<p><b>Par1</b>a</p>
297 <p>Par2</p>'
301 public function testAbsorbExtraEndingPTag()
303 $this->assertResult(
304 'Par1
306 Par2</p>',
307 '<p>Par1</p>
309 <p>Par2</p>'
313 public function testAbsorbExtraEndingDivTag()
315 $this->assertResult(
316 'Par1
318 Par2</div>',
319 '<p>Par1</p>
321 <p>Par2</p>'
325 public function testDoNotParagraphSingleSurroundingSpaceInBlockNode()
327 $this->assertResult(
328 '<div>
329 Par1
330 </div>'
334 public function testBlockNodeTextDelimeterInBlockNode()
336 $this->assertResult(
337 '<div>Par1
339 <div>Par2</div></div>',
340 '<div><p>Par1</p>
342 <div>Par2</div></div>'
346 public function testBlockNodeTextDelimeterWithoutDoublespaceInBlockNode()
348 $this->assertResult(
349 '<div>Par1
350 <div>Par2</div></div>'
354 public function testBlockNodeTextDelimeterWithoutDoublespace()
356 $this->assertResult(
357 'Par1
358 <div>Par2</div>',
359 '<p>Par1
360 </p>
362 <div>Par2</div>'
366 public function testTwoParagraphsOfTextAndInlineNode()
368 $this->assertResult(
369 'Par1
371 <b>Par2</b>',
372 '<p>Par1</p>
374 <p><b>Par2</b></p>'
378 public function testLeadingInlineNodeParagraph()
380 $this->assertResult(
381 '<img /> Foo',
382 '<p><img /> Foo</p>'
386 public function testTrailingInlineNodeParagraph()
388 $this->assertResult(
389 '<li>Foo <a>bar</a></li>'
393 public function testTwoInlineNodeParagraph()
395 $this->assertResult(
396 '<li><b>baz</b><a>bar</a></li>'
400 public function testNoParagraphTrailingBlockNodeInBlockNode()
402 $this->assertResult(
403 '<div><div>asdf</div><b>asdf</b></div>'
407 public function testParagraphTrailingBlockNodeWithDoublespaceInBlockNode()
409 $this->assertResult(
410 '<div><div>asdf</div>
412 <b>asdf</b></div>',
413 '<div><div>asdf</div>
415 <p><b>asdf</b></p></div>'
419 public function testParagraphTwoInlineNodesAndWhitespaceNode()
421 $this->assertResult(
422 '<b>One</b> <i>Two</i>',
423 '<p><b>One</b> <i>Two</i></p>'
427 public function testNoParagraphWithInlineRootNode()
429 $this->config->set('HTML.Parent', 'span');
430 $this->assertResult(
431 'Par
433 Par2'
437 public function testInlineAndBlockTagInDivNoParagraph()
439 $this->assertResult(
440 '<div><code>bar</code> mmm <pre>asdf</pre></div>'
444 public function testInlineAndBlockTagInDivNeedingParagraph()
446 $this->assertResult(
447 '<div><code>bar</code> mmm
449 <pre>asdf</pre></div>',
450 '<div><p><code>bar</code> mmm</p>
452 <pre>asdf</pre></div>'
456 public function testTextInlineNodeTextThenDoubleNewlineNeedsParagraph()
458 $this->assertResult(
459 '<div>asdf <code>bar</code> mmm
461 <pre>asdf</pre></div>',
462 '<div><p>asdf <code>bar</code> mmm</p>
464 <pre>asdf</pre></div>'
468 public function testUpcomingTokenHasNewline()
470 $this->assertResult(
471 '<div>Test<b>foo</b>bar<b>bing</b>bang
473 boo</div>',
474 '<div><p>Test<b>foo</b>bar<b>bing</b>bang</p>
476 <p>boo</p></div>'
480 public function testEmptyTokenAtEndOfDiv()
482 $this->assertResult(
483 '<div><p>foo</p>
484 </div>',
485 '<div><p>foo</p>
486 </div>'
490 public function testEmptyDoubleLineTokenAtEndOfDiv()
492 $this->assertResult(
493 '<div><p>foo</p>
495 </div>',
496 '<div><p>foo</p>
498 </div>'
502 public function testTextState11Root()
504 $this->assertResult('<div></div> ');
507 public function testTextState11Element()
509 $this->assertResult(
510 "<div><div></div>
512 </div>");
515 public function testTextStateLikeElementState111NoWhitespace()
517 $this->assertResult('<div><p>P</p>Boo</div>', '<div><p>P</p>Boo</div>');
520 public function testElementState111NoWhitespace()
522 $this->assertResult('<div><p>P</p><b>Boo</b></div>', '<div><p>P</p><b>Boo</b></div>');
525 public function testElementState133()
527 $this->assertResult(
528 "<div><b>B</b><pre>Ba</pre>
530 Bar</div>",
531 "<div><b>B</b><pre>Ba</pre>
533 <p>Bar</p></div>"
537 public function testElementState22()
539 $this->assertResult(
540 '<ul><li>foo</li></ul>'
544 public function testElementState311()
546 $this->assertResult(
547 '<p>Foo</p><b>Bar</b>',
548 '<p>Foo</p>
550 <p><b>Bar</b></p>'
554 public function testAutoClose()
556 $this->assertResult(
557 '<p></p>
558 <hr />'
562 public function testErrorNeeded()
564 $this->config->set('HTML.Allowed', 'b');
565 $this->expectError('Cannot enable AutoParagraph injector because p is not allowed');
566 $this->assertResult('<b>foobar</b>');
569 public function testParentElement()
571 $this->config->set('HTML.Allowed', 'p,ul,li');
572 $this->assertResult('Foo<ul><li>Bar</li></ul>', "<p>Foo</p>\n\n<ul><li>Bar</li></ul>");
577 // vim: et sw=4 sts=4