3 require_once 'application/NetscapeBookmarkUtils.php';
6 * Netscape bookmark export
8 class BookmarkExportTest
extends PHPUnit_Framework_TestCase
11 * @var string datastore to test write operations
13 protected static $testDatastore = 'sandbox/datastore.php';
16 * @var ReferenceLinkDB instance.
18 protected static $refDb = null;
21 * @var LinkDB private LinkDB instance.
23 protected static $linkDb = null;
26 * Instantiate reference data
28 public static function setUpBeforeClass()
30 self
::$refDb = new ReferenceLinkDB();
31 self
::$refDb->write(self
::$testDatastore);
32 self
::$linkDb = new LinkDB(self
::$testDatastore, true, false);
36 * Attempt to export an invalid link selection
37 * @expectedException Exception
38 * @expectedExceptionMessageRegExp /Invalid export selection/
40 public function testFilterAndFormatInvalid()
42 NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'derp', false, '');
46 * Prepare all links for export
48 public function testFilterAndFormatAll()
50 $links = NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'all', false, '');
51 $this->assertEquals(self
::$refDb->countLinks(), sizeof($links));
52 foreach ($links as $link) {
53 $date = DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, $link['linkdate']);
55 $date->getTimestamp(),
59 str_replace(' ', ',', $link['tags']),
66 * Prepare private links for export
68 public function testFilterAndFormatPrivate()
70 $links = NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'private', false, '');
71 $this->assertEquals(self
::$refDb->countPrivateLinks(), sizeof($links));
72 foreach ($links as $link) {
73 $date = DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, $link['linkdate']);
75 $date->getTimestamp(),
79 str_replace(' ', ',', $link['tags']),
86 * Prepare public links for export
88 public function testFilterAndFormatPublic()
90 $links = NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'public', false, '');
91 $this->assertEquals(self
::$refDb->countPublicLinks(), sizeof($links));
92 foreach ($links as $link) {
93 $date = DateTime
::createFromFormat(LinkDB
::LINK_DATE_FORMAT
, $link['linkdate']);
95 $date->getTimestamp(),
99 str_replace(' ', ',', $link['tags']),
106 * Do not prepend notes with the Shaarli index's URL
108 public function testFilterAndFormatDoNotPrependNoteUrl()
110 $links = NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'public', false, '');
118 * Prepend notes with the Shaarli index's URL
120 public function testFilterAndFormatPrependNoteUrl()
122 $indexUrl = 'http://localhost:7469/shaarli/';
123 $links = NetscapeBookmarkUtils
::filterAndFormat(
130 $indexUrl . '?WDWyig',