Fix an issue with private tags and fix nomarkdown tag

The new bookmark service wasn't handling private tags properly.

nomarkdown tag is now shown only for logged in user in bookmarks, and hidden for everyone in tag clouds/lists.

Fixes 
This commit is contained in:
ArthurHoaro 2020-01-18 11:33:23 +01:00
parent 3fb29fdda0
commit a39acb2518
13 changed files with 145 additions and 33 deletions

View file

@ -12,6 +12,7 @@ use ReflectionClass;
use Shaarli;
use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
use Shaarli\Config\ConfigManager;
use Shaarli\Formatter\BookmarkMarkdownFormatter;
use Shaarli\History;
/**
@ -1025,6 +1026,46 @@ 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));
}
/**
* Allows to test LinkDB's private methods
*

View file

@ -51,7 +51,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
$refLinkDB = new \ReferenceLinkDB();
$refLinkDB->write(self::$testDatastore);
$history = new History('sandbox/history.php');
$factory = new FormatterFactory($conf);
$factory = new FormatterFactory($conf, true);
self::$formatter = $factory->getFormatter();
self::$bookmarkService = new BookmarkFileService($conf, $history, true);

View file

@ -29,7 +29,7 @@ class BookmarkDefaultFormatterTest extends TestCase
{
copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
$this->conf = new ConfigManager(self::$testConf);
$this->formatter = new BookmarkDefaultFormatter($this->conf);
$this->formatter = new BookmarkDefaultFormatter($this->conf, true);
}
/**
@ -153,4 +153,25 @@ class BookmarkDefaultFormatterTest extends TestCase
$link['description']
);
}
/**
* Make sure that private tags are properly filtered out when the user is logged out.
*/
public function testFormatTagListRemovePrivate(): void
{
$this->formatter = new BookmarkDefaultFormatter($this->conf, false);
$bookmark = new Bookmark();
$bookmark->setId($id = 11);
$bookmark->setTags($tags = ['bookmark', '.private', 'othertag']);
$link = $this->formatter->format($bookmark);
unset($tags[1]);
$tags = array_values($tags);
$this->assertSame(11, $link['id']);
$this->assertSame($tags, $link['taglist']);
$this->assertSame(implode(' ', $tags), $link['tags']);
}
}

View file

@ -29,7 +29,7 @@ class BookmarkMarkdownFormatterTest extends TestCase
{
copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
$this->conf = new ConfigManager(self::$testConf);
$this->formatter = new BookmarkMarkdownFormatter($this->conf);
$this->formatter = new BookmarkMarkdownFormatter($this->conf, true);
}
/**

View file

@ -29,7 +29,7 @@ class BookmarkRawFormatterTest extends TestCase
{
copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
$this->conf = new ConfigManager(self::$testConf);
$this->formatter = new BookmarkRawFormatter($this->conf);
$this->formatter = new BookmarkRawFormatter($this->conf, true);
}
/**

View file

@ -28,7 +28,7 @@ class FormatterFactoryTest extends TestCase
{
copy('tests/utils/config/configJson.json.php', self::$testConf .'.json.php');
$this->conf = new ConfigManager(self::$testConf);
$this->factory = new FormatterFactory($this->conf);
$this->factory = new FormatterFactory($this->conf, true);
}
/**

View file

@ -46,7 +46,7 @@ class BookmarkExportTest extends \PHPUnit\Framework\TestCase
self::$refDb->write(self::$testDatastore);
$history = new History('sandbox/history.php');
self::$bookmarkService = new BookmarkFileService($conf, $history, true);
$factory = new FormatterFactory($conf);
$factory = new FormatterFactory($conf, true);
self::$formatter = $factory->getFormatter('raw');
}