URLifyTest.php 2.6 KB

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