* 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';
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;
/**
* 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()
{
'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));
}
/**
- * Filter links using a tag
- */
- public function testFilterOneTag()
- {
- $this->assertEquals(
- 3,
- sizeof(self::$publicLinkDB->filterTags('web', false))
- );
-
- $this->assertEquals(
- 4,
- sizeof(self::$privateLinkDB->filterTags('web', false))
- );
- }
-
- /**
- * Filter links using a tag - case-sensitive
- */
- public function testFilterCaseSensitiveTag()
- {
- $this->assertEquals(
- 0,
- sizeof(self::$privateLinkDB->filterTags('mercurial', true))
- );
-
- $this->assertEquals(
- 1,
- sizeof(self::$privateLinkDB->filterTags('Mercurial', true))
- );
- }
-
- /**
- * Filter links using a tag combination
- */
- public function testFilterMultipleTags()
- {
- $this->assertEquals(
- 1,
- sizeof(self::$publicLinkDB->filterTags('dev cartoon', false))
- );
-
- $this->assertEquals(
- 2,
- sizeof(self::$privateLinkDB->filterTags('dev cartoon', false))
- );
- }
-
- /**
- * Filter links using a non-existent tag
- */
- public function testFilterUnknownTag()
- {
- $this->assertEquals(
- 0,
- sizeof(self::$publicLinkDB->filterTags('null', false))
- );
- }
-
- /**
- * Return links for a given day
- */
- public function testFilterDay()
- {
- $this->assertEquals(
- 2,
- sizeof(self::$publicLinkDB->filterDay('20121206'))
- );
-
- $this->assertEquals(
- 3,
- sizeof(self::$privateLinkDB->filterDay('20121206'))
- );
- }
-
- /**
- * 404 - day not found
+ * Test real_url without redirector.
*/
- public function testFilterUnknownDay()
+ public function testLinkRealUrlWithoutRedirector()
{
- $this->assertEquals(
- 0,
- sizeof(self::$publicLinkDB->filterDay('19700101'))
- );
-
- $this->assertEquals(
- 0,
- sizeof(self::$privateLinkDB->filterDay('19700101'))
- );
- }
-
- /**
- * Use an invalid date format
- * @expectedException Exception
- * @expectedExceptionMessageRegExp /Invalid date format/
- */
- public function testFilterInvalidDayWithChars()
- {
- self::$privateLinkDB->filterDay('Rainy day, dream away');
- }
-
- /**
- * Use an invalid date format
- * @expectedException Exception
- * @expectedExceptionMessageRegExp /Invalid date format/
- */
- public function testFilterInvalidDayDigits()
- {
- self::$privateLinkDB->filterDay('20');
- }
-
- /**
- * Retrieve a link entry with its hash
- */
- public function testFilterSmallHash()
- {
- $links = self::$privateLinkDB->filterSmallHash('IuWvgA');
-
- $this->assertEquals(
- 1,
- sizeof($links)
- );
-
- $this->assertEquals(
- 'MediaGoblin',
- $links['20130614_184135']['title']
- );
-
- }
-
- /**
- * No link for this hash
- */
- public function testFilterUnknownSmallHash()
- {
- $this->assertEquals(
- 0,
- sizeof(self::$privateLinkDB->filterSmallHash('Iblaah'))
- );
- }
-
- /**
- * Full-text search - result from a link's URL
- */
- public function testFilterFullTextURL()
- {
- $this->assertEquals(
- 2,
- sizeof(self::$publicLinkDB->filterFullText('ars.userfriendly.org'))
- );
- }
-
- /**
- * Full-text search - result from a link's title only
- */
- public function testFilterFullTextTitle()
- {
- // use miscellaneous cases
- $this->assertEquals(
- 2,
- sizeof(self::$publicLinkDB->filterFullText('userfriendly -'))
- );
- $this->assertEquals(
- 2,
- sizeof(self::$publicLinkDB->filterFullText('UserFriendly -'))
- );
- $this->assertEquals(
- 2,
- sizeof(self::$publicLinkDB->filterFullText('uSeRFrIendlY -'))
- );
-
- // use miscellaneous case and offset
- $this->assertEquals(
- 2,
- sizeof(self::$publicLinkDB->filterFullText('RFrIendL'))
- );
+ $db = new LinkDB(self::$testDatastore, false, false);
+ foreach($db as $link) {
+ $this->assertEquals($link['url'], $link['real_url']);
+ }
}
/**
- * Full-text search - result from the link's description only
+ * Test real_url with redirector.
*/
- public function testFilterFullTextDescription()
+ public function testLinkRealUrlWithRedirector()
{
- $this->assertEquals(
- 1,
- sizeof(self::$publicLinkDB->filterFullText('media publishing'))
- );
+ $redirector = 'http://redirector.to?';
+ $db = new LinkDB(self::$testDatastore, false, false, $redirector);
+ foreach($db as $link) {
+ $this->assertStringStartsWith($redirector, $link['real_url']);
+ }
}
/**
- * Full-text search - result from the link's tags only
+ * Test filter with string.
*/
- public function testFilterFullTextTags()
+ public function testFilterString()
{
+ $tags = 'dev cartoon';
$this->assertEquals(
2,
- sizeof(self::$publicLinkDB->filterFullText('gnu'))
+ count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false))
);
}
/**
- * Full-text search - result set from mixed sources
+ * Test filter with string.
*/
- public function testFilterFullTextMixed()
+ public function testFilterArray()
{
+ $tags = array('dev', 'cartoon');
$this->assertEquals(
2,
- sizeof(self::$publicLinkDB->filterFullText('free software'))
+ count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false))
);
}
}
-?>