aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/LinkDBTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-03-21 21:40:49 +0100
committerArthurHoaro <arthur@hoa.ro>2016-03-25 19:17:59 +0100
commit528a6f8a232c060faf024008e4f8a09b4aa8dabc (patch)
tree86cac78b7f4d3998bedd923da83145c37ec88ff4 /tests/LinkDBTest.php
parentee88a4bcc29da721cf43b750663aebeac4969517 (diff)
downloadShaarli-528a6f8a232c060faf024008e4f8a09b4aa8dabc.tar.gz
Shaarli-528a6f8a232c060faf024008e4f8a09b4aa8dabc.tar.zst
Shaarli-528a6f8a232c060faf024008e4f8a09b4aa8dabc.zip
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
Diffstat (limited to 'tests/LinkDBTest.php')
-rw-r--r--tests/LinkDBTest.php56
1 files changed, 52 insertions, 4 deletions
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
17{ 17{
18 // datastore to test write operations 18 // datastore to test write operations
19 protected static $testDatastore = 'sandbox/datastore.php'; 19 protected static $testDatastore = 'sandbox/datastore.php';
20
21 /**
22 * @var ReferenceLinkDB instance.
23 */
20 protected static $refDB = null; 24 protected static $refDB = null;
25
26 /**
27 * @var LinkDB public LinkDB instance.
28 */
21 protected static $publicLinkDB = null; 29 protected static $publicLinkDB = null;
30
31 /**
32 * @var LinkDB private LinkDB instance.
33 */
22 protected static $privateLinkDB = null; 34 protected static $privateLinkDB = null;
23 35
24 /** 36 /**
@@ -335,9 +347,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
335 public function testFilterString() 347 public function testFilterString()
336 { 348 {
337 $tags = 'dev cartoon'; 349 $tags = 'dev cartoon';
350 $request = array('searchtags' => $tags);
338 $this->assertEquals( 351 $this->assertEquals(
339 2, 352 2,
340 count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) 353 count(self::$privateLinkDB->filterSearch($request, true, false))
341 ); 354 );
342 } 355 }
343 356
@@ -347,9 +360,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
347 public function testFilterArray() 360 public function testFilterArray()
348 { 361 {
349 $tags = array('dev', 'cartoon'); 362 $tags = array('dev', 'cartoon');
363 $request = array('searchtags' => $tags);
350 $this->assertEquals( 364 $this->assertEquals(
351 2, 365 2,
352 count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) 366 count(self::$privateLinkDB->filterSearch($request, true, false))
353 ); 367 );
354 } 368 }
355 369
@@ -360,14 +374,48 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
360 public function testHiddenTags() 374 public function testHiddenTags()
361 { 375 {
362 $tags = '.hidden'; 376 $tags = '.hidden';
377 $request = array('searchtags' => $tags);
363 $this->assertEquals( 378 $this->assertEquals(
364 1, 379 1,
365 count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) 380 count(self::$privateLinkDB->filterSearch($request, true, false))
366 ); 381 );
367 382
368 $this->assertEquals( 383 $this->assertEquals(
369 0, 384 0,
370 count(self::$publicLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) 385 count(self::$publicLinkDB->filterSearch($request, true, false))
371 ); 386 );
372 } 387 }
388
389 /**
390 * Test filterHash() with a valid smallhash.
391 */
392 public function testFilterHashValid()
393 {
394 $request = smallHash('20150310_114651');
395 $this->assertEquals(
396 1,
397 count(self::$publicLinkDB->filterHash($request))
398 );
399 }
400
401 /**
402 * Test filterHash() with an invalid smallhash.
403 *
404 * @expectedException LinkNotFoundException
405 */
406 public function testFilterHashInValid1()
407 {
408 $request = 'blabla';
409 self::$publicLinkDB->filterHash($request);
410 }
411
412 /**
413 * Test filterHash() with an empty smallhash.
414 *
415 * @expectedException LinkNotFoundException
416 */
417 public function testFilterHashInValid()
418 {
419 self::$publicLinkDB->filterHash('');
420 }
373} 421}