3 namespace Shaarli\Netscape
;
5 use PHPUnit\Framework\TestCase
;
6 use Shaarli\Bookmark\BookmarkFileService
;
7 use Shaarli\Config\ConfigManager
;
8 use Shaarli\Formatter\BookmarkFormatter
;
9 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()
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
80 * @expectedException Exception
81 * @expectedExceptionMessageRegExp /Invalid export selection/
83 public function testFilterAndFormatInvalid()
85 $this->netscapeBookmarkUtils
->filterAndFormat(
94 * Prepare all bookmarks for export
96 public function testFilterAndFormatAll()
98 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
104 $this->assertEquals(self
::$refDb->countLinks(), sizeof($links));
105 foreach ($links as $link) {
106 $date = $link['created'];
108 $date->getTimestamp(),
112 str_replace(' ', ',', $link['tags']),
119 * Prepare private bookmarks for export
121 public function testFilterAndFormatPrivate()
123 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
129 $this->assertEquals(self
::$refDb->countPrivateLinks(), sizeof($links));
130 foreach ($links as $link) {
131 $date = $link['created'];
133 $date->getTimestamp(),
137 str_replace(' ', ',', $link['tags']),
144 * Prepare public bookmarks for export
146 public function testFilterAndFormatPublic()
148 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
154 $this->assertEquals(self
::$refDb->countPublicLinks(), sizeof($links));
155 foreach ($links as $link) {
156 $date = $link['created'];
158 $date->getTimestamp(),
162 str_replace(' ', ',', $link['tags']),
169 * Do not prepend notes with the Shaarli index's URL
171 public function testFilterAndFormatDoNotPrependNoteUrl()
173 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
186 * Prepend notes with the Shaarli index's URL
188 public function testFilterAndFormatPrependNoteUrl()
190 $indexUrl = 'http://localhost:7469/shaarli/';
191 $links = $this->netscapeBookmarkUtils
->filterAndFormat(
198 $indexUrl . 'shaare/WDWyig',