ValidateAttributes_IDTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. class HTMLPurifier_Strategy_ValidateAttributes_IDTest extends HTMLPurifier_StrategyHarness
  3. {
  4. function setUp() {
  5. parent::setUp();
  6. $this->obj = new HTMLPurifier_Strategy_ValidateAttributes();
  7. $this->config->set('Attr.EnableID', true);
  8. }
  9. function testPreserveIDWhenEnabled() {
  10. $this->assertResult('<div id="valid">Preserve the ID.</div>');
  11. }
  12. function testRemoveInvalidID() {
  13. $this->assertResult(
  14. '<div id="0invalid">Kill the ID.</div>',
  15. '<div>Kill the ID.</div>'
  16. );
  17. }
  18. function testRemoveDuplicateID() {
  19. $this->assertResult(
  20. '<div id="valid">Valid</div><div id="valid">Invalid</div>',
  21. '<div id="valid">Valid</div><div>Invalid</div>'
  22. );
  23. }
  24. function testAttributeKeyCaseInsensitivity() {
  25. $this->assertResult(
  26. '<div ID="valid">Convert ID to lowercase.</div>',
  27. '<div id="valid">Convert ID to lowercase.</div>'
  28. );
  29. }
  30. function testTrimWhitespace() {
  31. $this->assertResult(
  32. '<div id=" valid ">Trim whitespace.</div>',
  33. '<div id="valid">Trim whitespace.</div>'
  34. );
  35. }
  36. function testIDBlacklist() {
  37. $this->config->set('Attr.IDBlacklist', array('invalid'));
  38. $this->assertResult(
  39. '<div id="invalid">Invalid</div>',
  40. '<div>Invalid</div>'
  41. );
  42. }
  43. function testNameConvertedToID() {
  44. $this->config->set('HTML.TidyLevel', 'heavy');
  45. $this->assertResult(
  46. '<a name="foobar" />',
  47. '<a id="foobar" />'
  48. );
  49. }
  50. }
  51. // vim: et sw=4 sts=4