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>
This commit is contained in:
parent
cbecab7735
commit
ca74886f30
12 changed files with 1231 additions and 257 deletions
tests
78
tests/UtilsTest.php
Normal file
78
tests/UtilsTest.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
/**
|
||||
* Utilities' tests
|
||||
*/
|
||||
|
||||
require_once 'application/Utils.php';
|
||||
|
||||
/**
|
||||
* Unitary tests for Shaarli utilities
|
||||
*/
|
||||
class UtilsTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Represent a link by its hash
|
||||
*/
|
||||
public function testSmallHash()
|
||||
{
|
||||
$this->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));
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue