aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/LinkDBTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-11-28 16:17:25 +0100
committerArthurHoaro <arthur@hoa.ro>2016-12-12 03:03:12 +0100
commitc3dfd8995921083ff7250c25d0b6ab1184b91aff (patch)
treecb7cb17ad607a5bd2e7d9ee59c0e804e590fa6af /tests/LinkDBTest.php
parent01878a75b93b9966f7366ea2937c118bbc3e459e (diff)
downloadShaarli-c3dfd8995921083ff7250c25d0b6ab1184b91aff.tar.gz
Shaarli-c3dfd8995921083ff7250c25d0b6ab1184b91aff.tar.zst
Shaarli-c3dfd8995921083ff7250c25d0b6ab1184b91aff.zip
Unit Test for the new ID system
Diffstat (limited to 'tests/LinkDBTest.php')
-rw-r--r--tests/LinkDBTest.php39
1 files changed, 33 insertions, 6 deletions
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
186 $dbSize = sizeof($testDB); 186 $dbSize = sizeof($testDB);
187 187
188 $link = array( 188 $link = array(
189 'id' => 42,
189 'title'=>'an additional link', 190 'title'=>'an additional link',
190 'url'=>'http://dum.my', 191 'url'=>'http://dum.my',
191 'description'=>'One more', 192 'description'=>'One more',
192 'private'=>0, 193 'private'=>0,
193 'linkdate'=>'20150518_190000', 194 'created'=> DateTime::createFromFormat('Ymd_His', '20150518_190000'),
194 'tags'=>'unit test' 195 'tags'=>'unit test'
195 ); 196 );
196 $testDB[$link['linkdate']] = $link; 197 $testDB[$link['id']] = $link;
197 $testDB->save('tests'); 198 $testDB->save('tests');
198 199
199 $testDB = new LinkDB(self::$testDatastore, true, false); 200 $testDB = new LinkDB(self::$testDatastore, true, false);
@@ -238,12 +239,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
238 public function testDays() 239 public function testDays()
239 { 240 {
240 $this->assertEquals( 241 $this->assertEquals(
241 array('20121206', '20130614', '20150310'), 242 array('20100310', '20121206', '20130614', '20150310'),
242 self::$publicLinkDB->days() 243 self::$publicLinkDB->days()
243 ); 244 );
244 245
245 $this->assertEquals( 246 $this->assertEquals(
246 array('20121206', '20130614', '20141125', '20150310'), 247 array('20100310', '20121206', '20130614', '20141125', '20150310'),
247 self::$privateLinkDB->days() 248 self::$privateLinkDB->days()
248 ); 249 );
249 } 250 }
@@ -290,10 +291,11 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
290 'stallman' => 1, 291 'stallman' => 1,
291 'free' => 1, 292 'free' => 1,
292 '-exclude' => 1, 293 '-exclude' => 1,
294 'hashtag' => 2,
293 // The DB contains a link with `sTuff` and another one with `stuff` tag. 295 // The DB contains a link with `sTuff` and another one with `stuff` tag.
294 // They need to be grouped with the first case found (`sTuff`). 296 // They need to be grouped with the first case found - order by date DESC: `sTuff`.
295 'sTuff' => 2, 297 'sTuff' => 2,
296 'hashtag' => 2, 298 'ut' => 1,
297 ), 299 ),
298 self::$publicLinkDB->allTags() 300 self::$publicLinkDB->allTags()
299 ); 301 );
@@ -321,6 +323,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
321 'tag2' => 1, 323 'tag2' => 1,
322 'tag3' => 1, 324 'tag3' => 1,
323 'tag4' => 1, 325 'tag4' => 1,
326 'ut' => 1,
324 ), 327 ),
325 self::$privateLinkDB->allTags() 328 self::$privateLinkDB->allTags()
326 ); 329 );
@@ -411,6 +414,11 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
411 1, 414 1,
412 count(self::$publicLinkDB->filterHash($request)) 415 count(self::$publicLinkDB->filterHash($request))
413 ); 416 );
417 $request = smallHash('20150310_114633' . 8);
418 $this->assertEquals(
419 1,
420 count(self::$publicLinkDB->filterHash($request))
421 );
414 } 422 }
415 423
416 /** 424 /**
@@ -433,4 +441,23 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
433 { 441 {
434 self::$publicLinkDB->filterHash(''); 442 self::$publicLinkDB->filterHash('');
435 } 443 }
444
445 /**
446 * Test reorder with asc/desc parameter.
447 */
448 public function testReorderLinksDesc()
449 {
450 self::$publicLinkDB->reorder('ASC');
451 $linkIdToTest = 42;
452 foreach (self::$publicLinkDB as $key => $value) {
453 $this->assertEquals($linkIdToTest, $key);
454 break;
455 }
456 self::$publicLinkDB->reorder('DESC');
457 $linkIdToTest = 41;
458 foreach (self::$publicLinkDB as $key => $value) {
459 $this->assertEquals($linkIdToTest, $key);
460 break;
461 }
462 }
436} 463}