FixNestingTest.php 4.5 KB

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