MakeWellFormedTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarness
  3. {
  4. function setUp() {
  5. parent::setUp();
  6. $this->obj = new HTMLPurifier_Strategy_MakeWellFormed();
  7. }
  8. function testEmptyInput() {
  9. $this->assertResult('');
  10. }
  11. function testWellFormedInput() {
  12. $this->assertResult('This is <b>bold text</b>.');
  13. }
  14. function testUnclosedTagTerminatedByDocumentEnd() {
  15. $this->assertResult(
  16. '<b>Unclosed tag, gasp!',
  17. '<b>Unclosed tag, gasp!</b>'
  18. );
  19. }
  20. function testUnclosedTagTerminatedByParentNodeEnd() {
  21. $this->assertResult(
  22. '<b><i>Bold and italic?</b>',
  23. '<b><i>Bold and italic?</i></b><i></i>'
  24. );
  25. }
  26. function testRemoveStrayClosingTag() {
  27. $this->assertResult(
  28. 'Unused end tags... recycle!</b>',
  29. 'Unused end tags... recycle!'
  30. );
  31. }
  32. function testConvertStartToEmpty() {
  33. $this->assertResult(
  34. '<br style="clear:both;">',
  35. '<br style="clear:both;" />'
  36. );
  37. }
  38. function testConvertEmptyToStart() {
  39. $this->assertResult(
  40. '<div style="clear:both;" />',
  41. '<div style="clear:both;"></div>'
  42. );
  43. }
  44. function testAutoCloseParagraph() {
  45. $this->assertResult(
  46. '<p>Paragraph 1<p>Paragraph 2',
  47. '<p>Paragraph 1</p><p>Paragraph 2</p>'
  48. );
  49. }
  50. function testAutoCloseParagraphInsideDiv() {
  51. $this->assertResult(
  52. '<div><p>Paragraphs<p>In<p>A<p>Div</div>',
  53. '<div><p>Paragraphs</p><p>In</p><p>A</p><p>Div</p></div>'
  54. );
  55. }
  56. function testAutoCloseListItem() {
  57. $this->assertResult(
  58. '<ol><li>Item 1<li>Item 2</ol>',
  59. '<ol><li>Item 1</li><li>Item 2</li></ol>'
  60. );
  61. }
  62. function testAutoCloseColgroup() {
  63. $this->assertResult(
  64. '<table><colgroup><col /><tr></tr></table>',
  65. '<table><colgroup><col /></colgroup><tr></tr></table>'
  66. );
  67. }
  68. function testAutoCloseMultiple() {
  69. $this->assertResult(
  70. '<b><span><div></div>asdf',
  71. '<b><span></span></b><div><b></b></div><b>asdf</b>'
  72. );
  73. }
  74. function testUnrecognized() {
  75. $this->assertResult(
  76. '<asdf><foobar /><biddles>foo</asdf>',
  77. '<asdf><foobar /><biddles>foo</biddles></asdf>'
  78. );
  79. }
  80. function testBlockquoteWithInline() {
  81. $this->config->set('HTML.Doctype', 'XHTML 1.0 Strict');
  82. $this->assertResult(
  83. // This is actually invalid, but will be fixed by
  84. // ChildDef_StrictBlockquote
  85. '<blockquote>foo<b>bar</b></blockquote>'
  86. );
  87. }
  88. function testLongCarryOver() {
  89. $this->assertResult(
  90. '<b>asdf<div>asdf<i>df</i></div>asdf</b>',
  91. '<b>asdf</b><div><b>asdf<i>df</i></b></div><b>asdf</b>'
  92. );
  93. }
  94. function testInterleaved() {
  95. $this->assertResult(
  96. '<u>foo<i>bar</u>baz</i>',
  97. '<u>foo<i>bar</i></u><i>baz</i>'
  98. );
  99. }
  100. function testNestedOl() {
  101. $this->assertResult(
  102. '<ol><ol><li>foo</li></ol></ol>',
  103. '<ol><ol><li>foo</li></ol></ol>'
  104. );
  105. }
  106. function testNestedUl() {
  107. $this->assertResult(
  108. '<ul><ul><li>foo</li></ul></ul>',
  109. '<ul><ul><li>foo</li></ul></ul>'
  110. );
  111. }
  112. function testNestedOlWithStrangeEnding() {
  113. $this->assertResult(
  114. '<ol><li><ol><ol><li>foo</li></ol></li><li>foo</li></ol>',
  115. '<ol><li><ol><ol><li>foo</li></ol></ol></li><li>foo</li></ol>'
  116. );
  117. }
  118. function testNoAutocloseIfNoParentsCanAccomodateTag() {
  119. $this->assertResult(
  120. '<table><tr><td><li>foo</li></td></tr></table>',
  121. '<table><tr><td>foo</td></tr></table>'
  122. );
  123. }
  124. }
  125. // vim: et sw=4 sts=4