UtilsTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Utilities' tests
  4. */
  5. require_once 'application/Utils.php';
  6. /**
  7. * Unitary tests for Shaarli utilities
  8. */
  9. class UtilsTest extends PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * Represent a link by its hash
  13. */
  14. public function testSmallHash()
  15. {
  16. $this->assertEquals('CyAAJw', smallHash('http://test.io'));
  17. $this->assertEquals(6, strlen(smallHash('https://github.com')));
  18. }
  19. /**
  20. * Look for a substring at the beginning of a string
  21. */
  22. public function testStartsWithCaseInsensitive()
  23. {
  24. $this->assertTrue(startsWith('Lorem ipsum', 'lorem', false));
  25. $this->assertTrue(startsWith('Lorem ipsum', 'LoReM i', false));
  26. }
  27. /**
  28. * Look for a substring at the beginning of a string (case-sensitive)
  29. */
  30. public function testStartsWithCaseSensitive()
  31. {
  32. $this->assertTrue(startsWith('Lorem ipsum', 'Lorem', true));
  33. $this->assertFalse(startsWith('Lorem ipsum', 'lorem', true));
  34. $this->assertFalse(startsWith('Lorem ipsum', 'LoReM i', true));
  35. }
  36. /**
  37. * Look for a substring at the beginning of a string (Unicode)
  38. */
  39. public function testStartsWithSpecialChars()
  40. {
  41. $this->assertTrue(startsWith('å!ùµ', 'å!', false));
  42. $this->assertTrue(startsWith('µ$åù', 'µ$', true));
  43. }
  44. /**
  45. * Look for a substring at the end of a string
  46. */
  47. public function testEndsWithCaseInsensitive()
  48. {
  49. $this->assertTrue(endsWith('Lorem ipsum', 'ipsum', false));
  50. $this->assertTrue(endsWith('Lorem ipsum', 'm IpsUM', false));
  51. }
  52. /**
  53. * Look for a substring at the end of a string (case-sensitive)
  54. */
  55. public function testEndsWithCaseSensitive()
  56. {
  57. $this->assertTrue(endsWith('lorem Ipsum', 'Ipsum', true));
  58. $this->assertFalse(endsWith('lorem Ipsum', 'ipsum', true));
  59. $this->assertFalse(endsWith('lorem Ipsum', 'M IPsuM', true));
  60. }
  61. /**
  62. * Look for a substring at the end of a string (Unicode)
  63. */
  64. public function testEndsWithSpecialChars()
  65. {
  66. $this->assertTrue(endsWith('å!ùµ', 'ùµ', false));
  67. $this->assertTrue(endsWith('µ$åù', 'åù', true));
  68. }
  69. }
  70. ?>