HashTagDetectionTests.php 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
  3. print "This script must be run from the command line\n";
  4. exit();
  5. }
  6. define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
  7. define('GNUSOCIAL', true);
  8. define('STATUSNET', true); // compatibility
  9. require_once INSTALLDIR . '/lib/common.php';
  10. class HashTagDetectionTests extends PHPUnit_Framework_TestCase
  11. {
  12. /**
  13. * @dataProvider provider
  14. *
  15. */
  16. public function testProduction($content, $expected)
  17. {
  18. $rendered = common_render_text($content);
  19. $this->assertEquals($expected, $rendered);
  20. }
  21. static public function provider()
  22. {
  23. return array(
  24. array('hello',
  25. 'hello'),
  26. array('#hello people',
  27. '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span> people'),
  28. array('"#hello" people',
  29. '&quot;#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>&quot; people'),
  30. array('say "#hello" people',
  31. 'say &quot;#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>&quot; people'),
  32. array('say (#hello) people',
  33. 'say (#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>) people'),
  34. array('say [#hello] people',
  35. 'say [#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>] people'),
  36. array('say {#hello} people',
  37. 'say {#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>} people'),
  38. array('say \'#hello\' people',
  39. 'say \'#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('hello'))) . '" rel="tag">hello</a></span>\' people'),
  40. // Unicode legit letters
  41. array('#éclair yummy',
  42. '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('éclair'))) . '" rel="tag">éclair</a></span> yummy'),
  43. array('#维基百科 zh.wikipedia!',
  44. '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span> zh.wikipedia!'),
  45. array('#Россия russia',
  46. '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('Россия'))) . '" rel="tag">Россия</a></span> russia'),
  47. // Unicode punctuators -- the ideographic "," separates the tag, just as "," does
  48. array('#维基百科,zh.wikipedia!',
  49. '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span>,zh.wikipedia!'),
  50. array('#维基百科,zh.wikipedia!',
  51. '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('维基百科'))) . '" rel="tag">维基百科</a></span>,zh.wikipedia!'),
  52. );
  53. }
  54. }