2016-04-10 17:34:07 +02:00
|
|
|
<?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()
|
|
|
|
{
|
2016-05-05 19:22:06 +02:00
|
|
|
NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'derp', false, '');
|
2016-04-10 17:34:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare all links for export
|
|
|
|
*/
|
|
|
|
public function testFilterAndFormatAll()
|
|
|
|
{
|
2016-05-05 19:22:06 +02:00
|
|
|
$links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'all', false, '');
|
2016-04-10 17:34:07 +02:00
|
|
|
$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()
|
|
|
|
{
|
2016-05-05 19:22:06 +02:00
|
|
|
$links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'private', false, '');
|
2016-04-10 17:34:07 +02:00
|
|
|
$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()
|
|
|
|
{
|
2016-05-05 19:22:06 +02:00
|
|
|
$links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, '');
|
2016-04-10 17:34:07 +02:00
|
|
|
$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']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-05-05 19:22:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Do not prepend notes with the Shaarli index's URL
|
|
|
|
*/
|
|
|
|
public function testFilterAndFormatDoNotPrependNoteUrl()
|
|
|
|
{
|
|
|
|
$links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, '');
|
|
|
|
$this->assertEquals(
|
|
|
|
'?WDWyig',
|
|
|
|
$links[0]['url']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepend notes with the Shaarli index's URL
|
|
|
|
*/
|
|
|
|
public function testFilterAndFormatPrependNoteUrl()
|
|
|
|
{
|
|
|
|
$indexUrl = 'http://localhost:7469/shaarli/';
|
|
|
|
$links = NetscapeBookmarkUtils::filterAndFormat(
|
|
|
|
self::$linkDb,
|
|
|
|
'public',
|
|
|
|
true,
|
|
|
|
$indexUrl
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$indexUrl . '?WDWyig',
|
|
|
|
$links[0]['url']
|
|
|
|
);
|
|
|
|
}
|
2016-04-10 17:34:07 +02:00
|
|
|
}
|