TableTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. // we're using empty tags to compact the tests: under real circumstances
  3. // there would be contents in them
  4. class HTMLPurifier_ChildDef_TableTest extends HTMLPurifier_ChildDefHarness
  5. {
  6. public function setUp()
  7. {
  8. parent::setUp();
  9. $this->obj = new HTMLPurifier_ChildDef_Table();
  10. }
  11. public function testEmptyInput()
  12. {
  13. $this->assertResult('', false);
  14. }
  15. public function testSingleRow()
  16. {
  17. $this->assertResult('<tr />');
  18. }
  19. public function testComplexContents()
  20. {
  21. $this->assertResult('<caption /><col /><thead /><tfoot /><tbody>'.
  22. '<tr><td>asdf</td></tr></tbody>');
  23. $this->assertResult('<col /><col /><col /><tr />');
  24. }
  25. public function testReorderContents()
  26. {
  27. $this->assertResult(
  28. '<col /><colgroup /><tbody /><tfoot /><thead /><tr>1</tr><caption /><tr />',
  29. '<caption /><col /><colgroup /><thead /><tfoot /><tbody /><tbody><tr>1</tr><tr /></tbody>');
  30. }
  31. public function testXhtml11Illegal()
  32. {
  33. $this->assertResult(
  34. '<thead><tr><th>a</th></tr></thead><tr><td>a</td></tr>',
  35. '<thead><tr><th>a</th></tr></thead><tbody><tr><td>a</td></tr></tbody>'
  36. );
  37. }
  38. public function testTheadOnlyNotRemoved()
  39. {
  40. $this->assertResult(
  41. '<thead><tr><th>a</th></tr></thead>',
  42. '<thead><tr><th>a</th></tr></thead>'
  43. );
  44. }
  45. public function testTbodyOnlyNotRemoved()
  46. {
  47. $this->assertResult(
  48. '<tbody><tr><th>a</th></tr></tbody>',
  49. '<tbody><tr><th>a</th></tr></tbody>'
  50. );
  51. }
  52. public function testTrOverflowAndClose()
  53. {
  54. $this->assertResult(
  55. '<tr><td>a</td></tr><tr><td>b</td></tr><tbody><tr><td>c</td></tr></tbody><tr><td>d</td></tr>',
  56. '<tbody><tr><td>a</td></tr><tr><td>b</td></tr></tbody><tbody><tr><td>c</td></tr></tbody><tbody><tr><td>d</td></tr></tbody>'
  57. );
  58. }
  59. public function testDuplicateProcessing()
  60. {
  61. $this->assertResult(
  62. '<caption>1</caption><caption /><tbody /><tbody /><tfoot>1</tfoot><tfoot />',
  63. '<caption>1</caption><tfoot>1</tfoot><tbody /><tbody /><tbody />'
  64. );
  65. }
  66. public function testRemoveText()
  67. {
  68. $this->assertResult('foo', false);
  69. }
  70. public function testStickyWhitespaceOnTr()
  71. {
  72. $this->config->set('Output.Newline', "\n");
  73. $this->assertResult("\n <tr />\n <tr />\n ");
  74. }
  75. public function testStickyWhitespaceOnTSection()
  76. {
  77. $this->config->set('Output.Newline', "\n");
  78. $this->assertResult(
  79. "\n\t<tbody />\n\t\t<tfoot />\n\t\t\t",
  80. "\n\t<tfoot />\n\t\t\t<tbody />\n\t\t"
  81. );
  82. }
  83. }
  84. // vim: et sw=4 sts=4