aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/LinkDBTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/LinkDBTest.php')
-rw-r--r--tests/LinkDBTest.php90
1 files changed, 86 insertions, 4 deletions
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php
index 1f62a34a..5b2f3667 100644
--- a/tests/LinkDBTest.php
+++ b/tests/LinkDBTest.php
@@ -101,7 +101,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
101 * Attempt to instantiate a LinkDB whereas the datastore is not writable 101 * Attempt to instantiate a LinkDB whereas the datastore is not writable
102 * 102 *
103 * @expectedException IOException 103 * @expectedException IOException
104 * @expectedExceptionMessageRegExp /Error accessing\nnull/ 104 * @expectedExceptionMessageRegExp /Error accessing "null"/
105 */ 105 */
106 public function testConstructDatastoreNotWriteable() 106 public function testConstructDatastoreNotWriteable()
107 { 107 {
@@ -297,7 +297,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
297 'sTuff' => 2, 297 'sTuff' => 2,
298 'ut' => 1, 298 'ut' => 1,
299 ), 299 ),
300 self::$publicLinkDB->allTags() 300 self::$publicLinkDB->linksCountPerTag()
301 ); 301 );
302 302
303 $this->assertEquals( 303 $this->assertEquals(
@@ -325,7 +325,34 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
325 'tag4' => 1, 325 'tag4' => 1,
326 'ut' => 1, 326 'ut' => 1,
327 ), 327 ),
328 self::$privateLinkDB->allTags() 328 self::$privateLinkDB->linksCountPerTag()
329 );
330 $this->assertEquals(
331 array(
332 'web' => 4,
333 'cartoon' => 2,
334 'gnu' => 1,
335 'dev' => 1,
336 'samba' => 1,
337 'media' => 1,
338 'html' => 1,
339 'w3c' => 1,
340 'css' => 1,
341 'Mercurial' => 1,
342 '.hidden' => 1,
343 'hashtag' => 1,
344 ),
345 self::$privateLinkDB->linksCountPerTag(['web'])
346 );
347 $this->assertEquals(
348 array(
349 'web' => 1,
350 'html' => 1,
351 'w3c' => 1,
352 'css' => 1,
353 'Mercurial' => 1,
354 ),
355 self::$privateLinkDB->linksCountPerTag(['web'], 'private')
329 ); 356 );
330 } 357 }
331 358
@@ -448,7 +475,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
448 public function testReorderLinksDesc() 475 public function testReorderLinksDesc()
449 { 476 {
450 self::$privateLinkDB->reorder('ASC'); 477 self::$privateLinkDB->reorder('ASC');
451 $linkIds = array(42, 4, 1, 0, 7, 6, 8, 41); 478 $linkIds = array(42, 4, 9, 1, 0, 7, 6, 8, 41);
452 $cpt = 0; 479 $cpt = 0;
453 foreach (self::$privateLinkDB as $key => $value) { 480 foreach (self::$privateLinkDB as $key => $value) {
454 $this->assertEquals($linkIds[$cpt++], $key); 481 $this->assertEquals($linkIds[$cpt++], $key);
@@ -460,4 +487,59 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
460 $this->assertEquals($linkIds[$cpt++], $key); 487 $this->assertEquals($linkIds[$cpt++], $key);
461 } 488 }
462 } 489 }
490
491 /**
492 * Test rename tag with a valid value present in multiple links
493 */
494 public function testRenameTagMultiple()
495 {
496 self::$refDB->write(self::$testDatastore);
497 $linkDB = new LinkDB(self::$testDatastore, true, false);
498
499 $res = $linkDB->renameTag('cartoon', 'Taz');
500 $this->assertEquals(3, count($res));
501 $this->assertContains(' Taz ', $linkDB[4]['tags']);
502 $this->assertContains(' Taz ', $linkDB[1]['tags']);
503 $this->assertContains(' Taz ', $linkDB[0]['tags']);
504 }
505
506 /**
507 * Test rename tag with a valid value
508 */
509 public function testRenameTagCaseSensitive()
510 {
511 self::$refDB->write(self::$testDatastore);
512 $linkDB = new LinkDB(self::$testDatastore, true, false, '');
513
514 $res = $linkDB->renameTag('sTuff', 'Taz');
515 $this->assertEquals(1, count($res));
516 $this->assertEquals('Taz', $linkDB[41]['tags']);
517 }
518
519 /**
520 * Test rename tag with invalid values
521 */
522 public function testRenameTagInvalid()
523 {
524 $linkDB = new LinkDB(self::$testDatastore, false, false);
525
526 $this->assertFalse($linkDB->renameTag('', 'test'));
527 $this->assertFalse($linkDB->renameTag('', ''));
528 // tag non existent
529 $this->assertEquals([], $linkDB->renameTag('test', ''));
530 $this->assertEquals([], $linkDB->renameTag('test', 'retest'));
531 }
532
533 /**
534 * Test delete tag with a valid value
535 */
536 public function testDeleteTag()
537 {
538 self::$refDB->write(self::$testDatastore);
539 $linkDB = new LinkDB(self::$testDatastore, true, false);
540
541 $res = $linkDB->renameTag('cartoon', null);
542 $this->assertEquals(3, count($res));
543 $this->assertNotContains('cartoon', $linkDB[4]['tags']);
544 }
463} 545}