URLifyTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. use PHPUnit\Framework\TestCase;
  3. class URLifyTest extends TestCase {
  4. function test_downcode () {
  5. $this->assertEquals (' J\'etudie le francais ', URLify::downcode (' J\'étudie le français '));
  6. $this->assertEquals ('Lo siento, no hablo espanol.', URLify::downcode ('Lo siento, no hablo español.'));
  7. $this->assertEquals ('F3PWS', URLify::downcode ('ΦΞΠΏΣ'));
  8. $this->assertEquals ('foo-bar', URLify::filter ('_foo_bar_'));
  9. }
  10. function test_filter () {
  11. $this->assertEquals ('jetudie-le-francais', URLify::filter (' J\'étudie le français '));
  12. $this->assertEquals ('lo-siento-no-hablo-espanol', URLify::filter ('Lo siento, no hablo español.'));
  13. $this->assertEquals ('f3pws', URLify::filter ('ΦΞΠΏΣ'));
  14. $this->assertEquals ('', URLify::filter('大般若經'));
  15. $this->assertEquals ('test-.txt', URLify::filter('test-大般若經.txt', 60, "", $file_name = true));
  16. $this->assertEquals ('yakrhy-ltoytr', URLify::filter('ياكرهي لتويتر'));
  17. $this->assertEquals ('saaat-25', URLify::filter('ساعت ۲۵'));
  18. $this->assertEquals ('foto.jpg', URLify::filter ('фото.jpg', 60, "", $file_name = true));
  19. // priorization of language-specific maps
  20. $this->assertEquals ('aouaou', URLify::filter ('ÄÖÜäöü',60,"tr"));
  21. $this->assertEquals ('aeoeueaeoeue', URLify::filter ('ÄÖÜäöü',60,"de"));
  22. $this->assertEquals ('bobby-mcferrin-dont-worry-be-happy', URLify::filter ("Bobby McFerrin — Don't worry be happy",600,"en"));
  23. // test stripping and conversion of UTF-8 spaces
  24. $this->assertEquals ('test-mahito-mukai', URLify::filter('向井 真人test (Mahito Mukai)'));
  25. // Treat underscore as space
  26. $this->assertEquals ('text_with_underscore', URLify::filter('text_with_underscore', 60, "en", true, true, true, false));
  27. }
  28. function test_add_chars () {
  29. $this->assertEquals ('¿ ® ¼ ¼ ¾ ¶', URLify::downcode ('¿ ® ¼ ¼ ¾ ¶'));
  30. URLify::add_chars (array (
  31. '¿' => '?', '®' => '(r)', '¼' => '1/4',
  32. '¼' => '1/2', '¾' => '3/4', '¶' => 'P'
  33. ));
  34. $this->assertEquals ('? (r) 1/2 1/2 3/4 P', URLify::downcode ('¿ ® ¼ ¼ ¾ ¶'));
  35. }
  36. function test_remove_words () {
  37. $this->assertEquals ('foo-bar', URLify::filter ('foo bar'));
  38. URLify::remove_words (array ('foo', 'bar'));
  39. $this->assertEquals ('', URLify::filter ('foo bar'));
  40. }
  41. function test_many_rounds_with_unknown_language_code () {
  42. for ($i = 0; $i < 1000; $i++) {
  43. URLify::downcode ('Lo siento, no hablo español.',-1);
  44. }
  45. }
  46. function test_remove_words_disable () {
  47. URLify::remove_words (array ('foo', 'bar'));
  48. $this->assertEquals ('foo-bar', URLify::filter ('foo bar', 60, '', false, false));
  49. }
  50. }
  51. ?>