RemoveEmptyTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. class HTMLPurifier_Injector_RemoveEmptyTest extends HTMLPurifier_InjectorHarness
  3. {
  4. public function setup() {
  5. parent::setup();
  6. $this->config->set('AutoFormat.RemoveEmpty', true);
  7. }
  8. function testPreserve() {
  9. $this->assertResult('<b>asdf</b>');
  10. }
  11. function testRemove() {
  12. $this->assertResult('<b></b>', '');
  13. }
  14. function testRemoveWithSpace() {
  15. $this->assertResult('<b> </b>', '');
  16. }
  17. function testRemoveWithAttr() {
  18. $this->assertResult('<b class="asdf"></b>', '');
  19. }
  20. function testRemoveIdAndName() {
  21. $this->assertResult('<a id="asdf" name="asdf"></a>', '');
  22. }
  23. function testPreserveColgroup() {
  24. $this->assertResult('<colgroup></colgroup>');
  25. }
  26. function testPreserveId() {
  27. $this->config->set('Attr.EnableID', true);
  28. $this->assertResult('<a id="asdf"></a>');
  29. }
  30. function testPreserveName() {
  31. $this->config->set('Attr.EnableID', true);
  32. $this->assertResult('<a name="asdf"></a>');
  33. }
  34. function testRemoveNested() {
  35. $this->assertResult('<b><i></i></b>', '');
  36. }
  37. function testRemoveNested2() {
  38. $this->assertResult('<b><i><u></u></i></b>', '');
  39. }
  40. function testRemoveNested3() {
  41. $this->assertResult('<b> <i> <u> </u> </i> </b>', '');
  42. }
  43. function testRemoveNbsp() {
  44. $this->config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
  45. $this->assertResult('<b>&nbsp;</b>', '');
  46. }
  47. function testRemoveNbspMix() {
  48. $this->config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
  49. $this->assertResult('<b>&nbsp; &nbsp;</b>', '');
  50. }
  51. function testDontRemoveNbsp() {
  52. $this->config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
  53. $this->assertResult('<td>&nbsp;</b>', "<td>\xC2\xA0</td>");
  54. }
  55. function testRemoveNbspExceptionsSpecial() {
  56. $this->config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
  57. $this->config->set('AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions', 'b');
  58. $this->assertResult('<b>&nbsp;</b>', "<b>\xC2\xA0</b>");
  59. }
  60. }
  61. // vim: et sw=4 sts=4