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 <virtualtam@flibidi.net>
This commit is contained in:
parent
745304c842
commit
cd5327bee8
5 changed files with 202 additions and 42 deletions
104
tests/NetscapeBookmarkUtilsTest.php
Normal file
104
tests/NetscapeBookmarkUtilsTest.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
require_once 'application/NetscapeBookmarkUtils.php';
|
||||
|
||||
/**
|
||||
* Netscape bookmark import and export
|
||||
*/
|
||||
class NetscapeBookmarkUtilsTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var string datastore to test write operations
|
||||
*/
|
||||
protected static $testDatastore = 'sandbox/datastore.php';
|
||||
|
||||
/**
|
||||
* @var ReferenceLinkDB instance.
|
||||
*/
|
||||
protected static $refDb = null;
|
||||
|
||||
/**
|
||||
* @var LinkDB private LinkDB instance.
|
||||
*/
|
||||
protected static $linkDb = null;
|
||||
|
||||
/**
|
||||
* Instantiate reference data
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$refDb = new ReferenceLinkDB();
|
||||
self::$refDb->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']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue