Skip to content

Commit

Permalink
Unit Test for the new ID system
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHoaro committed Nov 28, 2016
1 parent ba7a51c commit 8e7c729
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 95 deletions.
31 changes: 18 additions & 13 deletions tests/FeedBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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']);
}

/**
Expand All @@ -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']);
}

/**
Expand All @@ -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']);
}

/**
Expand All @@ -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']);
}

/**
Expand All @@ -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']);
Expand Down
39 changes: 33 additions & 6 deletions tests/LinkDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
);
}
Expand Down Expand Up @@ -290,10 +291,11 @@ public function testAllTags()
'stallman' => 1,
'free' => 1,
'-exclude' => 1,
'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 (`sTuff`).
// They need to be grouped with the first case found - order by date DESC: `sTuff`.
'sTuff' => 2,
'hashtag' => 2,
'ut' => 1,
),
self::$publicLinkDB->allTags()
);
Expand Down Expand Up @@ -321,6 +323,7 @@ public function testAllTags()
'tag2' => 1,
'tag3' => 1,
'tag4' => 1,
'ut' => 1,
),
self::$privateLinkDB->allTags()
);
Expand Down Expand Up @@ -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))
);
}

/**
Expand All @@ -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;
}
}
}
6 changes: 3 additions & 3 deletions tests/LinkFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function testFilterSmallHash()

$this->assertEquals(
'MediaGoblin',
$links['20130614_184135']['title']
$links[7]['title']
);
}

Expand Down Expand Up @@ -286,7 +286,7 @@ public function testExcludeSearch()
);

$this->assertEquals(
6,
7,
count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '-revolution'))
);
}
Expand Down Expand Up @@ -346,7 +346,7 @@ public function testTagFilterWithExclusion()
);

$this->assertEquals(
6,
7,
count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '-free'))
);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/NetscapeBookmarkUtils/BookmarkExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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']
Expand All @@ -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']
Expand Down
Loading

0 comments on commit 8e7c729

Please sign in to comment.