X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FLinkDBTest.php;fp=tests%2FLinkDBTest.php;h=1f62a34a160ea5e17c31bbaa0117ef7785ff4202;hb=8147ff76a49206a08999f420206d971de10db12e;hp=9d79386c0b0b5a76aecdfe8825434722278290d4;hpb=9eba6ff469bdea8f341af06ef23c8bb4bd3a6869;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 9d79386c..1f62a34a 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(LinkDB::LINK_DATE_FORMAT, '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::$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::$privateLinkDB->reorder('DESC'); + $linkIds = array_reverse($linkIds); + $cpt = 0; + foreach (self::$privateLinkDB as $key => $value) { + $this->assertEquals($linkIds[$cpt++], $key); + } + } }