namespace Shaarli\Formatter;
use DateTime;
-use PHPUnit\Framework\TestCase;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Config\ConfigManager;
+use Shaarli\TestCase;
/**
* Class BookmarkDefaultFormatterTest
/**
* Initialize formatter instance.
*/
- public function setUp()
+ protected function setUp(): void
{
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);
}
/**
$description[0] = 'This a <strong>description</strong><br />';
$url = 'https://sub.domain.tld?query=here&for=real#hash';
$description[1] = 'text <a href="'. $url .'">'. $url .'</a> more text<br />';
- $description[2] = 'Also, there is an <a href="?addtag=hashtag" '.
+ $description[2] = 'Also, there is an <a href="./add-tag/hashtag" '.
'title="Hashtag hashtag">#hashtag</a> added<br />';
$description[3] = ' A N D KEEP '.
'SPACES ! <br />';
$this->assertEquals($root . $short, $link['url']);
$this->assertEquals($root . $short, $link['real_url']);
$this->assertEquals(
- 'Text <a href="'. $root .'?addtag=hashtag" title="Hashtag hashtag">'.
+ 'Text <a href="'. $root .'./add-tag/hashtag" title="Hashtag hashtag">'.
'#hashtag</a> more text',
$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']);
+ }
}