diff options
Diffstat (limited to 'tests/bookmark')
-rw-r--r-- | tests/bookmark/BookmarkFileServiceTest.php | 33 | ||||
-rw-r--r-- | tests/bookmark/BookmarkInitializerTest.php | 14 | ||||
-rw-r--r-- | tests/bookmark/BookmarkTest.php | 4 | ||||
-rw-r--r-- | tests/bookmark/LinkUtilsTest.php | 4 |
4 files changed, 26 insertions, 29 deletions
diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index 4900d41d..7b1906d3 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php | |||
@@ -200,7 +200,7 @@ class BookmarkFileServiceTest extends TestCase | |||
200 | 200 | ||
201 | $bookmark = $this->privateLinkDB->get(43); | 201 | $bookmark = $this->privateLinkDB->get(43); |
202 | $this->assertEquals(43, $bookmark->getId()); | 202 | $this->assertEquals(43, $bookmark->getId()); |
203 | $this->assertRegExp('/\?[\w\-]{6}/', $bookmark->getUrl()); | 203 | $this->assertRegExp('#/shaare/[\w\-]{6}#', $bookmark->getUrl()); |
204 | $this->assertRegExp('/[\w\-]{6}/', $bookmark->getShortUrl()); | 204 | $this->assertRegExp('/[\w\-]{6}/', $bookmark->getShortUrl()); |
205 | $this->assertEquals($bookmark->getUrl(), $bookmark->getTitle()); | 205 | $this->assertEquals($bookmark->getUrl(), $bookmark->getTitle()); |
206 | $this->assertEmpty($bookmark->getDescription()); | 206 | $this->assertEmpty($bookmark->getDescription()); |
@@ -216,7 +216,7 @@ class BookmarkFileServiceTest extends TestCase | |||
216 | 216 | ||
217 | $bookmark = $this->privateLinkDB->get(43); | 217 | $bookmark = $this->privateLinkDB->get(43); |
218 | $this->assertEquals(43, $bookmark->getId()); | 218 | $this->assertEquals(43, $bookmark->getId()); |
219 | $this->assertRegExp('/\?[\w\-]{6}/', $bookmark->getUrl()); | 219 | $this->assertRegExp('#/shaare/[\w\-]{6}#', $bookmark->getUrl()); |
220 | $this->assertRegExp('/[\w\-]{6}/', $bookmark->getShortUrl()); | 220 | $this->assertRegExp('/[\w\-]{6}/', $bookmark->getShortUrl()); |
221 | $this->assertEquals($bookmark->getUrl(), $bookmark->getTitle()); | 221 | $this->assertEquals($bookmark->getUrl(), $bookmark->getTitle()); |
222 | $this->assertEmpty($bookmark->getDescription()); | 222 | $this->assertEmpty($bookmark->getDescription()); |
@@ -340,7 +340,7 @@ class BookmarkFileServiceTest extends TestCase | |||
340 | 340 | ||
341 | $bookmark = $this->privateLinkDB->get(42); | 341 | $bookmark = $this->privateLinkDB->get(42); |
342 | $this->assertEquals(42, $bookmark->getId()); | 342 | $this->assertEquals(42, $bookmark->getId()); |
343 | $this->assertEquals('?WDWyig', $bookmark->getUrl()); | 343 | $this->assertEquals('/shaare/WDWyig', $bookmark->getUrl()); |
344 | $this->assertEquals('1eYJ1Q', $bookmark->getShortUrl()); | 344 | $this->assertEquals('1eYJ1Q', $bookmark->getShortUrl()); |
345 | $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle()); | 345 | $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle()); |
346 | $this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription()); | 346 | $this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription()); |
@@ -359,7 +359,7 @@ class BookmarkFileServiceTest extends TestCase | |||
359 | 359 | ||
360 | $bookmark = $this->privateLinkDB->get(42); | 360 | $bookmark = $this->privateLinkDB->get(42); |
361 | $this->assertEquals(42, $bookmark->getId()); | 361 | $this->assertEquals(42, $bookmark->getId()); |
362 | $this->assertEquals('?WDWyig', $bookmark->getUrl()); | 362 | $this->assertEquals('/shaare/WDWyig', $bookmark->getUrl()); |
363 | $this->assertEquals('1eYJ1Q', $bookmark->getShortUrl()); | 363 | $this->assertEquals('1eYJ1Q', $bookmark->getShortUrl()); |
364 | $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle()); | 364 | $this->assertEquals('Note: I have a big ID but an old date', $bookmark->getTitle()); |
365 | $this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription()); | 365 | $this->assertEquals('Used to test bookmarks reordering.', $bookmark->getDescription()); |
@@ -816,7 +816,6 @@ class BookmarkFileServiceTest extends TestCase | |||
816 | ); | 816 | ); |
817 | $this->assertEquals( | 817 | $this->assertEquals( |
818 | [ | 818 | [ |
819 | 'web' => 4, | ||
820 | 'cartoon' => 2, | 819 | 'cartoon' => 2, |
821 | 'gnu' => 1, | 820 | 'gnu' => 1, |
822 | 'dev' => 1, | 821 | 'dev' => 1, |
@@ -833,7 +832,6 @@ class BookmarkFileServiceTest extends TestCase | |||
833 | ); | 832 | ); |
834 | $this->assertEquals( | 833 | $this->assertEquals( |
835 | [ | 834 | [ |
836 | 'web' => 1, | ||
837 | 'html' => 1, | 835 | 'html' => 1, |
838 | 'w3c' => 1, | 836 | 'w3c' => 1, |
839 | 'css' => 1, | 837 | 'css' => 1, |
@@ -894,35 +892,35 @@ class BookmarkFileServiceTest extends TestCase | |||
894 | public function testFilterHashValid() | 892 | public function testFilterHashValid() |
895 | { | 893 | { |
896 | $request = smallHash('20150310_114651'); | 894 | $request = smallHash('20150310_114651'); |
897 | $this->assertEquals( | 895 | $this->assertSame( |
898 | 1, | 896 | $request, |
899 | count($this->publicLinkDB->findByHash($request)) | 897 | $this->publicLinkDB->findByHash($request)->getShortUrl() |
900 | ); | 898 | ); |
901 | $request = smallHash('20150310_114633' . 8); | 899 | $request = smallHash('20150310_114633' . 8); |
902 | $this->assertEquals( | 900 | $this->assertSame( |
903 | 1, | 901 | $request, |
904 | count($this->publicLinkDB->findByHash($request)) | 902 | $this->publicLinkDB->findByHash($request)->getShortUrl() |
905 | ); | 903 | ); |
906 | } | 904 | } |
907 | 905 | ||
908 | /** | 906 | /** |
909 | * Test filterHash() with an invalid smallhash. | 907 | * Test filterHash() with an invalid smallhash. |
910 | * | ||
911 | * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException | ||
912 | */ | 908 | */ |
913 | public function testFilterHashInValid1() | 909 | public function testFilterHashInValid1() |
914 | { | 910 | { |
911 | $this->expectException(BookmarkNotFoundException::class); | ||
912 | |||
915 | $request = 'blabla'; | 913 | $request = 'blabla'; |
916 | $this->publicLinkDB->findByHash($request); | 914 | $this->publicLinkDB->findByHash($request); |
917 | } | 915 | } |
918 | 916 | ||
919 | /** | 917 | /** |
920 | * Test filterHash() with an empty smallhash. | 918 | * Test filterHash() with an empty smallhash. |
921 | * | ||
922 | * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException | ||
923 | */ | 919 | */ |
924 | public function testFilterHashInValid() | 920 | public function testFilterHashInValid() |
925 | { | 921 | { |
922 | $this->expectException(BookmarkNotFoundException::class); | ||
923 | |||
926 | $this->publicLinkDB->findByHash(''); | 924 | $this->publicLinkDB->findByHash(''); |
927 | } | 925 | } |
928 | 926 | ||
@@ -968,7 +966,6 @@ class BookmarkFileServiceTest extends TestCase | |||
968 | public function testCountLinkPerTagAllWithFilter() | 966 | public function testCountLinkPerTagAllWithFilter() |
969 | { | 967 | { |
970 | $expected = [ | 968 | $expected = [ |
971 | 'gnu' => 2, | ||
972 | 'hashtag' => 2, | 969 | 'hashtag' => 2, |
973 | '-exclude' => 1, | 970 | '-exclude' => 1, |
974 | '.hidden' => 1, | 971 | '.hidden' => 1, |
@@ -991,7 +988,6 @@ class BookmarkFileServiceTest extends TestCase | |||
991 | public function testCountLinkPerTagPublicWithFilter() | 988 | public function testCountLinkPerTagPublicWithFilter() |
992 | { | 989 | { |
993 | $expected = [ | 990 | $expected = [ |
994 | 'gnu' => 2, | ||
995 | 'hashtag' => 2, | 991 | 'hashtag' => 2, |
996 | '-exclude' => 1, | 992 | '-exclude' => 1, |
997 | '.hidden' => 1, | 993 | '.hidden' => 1, |
@@ -1015,7 +1011,6 @@ class BookmarkFileServiceTest extends TestCase | |||
1015 | { | 1011 | { |
1016 | $expected = [ | 1012 | $expected = [ |
1017 | 'cartoon' => 1, | 1013 | 'cartoon' => 1, |
1018 | 'dev' => 1, | ||
1019 | 'tag1' => 1, | 1014 | 'tag1' => 1, |
1020 | 'tag2' => 1, | 1015 | 'tag2' => 1, |
1021 | 'tag3' => 1, | 1016 | 'tag3' => 1, |
diff --git a/tests/bookmark/BookmarkInitializerTest.php b/tests/bookmark/BookmarkInitializerTest.php index d23eb069..3906cc7f 100644 --- a/tests/bookmark/BookmarkInitializerTest.php +++ b/tests/bookmark/BookmarkInitializerTest.php | |||
@@ -3,7 +3,6 @@ | |||
3 | namespace Shaarli\Bookmark; | 3 | namespace Shaarli\Bookmark; |
4 | 4 | ||
5 | use PHPUnit\Framework\TestCase; | 5 | use PHPUnit\Framework\TestCase; |
6 | use ReferenceLinkDB; | ||
7 | use Shaarli\Config\ConfigManager; | 6 | use Shaarli\Config\ConfigManager; |
8 | use Shaarli\History; | 7 | use Shaarli\History; |
9 | 8 | ||
@@ -54,9 +53,9 @@ class BookmarkInitializerTest extends TestCase | |||
54 | } | 53 | } |
55 | 54 | ||
56 | /** | 55 | /** |
57 | * Test initialize() with an empty data store. | 56 | * Test initialize() with a data store containing bookmarks. |
58 | */ | 57 | */ |
59 | public function testInitializeEmptyDataStore() | 58 | public function testInitializeNotEmptyDataStore(): void |
60 | { | 59 | { |
61 | $refDB = new \ReferenceLinkDB(); | 60 | $refDB = new \ReferenceLinkDB(); |
62 | $refDB->write(self::$testDatastore); | 61 | $refDB->write(self::$testDatastore); |
@@ -79,6 +78,8 @@ class BookmarkInitializerTest extends TestCase | |||
79 | ); | 78 | ); |
80 | $this->assertFalse($bookmark->isPrivate()); | 79 | $this->assertFalse($bookmark->isPrivate()); |
81 | 80 | ||
81 | $this->bookmarkService->save(); | ||
82 | |||
82 | // Reload from file | 83 | // Reload from file |
83 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | 84 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); |
84 | $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); | 85 | $this->assertEquals($refDB->countLinks() + 2, $this->bookmarkService->count()); |
@@ -97,10 +98,13 @@ class BookmarkInitializerTest extends TestCase | |||
97 | } | 98 | } |
98 | 99 | ||
99 | /** | 100 | /** |
100 | * Test initialize() with a data store containing bookmarks. | 101 | * Test initialize() with an a non existent datastore file . |
101 | */ | 102 | */ |
102 | public function testInitializeNotEmptyDataStore() | 103 | public function testInitializeNonExistentDataStore(): void |
103 | { | 104 | { |
105 | $this->conf->set('resource.datastore', static::$testDatastore . '_empty'); | ||
106 | $this->bookmarkService = new BookmarkFileService($this->conf, $this->history, true); | ||
107 | |||
104 | $this->initializer->initialize(); | 108 | $this->initializer->initialize(); |
105 | 109 | ||
106 | $this->assertEquals(2, $this->bookmarkService->count()); | 110 | $this->assertEquals(2, $this->bookmarkService->count()); |
diff --git a/tests/bookmark/BookmarkTest.php b/tests/bookmark/BookmarkTest.php index 9a3bbbfc..4b6a3c07 100644 --- a/tests/bookmark/BookmarkTest.php +++ b/tests/bookmark/BookmarkTest.php | |||
@@ -124,8 +124,8 @@ class BookmarkTest extends TestCase | |||
124 | $this->assertEquals(1, $bookmark->getId()); | 124 | $this->assertEquals(1, $bookmark->getId()); |
125 | $this->assertEquals('abc', $bookmark->getShortUrl()); | 125 | $this->assertEquals('abc', $bookmark->getShortUrl()); |
126 | $this->assertEquals($date, $bookmark->getCreated()); | 126 | $this->assertEquals($date, $bookmark->getCreated()); |
127 | $this->assertEquals('?abc', $bookmark->getUrl()); | 127 | $this->assertEquals('/shaare/abc', $bookmark->getUrl()); |
128 | $this->assertEquals('?abc', $bookmark->getTitle()); | 128 | $this->assertEquals('/shaare/abc', $bookmark->getTitle()); |
129 | $this->assertEquals('', $bookmark->getDescription()); | 129 | $this->assertEquals('', $bookmark->getDescription()); |
130 | $this->assertEquals([], $bookmark->getTags()); | 130 | $this->assertEquals([], $bookmark->getTags()); |
131 | $this->assertEquals('', $bookmark->getTagsString()); | 131 | $this->assertEquals('', $bookmark->getTagsString()); |
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php index 591976f2..7d4a7b89 100644 --- a/tests/bookmark/LinkUtilsTest.php +++ b/tests/bookmark/LinkUtilsTest.php | |||
@@ -3,8 +3,6 @@ | |||
3 | namespace Shaarli\Bookmark; | 3 | namespace Shaarli\Bookmark; |
4 | 4 | ||
5 | use PHPUnit\Framework\TestCase; | 5 | use PHPUnit\Framework\TestCase; |
6 | use ReferenceLinkDB; | ||
7 | use Shaarli\Config\ConfigManager; | ||
8 | 6 | ||
9 | require_once 'tests/utils/CurlUtils.php'; | 7 | require_once 'tests/utils/CurlUtils.php'; |
10 | 8 | ||
@@ -491,7 +489,7 @@ class LinkUtilsTest extends TestCase | |||
491 | */ | 489 | */ |
492 | private function getHashtagLink($hashtag, $index = '') | 490 | private function getHashtagLink($hashtag, $index = '') |
493 | { | 491 | { |
494 | $hashtagLink = '<a href="' . $index . '?addtag=$1" title="Hashtag $1">#$1</a>'; | 492 | $hashtagLink = '<a href="' . $index . './add-tag/$1" title="Hashtag $1">#$1</a>'; |
495 | return str_replace('$1', $hashtag, $hashtagLink); | 493 | return str_replace('$1', $hashtag, $hashtagLink); |
496 | } | 494 | } |
497 | } | 495 | } |