You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IDTest.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness
  3. {
  4. public function setUp()
  5. {
  6. parent::setUp();
  7. $id_accumulator = new HTMLPurifier_IDAccumulator();
  8. $this->context->register('IDAccumulator', $id_accumulator);
  9. $this->config->set('Attr.EnableID', true);
  10. $this->def = new HTMLPurifier_AttrDef_HTML_ID();
  11. }
  12. public function test()
  13. {
  14. // valid ID names
  15. $this->assertDef('alpha');
  16. $this->assertDef('al_ha');
  17. $this->assertDef('a0-:.');
  18. $this->assertDef('a');
  19. // invalid ID names
  20. $this->assertDef('<asa', false);
  21. $this->assertDef('0123', false);
  22. $this->assertDef('.asa', false);
  23. // test duplicate detection
  24. $this->assertDef('once');
  25. $this->assertDef('once', false);
  26. // valid once whitespace stripped, but needs to be amended
  27. $this->assertDef(' whee ', 'whee');
  28. }
  29. public function testPrefix()
  30. {
  31. $this->config->set('Attr.IDPrefix', 'user_');
  32. $this->assertDef('alpha', 'user_alpha');
  33. $this->assertDef('<asa', false);
  34. $this->assertDef('once', 'user_once');
  35. $this->assertDef('once', false);
  36. // if already prefixed, leave alone
  37. $this->assertDef('user_alas');
  38. $this->assertDef('user_user_alas'); // how to bypass
  39. }
  40. public function testTwoPrefixes()
  41. {
  42. $this->config->set('Attr.IDPrefix', 'user_');
  43. $this->config->set('Attr.IDPrefixLocal', 'story95_');
  44. $this->assertDef('alpha', 'user_story95_alpha');
  45. $this->assertDef('<asa', false);
  46. $this->assertDef('once', 'user_story95_once');
  47. $this->assertDef('once', false);
  48. $this->assertDef('user_story95_alas');
  49. $this->assertDef('user_alas', 'user_story95_user_alas'); // !
  50. }
  51. public function testLocalPrefixWithoutMainPrefix()
  52. {
  53. // no effect when IDPrefix isn't set
  54. $this->config->set('Attr.IDPrefix', '');
  55. $this->config->set('Attr.IDPrefixLocal', 'story95_');
  56. $this->expectError('%Attr.IDPrefixLocal cannot be used unless '.
  57. '%Attr.IDPrefix is set');
  58. $this->assertDef('amherst');
  59. }
  60. // reference functionality is disabled for now
  61. public function disabled_testIDReference()
  62. {
  63. $this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
  64. $this->assertDef('good_id');
  65. $this->assertDef('good_id'); // duplicates okay
  66. $this->assertDef('<b>', false);
  67. $this->def = new HTMLPurifier_AttrDef_HTML_ID();
  68. $this->assertDef('good_id');
  69. $this->assertDef('good_id', false); // duplicate now not okay
  70. $this->def = new HTMLPurifier_AttrDef_HTML_ID(true);
  71. $this->assertDef('good_id'); // reference still okay
  72. }
  73. public function testRegexp()
  74. {
  75. $this->config->set('Attr.IDBlacklistRegexp', '/^g_/');
  76. $this->assertDef('good_id');
  77. $this->assertDef('g_bad_id', false);
  78. }
  79. }
  80. // vim: et sw=4 sts=4