]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/LinkDBTest.php
Merge pull request #374 from virtualtam/cleanup
[github/shaarli/Shaarli.git] / tests / LinkDBTest.php
index 0d3433597adf2bfe1508ce04fb22b0910e752861..451f1d6f8360836b48cee1d173da79cb2c6c858b 100644 (file)
@@ -3,6 +3,7 @@
  * Link datastore tests
  */
 
+require_once 'application/Cache.php';
 require_once 'application/LinkDB.php';
 require_once 'application/Utils.php';
 require_once 'tests/utils/ReferenceLinkDB.php';
@@ -15,7 +16,6 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
 {
     // datastore to test write operations
     protected static $testDatastore = 'tests/datastore.php';
-    protected static $dummyDatastoreSHA1 = 'e3edea8ea7bb50be4bcb404df53fbb4546a7156e';
     protected static $refDB = null;
     protected static $publicLinkDB = null;
     protected static $privateLinkDB = null;
@@ -104,15 +104,12 @@ 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);
 
         // ensure the correct data has been written
-        $this->assertEquals(
-            self::$dummyDatastoreSHA1,
-            sha1_file(self::$testDatastore)
-        );
+        $this->assertGreaterThan(0, filesize(self::$testDatastore));
     }
 
     /**
@@ -121,18 +118,16 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
     public function testCheckDBLoad()
     {
         $linkDB = new LinkDB(self::$testDatastore, false, false);
-        $this->assertEquals(
-            self::$dummyDatastoreSHA1,
-            sha1_file(self::$testDatastore)
-        );
+        $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
         $this->assertEquals(
-            self::$dummyDatastoreSHA1,
-            sha1_file(self::$testDatastore)
+            $datastoreSize,
+            filesize(self::$testDatastore)
         );
     }
 
@@ -186,11 +181,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
             'tags'=>'unit test'
         );
         $testDB[$link['linkdate']] = $link;
-
-        // TODO: move PageCache to a proper class/file
-        function invalidateCaches() {}
-
-        $testDB->savedb();
+        $testDB->savedb('tests');
 
         $testDB = new LinkDB(self::$testDatastore, true, false);
         $this->assertEquals($dbSize + 1, sizeof($testDB));
@@ -234,12 +225,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
     public function testDays()
     {
         $this->assertEquals(
-            ['20121206', '20130614', '20150310'],
+            array('20121206', '20130614', '20150310'),
             self::$publicLinkDB->days()
         );
 
         $this->assertEquals(
-            ['20121206', '20130614', '20141125', '20150310'],
+            array('20121206', '20130614', '20141125', '20150310'),
             self::$privateLinkDB->days()
         );
     }
@@ -275,7 +266,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
     public function testAllTags()
     {
         $this->assertEquals(
-            [
+            array(
                 'web' => 3,
                 'cartoon' => 2,
                 'gnu' => 2,
@@ -285,12 +276,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
                 'software' => 1,
                 'stallman' => 1,
                 'free' => 1
-            ],
+            ),
             self::$publicLinkDB->allTags()
         );
 
         $this->assertEquals(
-            [
+            array(
                 'web' => 4,
                 'cartoon' => 3,
                 'gnu' => 2,
@@ -304,7 +295,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
                 'w3c' => 1,
                 'css' => 1,
                 'Mercurial' => 1
-            ],
+            ),
             self::$privateLinkDB->allTags()
         );
     }
@@ -402,19 +393,22 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
 
     /**
      * Use an invalid date format
+     * @expectedException              Exception
+     * @expectedExceptionMessageRegExp /Invalid date format/
      */
-    public function testFilterInvalidDay()
+    public function testFilterInvalidDayWithChars()
     {
-        $this->assertEquals(
-            0,
-            sizeof(self::$privateLinkDB->filterDay('Rainy day, dream away'))
-        );
+        self::$privateLinkDB->filterDay('Rainy day, dream away');
+    }
 
-        // TODO: check input format
-        $this->assertEquals(
-            6,
-            sizeof(self::$privateLinkDB->filterDay('20'))
-        );
+    /**
+     * Use an invalid date format
+     * @expectedException              Exception
+     * @expectedExceptionMessageRegExp /Invalid date format/
+     */
+    public function testFilterInvalidDayDigits()
+    {
+        self::$privateLinkDB->filterDay('20');
     }
 
     /**
@@ -517,4 +511,3 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
         );
     }
 }
-?>