LinkifyTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. class HTMLPurifier_Injector_LinkifyTest extends HTMLPurifier_InjectorHarness
  3. {
  4. public function setup()
  5. {
  6. parent::setup();
  7. $this->config->set('AutoFormat.Linkify', true);
  8. }
  9. public function testLinkifyURLInRootNode()
  10. {
  11. $this->assertResult(
  12. 'http://example.com',
  13. '<a href="http://example.com">http://example.com</a>'
  14. );
  15. }
  16. public function testLinkifyURLInInlineNode()
  17. {
  18. $this->assertResult(
  19. '<b>http://example.com</b>',
  20. '<b><a href="http://example.com">http://example.com</a></b>'
  21. );
  22. }
  23. public function testBasicUsageCase()
  24. {
  25. $this->assertResult(
  26. 'This URL http://example.com is what you need',
  27. 'This URL <a href="http://example.com">http://example.com</a> is what you need'
  28. );
  29. }
  30. public function testIgnoreURLInATag()
  31. {
  32. $this->assertResult(
  33. '<a>http://example.com/</a>'
  34. );
  35. }
  36. public function testNeeded()
  37. {
  38. $this->config->set('HTML.Allowed', 'b');
  39. $this->expectError('Cannot enable Linkify injector because a is not allowed');
  40. $this->assertResult('http://example.com/');
  41. }
  42. public function testExcludes()
  43. {
  44. $this->assertResult('<a><span>http://example.com</span></a>');
  45. }
  46. public function testRegexIsSmart()
  47. {
  48. $this->assertResult('http://example.com/foo.', '<a href="http://example.com/foo">http://example.com/foo</a>.');
  49. $this->assertResult('“http://example.com/foo”', '“<a href="http://example.com/foo">http://example.com/foo</a>”');
  50. $this->assertResult('“http://example.com”', '“<a href="http://example.com">http://example.com</a>”');
  51. $this->assertResult('(http://example.com/f(o)o)', '(<a href="http://example.com/f(o)o">http://example.com/f(o)o</a>)');
  52. }
  53. }
  54. // vim: et sw=4 sts=4