3 use Shaarli\Bookmark\LinkDB
;
5 require_once 'application/NetscapeBookmarkUtils.php';
8 * Netscape bookmark export
10 class BookmarkExportTest
extends PHPUnit_Framework_TestCase
13 * @var string datastore to test write operations
15 protected static $testDatastore = 'sandbox/datastore.php';
18 * @var ReferenceLinkDB instance.
20 protected static $refDb = null;
23 * @var LinkDB private LinkDB instance.
25 protected static $linkDb = null;
28 * Instantiate reference data
30 public static function setUpBeforeClass()
32 self
::$refDb = new ReferenceLinkDB();
33 self
::$refDb->write(self
::$testDatastore);
34 self
::$linkDb = new LinkDB(self
::$testDatastore, true, false);
38 * Attempt to export an invalid link selection
39 * @expectedException Exception
40 * @expectedExceptionMessageRegExp /Invalid export selection/
42 public function testFilterAndFormatInvalid()
44 NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'derp', false, '');
48 * Prepare all links for export
50 public function testFilterAndFormatAll()
52 $links = NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'all', false, '');
53 $this->assertEquals(self
::$refDb->countLinks(), sizeof($links));
54 foreach ($links as $link) {
55 $date = $link['created'];
57 $date->getTimestamp(),
61 str_replace(' ', ',', $link['tags']),
68 * Prepare private links for export
70 public function testFilterAndFormatPrivate()
72 $links = NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'private', false, '');
73 $this->assertEquals(self
::$refDb->countPrivateLinks(), sizeof($links));
74 foreach ($links as $link) {
75 $date = $link['created'];
77 $date->getTimestamp(),
81 str_replace(' ', ',', $link['tags']),
88 * Prepare public links for export
90 public function testFilterAndFormatPublic()
92 $links = NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'public', false, '');
93 $this->assertEquals(self
::$refDb->countPublicLinks(), sizeof($links));
94 foreach ($links as $link) {
95 $date = $link['created'];
97 $date->getTimestamp(),
101 str_replace(' ', ',', $link['tags']),
108 * Do not prepend notes with the Shaarli index's URL
110 public function testFilterAndFormatDoNotPrependNoteUrl()
112 $links = NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'public', false, '');
120 * Prepend notes with the Shaarli index's URL
122 public function testFilterAndFormatPrependNoteUrl()
124 $indexUrl = 'http://localhost:7469/shaarli/';
125 $links = NetscapeBookmarkUtils
::filterAndFormat(
132 $indexUrl . '?WDWyig',