X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FLinkDBTest.php;h=7b22b2704f8ba84f3e26995f36c84d071b71161d;hb=70a35e2a6dfeabcb657494a0f30eb630aeb57792;hp=ee8dbee3181840efae91014803e2ac809f63e6da;hpb=0037fbe1e062534ba8d1a19e08f875584cb0ce76;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index ee8dbee3..7b22b270 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -3,6 +3,8 @@ * Link datastore tests */ +require_once 'application/Cache.php'; +require_once 'application/FileUtils.php'; require_once 'application/LinkDB.php'; require_once 'application/Utils.php'; require_once 'tests/utils/ReferenceLinkDB.php'; @@ -14,7 +16,7 @@ require_once 'tests/utils/ReferenceLinkDB.php'; class LinkDBTest extends PHPUnit_Framework_TestCase { // datastore to test write operations - protected static $testDatastore = 'tests/datastore.php'; + protected static $testDatastore = 'sandbox/datastore.php'; protected static $refDB = null; protected static $publicLinkDB = null; protected static $privateLinkDB = null; @@ -86,8 +88,8 @@ class LinkDBTest extends PHPUnit_Framework_TestCase /** * Attempt to instantiate a LinkDB whereas the datastore is not writable * - * @expectedException PHPUnit_Framework_Error_Warning - * @expectedExceptionMessageRegExp /failed to open stream: No such file or directory/ + * @expectedException IOException + * @expectedExceptionMessageRegExp /Error accessing null/ */ public function testConstructDatastoreNotWriteable() { @@ -103,7 +105,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); @@ -120,7 +122,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 @@ -180,11 +182,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)); @@ -228,12 +226,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() ); } @@ -269,7 +267,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase public function testAllTags() { $this->assertEquals( - [ + array( 'web' => 3, 'cartoon' => 2, 'gnu' => 2, @@ -279,12 +277,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, @@ -298,7 +296,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase 'w3c' => 1, 'css' => 1, 'Mercurial' => 1 - ], + ), self::$privateLinkDB->allTags() ); } @@ -396,19 +394,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'); } /** @@ -510,5 +511,27 @@ class LinkDBTest extends PHPUnit_Framework_TestCase sizeof(self::$publicLinkDB->filterFullText('free software')) ); } + + /** + * Test real_url without redirector. + */ + public function testLinkRealUrlWithoutRedirector() + { + $db = new LinkDB(self::$testDatastore, false, false); + foreach($db as $link) { + $this->assertEquals($link['url'], $link['real_url']); + } + } + + /** + * Test real_url with redirector. + */ + public function testLinkRealUrlWithRedirector() + { + $redirector = 'http://redirector.to?'; + $db = new LinkDB(self::$testDatastore, false, false, $redirector); + foreach($db as $link) { + $this->assertStringStartsWith($redirector, $link['real_url']); + } + } } -?>