You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.1KB

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