aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-01-18 17:59:37 +0100
committerGitHub <noreply@github.com>2020-01-18 17:59:37 +0100
commit1001cc108fec759b076c9f6e12b71dea5d49fe9b (patch)
treed7b57a982129b2006d388c2f9d25d29eceee891a /tests
parent12523aea3458504be91854ce2f37d4f5991ccea2 (diff)
parenta39acb2518f272df8a601af72c13eabe2719dcb8 (diff)
downloadShaarli-1001cc108fec759b076c9f6e12b71dea5d49fe9b.tar.gz
Shaarli-1001cc108fec759b076c9f6e12b71dea5d49fe9b.tar.zst
Shaarli-1001cc108fec759b076c9f6e12b71dea5d49fe9b.zip
Fix an issue with private tags and fix nomarkdown tag (#1399)
Fix an issue with private tags and fix nomarkdown tag
Diffstat (limited to 'tests')
-rw-r--r--tests/bookmark/BookmarkFileServiceTest.php41
-rw-r--r--tests/feed/FeedBuilderTest.php2
-rw-r--r--tests/formatter/BookmarkDefaultFormatterTest.php23
-rw-r--r--tests/formatter/BookmarkMarkdownFormatterTest.php2
-rw-r--r--tests/formatter/BookmarkRawFormatterTest.php2
-rw-r--r--tests/formatter/FormatterFactoryTest.php2
-rw-r--r--tests/netscape/BookmarkExportTest.php2
7 files changed, 68 insertions, 6 deletions
diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php
index 1b438a7f..4900d41d 100644
--- a/tests/bookmark/BookmarkFileServiceTest.php
+++ b/tests/bookmark/BookmarkFileServiceTest.php
@@ -12,6 +12,7 @@ use ReflectionClass;
12use Shaarli; 12use Shaarli;
13use Shaarli\Bookmark\Exception\BookmarkNotFoundException; 13use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
14use Shaarli\Config\ConfigManager; 14use Shaarli\Config\ConfigManager;
15use Shaarli\Formatter\BookmarkMarkdownFormatter;
15use Shaarli\History; 16use Shaarli\History;
16 17
17/** 18/**
@@ -1026,6 +1027,46 @@ class BookmarkFileServiceTest extends TestCase
1026 } 1027 }
1027 1028
1028 /** 1029 /**
1030 * Test linksCountPerTag public tags with filter.
1031 * Equal occurrences should be sorted alphabetically.
1032 */
1033 public function testCountTagsNoMarkdown()
1034 {
1035 $expected = [
1036 'cartoon' => 3,
1037 'dev' => 2,
1038 'tag1' => 1,
1039 'tag2' => 1,
1040 'tag3' => 1,
1041 'tag4' => 1,
1042 'web' => 4,
1043 'gnu' => 2,
1044 'hashtag' => 2,
1045 'sTuff' => 2,
1046 '-exclude' => 1,
1047 '.hidden' => 1,
1048 'Mercurial' => 1,
1049 'css' => 1,
1050 'free' => 1,
1051 'html' => 1,
1052 'media' => 1,
1053 'newTagToCount' => 1,
1054 'samba' => 1,
1055 'software' => 1,
1056 'stallman' => 1,
1057 'ut' => 1,
1058 'w3c' => 1,
1059 ];
1060 $bookmark = new Bookmark();
1061 $bookmark->setTags(['newTagToCount', BookmarkMarkdownFormatter::NO_MD_TAG]);
1062 $this->privateLinkDB->add($bookmark);
1063
1064 $tags = $this->privateLinkDB->bookmarksCountPerTag();
1065
1066 $this->assertEquals($expected, $tags, var_export($tags, true));
1067 }
1068
1069 /**
1029 * Allows to test LinkDB's private methods 1070 * Allows to test LinkDB's private methods
1030 * 1071 *
1031 * @see 1072 * @see
diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php
index a43ff672..54671891 100644
--- a/tests/feed/FeedBuilderTest.php
+++ b/tests/feed/FeedBuilderTest.php
@@ -51,7 +51,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
51 $refLinkDB = new \ReferenceLinkDB(); 51 $refLinkDB = new \ReferenceLinkDB();
52 $refLinkDB->write(self::$testDatastore); 52 $refLinkDB->write(self::$testDatastore);
53 $history = new History('sandbox/history.php'); 53 $history = new History('sandbox/history.php');
54 $factory = new FormatterFactory($conf); 54 $factory = new FormatterFactory($conf, true);
55 self::$formatter = $factory->getFormatter(); 55 self::$formatter = $factory->getFormatter();
56 self::$bookmarkService = new BookmarkFileService($conf, $history, true); 56 self::$bookmarkService = new BookmarkFileService($conf, $history, true);
57 57
diff --git a/tests/formatter/BookmarkDefaultFormatterTest.php b/tests/formatter/BookmarkDefaultFormatterTest.php
index fe42a208..382a560e 100644
--- a/tests/formatter/BookmarkDefaultFormatterTest.php
+++ b/tests/formatter/BookmarkDefaultFormatterTest.php
@@ -29,7 +29,7 @@ class BookmarkDefaultFormatterTest extends TestCase
29 { 29 {
30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); 30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
31 $this->conf = new ConfigManager(self::$testConf); 31 $this->conf = new ConfigManager(self::$testConf);
32 $this->formatter = new BookmarkDefaultFormatter($this->conf); 32 $this->formatter = new BookmarkDefaultFormatter($this->conf, true);
33 } 33 }
34 34
35 /** 35 /**
@@ -153,4 +153,25 @@ class BookmarkDefaultFormatterTest extends TestCase
153 $link['description'] 153 $link['description']
154 ); 154 );
155 } 155 }
156
157 /**
158 * Make sure that private tags are properly filtered out when the user is logged out.
159 */
160 public function testFormatTagListRemovePrivate(): void
161 {
162 $this->formatter = new BookmarkDefaultFormatter($this->conf, false);
163
164 $bookmark = new Bookmark();
165 $bookmark->setId($id = 11);
166 $bookmark->setTags($tags = ['bookmark', '.private', 'othertag']);
167
168 $link = $this->formatter->format($bookmark);
169
170 unset($tags[1]);
171 $tags = array_values($tags);
172
173 $this->assertSame(11, $link['id']);
174 $this->assertSame($tags, $link['taglist']);
175 $this->assertSame(implode(' ', $tags), $link['tags']);
176 }
156} 177}
diff --git a/tests/formatter/BookmarkMarkdownFormatterTest.php b/tests/formatter/BookmarkMarkdownFormatterTest.php
index 0ca7f802..f1f12c04 100644
--- a/tests/formatter/BookmarkMarkdownFormatterTest.php
+++ b/tests/formatter/BookmarkMarkdownFormatterTest.php
@@ -29,7 +29,7 @@ class BookmarkMarkdownFormatterTest extends TestCase
29 { 29 {
30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); 30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
31 $this->conf = new ConfigManager(self::$testConf); 31 $this->conf = new ConfigManager(self::$testConf);
32 $this->formatter = new BookmarkMarkdownFormatter($this->conf); 32 $this->formatter = new BookmarkMarkdownFormatter($this->conf, true);
33 } 33 }
34 34
35 /** 35 /**
diff --git a/tests/formatter/BookmarkRawFormatterTest.php b/tests/formatter/BookmarkRawFormatterTest.php
index ceb6fb73..4491b035 100644
--- a/tests/formatter/BookmarkRawFormatterTest.php
+++ b/tests/formatter/BookmarkRawFormatterTest.php
@@ -29,7 +29,7 @@ class BookmarkRawFormatterTest extends TestCase
29 { 29 {
30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); 30 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
31 $this->conf = new ConfigManager(self::$testConf); 31 $this->conf = new ConfigManager(self::$testConf);
32 $this->formatter = new BookmarkRawFormatter($this->conf); 32 $this->formatter = new BookmarkRawFormatter($this->conf, true);
33 } 33 }
34 34
35 /** 35 /**
diff --git a/tests/formatter/FormatterFactoryTest.php b/tests/formatter/FormatterFactoryTest.php
index 317c0b2d..5adf3ffd 100644
--- a/tests/formatter/FormatterFactoryTest.php
+++ b/tests/formatter/FormatterFactoryTest.php
@@ -28,7 +28,7 @@ class FormatterFactoryTest extends TestCase
28 { 28 {
29 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php'); 29 copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
30 $this->conf = new ConfigManager(self::$testConf); 30 $this->conf = new ConfigManager(self::$testConf);
31 $this->factory = new FormatterFactory($this->conf); 31 $this->factory = new FormatterFactory($this->conf, true);
32 } 32 }
33 33
34 /** 34 /**
diff --git a/tests/netscape/BookmarkExportTest.php b/tests/netscape/BookmarkExportTest.php
index 011d19ac..6c948bba 100644
--- a/tests/netscape/BookmarkExportTest.php
+++ b/tests/netscape/BookmarkExportTest.php
@@ -46,7 +46,7 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase
46 self::$refDb->write(self::$testDatastore); 46 self::$refDb->write(self::$testDatastore);
47 $history = new History('sandbox/history.php'); 47 $history = new History('sandbox/history.php');
48 self::$bookmarkService = new BookmarkFileService($conf, $history, true); 48 self::$bookmarkService = new BookmarkFileService($conf, $history, true);
49 $factory = new FormatterFactory($conf); 49 $factory = new FormatterFactory($conf, true);
50 self::$formatter = $factory->getFormatter('raw'); 50 self::$formatter = $factory->getFormatter('raw');
51 } 51 }
52 52