2 namespace Shaarli\Netscape
;
4 use Shaarli\Bookmark\BookmarkFileService
;
5 use Shaarli\Bookmark\LinkDB
;
6 use Shaarli\Config\ConfigManager
;
7 use Shaarli\Formatter\FormatterFactory
;
8 use Shaarli\Formatter\BookmarkFormatter
;
11 require_once 'tests/utils/ReferenceLinkDB.php';
14 * Netscape bookmark export
16 class BookmarkExportTest
extends \PHPUnit\Framework\TestCase
19 * @var string datastore to test write operations
21 protected static $testDatastore = 'sandbox/datastore.php';
24 * @var \ReferenceLinkDB instance.
26 protected static $refDb = null;
29 * @var BookmarkFileService private instance.
31 protected static $bookmarkService = null;
34 * @var BookmarkFormatter instance
36 protected static $formatter;
39 * Instantiate reference data
41 public static function setUpBeforeClass()
43 $conf = new ConfigManager('tests/utils/config/configJson');
44 $conf->set('resource.datastore', self
::$testDatastore);
45 self
::$refDb = new \
ReferenceLinkDB();
46 self
::$refDb->write(self
::$testDatastore);
47 $history = new History('sandbox/history.php');
48 self
::$bookmarkService = new BookmarkFileService($conf, $history, true);
49 $factory = new FormatterFactory($conf, true);
50 self
::$formatter = $factory->getFormatter('raw');
54 * Attempt to export an invalid link selection
55 * @expectedException Exception
56 * @expectedExceptionMessageRegExp /Invalid export selection/
58 public function testFilterAndFormatInvalid()
60 NetscapeBookmarkUtils
::filterAndFormat(
61 self
::$bookmarkService,
70 * Prepare all bookmarks for export
72 public function testFilterAndFormatAll()
74 $links = NetscapeBookmarkUtils
::filterAndFormat(
75 self
::$bookmarkService,
81 $this->assertEquals(self
::$refDb->countLinks(), sizeof($links));
82 foreach ($links as $link) {
83 $date = $link['created'];
85 $date->getTimestamp(),
89 str_replace(' ', ',', $link['tags']),
96 * Prepare private bookmarks for export
98 public function testFilterAndFormatPrivate()
100 $links = NetscapeBookmarkUtils
::filterAndFormat(
101 self
::$bookmarkService,
107 $this->assertEquals(self
::$refDb->countPrivateLinks(), sizeof($links));
108 foreach ($links as $link) {
109 $date = $link['created'];
111 $date->getTimestamp(),
115 str_replace(' ', ',', $link['tags']),
122 * Prepare public bookmarks for export
124 public function testFilterAndFormatPublic()
126 $links = NetscapeBookmarkUtils
::filterAndFormat(
127 self
::$bookmarkService,
133 $this->assertEquals(self
::$refDb->countPublicLinks(), sizeof($links));
134 foreach ($links as $link) {
135 $date = $link['created'];
137 $date->getTimestamp(),
141 str_replace(' ', ',', $link['tags']),
148 * Do not prepend notes with the Shaarli index's URL
150 public function testFilterAndFormatDoNotPrependNoteUrl()
152 $links = NetscapeBookmarkUtils
::filterAndFormat(
153 self
::$bookmarkService,
166 * Prepend notes with the Shaarli index's URL
168 public function testFilterAndFormatPrependNoteUrl()
170 $indexUrl = 'http://localhost:7469/shaarli/';
171 $links = NetscapeBookmarkUtils
::filterAndFormat(
172 self
::$bookmarkService,
179 $indexUrl . '?WDWyig',