From f8c5660df82432c7f3bb0686e393db5a2b46eeb5 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 29 May 2018 20:52:30 +0200 Subject: Tag sort - UT + comment + fix filter and visibility Before this, linksCountPerTag call without would have ignored visibility parameter --- tests/LinkDBTest.php | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) (limited to 'tests/LinkDBTest.php') diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 5b2f3667..3b980878 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -542,4 +542,104 @@ class LinkDBTest extends PHPUnit_Framework_TestCase $this->assertEquals(3, count($res)); $this->assertNotContains('cartoon', $linkDB[4]['tags']); } + + /** + * Test linksCountPerTag all tags without filter. + * Equal occurrences should be sorted alphabetically. + */ + public function testCountLinkPerTagAllNoFilter() + { + $expected = [ + 'web' => 4, + 'cartoon' => 3, + 'dev' => 2, + 'gnu' => 2, + 'hashtag' => 2, + 'sTuff' => 2, + '-exclude' => 1, + '.hidden' => 1, + 'Mercurial' => 1, + 'css' => 1, + 'free' => 1, + 'html' => 1, + 'media' => 1, + 'samba' => 1, + 'software' => 1, + 'stallman' => 1, + 'tag1' => 1, + 'tag2' => 1, + 'tag3' => 1, + 'tag4' => 1, + 'ut' => 1, + 'w3c' => 1, + ]; + $tags = self::$privateLinkDB->linksCountPerTag(); + + $this->assertEquals($expected, $tags, var_export($tags, true)); + } + + /** + * Test linksCountPerTag all tags with filter. + * Equal occurrences should be sorted alphabetically. + */ + public function testCountLinkPerTagAllWithFilter() + { + $expected = [ + 'gnu' => 2, + 'hashtag' => 2, + '-exclude' => 1, + '.hidden' => 1, + 'free' => 1, + 'media' => 1, + 'software' => 1, + 'stallman' => 1, + 'stuff' => 1, + 'web' => 1, + ]; + $tags = self::$privateLinkDB->linksCountPerTag(['gnu']); + + $this->assertEquals($expected, $tags, var_export($tags, true)); + } + + /** + * Test linksCountPerTag public tags with filter. + * Equal occurrences should be sorted alphabetically. + */ + public function testCountLinkPerTagPublicWithFilter() + { + $expected = [ + 'gnu' => 2, + 'hashtag' => 2, + '-exclude' => 1, + '.hidden' => 1, + 'free' => 1, + 'media' => 1, + 'software' => 1, + 'stallman' => 1, + 'stuff' => 1, + 'web' => 1, + ]; + $tags = self::$privateLinkDB->linksCountPerTag(['gnu'], 'public'); + + $this->assertEquals($expected, $tags, var_export($tags, true)); + } + + /** + * Test linksCountPerTag public tags with filter. + * Equal occurrences should be sorted alphabetically. + */ + public function testCountLinkPerTagPrivateWithFilter() + { + $expected = [ + 'cartoon' => 1, + 'dev' => 1, + 'tag1' => 1, + 'tag2' => 1, + 'tag3' => 1, + 'tag4' => 1, + ]; + $tags = self::$privateLinkDB->linksCountPerTag(['dev'], 'private'); + + $this->assertEquals($expected, $tags, var_export($tags, true)); + } } -- cgit v1.2.3 From 4154c25b5f2f8044a37d7f84e04173bb54f2375b Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 22 May 2018 22:44:38 +0200 Subject: Add a button to set links as sticky Meaning that they always appear on top of all links Fixes #186 --- tests/LinkDBTest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tests/LinkDBTest.php') diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 3b980878..fcab76f6 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -239,12 +239,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase public function testDays() { $this->assertEquals( - array('20100310', '20121206', '20130614', '20150310'), + array('20100309', '20100310', '20121206', '20121207', '20130614', '20150310'), self::$publicLinkDB->days() ); $this->assertEquals( - array('20100310', '20121206', '20130614', '20141125', '20150310'), + array('20100309', '20100310', '20121206', '20121207', '20130614', '20141125', '20150310'), self::$privateLinkDB->days() ); } @@ -475,13 +475,15 @@ class LinkDBTest extends PHPUnit_Framework_TestCase public function testReorderLinksDesc() { self::$privateLinkDB->reorder('ASC'); - $linkIds = array(42, 4, 9, 1, 0, 7, 6, 8, 41); + $stickyIds = [11, 10]; + $standardIds = [42, 4, 9, 1, 0, 7, 6, 8, 41]; + $linkIds = array_merge($stickyIds, $standardIds); $cpt = 0; foreach (self::$privateLinkDB as $key => $value) { $this->assertEquals($linkIds[$cpt++], $key); } self::$privateLinkDB->reorder('DESC'); - $linkIds = array_reverse($linkIds); + $linkIds = array_merge(array_reverse($stickyIds), array_reverse($standardIds)); $cpt = 0; foreach (self::$privateLinkDB as $key => $value) { $this->assertEquals($linkIds[$cpt++], $key); -- cgit v1.2.3 From 067c2dd8f5f6eb6cc808ddc4bd30aec104caf73d Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sat, 13 Oct 2018 00:35:47 +0200 Subject: lint: apply phpcbf to tests/ Signed-off-by: VirtualTam --- tests/LinkDBTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/LinkDBTest.php') diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index fcab76f6..c763c0cb 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -362,7 +362,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase public function testLinkRealUrlWithoutRedirector() { $db = new LinkDB(self::$testDatastore, false, false); - foreach($db as $link) { + foreach ($db as $link) { $this->assertEquals($link['url'], $link['real_url']); } } @@ -374,13 +374,13 @@ class LinkDBTest extends PHPUnit_Framework_TestCase { $redirector = 'http://redirector.to?'; $db = new LinkDB(self::$testDatastore, false, false, $redirector); - foreach($db as $link) { + 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) { + foreach ($db as $link) { $this->assertStringStartsWith($redirector, $link['real_url']); $this->assertFalse(strpos($link['real_url'], urlencode('://'))); } -- cgit v1.2.3