Use info_parent_def to get parent information, since it may not be present in info...
[htmlpurifier.git] / tests / HTMLPurifier / Injector / AutoParagraphTest.php
blob8f149011a0ef584094d3f135a6f5345d14a50441
1 <?php
3 class HTMLPurifier_Injector_AutoParagraphTest extends HTMLPurifier_InjectorHarness
6 function setup() {
7 parent::setup();
8 $this->config->set('AutoFormat.AutoParagraph', true);
11 function testSingleParagraph() {
12 $this->assertResult(
13 'Foobar',
14 '<p>Foobar</p>'
18 function testSingleMultiLineParagraph() {
19 $this->assertResult(
20 'Par 1
21 Par 1 still',
22 '<p>Par 1
23 Par 1 still</p>'
27 function testTwoParagraphs() {
28 $this->assertResult(
29 'Par1
31 Par2',
32 "<p>Par1</p>
34 <p>Par2</p>"
38 function testTwoParagraphsWithLotsOfSpace() {
39 $this->assertResult(
40 'Par1
44 Par2',
45 '<p>Par1</p>
47 <p>Par2</p>'
51 function testTwoParagraphsWithInlineElements() {
52 $this->assertResult(
53 '<b>Par1</b>
55 <i>Par2</i>',
56 '<p><b>Par1</b></p>
58 <p><i>Par2</i></p>'
62 function testSingleParagraphThatLooksLikeTwo() {
63 $this->assertResult(
64 '<b>Par1
66 Par2</b>',
67 '<p><b>Par1
69 Par2</b></p>'
73 function testAddParagraphAdjacentToParagraph() {
74 $this->assertResult(
75 'Par1<p>Par2</p>',
76 '<p>Par1</p>
78 <p>Par2</p>'
82 function testParagraphUnclosedInlineElement() {
83 $this->assertResult(
84 '<b>Par1',
85 '<p><b>Par1</b></p>'
89 function testPreservePreTags() {
90 $this->assertResult(
91 '<pre>Par1
93 Par1</pre>'
97 function testIgnoreTrailingWhitespace() {
98 $this->assertResult(
99 'Par1
102 '<p>Par1</p>
108 function testDoNotParagraphBlockElements() {
109 $this->assertResult(
110 'Par1
112 <div>Par2</div>
114 Par3',
115 '<p>Par1</p>
117 <div>Par2</div>
119 <p>Par3</p>'
123 function testParagraphTextAndInlineNodes() {
124 $this->assertResult(
125 'Par<b>1</b>',
126 '<p>Par<b>1</b></p>'
130 function testPreserveLeadingWhitespace() {
131 $this->assertResult(
134 Par',
137 <p>Par</p>'
141 function testPreserveSurroundingWhitespace() {
142 $this->assertResult(
150 <p>Par</p>
156 function testParagraphInsideBlockNode() {
157 $this->assertResult(
158 '<div>Par1
160 Par2</div>',
161 '<div><p>Par1</p>
163 <p>Par2</p></div>'
167 function testParagraphInlineNodeInsideBlockNode() {
168 $this->assertResult(
169 '<div><b>Par1</b>
171 Par2</div>',
172 '<div><p><b>Par1</b></p>
174 <p>Par2</p></div>'
178 function testNoParagraphWhenOnlyOneInsideBlockNode() {
179 $this->assertResult('<div>Par1</div>');
182 function testParagraphTwoInlineNodesInsideBlockNode() {
183 $this->assertResult(
184 '<div><b>Par1</b>
186 <i>Par2</i></div>',
187 '<div><p><b>Par1</b></p>
189 <p><i>Par2</i></p></div>'
193 function testPreserveInlineNodesInPreTag() {
194 $this->assertResult(
195 '<pre><b>Par1</b>
197 <i>Par2</i></pre>'
201 function testSplitUpInternalsOfPTagInBlockNode() {
202 $this->assertResult(
203 '<div><p>Foo
205 Bar</p></div>',
206 '<div><p>Foo</p>
208 <p>Bar</p></div>'
212 function testSplitUpInlineNodesInPTagInBlockNode() {
213 $this->assertResult(
214 '<div><p><b>Foo</b>
216 <i>Bar</i></p></div>',
217 '<div><p><b>Foo</b></p>
219 <p><i>Bar</i></p></div>'
223 function testNoParagraphSingleInlineNodeInBlockNode() {
224 $this->assertResult( '<div><b>Foo</b></div>' );
227 function testParagraphInBlockquote() {
228 $this->assertResult(
229 '<blockquote>Par1
231 Par2</blockquote>',
232 '<blockquote><p>Par1</p>
234 <p>Par2</p></blockquote>'
238 function testNoParagraphBetweenListItem() {
239 $this->assertResult(
240 '<ul><li>Foo</li>
242 <li>Bar</li></ul>'
246 function testParagraphSingleElementWithSurroundingSpace() {
247 $this->assertResult(
248 '<div>
252 </div>',
253 '<div>
255 <p>Bar</p>
257 </div>'
261 function testIgnoreExtraSpaceWithLeadingInlineNode() {
262 $this->assertResult(
263 '<b>Par1</b>a
267 Par2',
268 '<p><b>Par1</b>a</p>
270 <p>Par2</p>'
274 function testAbsorbExtraEndingPTag() {
275 $this->assertResult(
276 'Par1
278 Par2</p>',
279 '<p>Par1</p>
281 <p>Par2</p>'
285 function testAbsorbExtraEndingDivTag() {
286 $this->assertResult(
287 'Par1
289 Par2</div>',
290 '<p>Par1</p>
292 <p>Par2</p>'
296 function testDoNotParagraphSingleSurroundingSpaceInBlockNode() {
297 $this->assertResult(
298 '<div>
299 Par1
300 </div>'
304 function testBlockNodeTextDelimeterInBlockNode() {
305 $this->assertResult(
306 '<div>Par1
308 <div>Par2</div></div>',
309 '<div><p>Par1</p>
311 <div>Par2</div></div>'
315 function testBlockNodeTextDelimeterWithoutDoublespaceInBlockNode() {
316 $this->assertResult(
317 '<div>Par1
318 <div>Par2</div></div>'
322 function testBlockNodeTextDelimeterWithoutDoublespace() {
323 $this->assertResult(
324 'Par1
325 <div>Par2</div>',
326 '<p>Par1
327 </p>
329 <div>Par2</div>'
333 function testTwoParagraphsOfTextAndInlineNode() {
334 $this->assertResult(
335 'Par1
337 <b>Par2</b>',
338 '<p>Par1</p>
340 <p><b>Par2</b></p>'
344 function testLeadingInlineNodeParagraph() {
345 $this->assertResult(
346 '<img /> Foo',
347 '<p><img /> Foo</p>'
351 function testTrailingInlineNodeParagraph() {
352 $this->assertResult(
353 '<li>Foo <a>bar</a></li>'
357 function testTwoInlineNodeParagraph() {
358 $this->assertResult(
359 '<li><b>baz</b><a>bar</a></li>'
363 function testNoParagraphTrailingBlockNodeInBlockNode() {
364 $this->assertResult(
365 '<div><div>asdf</div><b>asdf</b></div>'
369 function testParagraphTrailingBlockNodeWithDoublespaceInBlockNode() {
370 $this->assertResult(
371 '<div><div>asdf</div>
373 <b>asdf</b></div>',
374 '<div><div>asdf</div>
376 <p><b>asdf</b></p></div>'
380 function testParagraphTwoInlineNodesAndWhitespaceNode() {
381 $this->assertResult(
382 '<b>One</b> <i>Two</i>',
383 '<p><b>One</b> <i>Two</i></p>'
387 function testNoParagraphWithInlineRootNode() {
388 $this->config->set('HTML.Parent', 'span');
389 $this->assertResult(
390 'Par
392 Par2'
396 function testInlineAndBlockTagInDivNoParagraph() {
397 $this->assertResult(
398 '<div><code>bar</code> mmm <pre>asdf</pre></div>'
402 function testInlineAndBlockTagInDivNeedingParagraph() {
403 $this->assertResult(
404 '<div><code>bar</code> mmm
406 <pre>asdf</pre></div>',
407 '<div><p><code>bar</code> mmm</p>
409 <pre>asdf</pre></div>'
413 function testTextInlineNodeTextThenDoubleNewlineNeedsParagraph() {
414 $this->assertResult(
415 '<div>asdf <code>bar</code> mmm
417 <pre>asdf</pre></div>',
418 '<div><p>asdf <code>bar</code> mmm</p>
420 <pre>asdf</pre></div>'
424 function testUpcomingTokenHasNewline() {
425 $this->assertResult(
426 '<div>Test<b>foo</b>bar<b>bing</b>bang
428 boo</div>',
429 '<div><p>Test<b>foo</b>bar<b>bing</b>bang</p>
431 <p>boo</p></div>'
435 function testEmptyTokenAtEndOfDiv() {
436 $this->assertResult(
437 '<div><p>foo</p>
438 </div>',
439 '<div><p>foo</p>
440 </div>'
444 function testEmptyDoubleLineTokenAtEndOfDiv() {
445 $this->assertResult(
446 '<div><p>foo</p>
448 </div>',
449 '<div><p>foo</p>
451 </div>'
455 function testTextState11Root() {
456 $this->assertResult('<div></div> ');
459 function testTextState11Element() {
460 $this->assertResult(
461 "<div><div></div>
463 </div>");
466 function testTextStateLikeElementState111NoWhitespace() {
467 $this->assertResult('<div><p>P</p>Boo</div>', '<div><p>P</p>Boo</div>');
470 function testElementState111NoWhitespace() {
471 $this->assertResult('<div><p>P</p><b>Boo</b></div>', '<div><p>P</p><b>Boo</b></div>');
474 function testElementState133() {
475 $this->assertResult(
476 "<div><b>B</b><pre>Ba</pre>
478 Bar</div>",
479 "<div><b>B</b><pre>Ba</pre>
481 <p>Bar</p></div>"
485 function testElementState22() {
486 $this->assertResult(
487 '<ul><li>foo</li></ul>'
491 function testElementState311() {
492 $this->assertResult(
493 '<p>Foo</p><b>Bar</b>',
494 '<p>Foo</p>
496 <p><b>Bar</b></p>'
500 function testAutoClose() {
501 $this->assertResult(
502 '<p></p>
503 <hr />'
507 function testErrorNeeded() {
508 $this->config->set('HTML.Allowed', 'b');
509 $this->expectError('Cannot enable AutoParagraph injector because p is not allowed');
510 $this->assertResult('<b>foobar</b>');
513 function testParentElement() {
514 $this->config->set('HTML.Allowed', 'p,ul,li');
515 $this->assertResult('Foo<ul><li>Bar</li></ul>', "<p>Foo</p>\n\n<ul><li>Bar</li></ul>");
520 // vim: et sw=4 sts=4