aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/LinkDBTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/LinkDBTest.php')
-rw-r--r--tests/LinkDBTest.php116
1 files changed, 109 insertions, 7 deletions
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php
index 5b2f3667..c763c0cb 100644
--- a/tests/LinkDBTest.php
+++ b/tests/LinkDBTest.php
@@ -239,12 +239,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
239 public function testDays() 239 public function testDays()
240 { 240 {
241 $this->assertEquals( 241 $this->assertEquals(
242 array('20100310', '20121206', '20130614', '20150310'), 242 array('20100309', '20100310', '20121206', '20121207', '20130614', '20150310'),
243 self::$publicLinkDB->days() 243 self::$publicLinkDB->days()
244 ); 244 );
245 245
246 $this->assertEquals( 246 $this->assertEquals(
247 array('20100310', '20121206', '20130614', '20141125', '20150310'), 247 array('20100309', '20100310', '20121206', '20121207', '20130614', '20141125', '20150310'),
248 self::$privateLinkDB->days() 248 self::$privateLinkDB->days()
249 ); 249 );
250 } 250 }
@@ -362,7 +362,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
362 public function testLinkRealUrlWithoutRedirector() 362 public function testLinkRealUrlWithoutRedirector()
363 { 363 {
364 $db = new LinkDB(self::$testDatastore, false, false); 364 $db = new LinkDB(self::$testDatastore, false, false);
365 foreach($db as $link) { 365 foreach ($db as $link) {
366 $this->assertEquals($link['url'], $link['real_url']); 366 $this->assertEquals($link['url'], $link['real_url']);
367 } 367 }
368 } 368 }
@@ -374,13 +374,13 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
374 { 374 {
375 $redirector = 'http://redirector.to?'; 375 $redirector = 'http://redirector.to?';
376 $db = new LinkDB(self::$testDatastore, false, false, $redirector); 376 $db = new LinkDB(self::$testDatastore, false, false, $redirector);
377 foreach($db as $link) { 377 foreach ($db as $link) {
378 $this->assertStringStartsWith($redirector, $link['real_url']); 378 $this->assertStringStartsWith($redirector, $link['real_url']);
379 $this->assertNotFalse(strpos($link['real_url'], urlencode('://'))); 379 $this->assertNotFalse(strpos($link['real_url'], urlencode('://')));
380 } 380 }
381 381
382 $db = new LinkDB(self::$testDatastore, false, false, $redirector, false); 382 $db = new LinkDB(self::$testDatastore, false, false, $redirector, false);
383 foreach($db as $link) { 383 foreach ($db as $link) {
384 $this->assertStringStartsWith($redirector, $link['real_url']); 384 $this->assertStringStartsWith($redirector, $link['real_url']);
385 $this->assertFalse(strpos($link['real_url'], urlencode('://'))); 385 $this->assertFalse(strpos($link['real_url'], urlencode('://')));
386 } 386 }
@@ -475,13 +475,15 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
475 public function testReorderLinksDesc() 475 public function testReorderLinksDesc()
476 { 476 {
477 self::$privateLinkDB->reorder('ASC'); 477 self::$privateLinkDB->reorder('ASC');
478 $linkIds = array(42, 4, 9, 1, 0, 7, 6, 8, 41); 478 $stickyIds = [11, 10];
479 $standardIds = [42, 4, 9, 1, 0, 7, 6, 8, 41];
480 $linkIds = array_merge($stickyIds, $standardIds);
479 $cpt = 0; 481 $cpt = 0;
480 foreach (self::$privateLinkDB as $key => $value) { 482 foreach (self::$privateLinkDB as $key => $value) {
481 $this->assertEquals($linkIds[$cpt++], $key); 483 $this->assertEquals($linkIds[$cpt++], $key);
482 } 484 }
483 self::$privateLinkDB->reorder('DESC'); 485 self::$privateLinkDB->reorder('DESC');
484 $linkIds = array_reverse($linkIds); 486 $linkIds = array_merge(array_reverse($stickyIds), array_reverse($standardIds));
485 $cpt = 0; 487 $cpt = 0;
486 foreach (self::$privateLinkDB as $key => $value) { 488 foreach (self::$privateLinkDB as $key => $value) {
487 $this->assertEquals($linkIds[$cpt++], $key); 489 $this->assertEquals($linkIds[$cpt++], $key);
@@ -542,4 +544,104 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
542 $this->assertEquals(3, count($res)); 544 $this->assertEquals(3, count($res));
543 $this->assertNotContains('cartoon', $linkDB[4]['tags']); 545 $this->assertNotContains('cartoon', $linkDB[4]['tags']);
544 } 546 }
547
548 /**
549 * Test linksCountPerTag all tags without filter.
550 * Equal occurrences should be sorted alphabetically.
551 */
552 public function testCountLinkPerTagAllNoFilter()
553 {
554 $expected = [
555 'web' => 4,
556 'cartoon' => 3,
557 'dev' => 2,
558 'gnu' => 2,
559 'hashtag' => 2,
560 'sTuff' => 2,
561 '-exclude' => 1,
562 '.hidden' => 1,
563 'Mercurial' => 1,
564 'css' => 1,
565 'free' => 1,
566 'html' => 1,
567 'media' => 1,
568 'samba' => 1,
569 'software' => 1,
570 'stallman' => 1,
571 'tag1' => 1,
572 'tag2' => 1,
573 'tag3' => 1,
574 'tag4' => 1,
575 'ut' => 1,
576 'w3c' => 1,
577 ];
578 $tags = self::$privateLinkDB->linksCountPerTag();
579
580 $this->assertEquals($expected, $tags, var_export($tags, true));
581 }
582
583 /**
584 * Test linksCountPerTag all tags with filter.
585 * Equal occurrences should be sorted alphabetically.
586 */
587 public function testCountLinkPerTagAllWithFilter()
588 {
589 $expected = [
590 'gnu' => 2,
591 'hashtag' => 2,
592 '-exclude' => 1,
593 '.hidden' => 1,
594 'free' => 1,
595 'media' => 1,
596 'software' => 1,
597 'stallman' => 1,
598 'stuff' => 1,
599 'web' => 1,
600 ];
601 $tags = self::$privateLinkDB->linksCountPerTag(['gnu']);
602
603 $this->assertEquals($expected, $tags, var_export($tags, true));
604 }
605
606 /**
607 * Test linksCountPerTag public tags with filter.
608 * Equal occurrences should be sorted alphabetically.
609 */
610 public function testCountLinkPerTagPublicWithFilter()
611 {
612 $expected = [
613 'gnu' => 2,
614 'hashtag' => 2,
615 '-exclude' => 1,
616 '.hidden' => 1,
617 'free' => 1,
618 'media' => 1,
619 'software' => 1,
620 'stallman' => 1,
621 'stuff' => 1,
622 'web' => 1,
623 ];
624 $tags = self::$privateLinkDB->linksCountPerTag(['gnu'], 'public');
625
626 $this->assertEquals($expected, $tags, var_export($tags, true));
627 }
628
629 /**
630 * Test linksCountPerTag public tags with filter.
631 * Equal occurrences should be sorted alphabetically.
632 */
633 public function testCountLinkPerTagPrivateWithFilter()
634 {
635 $expected = [
636 'cartoon' => 1,
637 'dev' => 1,
638 'tag1' => 1,
639 'tag2' => 1,
640 'tag3' => 1,
641 'tag4' => 1,
642 ];
643 $tags = self::$privateLinkDB->linksCountPerTag(['dev'], 'private');
644
645 $this->assertEquals($expected, $tags, var_export($tags, true));
646 }
545} 647}