6 require_once 'application/Utils.php';
9 * Unitary tests for Shaarli utilities
11 class UtilsTest
extends PHPUnit_Framework_TestCase
14 * Represent a link by its hash
16 public function testSmallHash()
18 $this->assertEquals('CyAAJw', smallHash('http://test.io'));
19 $this->assertEquals(6, strlen(smallHash('https://github.com')));
23 * Look for a substring at the beginning of a string
25 public function testStartsWithCaseInsensitive()
27 $this->assertTrue(startsWith('Lorem ipsum', 'lorem', false));
28 $this->assertTrue(startsWith('Lorem ipsum', 'LoReM i', false));
32 * Look for a substring at the beginning of a string (case-sensitive)
34 public function testStartsWithCaseSensitive()
36 $this->assertTrue(startsWith('Lorem ipsum', 'Lorem', true));
37 $this->assertFalse(startsWith('Lorem ipsum', 'lorem', true));
38 $this->assertFalse(startsWith('Lorem ipsum', 'LoReM i', true));
42 * Look for a substring at the beginning of a string (Unicode)
44 public function testStartsWithSpecialChars()
46 $this->assertTrue(startsWith('å!ùµ', 'å!', false));
47 $this->assertTrue(startsWith('µ$åù', 'µ$', true));
51 * Look for a substring at the end of a string
53 public function testEndsWithCaseInsensitive()
55 $this->assertTrue(endsWith('Lorem ipsum
', 'ipsum
', false));
56 $this->assertTrue(endsWith('Lorem ipsum
', 'm IpsUM
', false));
60 * Look for a substring at the end of a string (case-sensitive)
62 public function testEndsWithCaseSensitive()
64 $this->assertTrue(endsWith('lorem Ipsum
', 'Ipsum
', true));
65 $this->assertFalse(endsWith('lorem Ipsum
', 'ipsum
', true));
66 $this->assertFalse(endsWith('lorem Ipsum
', 'M IPsuM
', true));
70 * Look for a substring at the end of a string (Unicode)
72 public function testEndsWithSpecialChars()
74 $this->assertTrue(endsWith('å
!ùµ
', 'ùµ
', false));
75 $this->assertTrue(endsWith('µ$åù
', 'åù
', true));