From 528a6f8a232c060faf024008e4f8a09b4aa8dabc Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 21 Mar 2016 21:40:49 +0100 Subject: Refactor filter in LinkDB * search type now carried by LinkDB in order to factorize code between different search sources. * LinkDB->filter split in 3 method: filterSearch, filterHash, filterDay (we know what type of filter is needed). * filterHash now throw a LinkNotFoundException if it doesn't exist: internal implementation choice, still displays a 404. * Smallhash regex has been rewritten. * Unit tests update --- tests/LinkDBTest.php | 56 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'tests/LinkDBTest.php') diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index b6a273b3..52d31400 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; /** @@ -335,9 +347,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)) ); } @@ -347,9 +360,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)) ); } @@ -360,14 +374,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(''); + } } -- cgit v1.2.3