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
;
11 use Shaarli\Plugin\PluginManager
;
14 require_once 'tests/utils/ReferenceLinkDB.php';
17 * Netscape bookmark export
19 class BookmarkExportTest
extends TestCase
22 * @var string datastore to test write operations
24 protected static $testDatastore = 'sandbox/datastore.php';
27 * @var ConfigManager instance.
29 protected static $conf;
32 * @var \ReferenceLinkDB instance.
34 protected static $refDb = null;
37 * @var BookmarkFileService private instance.
39 protected static $bookmarkService = null;
42 * @var BookmarkFormatter instance
44 protected static $formatter;
47 * @var History instance
49 protected static $history;
51 /** @var PluginManager */
52 protected static $pluginManager;
55 * @var NetscapeBookmarkUtils
57 protected $netscapeBookmarkUtils;
60 * Instantiate reference data
62 public static function setUpBeforeClass(): void
64 $mutex = new NoMutex();
65 static::$conf = new ConfigManager('tests/utils/config/configJson');
66 static::$conf->set('resource.datastore', static::$testDatastore);
67 static::$refDb = new \
ReferenceLinkDB();
68 static::$refDb->write(static::$testDatastore);
69 static::$history = new History('sandbox/history.php');
70 static::$pluginManager = new PluginManager(static::$conf);
71 static::$bookmarkService = new BookmarkFileService(
73 static::$pluginManager,
78 $factory = new FormatterFactory(static::$conf, true);
79 static::$formatter = $factory->getFormatter('raw');
82 public function setUp(): void
84 $this->netscapeBookmarkUtils
= new NetscapeBookmarkUtils(
85 static::$bookmarkService,
92 * Attempt to export an invalid link selection
94 public function testFilterAndFormatInvalid()
96 $this->expectException(\Exception
::class);
97 $this->expectExceptionMessageRegExp('/Invalid export selection/');
99 $this->netscapeBookmarkUtils
->filterAndFormat(
108 * Prepare all bookmarks for export
110 public function testFilterAndFormatAll()
112 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
118 $this->assertEquals(self
::$refDb->countLinks(), sizeof($links));
119 foreach ($links as $link) {
120 $date = $link['created'];
122 $date->getTimestamp(),
126 str_replace(' ', ',', $link['tags']),
133 * Prepare private bookmarks for export
135 public function testFilterAndFormatPrivate()
137 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
143 $this->assertEquals(self
::$refDb->countPrivateLinks(), sizeof($links));
144 foreach ($links as $link) {
145 $date = $link['created'];
147 $date->getTimestamp(),
151 str_replace(' ', ',', $link['tags']),
158 * Prepare public bookmarks for export
160 public function testFilterAndFormatPublic()
162 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
168 $this->assertEquals(self
::$refDb->countPublicLinks(), sizeof($links));
169 foreach ($links as $link) {
170 $date = $link['created'];
172 $date->getTimestamp(),
176 str_replace(' ', ',', $link['tags']),
183 * Do not prepend notes with the Shaarli index's URL
185 public function testFilterAndFormatDoNotPrependNoteUrl()
187 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
200 * Prepend notes with the Shaarli index's URL
202 public function testFilterAndFormatPrependNoteUrl()
204 $indexUrl = 'http://localhost:7469/shaarli/';
205 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
212 $indexUrl . 'shaare/WDWyig',