X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FLinkDBTest.php;h=b055fe9169e2a57377c3ed08ef9b27a9af546ae0;hb=9f400b0dad68b82d65692bd6ab6190f6a787fa89;hp=765f771ec5381c1cbf8f3fe21843fc892488e566;hpb=3a38c95d4232aed4a40f70eb11d26cafc9188bac;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 765f771e..b055fe91 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -17,8 +17,20 @@ class LinkDBTest extends PHPUnit_Framework_TestCase { // datastore to test write operations protected static $testDatastore = 'sandbox/datastore.php'; + + /** + * @var ReferenceLinkDB instance. + */ protected static $refDB = null; + + /** + * @var LinkDB public LinkDB instance. + */ protected static $publicLinkDB = null; + + /** + * @var LinkDB private LinkDB instance. + */ protected static $privateLinkDB = null; /** @@ -278,6 +290,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase 'stallman' => 1, 'free' => 1, '-exclude' => 1, + 'stuff' => 2, ), self::$publicLinkDB->allTags() ); @@ -297,6 +310,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase 'w3c' => 1, 'css' => 1, 'Mercurial' => 1, + 'stuff' => 2, '-exclude' => 1, '.hidden' => 1, ), @@ -324,6 +338,13 @@ class LinkDBTest extends PHPUnit_Framework_TestCase $db = new LinkDB(self::$testDatastore, false, false, $redirector); foreach($db as $link) { $this->assertStringStartsWith($redirector, $link['real_url']); + $this->assertNotFalse(strpos($link['real_url'], urlencode('://'))); + } + + $db = new LinkDB(self::$testDatastore, false, false, $redirector, false); + foreach($db as $link) { + $this->assertStringStartsWith($redirector, $link['real_url']); + $this->assertFalse(strpos($link['real_url'], urlencode('://'))); } } @@ -333,9 +354,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase public function testFilterString() { $tags = 'dev cartoon'; + $request = array('searchtags' => $tags); $this->assertEquals( 2, - count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) + count(self::$privateLinkDB->filterSearch($request, true, false)) ); } @@ -345,9 +367,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase public function testFilterArray() { $tags = array('dev', 'cartoon'); + $request = array('searchtags' => $tags); $this->assertEquals( 2, - count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) + count(self::$privateLinkDB->filterSearch($request, true, false)) ); } @@ -358,14 +381,48 @@ class LinkDBTest extends PHPUnit_Framework_TestCase public function testHiddenTags() { $tags = '.hidden'; + $request = array('searchtags' => $tags); $this->assertEquals( 1, - count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) + count(self::$privateLinkDB->filterSearch($request, true, false)) ); $this->assertEquals( 0, - count(self::$publicLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) + count(self::$publicLinkDB->filterSearch($request, true, false)) ); } + + /** + * Test filterHash() with a valid smallhash. + */ + public function testFilterHashValid() + { + $request = smallHash('20150310_114651'); + $this->assertEquals( + 1, + count(self::$publicLinkDB->filterHash($request)) + ); + } + + /** + * Test filterHash() with an invalid smallhash. + * + * @expectedException LinkNotFoundException + */ + public function testFilterHashInValid1() + { + $request = 'blabla'; + self::$publicLinkDB->filterHash($request); + } + + /** + * Test filterHash() with an empty smallhash. + * + * @expectedException LinkNotFoundException + */ + public function testFilterHashInValid() + { + self::$publicLinkDB->filterHash(''); + } }