HashTagDetectionTests.php 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. namespace Tests\Unit;
  17. if (!defined('INSTALLDIR')) {
  18. define('INSTALLDIR', dirname(dirname(__DIR__)));
  19. }
  20. if (!defined('PUBLICDIR')) {
  21. define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
  22. }
  23. if (!defined('GNUSOCIAL')) {
  24. define('GNUSOCIAL', true);
  25. }
  26. if (!defined('STATUSNET')) { // Compatibility
  27. define('STATUSNET', true);
  28. }
  29. use PHPUnit\Framework\TestCase;
  30. require_once INSTALLDIR . '/lib/util/common.php';
  31. final class HashTagDetectionTests extends TestCase
  32. {
  33. /**
  34. * @dataProvider provider
  35. *
  36. * @param $content
  37. * @param $expected
  38. */
  39. public function testProduction($content, $expected)
  40. {
  41. $rendered = common_render_text($content);
  42. static::assertSame($expected, $rendered);
  43. }
  44. public static function provider()
  45. {
  46. return [
  47. ['hello',
  48. 'hello',],
  49. ['#hello people',
  50. '#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span> people',],
  51. ['"#hello" people',
  52. '&quot;#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>&quot; people',],
  53. ['say "#hello" people',
  54. 'say &quot;#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>&quot; people',],
  55. ['say (#hello) people',
  56. 'say (#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>) people',],
  57. ['say [#hello] people',
  58. 'say [#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>] people',],
  59. ['say {#hello} people',
  60. 'say {#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>} people',],
  61. ['say \'#hello\' people',
  62. 'say \'#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('hello')]) . '" rel="tag">hello</a></span>\' people',],
  63. // Unicode legit letters
  64. ['#éclair yummy',
  65. '#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('éclair')]) . '" rel="tag">éclair</a></span> yummy',],
  66. ['#维基百科 zh.wikipedia!',
  67. '#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('维基百科')]) . '" rel="tag">维基百科</a></span> zh.wikipedia!',],
  68. ['#Россия russia',
  69. '#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('Россия')]) . '" rel="tag">Россия</a></span> russia',],
  70. // Unicode punctuators -- the ideographic "," separates the tag, just as "," does
  71. ['#维基百科,zh.wikipedia!',
  72. '#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('维基百科')]) . '" rel="tag">维基百科</a></span>,zh.wikipedia!',],
  73. ['#维基百科,zh.wikipedia!',
  74. '#<span class="tag"><a href="' . common_local_url('tag', ['tag' => common_canonical_tag('维基百科')]) . '" rel="tag">维基百科</a></span>,zh.wikipedia!',],
  75. ];
  76. }
  77. }