3 namespace Shaarli\Netscape
;
5 use malkusch\lock\mutex\NoMutex
;
6 use Shaarli\Bookmark\BookmarkFileService
;
7 use Shaarli\Config\ConfigManager
;
8 use Shaarli\Formatter\BookmarkFormatter
;
9 use Shaarli\Formatter\FormatterFactory
;
13 require_once 'tests/utils/ReferenceLinkDB.php';
16 * Netscape bookmark export
18 class BookmarkExportTest
extends TestCase
21 * @var string datastore to test write operations
23 protected static $testDatastore = 'sandbox/datastore.php';
26 * @var ConfigManager instance.
28 protected static $conf;
31 * @var \ReferenceLinkDB instance.
33 protected static $refDb = null;
36 * @var BookmarkFileService private instance.
38 protected static $bookmarkService = null;
41 * @var BookmarkFormatter instance
43 protected static $formatter;
46 * @var History instance
48 protected static $history;
51 * @var NetscapeBookmarkUtils
53 protected $netscapeBookmarkUtils;
56 * Instantiate reference data
58 public static function setUpBeforeClass(): void
60 $mutex = new NoMutex();
61 static::$conf = new ConfigManager('tests/utils/config/configJson');
62 static::$conf->set('resource.datastore', static::$testDatastore);
63 static::$refDb = new \
ReferenceLinkDB();
64 static::$refDb->write(static::$testDatastore);
65 static::$history = new History('sandbox/history.php');
66 static::$bookmarkService = new BookmarkFileService(static::$conf, static::$history, $mutex, true);
67 $factory = new FormatterFactory(static::$conf, true);
68 static::$formatter = $factory->getFormatter('raw');
71 public function setUp(): void
73 $this->netscapeBookmarkUtils
= new NetscapeBookmarkUtils(
74 static::$bookmarkService,
81 * Attempt to export an invalid link selection
83 public function testFilterAndFormatInvalid()
85 $this->expectException(\Exception
::class);
86 $this->expectExceptionMessageRegExp('/Invalid export selection/');
88 $this->netscapeBookmarkUtils
->filterAndFormat(
97 * Prepare all bookmarks for export
99 public function testFilterAndFormatAll()
101 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
107 $this->assertEquals(self
::$refDb->countLinks(), sizeof($links));
108 foreach ($links as $link) {
109 $date = $link['created'];
111 $date->getTimestamp(),
115 str_replace(' ', ',', $link['tags']),
122 * Prepare private bookmarks for export
124 public function testFilterAndFormatPrivate()
126 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
132 $this->assertEquals(self
::$refDb->countPrivateLinks(), sizeof($links));
133 foreach ($links as $link) {
134 $date = $link['created'];
136 $date->getTimestamp(),
140 str_replace(' ', ',', $link['tags']),
147 * Prepare public bookmarks for export
149 public function testFilterAndFormatPublic()
151 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
157 $this->assertEquals(self
::$refDb->countPublicLinks(), sizeof($links));
158 foreach ($links as $link) {
159 $date = $link['created'];
161 $date->getTimestamp(),
165 str_replace(' ', ',', $link['tags']),
172 * Do not prepend notes with the Shaarli index's URL
174 public function testFilterAndFormatDoNotPrependNoteUrl()
176 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
189 * Prepend notes with the Shaarli index's URL
191 public function testFilterAndFormatPrependNoteUrl()
193 $indexUrl = 'http://localhost:7469/shaarli/';
194 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
201 $indexUrl . 'shaare/WDWyig',