X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Fbookmark%2FBookmarkFileServiceTest.php;h=a4ec10138b75c30bfb6a78c9726f3dc9f49229bf;hb=6128ab6a55430a2b705be31ff417c0c552a0db1f;hp=1b438a7f97304503e310093b457c11a86cba4e01;hpb=e26e2060f5470ce8bf4c5973284bae07b8af170a;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index 1b438a7f..a4ec1013 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php @@ -12,6 +12,7 @@ use ReflectionClass; use Shaarli; use Shaarli\Bookmark\Exception\BookmarkNotFoundException; use Shaarli\Config\ConfigManager; +use Shaarli\Formatter\BookmarkMarkdownFormatter; use Shaarli\History; /** @@ -199,7 +200,7 @@ class BookmarkFileServiceTest extends TestCase $bookmark = $this->privateLinkDB->get(43); $this->assertEquals(43, $bookmark->getId()); - $this->assertRegExp('/\?[\w\-]{6}/', $bookmark->getUrl()); + $this->assertRegExp('#/shaare/[\w\-]{6}#', $bookmark->getUrl()); $this->assertRegExp('/[\w\-]{6}/', $bookmark->getShortUrl()); $this->assertEquals($bookmark->getUrl(), $bookmark->getTitle()); $this->assertEmpty($bookmark->getDescription()); @@ -215,7 +216,7 @@ class BookmarkFileServiceTest extends TestCase $bookmark = $this->privateLinkDB->get(43); $this->assertEquals(43, $bookmark->getId()); - $this->assertRegExp('/\?[\w\-]{6}/', $bookmark->getUrl()); + $this->assertRegExp('#/shaare/[\w\-]{6}#', $bookmark->getUrl()); $this->assertRegExp('/[\w\-]{6}/', $bookmark->getShortUrl()); $this->assertEquals($bookmark->getUrl(), $bookmark->getTitle()); $this->assertEmpty($bookmark->getDescription()); @@ -339,7 +340,7 @@ class BookmarkFileServiceTest extends TestCase $bookmark = $this->privateLinkDB->get(42); $this->assertEquals(42, $bookmark->getId()); - $this->assertEquals('?WDWyig', $bookmark->getUrl()); + $this->assertEquals('/shaare/WDWyig', $bookmark->getUrl()); $this->assertEquals('1eYJ1Q', $bookmark->getShortUrl()); $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle()); $this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription()); @@ -358,7 +359,7 @@ class BookmarkFileServiceTest extends TestCase $bookmark = $this->privateLinkDB->get(42); $this->assertEquals(42, $bookmark->getId()); - $this->assertEquals('?WDWyig', $bookmark->getUrl()); + $this->assertEquals('/shaare/WDWyig', $bookmark->getUrl()); $this->assertEquals('1eYJ1Q', $bookmark->getShortUrl()); $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle()); $this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription()); @@ -614,14 +615,18 @@ class BookmarkFileServiceTest extends TestCase { $dbSize = $this->privateLinkDB->count(); $this->privateLinkDB->initialize(); - $this->assertEquals($dbSize + 2, $this->privateLinkDB->count()); - $this->assertEquals( - 'My secret stuff... - Pastebin.com', - $this->privateLinkDB->get(43)->getTitle() + $this->assertEquals($dbSize + 3, $this->privateLinkDB->count()); + $this->assertStringStartsWith( + 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.', + $this->privateLinkDB->get(43)->getDescription() ); - $this->assertEquals( - 'The personal, minimalist, super-fast, database free, bookmarking service', - $this->privateLinkDB->get(44)->getTitle() + $this->assertStringStartsWith( + 'Adding a shaare without entering a URL creates a text-only "note" post such as this one.', + $this->privateLinkDB->get(44)->getDescription() + ); + $this->assertStringStartsWith( + 'Welcome to Shaarli!', + $this->privateLinkDB->get(45)->getDescription() ); } @@ -815,7 +820,6 @@ class BookmarkFileServiceTest extends TestCase ); $this->assertEquals( [ - 'web' => 4, 'cartoon' => 2, 'gnu' => 1, 'dev' => 1, @@ -832,7 +836,6 @@ class BookmarkFileServiceTest extends TestCase ); $this->assertEquals( [ - 'web' => 1, 'html' => 1, 'w3c' => 1, 'css' => 1, @@ -893,35 +896,35 @@ class BookmarkFileServiceTest extends TestCase public function testFilterHashValid() { $request = smallHash('20150310_114651'); - $this->assertEquals( - 1, - count($this->publicLinkDB->findByHash($request)) + $this->assertSame( + $request, + $this->publicLinkDB->findByHash($request)->getShortUrl() ); $request = smallHash('20150310_114633' . 8); - $this->assertEquals( - 1, - count($this->publicLinkDB->findByHash($request)) + $this->assertSame( + $request, + $this->publicLinkDB->findByHash($request)->getShortUrl() ); } /** * Test filterHash() with an invalid smallhash. - * - * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testFilterHashInValid1() { + $this->expectException(BookmarkNotFoundException::class); + $request = 'blabla'; $this->publicLinkDB->findByHash($request); } /** * Test filterHash() with an empty smallhash. - * - * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testFilterHashInValid() { + $this->expectException(BookmarkNotFoundException::class); + $this->publicLinkDB->findByHash(''); } @@ -967,7 +970,6 @@ class BookmarkFileServiceTest extends TestCase public function testCountLinkPerTagAllWithFilter() { $expected = [ - 'gnu' => 2, 'hashtag' => 2, '-exclude' => 1, '.hidden' => 1, @@ -990,7 +992,6 @@ class BookmarkFileServiceTest extends TestCase public function testCountLinkPerTagPublicWithFilter() { $expected = [ - 'gnu' => 2, 'hashtag' => 2, '-exclude' => 1, '.hidden' => 1, @@ -1014,7 +1015,6 @@ class BookmarkFileServiceTest extends TestCase { $expected = [ 'cartoon' => 1, - 'dev' => 1, 'tag1' => 1, 'tag2' => 1, 'tag3' => 1, @@ -1025,6 +1025,76 @@ class BookmarkFileServiceTest extends TestCase $this->assertEquals($expected, $tags, var_export($tags, true)); } + /** + * Test linksCountPerTag public tags with filter. + * Equal occurrences should be sorted alphabetically. + */ + public function testCountTagsNoMarkdown() + { + $expected = [ + 'cartoon' => 3, + 'dev' => 2, + 'tag1' => 1, + 'tag2' => 1, + 'tag3' => 1, + 'tag4' => 1, + 'web' => 4, + 'gnu' => 2, + 'hashtag' => 2, + 'sTuff' => 2, + '-exclude' => 1, + '.hidden' => 1, + 'Mercurial' => 1, + 'css' => 1, + 'free' => 1, + 'html' => 1, + 'media' => 1, + 'newTagToCount' => 1, + 'samba' => 1, + 'software' => 1, + 'stallman' => 1, + 'ut' => 1, + 'w3c' => 1, + ]; + $bookmark = new Bookmark(); + $bookmark->setTags(['newTagToCount', BookmarkMarkdownFormatter::NO_MD_TAG]); + $this->privateLinkDB->add($bookmark); + + $tags = $this->privateLinkDB->bookmarksCountPerTag(); + + $this->assertEquals($expected, $tags, var_export($tags, true)); + } + + /** + * Test filterDay while logged in + */ + public function testFilterDayLoggedIn(): void + { + $bookmarks = $this->privateLinkDB->filterDay('20121206'); + $expectedIds = [4, 9, 1, 0]; + + static::assertCount(4, $bookmarks); + foreach ($bookmarks as $bookmark) { + $i = ($i ?? -1) + 1; + static::assertSame($expectedIds[$i], $bookmark->getId()); + } + } + + /** + * Test filterDay while logged out + */ + public function testFilterDayLoggedOut(): void + { + $bookmarks = $this->publicLinkDB->filterDay('20121206'); + $expectedIds = [4, 9, 1]; + + static::assertCount(3, $bookmarks); + foreach ($bookmarks as $bookmark) { + $i = ($i ?? -1) + 1; + static::assertSame($expectedIds[$i], $bookmark->getId()); + } + } + /** * Allows to test LinkDB's private methods *