From 628b97cbdf276785eb9ff4f7a124e81e67d2f76c Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Thu, 20 Oct 2016 21:10:56 +0200 Subject: LinkDB: do not prefix privates with an underscore Relates to #95 Signed-off-by: VirtualTam --- tests/LinkDBTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/LinkDBTest.php') diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 31306069..43652e72 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -117,7 +117,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase unlink(self::$testDatastore); $this->assertFileNotExists(self::$testDatastore); - $checkDB = self::getMethod('_checkDB'); + $checkDB = self::getMethod('checkDB'); $checkDB->invokeArgs($linkDB, array()); $this->assertFileExists(self::$testDatastore); @@ -134,7 +134,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase $datastoreSize = filesize(self::$testDatastore); $this->assertGreaterThan(0, $datastoreSize); - $checkDB = self::getMethod('_checkDB'); + $checkDB = self::getMethod('checkDB'); $checkDB->invokeArgs($linkDB, array()); // ensure the datastore is left unmodified -- cgit v1.2.3 From f21abf329234ae4d5a1d56c5a9dd0bc11f80bac8 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Thu, 20 Oct 2016 21:19:51 +0200 Subject: LinkDB: update datastore method names Relates to https://github.com/shaarli/Shaarli/issues/95 Signed-off-by: VirtualTam --- tests/LinkDBTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/LinkDBTest.php') diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 43652e72..9d79386c 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -117,7 +117,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase unlink(self::$testDatastore); $this->assertFileNotExists(self::$testDatastore); - $checkDB = self::getMethod('checkDB'); + $checkDB = self::getMethod('check'); $checkDB->invokeArgs($linkDB, array()); $this->assertFileExists(self::$testDatastore); @@ -134,7 +134,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase $datastoreSize = filesize(self::$testDatastore); $this->assertGreaterThan(0, $datastoreSize); - $checkDB = self::getMethod('checkDB'); + $checkDB = self::getMethod('check'); $checkDB->invokeArgs($linkDB, array()); // ensure the datastore is left unmodified @@ -180,7 +180,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase /** * Save the links to the DB */ - public function testSaveDB() + public function testSave() { $testDB = new LinkDB(self::$testDatastore, true, false); $dbSize = sizeof($testDB); @@ -194,7 +194,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase 'tags'=>'unit test' ); $testDB[$link['linkdate']] = $link; - $testDB->savedb('tests'); + $testDB->save('tests'); $testDB = new LinkDB(self::$testDatastore, true, false); $this->assertEquals($dbSize + 1, sizeof($testDB)); -- cgit v1.2.3 From c3dfd8995921083ff7250c25d0b6ab1184b91aff Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 28 Nov 2016 16:17:25 +0100 Subject: Unit Test for the new ID system --- tests/LinkDBTest.php | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'tests/LinkDBTest.php') diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 9d79386c..bedc680e 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -186,14 +186,15 @@ class LinkDBTest extends PHPUnit_Framework_TestCase $dbSize = sizeof($testDB); $link = array( + 'id' => 42, 'title'=>'an additional link', 'url'=>'http://dum.my', 'description'=>'One more', 'private'=>0, - 'linkdate'=>'20150518_190000', + 'created'=> DateTime::createFromFormat('Ymd_His', '20150518_190000'), 'tags'=>'unit test' ); - $testDB[$link['linkdate']] = $link; + $testDB[$link['id']] = $link; $testDB->save('tests'); $testDB = new LinkDB(self::$testDatastore, true, false); @@ -238,12 +239,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase public function testDays() { $this->assertEquals( - array('20121206', '20130614', '20150310'), + array('20100310', '20121206', '20130614', '20150310'), self::$publicLinkDB->days() ); $this->assertEquals( - array('20121206', '20130614', '20141125', '20150310'), + array('20100310', '20121206', '20130614', '20141125', '20150310'), self::$privateLinkDB->days() ); } @@ -290,10 +291,11 @@ class LinkDBTest extends PHPUnit_Framework_TestCase 'stallman' => 1, 'free' => 1, '-exclude' => 1, + 'hashtag' => 2, // The DB contains a link with `sTuff` and another one with `stuff` tag. - // They need to be grouped with the first case found (`sTuff`). + // They need to be grouped with the first case found - order by date DESC: `sTuff`. 'sTuff' => 2, - 'hashtag' => 2, + 'ut' => 1, ), self::$publicLinkDB->allTags() ); @@ -321,6 +323,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase 'tag2' => 1, 'tag3' => 1, 'tag4' => 1, + 'ut' => 1, ), self::$privateLinkDB->allTags() ); @@ -411,6 +414,11 @@ class LinkDBTest extends PHPUnit_Framework_TestCase 1, count(self::$publicLinkDB->filterHash($request)) ); + $request = smallHash('20150310_114633' . 8); + $this->assertEquals( + 1, + count(self::$publicLinkDB->filterHash($request)) + ); } /** @@ -433,4 +441,23 @@ class LinkDBTest extends PHPUnit_Framework_TestCase { self::$publicLinkDB->filterHash(''); } + + /** + * Test reorder with asc/desc parameter. + */ + public function testReorderLinksDesc() + { + self::$publicLinkDB->reorder('ASC'); + $linkIdToTest = 42; + foreach (self::$publicLinkDB as $key => $value) { + $this->assertEquals($linkIdToTest, $key); + break; + } + self::$publicLinkDB->reorder('DESC'); + $linkIdToTest = 41; + foreach (self::$publicLinkDB as $key => $value) { + $this->assertEquals($linkIdToTest, $key); + break; + } + } } -- cgit v1.2.3 From d592daea8343bb4dfecff5d97e93699581ccc58c Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 28 Nov 2016 18:24:15 +0100 Subject: Add a persistent 'shorturl' key to all links All existing link will keep their permalinks. New links will have smallhash generated with date+id. The purpose of this is to avoid collision between links due to their creation date. --- tests/LinkDBTest.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'tests/LinkDBTest.php') diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index bedc680e..1f62a34a 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -191,7 +191,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase 'url'=>'http://dum.my', 'description'=>'One more', 'private'=>0, - 'created'=> DateTime::createFromFormat('Ymd_His', '20150518_190000'), + 'created'=> DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150518_190000'), 'tags'=>'unit test' ); $testDB[$link['id']] = $link; @@ -447,17 +447,17 @@ class LinkDBTest extends PHPUnit_Framework_TestCase */ public function testReorderLinksDesc() { - self::$publicLinkDB->reorder('ASC'); - $linkIdToTest = 42; - foreach (self::$publicLinkDB as $key => $value) { - $this->assertEquals($linkIdToTest, $key); - break; + self::$privateLinkDB->reorder('ASC'); + $linkIds = array(42, 4, 1, 0, 7, 6, 8, 41); + $cpt = 0; + foreach (self::$privateLinkDB as $key => $value) { + $this->assertEquals($linkIds[$cpt++], $key); } - self::$publicLinkDB->reorder('DESC'); - $linkIdToTest = 41; - foreach (self::$publicLinkDB as $key => $value) { - $this->assertEquals($linkIdToTest, $key); - break; + self::$privateLinkDB->reorder('DESC'); + $linkIds = array_reverse($linkIds); + $cpt = 0; + foreach (self::$privateLinkDB as $key => $value) { + $this->assertEquals($linkIds[$cpt++], $key); } } } -- cgit v1.2.3