aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/LinkDBTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-10-12 13:58:35 +0200
committerArthurHoaro <arthur@hoa.ro>2016-10-12 13:58:35 +0200
commitbc22c9a0acb095970e9494cbe8954f0612e05dc0 (patch)
tree4e3a94b7469f5b2e3eaf946756235730429bf9d4 /tests/LinkDBTest.php
parent890afc32f744859d11b97eb26ed5c030af9b4145 (diff)
parentebd67c6e1b40aebdd3a52285ce9ff9412b2a3038 (diff)
downloadShaarli-bc22c9a0acb095970e9494cbe8954f0612e05dc0.tar.gz
Shaarli-bc22c9a0acb095970e9494cbe8954f0612e05dc0.tar.zst
Shaarli-bc22c9a0acb095970e9494cbe8954f0612e05dc0.zip
Merge tag 'v0.7.0' of github.com:shaarli/Shaarli into stable
Release v0.7.0
Diffstat (limited to 'tests/LinkDBTest.php')
-rw-r--r--tests/LinkDBTest.php63
1 files changed, 59 insertions, 4 deletions
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php
index b6a273b3..b055fe91 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 /**
@@ -326,6 +338,13 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
326 $db = new LinkDB(self::$testDatastore, false, false, $redirector); 338 $db = new LinkDB(self::$testDatastore, false, false, $redirector);
327 foreach($db as $link) { 339 foreach($db as $link) {
328 $this->assertStringStartsWith($redirector, $link['real_url']); 340 $this->assertStringStartsWith($redirector, $link['real_url']);
341 $this->assertNotFalse(strpos($link['real_url'], urlencode('://')));
342 }
343
344 $db = new LinkDB(self::$testDatastore, false, false, $redirector, false);
345 foreach($db as $link) {
346 $this->assertStringStartsWith($redirector, $link['real_url']);
347 $this->assertFalse(strpos($link['real_url'], urlencode('://')));
329 } 348 }
330 } 349 }
331 350
@@ -335,9 +354,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
335 public function testFilterString() 354 public function testFilterString()
336 { 355 {
337 $tags = 'dev cartoon'; 356 $tags = 'dev cartoon';
357 $request = array('searchtags' => $tags);
338 $this->assertEquals( 358 $this->assertEquals(
339 2, 359 2,
340 count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) 360 count(self::$privateLinkDB->filterSearch($request, true, false))
341 ); 361 );
342 } 362 }
343 363
@@ -347,9 +367,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
347 public function testFilterArray() 367 public function testFilterArray()
348 { 368 {
349 $tags = array('dev', 'cartoon'); 369 $tags = array('dev', 'cartoon');
370 $request = array('searchtags' => $tags);
350 $this->assertEquals( 371 $this->assertEquals(
351 2, 372 2,
352 count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) 373 count(self::$privateLinkDB->filterSearch($request, true, false))
353 ); 374 );
354 } 375 }
355 376
@@ -360,14 +381,48 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
360 public function testHiddenTags() 381 public function testHiddenTags()
361 { 382 {
362 $tags = '.hidden'; 383 $tags = '.hidden';
384 $request = array('searchtags' => $tags);
363 $this->assertEquals( 385 $this->assertEquals(
364 1, 386 1,
365 count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) 387 count(self::$privateLinkDB->filterSearch($request, true, false))
366 ); 388 );
367 389
368 $this->assertEquals( 390 $this->assertEquals(
369 0, 391 0,
370 count(self::$publicLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) 392 count(self::$publicLinkDB->filterSearch($request, true, false))
371 ); 393 );
372 } 394 }
395
396 /**
397 * Test filterHash() with a valid smallhash.
398 */
399 public function testFilterHashValid()
400 {
401 $request = smallHash('20150310_114651');
402 $this->assertEquals(
403 1,
404 count(self::$publicLinkDB->filterHash($request))
405 );
406 }
407
408 /**
409 * Test filterHash() with an invalid smallhash.
410 *
411 * @expectedException LinkNotFoundException
412 */
413 public function testFilterHashInValid1()
414 {
415 $request = 'blabla';
416 self::$publicLinkDB->filterHash($request);
417 }
418
419 /**
420 * Test filterHash() with an empty smallhash.
421 *
422 * @expectedException LinkNotFoundException
423 */
424 public function testFilterHashInValid()
425 {
426 self::$publicLinkDB->filterHash('');
427 }
373} 428}