2 namespace Shaarli\Netscape
;
4 use Shaarli\Bookmark\LinkDB
;
6 require_once 'tests/utils/ReferenceLinkDB.php';
9 * Netscape bookmark export
11 class BookmarkExportTest
extends \PHPUnit\Framework\TestCase
14 * @var string datastore to test write operations
16 protected static $testDatastore = 'sandbox/datastore.php';
19 * @var \ReferenceLinkDB instance.
21 protected static $refDb = null;
24 * @var LinkDB private LinkDB instance.
26 protected static $linkDb = null;
29 * Instantiate reference data
31 public static function setUpBeforeClass()
33 self
::$refDb = new \
ReferenceLinkDB();
34 self
::$refDb->write(self
::$testDatastore);
35 self
::$linkDb = new LinkDB(self
::$testDatastore, true, false);
39 * Attempt to export an invalid link selection
40 * @expectedException Exception
41 * @expectedExceptionMessageRegExp /Invalid export selection/
43 public function testFilterAndFormatInvalid()
45 NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'derp', false, '');
49 * Prepare all links for export
51 public function testFilterAndFormatAll()
53 $links = NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'all', false, '');
54 $this->assertEquals(self
::$refDb->countLinks(), sizeof($links));
55 foreach ($links as $link) {
56 $date = $link['created'];
58 $date->getTimestamp(),
62 str_replace(' ', ',', $link['tags']),
69 * Prepare private links for export
71 public function testFilterAndFormatPrivate()
73 $links = NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'private', false, '');
74 $this->assertEquals(self
::$refDb->countPrivateLinks(), sizeof($links));
75 foreach ($links as $link) {
76 $date = $link['created'];
78 $date->getTimestamp(),
82 str_replace(' ', ',', $link['tags']),
89 * Prepare public links for export
91 public function testFilterAndFormatPublic()
93 $links = NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'public', false, '');
94 $this->assertEquals(self
::$refDb->countPublicLinks(), sizeof($links));
95 foreach ($links as $link) {
96 $date = $link['created'];
98 $date->getTimestamp(),
102 str_replace(' ', ',', $link['tags']),
109 * Do not prepend notes with the Shaarli index's URL
111 public function testFilterAndFormatDoNotPrependNoteUrl()
113 $links = NetscapeBookmarkUtils
::filterAndFormat(self
::$linkDb, 'public', false, '');
121 * Prepend notes with the Shaarli index's URL
123 public function testFilterAndFormatPrependNoteUrl()
125 $indexUrl = 'http://localhost:7469/shaarli/';
126 $links = NetscapeBookmarkUtils
::filterAndFormat(
133 $indexUrl . '?WDWyig',