From cd5327bee83f3e9467d786752bbd447963b941f7 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Sun, 10 Apr 2016 17:34:07 +0200 Subject: Refactor Netscape bookmark exporting Relates to https://github.com/shaarli/netscape-bookmark-parser/issues/5 Fixes: - respect the Netscape bookmark format "specification" Modifications: - [application] introduce the NetscapeBookmarkUtils class - [template] export - improve formatting, rename export selection parameter - [template] export.bookmarks - template for Netscape exports - [tests] bookmark filtering, additional field generation Signed-off-by: VirtualTam --- tests/NetscapeBookmarkUtilsTest.php | 104 ++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 tests/NetscapeBookmarkUtilsTest.php (limited to 'tests/NetscapeBookmarkUtilsTest.php') diff --git a/tests/NetscapeBookmarkUtilsTest.php b/tests/NetscapeBookmarkUtilsTest.php new file mode 100644 index 00000000..b7472d92 --- /dev/null +++ b/tests/NetscapeBookmarkUtilsTest.php @@ -0,0 +1,104 @@ +write(self::$testDatastore); + self::$linkDb = new LinkDB(self::$testDatastore, true, false); + } + + /** + * Attempt to export an invalid link selection + * @expectedException Exception + * @expectedExceptionMessageRegExp /Invalid export selection/ + */ + public function testFilterAndFormatInvalid() + { + NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'derp'); + } + + /** + * Prepare all links for export + */ + public function testFilterAndFormatAll() + { + $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'all'); + $this->assertEquals(self::$refDb->countLinks(), sizeof($links)); + foreach ($links as $link) { + $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); + $this->assertEquals( + $date->getTimestamp(), + $link['timestamp'] + ); + $this->assertEquals( + str_replace(' ', ',', $link['tags']), + $link['taglist'] + ); + } + } + + /** + * Prepare private links for export + */ + public function testFilterAndFormatPrivate() + { + $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'private'); + $this->assertEquals(self::$refDb->countPrivateLinks(), sizeof($links)); + foreach ($links as $link) { + $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); + $this->assertEquals( + $date->getTimestamp(), + $link['timestamp'] + ); + $this->assertEquals( + str_replace(' ', ',', $link['tags']), + $link['taglist'] + ); + } + } + + /** + * Prepare public links for export + */ + public function testFilterAndFormatPublic() + { + $links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public'); + $this->assertEquals(self::$refDb->countPublicLinks(), sizeof($links)); + foreach ($links as $link) { + $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']); + $this->assertEquals( + $date->getTimestamp(), + $link['timestamp'] + ); + $this->assertEquals( + str_replace(' ', ',', $link['tags']), + $link['taglist'] + ); + } + } +} -- cgit v1.2.3