PurifierLinkifyTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. class HTMLPurifier_Injector_PurifierLinkifyTest extends HTMLPurifier_InjectorHarness
  3. {
  4. function setup() {
  5. parent::setup();
  6. $this->config->set('AutoFormat.PurifierLinkify', true);
  7. $this->config->set('AutoFormat.PurifierLinkify.DocURL', '#%s');
  8. }
  9. function testNoTriggerCharacer() {
  10. $this->assertResult('Foobar');
  11. }
  12. function testTriggerCharacterInIrrelevantContext() {
  13. $this->assertResult('20% off!');
  14. }
  15. function testPreserveNamespace() {
  16. $this->assertResult('%Core namespace (not recognized)');
  17. }
  18. function testLinkifyBasic() {
  19. $this->assertResult(
  20. '%Namespace.Directive',
  21. '<a href="#Namespace.Directive">%Namespace.Directive</a>'
  22. );
  23. }
  24. function testLinkifyWithAdjacentTextNodes() {
  25. $this->assertResult(
  26. 'This %Namespace.Directive thing',
  27. 'This <a href="#Namespace.Directive">%Namespace.Directive</a> thing'
  28. );
  29. }
  30. function testLinkifyInBlock() {
  31. $this->assertResult(
  32. '<div>This %Namespace.Directive thing</div>',
  33. '<div>This <a href="#Namespace.Directive">%Namespace.Directive</a> thing</div>'
  34. );
  35. }
  36. function testPreserveInATag() {
  37. $this->assertResult(
  38. '<a>%Namespace.Directive</a>'
  39. );
  40. }
  41. function testNeeded() {
  42. $this->config->set('HTML.Allowed', 'b');
  43. $this->expectError('Cannot enable PurifierLinkify injector because a is not allowed');
  44. $this->assertResult('%Namespace.Directive');
  45. }
  46. }
  47. // vim: et sw=4 sts=4