X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FLinkDBTest.php;h=7b22b2704f8ba84f3e26995f36c84d071b71161d;hb=a6aa37b96fc59d3e6218dbcfd8f6ea8e5ba313b4;hp=504c81901a8fc402278e66eb50689d51e5fe0b92;hpb=d1e2f8e52c931f84c11d4f54f32959710d528182;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 504c8190..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() { @@ -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)); @@ -513,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']); + } + } } -?>