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.

157 lines
4.2KB

  1. <?php
  2. class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness
  3. {
  4. public function setUp()
  5. {
  6. parent::setUp();
  7. $this->obj = new HTMLPurifier_Strategy_FixNesting();
  8. }
  9. public function testPreserveInlineInRoot()
  10. {
  11. $this->assertResult('<b>Bold text</b>');
  12. }
  13. public function testPreserveInlineAndBlockInRoot()
  14. {
  15. $this->assertResult('<a href="about:blank">Blank</a><div>Block</div>');
  16. }
  17. public function testRemoveBlockInInline()
  18. {
  19. $this->assertResult(
  20. '<b><div>Illegal div.</div></b>',
  21. '<b>Illegal div.</b>'
  22. );
  23. }
  24. public function testRemoveNodeWithMissingRequiredElements()
  25. {
  26. $this->assertResult('<ul></ul>', '');
  27. }
  28. public function testListHandleIllegalPCDATA()
  29. {
  30. $this->assertResult(
  31. '<ul>Illegal text<li>Legal item</li></ul>',
  32. '<ul><li>Illegal text</li><li>Legal item</li></ul>'
  33. );
  34. }
  35. public function testRemoveIllegalPCDATA()
  36. {
  37. $this->assertResult(
  38. '<table><tr>Illegal text<td></td></tr></table>',
  39. '<table><tr><td></td></tr></table>'
  40. );
  41. }
  42. public function testCustomTableDefinition()
  43. {
  44. $this->assertResult('<table><tr><td>Cell 1</td></tr></table>');
  45. }
  46. public function testRemoveEmptyTable()
  47. {
  48. $this->assertResult('<table></table>', '');
  49. }
  50. public function testChameleonRemoveBlockInNodeInInline()
  51. {
  52. $this->assertResult(
  53. '<span><ins><div>Not allowed!</div></ins></span>',
  54. '<span><ins>Not allowed!</ins></span>'
  55. );
  56. }
  57. public function testChameleonRemoveBlockInBlockNodeWithInlineContent()
  58. {
  59. $this->assertResult(
  60. '<h1><ins><div>Not allowed!</div></ins></h1>',
  61. '<h1><ins>Not allowed!</ins></h1>'
  62. );
  63. }
  64. public function testNestedChameleonRemoveBlockInNodeWithInlineContent()
  65. {
  66. $this->assertResult(
  67. '<h1><ins><del><div>Not allowed!</div></del></ins></h1>',
  68. '<h1><ins><del>Not allowed!</del></ins></h1>'
  69. );
  70. }
  71. public function testNestedChameleonPreserveBlockInBlock()
  72. {
  73. $this->assertResult(
  74. '<div><ins><del><div>Allowed!</div></del></ins></div>'
  75. );
  76. }
  77. public function testExclusionsIntegration()
  78. {
  79. // test exclusions
  80. $this->assertResult(
  81. '<a><span><a>Not allowed</a></span></a>',
  82. '<a><span></span></a>'
  83. );
  84. }
  85. public function testPreserveInlineNodeInInlineRootNode()
  86. {
  87. $this->config->set('HTML.Parent', 'span');
  88. $this->assertResult('<b>Bold</b>');
  89. }
  90. public function testRemoveBlockNodeInInlineRootNode()
  91. {
  92. $this->config->set('HTML.Parent', 'span');
  93. $this->assertResult('<div>Reject</div>', 'Reject');
  94. }
  95. public function testInvalidParentError()
  96. {
  97. // test fallback to div
  98. $this->config->set('HTML.Parent', 'obviously-impossible');
  99. $this->config->set('Cache.DefinitionImpl', null);
  100. $this->expectError('Cannot use unrecognized element as parent');
  101. $this->assertResult('<div>Accept</div>');
  102. }
  103. public function testCascadingRemovalOfNodesMissingRequiredChildren()
  104. {
  105. $this->assertResult('<table><tr></tr></table>', '');
  106. }
  107. public function testCascadingRemovalSpecialCaseCannotScrollOneBack()
  108. {
  109. $this->assertResult('<table><tr></tr><tr></tr></table>', '');
  110. }
  111. public function testLotsOfCascadingRemovalOfNodes()
  112. {
  113. $this->assertResult('<table><tbody><tr></tr><tr></tr></tbody><tr></tr><tr></tr></table>', '');
  114. }
  115. public function testAdjacentRemovalOfNodeMissingRequiredChildren()
  116. {
  117. $this->assertResult('<table></table><table></table>', '');
  118. }
  119. public function testStrictBlockquoteInHTML401()
  120. {
  121. $this->config->set('HTML.Doctype', 'HTML 4.01 Strict');
  122. $this->assertResult('<blockquote>text</blockquote>', '<blockquote><p>text</p></blockquote>');
  123. }
  124. public function testDisabledExcludes()
  125. {
  126. $this->config->set('Core.DisableExcludes', true);
  127. $this->assertResult('<pre><font><font></font></font></pre>');
  128. }
  129. }
  130. // vim: et sw=4 sts=4