RemoveEmptyTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. class HTMLPurifier_Injector_RemoveEmptyTest extends HTMLPurifier_InjectorHarness
  3. {
  4. public function setup()
  5. {
  6. parent::setup();
  7. $this->config->set('AutoFormat.RemoveEmpty', true);
  8. }
  9. public function testPreserve()
  10. {
  11. $this->assertResult('<b>asdf</b>');
  12. }
  13. public function testRemove()
  14. {
  15. $this->assertResult('<b></b>', '');
  16. }
  17. public function testRemoveWithSpace()
  18. {
  19. $this->assertResult('<b> </b>', '');
  20. }
  21. public function testRemoveWithAttr()
  22. {
  23. $this->assertResult('<b class="asdf"></b>', '');
  24. }
  25. public function testRemoveIdAndName()
  26. {
  27. $this->assertResult('<a id="asdf" name="asdf"></a>', '');
  28. }
  29. public function testPreserveColgroup()
  30. {
  31. $this->assertResult('<colgroup></colgroup>');
  32. }
  33. public function testPreserveId()
  34. {
  35. $this->config->set('Attr.EnableID', true);
  36. $this->assertResult('<a id="asdf"></a>');
  37. }
  38. public function testPreserveName()
  39. {
  40. $this->config->set('Attr.EnableID', true);
  41. $this->assertResult('<a name="asdf"></a>');
  42. }
  43. public function testRemoveNested()
  44. {
  45. $this->assertResult('<b><i></i></b>', '');
  46. }
  47. public function testRemoveNested2()
  48. {
  49. $this->assertResult('<b><i><u></u></i></b>', '');
  50. }
  51. public function testRemoveNested3()
  52. {
  53. $this->assertResult('<b> <i> <u> </u> </i> </b>', '');
  54. }
  55. public function testRemoveNbsp()
  56. {
  57. $this->config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
  58. $this->assertResult('<b>&nbsp;</b>', '');
  59. }
  60. public function testRemoveNbspMix()
  61. {
  62. $this->config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
  63. $this->assertResult('<b>&nbsp; &nbsp;</b>', '');
  64. }
  65. public function testRemoveLi()
  66. {
  67. $this->assertResult("<ul><li>\n\n\n</li></ul>", '');
  68. }
  69. public function testDontRemoveNbsp()
  70. {
  71. $this->config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
  72. $this->assertResult('<td>&nbsp;</b>', "<td>\xC2\xA0</td>");
  73. }
  74. public function testRemoveNbspExceptionsSpecial()
  75. {
  76. $this->config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
  77. $this->config->set('AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions', 'b');
  78. $this->assertResult('<b>&nbsp;</b>', "<b>\xC2\xA0</b>");
  79. }
  80. public function testRemoveIframe()
  81. {
  82. $this->config->set('HTML.SafeIframe', true);
  83. $this->assertResult('<iframe></iframe>', '');
  84. }
  85. public function testNoRemoveIframe()
  86. {
  87. $this->config->set('HTML.SafeIframe', true);
  88. $this->assertResult('<iframe src="http://google.com"></iframe>', '');
  89. }
  90. public function testRemoveDisallowedIframe()
  91. {
  92. $this->config->set('HTML.SafeIframe', true);
  93. $this->config->set('URI.SafeIframeRegexp', '%^http://www.youtube.com/embed/%');
  94. $this->assertResult('<iframe src="http://google.com"></iframe>', '');
  95. }
  96. }
  97. // vim: et sw=4 sts=4