X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FLinkDBTest.php;h=06edea79201a2fe18ea53cf9a7277b95153b055e;hb=21979ff11ceee0042642ac17147858a4155d54c5;hp=ff917f6d54dba81c6c736352b6b7e56043b67e1c;hpb=61873e3ded8dfba397b39aebd2322d0939c82caa;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index ff917f6d..06edea79 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php @@ -16,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; @@ -276,7 +276,8 @@ class LinkDBTest extends PHPUnit_Framework_TestCase 'media' => 1, 'software' => 1, 'stallman' => 1, - 'free' => 1 + 'free' => 1, + '-exclude' => 1, ), self::$publicLinkDB->allTags() ); @@ -295,243 +296,57 @@ class LinkDBTest extends PHPUnit_Framework_TestCase 'html' => 1, 'w3c' => 1, 'css' => 1, - 'Mercurial' => 1 + 'Mercurial' => 1, + '-exclude' => 1, ), self::$privateLinkDB->allTags() ); } /** - * 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 - */ - public function testFilterUnknownDay() - { - $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 + * Test real_url without redirector. */ - public function testFilterFullTextTitle() + public function testLinkRealUrlWithoutRedirector() { - // 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)) ); } - - /** - * 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']); - } - } }