aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/UtilsTest.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.org>2015-03-12 00:43:02 +0100
committerVirtualTam <virtualtam@flibidi.net>2015-06-11 00:45:45 +0200
commitca74886f30da323f42aa4bd70461003f46ef299b (patch)
tree3714895c25d80bdb472211a564f83d3744d90f34 /tests/UtilsTest.php
parentcbecab773526b0c39f3cffa1d4595b5caa781bda (diff)
downloadShaarli-ca74886f30da323f42aa4bd70461003f46ef299b.tar.gz
Shaarli-ca74886f30da323f42aa4bd70461003f46ef299b.tar.zst
Shaarli-ca74886f30da323f42aa4bd70461003f46ef299b.zip
LinkDB: move to a proper file, add test coverage
Relates to #71 LinkDB - move to application/LinkDB.php - code cleanup - indentation - whitespaces - formatting - comment cleanup - add missing documentation - unify formatting Test coverage for LinkDB - constructor - public / private access - link-related methods Shaarli utilities (LinkDB dependencies) - move startsWith() and endsWith() functions to application/Utils.php - add test coverage Dev utilities - Composer: add PHPUnit to dev dependencies - Makefile: - update lint targets - add test targets - generate coverage reports Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'tests/UtilsTest.php')
-rw-r--r--tests/UtilsTest.php78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php
new file mode 100644
index 00000000..bbba99f2
--- /dev/null
+++ b/tests/UtilsTest.php
@@ -0,0 +1,78 @@
1<?php
2/**
3 * Utilities' tests
4 */
5
6require_once 'application/Utils.php';
7
8/**
9 * Unitary tests for Shaarli utilities
10 */
11class UtilsTest extends PHPUnit_Framework_TestCase
12{
13 /**
14 * Represent a link by its hash
15 */
16 public function testSmallHash()
17 {
18 $this->assertEquals('CyAAJw', smallHash('http://test.io'));
19 $this->assertEquals(6, strlen(smallHash('https://github.com')));
20 }
21
22 /**
23 * Look for a substring at the beginning of a string
24 */
25 public function testStartsWithCaseInsensitive()
26 {
27 $this->assertTrue(startsWith('Lorem ipsum', 'lorem', false));
28 $this->assertTrue(startsWith('Lorem ipsum', 'LoReM i', false));
29 }
30
31 /**
32 * Look for a substring at the beginning of a string (case-sensitive)
33 */
34 public function testStartsWithCaseSensitive()
35 {
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));
39 }
40
41 /**
42 * Look for a substring at the beginning of a string (Unicode)
43 */
44 public function testStartsWithSpecialChars()
45 {
46 $this->assertTrue(startsWith('å!ùµ', 'å!', false));
47 $this->assertTrue(startsWith('µ$åù', 'µ$', true));
48 }
49
50 /**
51 * Look for a substring at the end of a string
52 */
53 public function testEndsWithCaseInsensitive()
54 {
55 $this->assertTrue(endsWith('Lorem ipsum', 'ipsum', false));
56 $this->assertTrue(endsWith('Lorem ipsum', 'm IpsUM', false));
57 }
58
59 /**
60 * Look for a substring at the end of a string (case-sensitive)
61 */
62 public function testEndsWithCaseSensitive()
63 {
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));
67 }
68
69 /**
70 * Look for a substring at the end of a string (Unicode)
71 */
72 public function testEndsWithSpecialChars()
73 {
74 $this->assertTrue(endsWith('å!ùµ', 'ùµ', false));
75 $this->assertTrue(endsWith('µ$åù', 'åù', true));
76 }
77}
78?>