RemoveSpansWithoutAttributesTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. class HTMLPurifier_Injector_RemoveSpansWithoutAttributesTest extends HTMLPurifier_InjectorHarness
  3. {
  4. function setup() {
  5. parent::setup();
  6. $this->config->set('HTML.Allowed', 'span[class],div,p,strong,em');
  7. $this->config->set('AutoFormat.RemoveSpansWithoutAttributes', true);
  8. }
  9. function testSingleSpan() {
  10. $this->assertResult(
  11. '<span>foo</span>',
  12. 'foo'
  13. );
  14. }
  15. function testSingleSpanWithAttributes() {
  16. $this->assertResult(
  17. '<span class="bar">foo</span>',
  18. '<span class="bar">foo</span>'
  19. );
  20. }
  21. function testSingleNestedSpan() {
  22. $this->assertResult(
  23. '<p><span>foo</span></p>',
  24. '<p>foo</p>'
  25. );
  26. }
  27. function testSingleNestedSpanWithAttributes() {
  28. $this->assertResult(
  29. '<p><span class="bar">foo</span></p>',
  30. '<p><span class="bar">foo</span></p>'
  31. );
  32. }
  33. function testSpanWithChildren() {
  34. $this->assertResult(
  35. '<span>foo <strong>bar</strong> <em>baz</em></span>',
  36. 'foo <strong>bar</strong> <em>baz</em>'
  37. );
  38. }
  39. function testSpanWithSiblings() {
  40. $this->assertResult(
  41. '<p>before <span>inside</span> <strong>after</strong></p>',
  42. '<p>before inside <strong>after</strong></p>'
  43. );
  44. }
  45. function testNestedSpanWithSiblingsAndChildren() {
  46. $this->assertResult(
  47. '<p>a <span>b <em>c</em> d</span> e</p>',
  48. '<p>a b <em>c</em> d e</p>'
  49. );
  50. }
  51. function testNestedSpansWithoutAttributes() {
  52. $this->assertResult(
  53. '<span>one<span>two<span>three</span></span></span>',
  54. 'onetwothree'
  55. );
  56. }
  57. function testDeeplyNestedSpan() {
  58. $this->assertResult(
  59. '<div><div><div><span class="a">a <span>b</span> c</span></div></div></div>',
  60. '<div><div><div><span class="a">a b c</span></div></div></div>'
  61. );
  62. }
  63. function testSpanWithInvalidAttributes() {
  64. $this->assertResult(
  65. '<p><span snorkel buzzer="emu">foo</span></p>',
  66. '<p>foo</p>'
  67. );
  68. }
  69. function testNestedAlternateSpans() {
  70. $this->assertResult(
  71. '<span>a <span class="x">b <span>c <span class="y">d <span>e <span class="z">f
  72. </span></span></span></span></span></span>',
  73. 'a <span class="x">b c <span class="y">d e <span class="z">f
  74. </span></span></span>'
  75. );
  76. }
  77. function testSpanWithSomeInvalidAttributes() {
  78. $this->assertResult(
  79. '<p><span buzzer="emu" class="bar">foo</span></p>',
  80. '<p><span class="bar">foo</span></p>'
  81. );
  82. }
  83. }
  84. // vim: et sw=4 sts=4