From ca74886f30da323f42aa4bd70461003f46ef299b Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Thu, 12 Mar 2015 00:43:02 +0100 Subject: 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 --- tests/UtilsTest.php | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 tests/UtilsTest.php (limited to 'tests/UtilsTest.php') 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 @@ +assertEquals('CyAAJw', smallHash('http://test.io')); + $this->assertEquals(6, strlen(smallHash('https://github.com'))); + } + + /** + * Look for a substring at the beginning of a string + */ + public function testStartsWithCaseInsensitive() + { + $this->assertTrue(startsWith('Lorem ipsum', 'lorem', false)); + $this->assertTrue(startsWith('Lorem ipsum', 'LoReM i', false)); + } + + /** + * Look for a substring at the beginning of a string (case-sensitive) + */ + public function testStartsWithCaseSensitive() + { + $this->assertTrue(startsWith('Lorem ipsum', 'Lorem', true)); + $this->assertFalse(startsWith('Lorem ipsum', 'lorem', true)); + $this->assertFalse(startsWith('Lorem ipsum', 'LoReM i', true)); + } + + /** + * Look for a substring at the beginning of a string (Unicode) + */ + public function testStartsWithSpecialChars() + { + $this->assertTrue(startsWith('å!ùµ', 'å!', false)); + $this->assertTrue(startsWith('µ$åù', 'µ$', true)); + } + + /** + * Look for a substring at the end of a string + */ + public function testEndsWithCaseInsensitive() + { + $this->assertTrue(endsWith('Lorem ipsum', 'ipsum', false)); + $this->assertTrue(endsWith('Lorem ipsum', 'm IpsUM', false)); + } + + /** + * Look for a substring at the end of a string (case-sensitive) + */ + public function testEndsWithCaseSensitive() + { + $this->assertTrue(endsWith('lorem Ipsum', 'Ipsum', true)); + $this->assertFalse(endsWith('lorem Ipsum', 'ipsum', true)); + $this->assertFalse(endsWith('lorem Ipsum', 'M IPsuM', true)); + } + + /** + * Look for a substring at the end of a string (Unicode) + */ + public function testEndsWithSpecialChars() + { + $this->assertTrue(endsWith('å!ùµ', 'ùµ', false)); + $this->assertTrue(endsWith('µ$åù', 'åù', true)); + } +} +?> -- cgit v1.2.3