3 namespace Shaarli\Netscape
;
5 use Shaarli\Bookmark\BookmarkFileService
;
6 use Shaarli\Config\ConfigManager
;
7 use Shaarli\Formatter\BookmarkFormatter
;
8 use Shaarli\Formatter\FormatterFactory
;
12 require_once 'tests/utils/ReferenceLinkDB.php';
15 * Netscape bookmark export
17 class BookmarkExportTest
extends TestCase
20 * @var string datastore to test write operations
22 protected static $testDatastore = 'sandbox/datastore.php';
25 * @var ConfigManager instance.
27 protected static $conf;
30 * @var \ReferenceLinkDB instance.
32 protected static $refDb = null;
35 * @var BookmarkFileService private instance.
37 protected static $bookmarkService = null;
40 * @var BookmarkFormatter instance
42 protected static $formatter;
45 * @var History instance
47 protected static $history;
50 * @var NetscapeBookmarkUtils
52 protected $netscapeBookmarkUtils;
55 * Instantiate reference data
57 public static function setUpBeforeClass(): void
59 static::$conf = new ConfigManager('tests/utils/config/configJson');
60 static::$conf->set('resource.datastore', static::$testDatastore);
61 static::$refDb = new \
ReferenceLinkDB();
62 static::$refDb->write(static::$testDatastore);
63 static::$history = new History('sandbox/history.php');
64 static::$bookmarkService = new BookmarkFileService(static::$conf, static::$history, true);
65 $factory = new FormatterFactory(static::$conf, true);
66 static::$formatter = $factory->getFormatter('raw');
69 public function setUp(): void
71 $this->netscapeBookmarkUtils
= new NetscapeBookmarkUtils(
72 static::$bookmarkService,
79 * Attempt to export an invalid link selection
81 public function testFilterAndFormatInvalid()
83 $this->expectException(\Exception
::class);
84 $this->expectExceptionMessageRegExp('/Invalid export selection/');
86 $this->netscapeBookmarkUtils
->filterAndFormat(
95 * Prepare all bookmarks for export
97 public function testFilterAndFormatAll()
99 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
105 $this->assertEquals(self
::$refDb->countLinks(), sizeof($links));
106 foreach ($links as $link) {
107 $date = $link['created'];
109 $date->getTimestamp(),
113 str_replace(' ', ',', $link['tags']),
120 * Prepare private bookmarks for export
122 public function testFilterAndFormatPrivate()
124 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
130 $this->assertEquals(self
::$refDb->countPrivateLinks(), sizeof($links));
131 foreach ($links as $link) {
132 $date = $link['created'];
134 $date->getTimestamp(),
138 str_replace(' ', ',', $link['tags']),
145 * Prepare public bookmarks for export
147 public function testFilterAndFormatPublic()
149 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
155 $this->assertEquals(self
::$refDb->countPublicLinks(), sizeof($links));
156 foreach ($links as $link) {
157 $date = $link['created'];
159 $date->getTimestamp(),
163 str_replace(' ', ',', $link['tags']),
170 * Do not prepend notes with the Shaarli index's URL
172 public function testFilterAndFormatDoNotPrependNoteUrl()
174 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
187 * Prepend notes with the Shaarli index's URL
189 public function testFilterAndFormatPrependNoteUrl()
191 $indexUrl = 'http://localhost:7469/shaarli/';
192 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
199 $indexUrl . 'shaare/WDWyig',