Unit Test for the new ID system
This commit is contained in:
parent
01878a75b9
commit
c3dfd89959
8 changed files with 307 additions and 96 deletions
|
@ -84,8 +84,9 @@ public function testRSSBuildData()
|
|||
$this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
|
||||
|
||||
// Test first link (note link)
|
||||
$link = array_shift($data['links']);
|
||||
$this->assertEquals('20150310_114651', $link['linkdate']);
|
||||
$link = reset($data['links']);
|
||||
$this->assertEquals(41, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
|
||||
$this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
|
||||
$this->assertEquals('http://host.tld/?WDWyig', $link['url']);
|
||||
$this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
|
||||
|
@ -99,14 +100,14 @@ public function testRSSBuildData()
|
|||
$this->assertEquals('sTuff', $link['taglist'][0]);
|
||||
|
||||
// Test URL with external link.
|
||||
$this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $data['links']['20150310_114633']['url']);
|
||||
$this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $data['links'][8]['url']);
|
||||
|
||||
// Test multitags.
|
||||
$this->assertEquals(5, count($data['links']['20141125_084734']['taglist']));
|
||||
$this->assertEquals('css', $data['links']['20141125_084734']['taglist'][0]);
|
||||
$this->assertEquals(5, count($data['links'][6]['taglist']));
|
||||
$this->assertEquals('css', $data['links'][6]['taglist'][0]);
|
||||
|
||||
// Test update date
|
||||
$this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links']['20150310_114633']['up_iso_date']);
|
||||
$this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,9 +120,9 @@ public function testAtomBuildData()
|
|||
$data = $feedBuilder->buildData();
|
||||
$this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
|
||||
$this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['last_update']);
|
||||
$link = array_shift($data['links']);
|
||||
$link = reset($data['links']);
|
||||
$this->assertRegExp('/2015-03-10T11:46:51\+\d{2}:\d{2}/', $link['pub_iso_date']);
|
||||
$this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links']['20150310_114633']['up_iso_date']);
|
||||
$this->assertRegExp('/2016-08-03T09:30:33\+\d{2}:\d{2}/', $data['links'][8]['up_iso_date']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,7 +139,8 @@ public function testBuildDataFiltered()
|
|||
$data = $feedBuilder->buildData();
|
||||
$this->assertEquals(1, count($data['links']));
|
||||
$link = array_shift($data['links']);
|
||||
$this->assertEquals('20150310_114651', $link['linkdate']);
|
||||
$this->assertEquals(41, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,7 +156,8 @@ public function testBuildDataCount()
|
|||
$data = $feedBuilder->buildData();
|
||||
$this->assertEquals(1, count($data['links']));
|
||||
$link = array_shift($data['links']);
|
||||
$this->assertEquals('20150310_114651', $link['linkdate']);
|
||||
$this->assertEquals(41, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,15 +173,17 @@ public function testBuildDataPermalinks()
|
|||
$this->assertTrue($data['usepermalinks']);
|
||||
// First link is a permalink
|
||||
$link = array_shift($data['links']);
|
||||
$this->assertEquals('20150310_114651', $link['linkdate']);
|
||||
$this->assertEquals(41, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
|
||||
$this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
|
||||
$this->assertEquals('http://host.tld/?WDWyig', $link['url']);
|
||||
$this->assertContains('Direct link', $link['description']);
|
||||
$this->assertContains('http://host.tld/?WDWyig', $link['description']);
|
||||
// Second link is a direct link
|
||||
$link = array_shift($data['links']);
|
||||
$this->assertEquals('20150310_114633', $link['linkdate']);
|
||||
$this->assertEquals('http://host.tld/?kLHmZg', $link['guid']);
|
||||
$this->assertEquals(8, $link['id']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114633'), $link['created']);
|
||||
$this->assertEquals('http://host.tld/?RttfEw', $link['guid']);
|
||||
$this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']);
|
||||
$this->assertContains('Direct link', $link['description']);
|
||||
$this->assertContains('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['description']);
|
||||
|
|
|
@ -186,14 +186,15 @@ public function testSave()
|
|||
$dbSize = sizeof($testDB);
|
||||
|
||||
$link = array(
|
||||
'id' => 42,
|
||||
'title'=>'an additional link',
|
||||
'url'=>'http://dum.my',
|
||||
'description'=>'One more',
|
||||
'private'=>0,
|
||||
'linkdate'=>'20150518_190000',
|
||||
'created'=> DateTime::createFromFormat('Ymd_His', '20150518_190000'),
|
||||
'tags'=>'unit test'
|
||||
);
|
||||
$testDB[$link['linkdate']] = $link;
|
||||
$testDB[$link['id']] = $link;
|
||||
$testDB->save('tests');
|
||||
|
||||
$testDB = new LinkDB(self::$testDatastore, true, false);
|
||||
|
@ -238,12 +239,12 @@ public function testCountHiddenPublic()
|
|||
public function testDays()
|
||||
{
|
||||
$this->assertEquals(
|
||||
array('20121206', '20130614', '20150310'),
|
||||
array('20100310', '20121206', '20130614', '20150310'),
|
||||
self::$publicLinkDB->days()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
array('20121206', '20130614', '20141125', '20150310'),
|
||||
array('20100310', '20121206', '20130614', '20141125', '20150310'),
|
||||
self::$privateLinkDB->days()
|
||||
);
|
||||
}
|
||||
|
@ -290,10 +291,11 @@ public function testAllTags()
|
|||
'stallman' => 1,
|
||||
'free' => 1,
|
||||
'-exclude' => 1,
|
||||
// The DB contains a link with `sTuff` and another one with `stuff` tag.
|
||||
// They need to be grouped with the first case found (`sTuff`).
|
||||
'sTuff' => 2,
|
||||
'hashtag' => 2,
|
||||
// The DB contains a link with `sTuff` and another one with `stuff` tag.
|
||||
// They need to be grouped with the first case found - order by date DESC: `sTuff`.
|
||||
'sTuff' => 2,
|
||||
'ut' => 1,
|
||||
),
|
||||
self::$publicLinkDB->allTags()
|
||||
);
|
||||
|
@ -321,6 +323,7 @@ public function testAllTags()
|
|||
'tag2' => 1,
|
||||
'tag3' => 1,
|
||||
'tag4' => 1,
|
||||
'ut' => 1,
|
||||
),
|
||||
self::$privateLinkDB->allTags()
|
||||
);
|
||||
|
@ -411,6 +414,11 @@ public function testFilterHashValid()
|
|||
1,
|
||||
count(self::$publicLinkDB->filterHash($request))
|
||||
);
|
||||
$request = smallHash('20150310_114633' . 8);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
count(self::$publicLinkDB->filterHash($request))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -433,4 +441,23 @@ public function testFilterHashInValid()
|
|||
{
|
||||
self::$publicLinkDB->filterHash('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test reorder with asc/desc parameter.
|
||||
*/
|
||||
public function testReorderLinksDesc()
|
||||
{
|
||||
self::$publicLinkDB->reorder('ASC');
|
||||
$linkIdToTest = 42;
|
||||
foreach (self::$publicLinkDB as $key => $value) {
|
||||
$this->assertEquals($linkIdToTest, $key);
|
||||
break;
|
||||
}
|
||||
self::$publicLinkDB->reorder('DESC');
|
||||
$linkIdToTest = 41;
|
||||
foreach (self::$publicLinkDB as $key => $value) {
|
||||
$this->assertEquals($linkIdToTest, $key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -159,7 +159,7 @@ public function testFilterSmallHash()
|
|||
|
||||
$this->assertEquals(
|
||||
'MediaGoblin',
|
||||
$links['20130614_184135']['title']
|
||||
$links[7]['title']
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -286,7 +286,7 @@ public function testExcludeSearch()
|
|||
);
|
||||
|
||||
$this->assertEquals(
|
||||
6,
|
||||
7,
|
||||
count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '-revolution'))
|
||||
);
|
||||
}
|
||||
|
@ -346,7 +346,7 @@ public function testTagFilterWithExclusion()
|
|||
);
|
||||
|
||||
$this->assertEquals(
|
||||
6,
|
||||
7,
|
||||
count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '-free'))
|
||||
);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public function testFilterAndFormatAll()
|
|||
$links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'all', false, '');
|
||||
$this->assertEquals(self::$refDb->countLinks(), sizeof($links));
|
||||
foreach ($links as $link) {
|
||||
$date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
|
||||
$date = $link['created'];
|
||||
$this->assertEquals(
|
||||
$date->getTimestamp(),
|
||||
$link['timestamp']
|
||||
|
@ -70,7 +70,7 @@ public function testFilterAndFormatPrivate()
|
|||
$links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'private', false, '');
|
||||
$this->assertEquals(self::$refDb->countPrivateLinks(), sizeof($links));
|
||||
foreach ($links as $link) {
|
||||
$date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
|
||||
$date = $link['created'];
|
||||
$this->assertEquals(
|
||||
$date->getTimestamp(),
|
||||
$link['timestamp']
|
||||
|
@ -90,7 +90,7 @@ public function testFilterAndFormatPublic()
|
|||
$links = NetscapeBookmarkUtils::filterAndFormat(self::$linkDb, 'public', false, '');
|
||||
$this->assertEquals(self::$refDb->countPublicLinks(), sizeof($links));
|
||||
foreach ($links as $link) {
|
||||
$date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
|
||||
$date = $link['created'];
|
||||
$this->assertEquals(
|
||||
$date->getTimestamp(),
|
||||
$link['timestamp']
|
||||
|
|
|
@ -42,6 +42,18 @@ class BookmarkImportTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
protected $pagecache = 'tests';
|
||||
|
||||
/**
|
||||
* @var string Save the current timezone.
|
||||
*/
|
||||
protected static $defaultTimeZone;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$defaultTimeZone = date_default_timezone_get();
|
||||
// Timezone without DST for test consistency
|
||||
date_default_timezone_set('Africa/Nairobi');
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets test data before each test
|
||||
*/
|
||||
|
@ -55,6 +67,11 @@ protected function setUp()
|
|||
$this->linkDb = new LinkDB(self::$testDatastore, true, false);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
date_default_timezone_set(self::$defaultTimeZone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to import bookmarks from an empty file
|
||||
*/
|
||||
|
@ -98,18 +115,19 @@ public function testImportInternetExplorerEncoding()
|
|||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'linkdate' => '20160618_173944',
|
||||
'id' => 0,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160618_203944'),
|
||||
'title' => 'Hg Init a Mercurial tutorial by Joel Spolsky',
|
||||
'url' => 'http://hginit.com/',
|
||||
'description' => '',
|
||||
'private' => 0,
|
||||
'tags' => ''
|
||||
'tags' => '',
|
||||
'shorturl' => 'La37cg',
|
||||
),
|
||||
$this->linkDb->getLinkFromUrl('http://hginit.com/')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Import bookmarks nested in a folder hierarchy
|
||||
*/
|
||||
|
@ -126,89 +144,105 @@ public function testImportNested()
|
|||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'linkdate' => '20160225_205541',
|
||||
'id' => 0,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235541'),
|
||||
'title' => 'Nested 1',
|
||||
'url' => 'http://nest.ed/1',
|
||||
'description' => '',
|
||||
'private' => 0,
|
||||
'tags' => 'tag1 tag2'
|
||||
'tags' => 'tag1 tag2',
|
||||
'shorturl' => 'KyDNKA',
|
||||
),
|
||||
$this->linkDb->getLinkFromUrl('http://nest.ed/1')
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'linkdate' => '20160225_205542',
|
||||
'id' => 1,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235542'),
|
||||
'title' => 'Nested 1-1',
|
||||
'url' => 'http://nest.ed/1-1',
|
||||
'description' => '',
|
||||
'private' => 0,
|
||||
'tags' => 'folder1 tag1 tag2'
|
||||
'tags' => 'folder1 tag1 tag2',
|
||||
'shorturl' => 'T2LnXg',
|
||||
),
|
||||
$this->linkDb->getLinkFromUrl('http://nest.ed/1-1')
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'linkdate' => '20160225_205547',
|
||||
'id' => 2,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235547'),
|
||||
'title' => 'Nested 1-2',
|
||||
'url' => 'http://nest.ed/1-2',
|
||||
'description' => '',
|
||||
'private' => 0,
|
||||
'tags' => 'folder1 tag3 tag4'
|
||||
'tags' => 'folder1 tag3 tag4',
|
||||
'shorturl' => '46SZxA',
|
||||
),
|
||||
$this->linkDb->getLinkFromUrl('http://nest.ed/1-2')
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'linkdate' => '20160202_172222',
|
||||
'id' => 3,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160202_202222'),
|
||||
'title' => 'Nested 2-1',
|
||||
'url' => 'http://nest.ed/2-1',
|
||||
'description' => 'First link of the second section',
|
||||
'private' => 1,
|
||||
'tags' => 'folder2'
|
||||
'tags' => 'folder2',
|
||||
'shorturl' => '4UHOSw',
|
||||
),
|
||||
$this->linkDb->getLinkFromUrl('http://nest.ed/2-1')
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'linkdate' => '20160119_200227',
|
||||
'id' => 4,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160119_230227'),
|
||||
'title' => 'Nested 2-2',
|
||||
'url' => 'http://nest.ed/2-2',
|
||||
'description' => 'Second link of the second section',
|
||||
'private' => 1,
|
||||
'tags' => 'folder2'
|
||||
'tags' => 'folder2',
|
||||
'shorturl' => 'yfzwbw',
|
||||
),
|
||||
$this->linkDb->getLinkFromUrl('http://nest.ed/2-2')
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'linkdate' => '20160202_172223',
|
||||
'id' => 5,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160202_202222'),
|
||||
'title' => 'Nested 3-1',
|
||||
'url' => 'http://nest.ed/3-1',
|
||||
'description' => '',
|
||||
'private' => 0,
|
||||
'tags' => 'folder3 folder3-1 tag3'
|
||||
'tags' => 'folder3 folder3-1 tag3',
|
||||
'shorturl' => 'UwxIUQ',
|
||||
),
|
||||
$this->linkDb->getLinkFromUrl('http://nest.ed/3-1')
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'linkdate' => '20160119_200228',
|
||||
'id' => 6,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160119_230227'),
|
||||
'title' => 'Nested 3-2',
|
||||
'url' => 'http://nest.ed/3-2',
|
||||
'description' => '',
|
||||
'private' => 0,
|
||||
'tags' => 'folder3 folder3-1'
|
||||
'tags' => 'folder3 folder3-1',
|
||||
'shorturl' => 'p8dyZg',
|
||||
),
|
||||
$this->linkDb->getLinkFromUrl('http://nest.ed/3-2')
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'linkdate' => '20160229_081541',
|
||||
'id' => 7,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160229_111541'),
|
||||
'title' => 'Nested 2',
|
||||
'url' => 'http://nest.ed/2',
|
||||
'description' => '',
|
||||
'private' => 0,
|
||||
'tags' => 'tag4'
|
||||
'tags' => 'tag4',
|
||||
'shorturl' => 'Gt3Uug',
|
||||
),
|
||||
$this->linkDb->getLinkFromUrl('http://nest.ed/2')
|
||||
);
|
||||
|
@ -227,28 +261,34 @@ public function testImportDefaultPrivacyNoPost()
|
|||
.' 2 links imported, 0 links overwritten, 0 links skipped.',
|
||||
NetscapeBookmarkUtils::import(array(), $files, $this->linkDb, $this->pagecache)
|
||||
);
|
||||
|
||||
$this->assertEquals(2, count($this->linkDb));
|
||||
$this->assertEquals(1, count_private($this->linkDb));
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'linkdate' => '20001010_105536',
|
||||
'id' => 0,
|
||||
// Old link - UTC+4 (note that TZ in the import file is ignored).
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20001010_135536'),
|
||||
'title' => 'Secret stuff',
|
||||
'url' => 'https://private.tld',
|
||||
'description' => "Super-secret stuff you're not supposed to know about",
|
||||
'private' => 1,
|
||||
'tags' => 'private secret'
|
||||
'tags' => 'private secret',
|
||||
'shorturl' => 'EokDtA',
|
||||
),
|
||||
$this->linkDb->getLinkFromUrl('https://private.tld')
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'linkdate' => '20160225_205548',
|
||||
'id' => 1,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235548'),
|
||||
'title' => 'Public stuff',
|
||||
'url' => 'http://public.tld',
|
||||
'description' => '',
|
||||
'private' => 0,
|
||||
'tags' => 'public hello world'
|
||||
'tags' => 'public hello world',
|
||||
'shorturl' => 'Er9ddA',
|
||||
),
|
||||
$this->linkDb->getLinkFromUrl('http://public.tld')
|
||||
);
|
||||
|
@ -271,23 +311,28 @@ public function testImportKeepPrivacy()
|
|||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'linkdate' => '20001010_105536',
|
||||
'id' => 0,
|
||||
// Note that TZ in the import file is ignored.
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20001010_135536'),
|
||||
'title' => 'Secret stuff',
|
||||
'url' => 'https://private.tld',
|
||||
'description' => "Super-secret stuff you're not supposed to know about",
|
||||
'private' => 1,
|
||||
'tags' => 'private secret'
|
||||
'tags' => 'private secret',
|
||||
'shorturl' => 'EokDtA',
|
||||
),
|
||||
$this->linkDb->getLinkFromUrl('https://private.tld')
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(
|
||||
'linkdate' => '20160225_205548',
|
||||
'id' => 1,
|
||||
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235548'),
|
||||
'title' => 'Public stuff',
|
||||
'url' => 'http://public.tld',
|
||||
'description' => '',
|
||||
'private' => 0,
|
||||
'tags' => 'public hello world'
|
||||
'tags' => 'public hello world',
|
||||
'shorturl' => 'Er9ddA',
|
||||
),
|
||||
$this->linkDb->getLinkFromUrl('http://public.tld')
|
||||
);
|
||||
|
@ -309,11 +354,11 @@ public function testImportAsPublic()
|
|||
$this->assertEquals(0, count_private($this->linkDb));
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->linkDb['20001010_105536']['private']
|
||||
$this->linkDb[0]['private']
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->linkDb['20160225_205548']['private']
|
||||
$this->linkDb[1]['private']
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -333,11 +378,11 @@ public function testImportAsPrivate()
|
|||
$this->assertEquals(2, count_private($this->linkDb));
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->linkDb['20001010_105536']['private']
|
||||
$this->linkDb['0']['private']
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->linkDb['20160225_205548']['private']
|
||||
$this->linkDb['1']['private']
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -359,13 +404,12 @@ public function testOverwriteAsPublic()
|
|||
$this->assertEquals(2, count_private($this->linkDb));
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->linkDb['20001010_105536']['private']
|
||||
$this->linkDb[0]['private']
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->linkDb['20160225_205548']['private']
|
||||
$this->linkDb[1]['private']
|
||||
);
|
||||
|
||||
// re-import as public, enable overwriting
|
||||
$post = array(
|
||||
'privacy' => 'public',
|
||||
|
@ -380,11 +424,11 @@ public function testOverwriteAsPublic()
|
|||
$this->assertEquals(0, count_private($this->linkDb));
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->linkDb['20001010_105536']['private']
|
||||
$this->linkDb[0]['private']
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->linkDb['20160225_205548']['private']
|
||||
$this->linkDb[1]['private']
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -406,11 +450,11 @@ public function testOverwriteAsPrivate()
|
|||
$this->assertEquals(0, count_private($this->linkDb));
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->linkDb['20001010_105536']['private']
|
||||
$this->linkDb['0']['private']
|
||||
);
|
||||
$this->assertEquals(
|
||||
0,
|
||||
$this->linkDb['20160225_205548']['private']
|
||||
$this->linkDb['1']['private']
|
||||
);
|
||||
|
||||
// re-import as private, enable overwriting
|
||||
|
@ -427,11 +471,11 @@ public function testOverwriteAsPrivate()
|
|||
$this->assertEquals(2, count_private($this->linkDb));
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->linkDb['20001010_105536']['private']
|
||||
$this->linkDb['0']['private']
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$this->linkDb['20160225_205548']['private']
|
||||
$this->linkDb['1']['private']
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -480,11 +524,11 @@ public function testSetDefaultTags()
|
|||
$this->assertEquals(0, count_private($this->linkDb));
|
||||
$this->assertEquals(
|
||||
'tag1 tag2 tag3 private secret',
|
||||
$this->linkDb['20001010_105536']['tags']
|
||||
$this->linkDb['0']['tags']
|
||||
);
|
||||
$this->assertEquals(
|
||||
'tag1 tag2 tag3 public hello world',
|
||||
$this->linkDb['20160225_205548']['tags']
|
||||
$this->linkDb['1']['tags']
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -507,16 +551,16 @@ public function testSanitizeDefaultTags()
|
|||
$this->assertEquals(0, count_private($this->linkDb));
|
||||
$this->assertEquals(
|
||||
'tag1& tag2 "tag3" private secret',
|
||||
$this->linkDb['20001010_105536']['tags']
|
||||
$this->linkDb['0']['tags']
|
||||
);
|
||||
$this->assertEquals(
|
||||
'tag1& tag2 "tag3" public hello world',
|
||||
$this->linkDb['20160225_205548']['tags']
|
||||
$this->linkDb['1']['tags']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure each imported bookmark has a unique linkdate
|
||||
* Ensure each imported bookmark has a unique id
|
||||
*
|
||||
* See https://github.com/shaarli/Shaarli/issues/351
|
||||
*/
|
||||
|
@ -531,16 +575,16 @@ public function testImportSameDate()
|
|||
$this->assertEquals(3, count($this->linkDb));
|
||||
$this->assertEquals(0, count_private($this->linkDb));
|
||||
$this->assertEquals(
|
||||
'20160225_205548',
|
||||
$this->linkDb['20160225_205548']['linkdate']
|
||||
0,
|
||||
$this->linkDb[0]['id']
|
||||
);
|
||||
$this->assertEquals(
|
||||
'20160225_205549',
|
||||
$this->linkDb['20160225_205549']['linkdate']
|
||||
1,
|
||||
$this->linkDb[1]['id']
|
||||
);
|
||||
$this->assertEquals(
|
||||
'20160225_205550',
|
||||
$this->linkDb['20160225_205550']['linkdate']
|
||||
2,
|
||||
$this->linkDb[2]['id']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -214,6 +214,7 @@ public function testRenameDashTags()
|
|||
$refDB = new ReferenceLinkDB();
|
||||
$refDB->write(self::$testDatastore);
|
||||
$linkDB = new LinkDB(self::$testDatastore, true, false);
|
||||
|
||||
$this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude')));
|
||||
$updater = new Updater(array(), $linkDB, $this->conf, true);
|
||||
$updater->updateMethodRenameDashTags();
|
||||
|
@ -287,4 +288,101 @@ public function testEscapeConfig()
|
|||
$this->assertEquals(escape($redirectorUrl), $this->conf->get('redirector.url'));
|
||||
unlink($sandbox .'.json.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateMethodDatastoreIds().
|
||||
*/
|
||||
public function testDatastoreIds()
|
||||
{
|
||||
$links = array(
|
||||
'20121206_182539' => array(
|
||||
'linkdate' => '20121206_182539',
|
||||
'title' => 'Geek and Poke',
|
||||
'url' => 'http://geek-and-poke.com/',
|
||||
'description' => 'desc',
|
||||
'tags' => 'dev cartoon tag1 tag2 tag3 tag4 ',
|
||||
'updated' => '20121206_190301',
|
||||
'private' => false,
|
||||
),
|
||||
'20121206_172539' => array(
|
||||
'linkdate' => '20121206_172539',
|
||||
'title' => 'UserFriendly - Samba',
|
||||
'url' => 'http://ars.userfriendly.org/cartoons/?id=20010306',
|
||||
'description' => '',
|
||||
'tags' => 'samba cartoon web',
|
||||
'private' => false,
|
||||
),
|
||||
'20121206_142300' => array(
|
||||
'linkdate' => '20121206_142300',
|
||||
'title' => 'UserFriendly - Web Designer',
|
||||
'url' => 'http://ars.userfriendly.org/cartoons/?id=20121206',
|
||||
'description' => 'Naming conventions... #private',
|
||||
'tags' => 'samba cartoon web',
|
||||
'private' => true,
|
||||
),
|
||||
);
|
||||
$refDB = new ReferenceLinkDB();
|
||||
$refDB->setLinks($links);
|
||||
$refDB->write(self::$testDatastore);
|
||||
$linkDB = new LinkDB(self::$testDatastore, true, false);
|
||||
|
||||
$checksum = hash_file('sha1', self::$testDatastore);
|
||||
|
||||
$this->conf->set('resource.data_dir', 'sandbox');
|
||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||
|
||||
$updater = new Updater(array(), $linkDB, $this->conf, true);
|
||||
$this->assertTrue($updater->updateMethodDatastoreIds());
|
||||
|
||||
$linkDB = new LinkDB(self::$testDatastore, true, false);
|
||||
|
||||
$backup = glob($this->conf->get('resource.data_dir') . '/datastore.'. date('YmdH') .'*.php');
|
||||
$backup = $backup[0];
|
||||
|
||||
$this->assertFileExists($backup);
|
||||
$this->assertEquals($checksum, hash_file('sha1', $backup));
|
||||
unlink($backup);
|
||||
|
||||
$this->assertEquals(3, count($linkDB));
|
||||
$this->assertTrue(isset($linkDB[0]));
|
||||
$this->assertFalse(isset($linkDB[0]['linkdate']));
|
||||
$this->assertEquals(0, $linkDB[0]['id']);
|
||||
$this->assertEquals('UserFriendly - Web Designer', $linkDB[0]['title']);
|
||||
$this->assertEquals('http://ars.userfriendly.org/cartoons/?id=20121206', $linkDB[0]['url']);
|
||||
$this->assertEquals('Naming conventions... #private', $linkDB[0]['description']);
|
||||
$this->assertEquals('samba cartoon web', $linkDB[0]['tags']);
|
||||
$this->assertTrue($linkDB[0]['private']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_142300'), $linkDB[0]['created']);
|
||||
|
||||
$this->assertTrue(isset($linkDB[1]));
|
||||
$this->assertFalse(isset($linkDB[1]['linkdate']));
|
||||
$this->assertEquals(1, $linkDB[1]['id']);
|
||||
$this->assertEquals('UserFriendly - Samba', $linkDB[1]['title']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_172539'), $linkDB[1]['created']);
|
||||
|
||||
$this->assertTrue(isset($linkDB[2]));
|
||||
$this->assertFalse(isset($linkDB[2]['linkdate']));
|
||||
$this->assertEquals(2, $linkDB[2]['id']);
|
||||
$this->assertEquals('Geek and Poke', $linkDB[2]['title']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_182539'), $linkDB[2]['created']);
|
||||
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_190301'), $linkDB[2]['updated']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test updateMethodDatastoreIds() with the update already applied: nothing to do.
|
||||
*/
|
||||
public function testDatastoreIdsNothingToDo()
|
||||
{
|
||||
$refDB = new ReferenceLinkDB();
|
||||
$refDB->write(self::$testDatastore);
|
||||
$linkDB = new LinkDB(self::$testDatastore, true, false);
|
||||
|
||||
$this->conf->set('resource.data_dir', 'sandbox');
|
||||
$this->conf->set('resource.datastore', self::$testDatastore);
|
||||
|
||||
$checksum = hash_file('sha1', self::$testDatastore);
|
||||
$updater = new Updater(array(), $linkDB, $this->conf, true);
|
||||
$this->assertTrue($updater->updateMethodDatastoreIds());
|
||||
$this->assertEquals($checksum, hash_file('sha1', self::$testDatastore));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,12 +47,13 @@ function testIssoDisplayed()
|
|||
$conf->set('plugins.ISSO_SERVER', 'value');
|
||||
|
||||
$str = 'http://randomstr.com/test';
|
||||
$date = '20161118_100001';
|
||||
$data = array(
|
||||
'title' => $str,
|
||||
'links' => array(
|
||||
array(
|
||||
'url' => $str,
|
||||
'linkdate' => 'abc',
|
||||
'created' => DateTime::createFromFormat('Ymd_His', $date),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
@ -65,7 +66,7 @@ function testIssoDisplayed()
|
|||
|
||||
// plugin data
|
||||
$this->assertEquals(1, count($data['plugin_end_zone']));
|
||||
$this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'abc'));
|
||||
$this->assertNotFalse(strpos($data['plugin_end_zone'][0], $date));
|
||||
$this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
|
||||
}
|
||||
|
||||
|
@ -78,16 +79,18 @@ function testIssoMultipleLinks()
|
|||
$conf->set('plugins.ISSO_SERVER', 'value');
|
||||
|
||||
$str = 'http://randomstr.com/test';
|
||||
$date1 = '20161118_100001';
|
||||
$date2 = '20161118_100002';
|
||||
$data = array(
|
||||
'title' => $str,
|
||||
'links' => array(
|
||||
array(
|
||||
'url' => $str,
|
||||
'linkdate' => 'abc',
|
||||
'created' => DateTime::createFromFormat('Ymd_His', $date1),
|
||||
),
|
||||
array(
|
||||
'url' => $str . '2',
|
||||
'linkdate' => 'abc2',
|
||||
'created' => DateTime::createFromFormat('Ymd_His', $date2),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
@ -106,12 +109,13 @@ function testIssoNotDisplayedWhenSearch()
|
|||
$conf->set('plugins.ISSO_SERVER', 'value');
|
||||
|
||||
$str = 'http://randomstr.com/test';
|
||||
$date = '20161118_100001';
|
||||
$data = array(
|
||||
'title' => $str,
|
||||
'links' => array(
|
||||
array(
|
||||
'url' => $str,
|
||||
'linkdate' => 'abc',
|
||||
'created' => DateTime::createFromFormat('Ymd_His', $date),
|
||||
)
|
||||
),
|
||||
'search_term' => $str
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
class ReferenceLinkDB
|
||||
{
|
||||
public static $NB_LINKS_TOTAL = 7;
|
||||
public static $NB_LINKS_TOTAL = 8;
|
||||
|
||||
private $_links = array();
|
||||
private $_publicCount = 0;
|
||||
|
@ -16,66 +16,87 @@ class ReferenceLinkDB
|
|||
public function __construct()
|
||||
{
|
||||
$this->addLink(
|
||||
41,
|
||||
'Link title: @website',
|
||||
'?WDWyig',
|
||||
'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this. #hashtag',
|
||||
0,
|
||||
'20150310_114651',
|
||||
'sTuff'
|
||||
DateTime::createFromFormat('Ymd_His', '20150310_114651'),
|
||||
'sTuff',
|
||||
null,
|
||||
'WDWyig'
|
||||
);
|
||||
|
||||
$this->addLink(
|
||||
42,
|
||||
'Note: I have a big ID but an old date',
|
||||
'?WDWyig',
|
||||
'Used to test links reordering.',
|
||||
0,
|
||||
DateTime::createFromFormat('Ymd_His', '20100310_101010'),
|
||||
'ut'
|
||||
);
|
||||
|
||||
$this->addLink(
|
||||
8,
|
||||
'Free as in Freedom 2.0 @website',
|
||||
'https://static.fsf.org/nosvn/faif-2.0.pdf',
|
||||
'Richard Stallman and the Free Software Revolution. Read this. #hashtag',
|
||||
0,
|
||||
'20150310_114633',
|
||||
DateTime::createFromFormat('Ymd_His', '20150310_114633'),
|
||||
'free gnu software stallman -exclude stuff hashtag',
|
||||
'20160803_093033'
|
||||
DateTime::createFromFormat('Ymd_His', '20160803_093033')
|
||||
);
|
||||
|
||||
$this->addLink(
|
||||
7,
|
||||
'MediaGoblin',
|
||||
'http://mediagoblin.org/',
|
||||
'A free software media publishing platform #hashtagOther',
|
||||
0,
|
||||
'20130614_184135',
|
||||
'gnu media web .hidden hashtag'
|
||||
DateTime::createFromFormat('Ymd_His', '20130614_184135'),
|
||||
'gnu media web .hidden hashtag',
|
||||
null,
|
||||
'IuWvgA'
|
||||
);
|
||||
|
||||
$this->addLink(
|
||||
6,
|
||||
'w3c-markup-validator',
|
||||
'https://dvcs.w3.org/hg/markup-validator/summary',
|
||||
'Mercurial repository for the W3C Validator #private',
|
||||
1,
|
||||
'20141125_084734',
|
||||
DateTime::createFromFormat('Ymd_His', '20141125_084734'),
|
||||
'css html w3c web Mercurial'
|
||||
);
|
||||
|
||||
$this->addLink(
|
||||
4,
|
||||
'UserFriendly - Web Designer',
|
||||
'http://ars.userfriendly.org/cartoons/?id=20121206',
|
||||
'Naming conventions... #private',
|
||||
0,
|
||||
'20121206_142300',
|
||||
DateTime::createFromFormat('Ymd_His', '20121206_142300'),
|
||||
'dev cartoon web'
|
||||
);
|
||||
|
||||
$this->addLink(
|
||||
1,
|
||||
'UserFriendly - Samba',
|
||||
'http://ars.userfriendly.org/cartoons/?id=20010306',
|
||||
'Tropical printing',
|
||||
0,
|
||||
'20121206_172539',
|
||||
DateTime::createFromFormat('Ymd_His', '20121206_172539'),
|
||||
'samba cartoon web'
|
||||
);
|
||||
|
||||
$this->addLink(
|
||||
0,
|
||||
'Geek and Poke',
|
||||
'http://geek-and-poke.com/',
|
||||
'',
|
||||
1,
|
||||
'20121206_182539',
|
||||
DateTime::createFromFormat('Ymd_His', '20121206_182539'),
|
||||
'dev cartoon tag1 tag2 tag3 tag4 '
|
||||
);
|
||||
}
|
||||
|
@ -83,18 +104,20 @@ public function __construct()
|
|||
/**
|
||||
* Adds a new link
|
||||
*/
|
||||
protected function addLink($title, $url, $description, $private, $date, $tags, $updated = '')
|
||||
protected function addLink($id, $title, $url, $description, $private, $date, $tags, $updated = '', $shorturl = '')
|
||||
{
|
||||
$link = array(
|
||||
'id' => $id,
|
||||
'title' => $title,
|
||||
'url' => $url,
|
||||
'description' => $description,
|
||||
'private' => $private,
|
||||
'linkdate' => $date,
|
||||
'tags' => $tags,
|
||||
'created' => $date,
|
||||
'updated' => $updated,
|
||||
'shorturl' => $shorturl ? $shorturl : smallHash($date->format('Ymd_His') . $id),
|
||||
);
|
||||
$this->_links[$date] = $link;
|
||||
$this->_links[$id] = $link;
|
||||
|
||||
if ($private) {
|
||||
$this->_privateCount++;
|
||||
|
@ -142,4 +165,14 @@ public function getLinks()
|
|||
{
|
||||
return $this->_links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter to override link creation.
|
||||
*
|
||||
* @param array $links List of links.
|
||||
*/
|
||||
public function setLinks($links)
|
||||
{
|
||||
$this->_links = $links;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue