diff options
Diffstat (limited to 'tests/LinkDBTest.php')
-rw-r--r-- | tests/LinkDBTest.php | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index b055fe91..1f62a34a 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php | |||
@@ -101,7 +101,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
101 | * Attempt to instantiate a LinkDB whereas the datastore is not writable | 101 | * Attempt to instantiate a LinkDB whereas the datastore is not writable |
102 | * | 102 | * |
103 | * @expectedException IOException | 103 | * @expectedException IOException |
104 | * @expectedExceptionMessageRegExp /Error accessing null/ | 104 | * @expectedExceptionMessageRegExp /Error accessing\nnull/ |
105 | */ | 105 | */ |
106 | public function testConstructDatastoreNotWriteable() | 106 | public function testConstructDatastoreNotWriteable() |
107 | { | 107 | { |
@@ -117,7 +117,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
117 | unlink(self::$testDatastore); | 117 | unlink(self::$testDatastore); |
118 | $this->assertFileNotExists(self::$testDatastore); | 118 | $this->assertFileNotExists(self::$testDatastore); |
119 | 119 | ||
120 | $checkDB = self::getMethod('_checkDB'); | 120 | $checkDB = self::getMethod('check'); |
121 | $checkDB->invokeArgs($linkDB, array()); | 121 | $checkDB->invokeArgs($linkDB, array()); |
122 | $this->assertFileExists(self::$testDatastore); | 122 | $this->assertFileExists(self::$testDatastore); |
123 | 123 | ||
@@ -134,7 +134,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
134 | $datastoreSize = filesize(self::$testDatastore); | 134 | $datastoreSize = filesize(self::$testDatastore); |
135 | $this->assertGreaterThan(0, $datastoreSize); | 135 | $this->assertGreaterThan(0, $datastoreSize); |
136 | 136 | ||
137 | $checkDB = self::getMethod('_checkDB'); | 137 | $checkDB = self::getMethod('check'); |
138 | $checkDB->invokeArgs($linkDB, array()); | 138 | $checkDB->invokeArgs($linkDB, array()); |
139 | 139 | ||
140 | // ensure the datastore is left unmodified | 140 | // ensure the datastore is left unmodified |
@@ -180,21 +180,22 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
180 | /** | 180 | /** |
181 | * Save the links to the DB | 181 | * Save the links to the DB |
182 | */ | 182 | */ |
183 | public function testSaveDB() | 183 | public function testSave() |
184 | { | 184 | { |
185 | $testDB = new LinkDB(self::$testDatastore, true, false); | 185 | $testDB = new LinkDB(self::$testDatastore, true, false); |
186 | $dbSize = sizeof($testDB); | 186 | $dbSize = sizeof($testDB); |
187 | 187 | ||
188 | $link = array( | 188 | $link = array( |
189 | 'id' => 42, | ||
189 | 'title'=>'an additional link', | 190 | 'title'=>'an additional link', |
190 | 'url'=>'http://dum.my', | 191 | 'url'=>'http://dum.my', |
191 | 'description'=>'One more', | 192 | 'description'=>'One more', |
192 | 'private'=>0, | 193 | 'private'=>0, |
193 | 'linkdate'=>'20150518_190000', | 194 | 'created'=> DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150518_190000'), |
194 | 'tags'=>'unit test' | 195 | 'tags'=>'unit test' |
195 | ); | 196 | ); |
196 | $testDB[$link['linkdate']] = $link; | 197 | $testDB[$link['id']] = $link; |
197 | $testDB->savedb('tests'); | 198 | $testDB->save('tests'); |
198 | 199 | ||
199 | $testDB = new LinkDB(self::$testDatastore, true, false); | 200 | $testDB = new LinkDB(self::$testDatastore, true, false); |
200 | $this->assertEquals($dbSize + 1, sizeof($testDB)); | 201 | $this->assertEquals($dbSize + 1, sizeof($testDB)); |
@@ -238,12 +239,12 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
238 | public function testDays() | 239 | public function testDays() |
239 | { | 240 | { |
240 | $this->assertEquals( | 241 | $this->assertEquals( |
241 | array('20121206', '20130614', '20150310'), | 242 | array('20100310', '20121206', '20130614', '20150310'), |
242 | self::$publicLinkDB->days() | 243 | self::$publicLinkDB->days() |
243 | ); | 244 | ); |
244 | 245 | ||
245 | $this->assertEquals( | 246 | $this->assertEquals( |
246 | array('20121206', '20130614', '20141125', '20150310'), | 247 | array('20100310', '20121206', '20130614', '20141125', '20150310'), |
247 | self::$privateLinkDB->days() | 248 | self::$privateLinkDB->days() |
248 | ); | 249 | ); |
249 | } | 250 | } |
@@ -256,7 +257,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
256 | $link = self::$publicLinkDB->getLinkFromUrl('http://mediagoblin.org/'); | 257 | $link = self::$publicLinkDB->getLinkFromUrl('http://mediagoblin.org/'); |
257 | 258 | ||
258 | $this->assertNotEquals(false, $link); | 259 | $this->assertNotEquals(false, $link); |
259 | $this->assertEquals( | 260 | $this->assertContains( |
260 | 'A free software media publishing platform', | 261 | 'A free software media publishing platform', |
261 | $link['description'] | 262 | $link['description'] |
262 | ); | 263 | ); |
@@ -290,7 +291,11 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
290 | 'stallman' => 1, | 291 | 'stallman' => 1, |
291 | 'free' => 1, | 292 | 'free' => 1, |
292 | '-exclude' => 1, | 293 | '-exclude' => 1, |
293 | 'stuff' => 2, | 294 | 'hashtag' => 2, |
295 | // The DB contains a link with `sTuff` and another one with `stuff` tag. | ||
296 | // They need to be grouped with the first case found - order by date DESC: `sTuff`. | ||
297 | 'sTuff' => 2, | ||
298 | 'ut' => 1, | ||
294 | ), | 299 | ), |
295 | self::$publicLinkDB->allTags() | 300 | self::$publicLinkDB->allTags() |
296 | ); | 301 | ); |
@@ -310,9 +315,15 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
310 | 'w3c' => 1, | 315 | 'w3c' => 1, |
311 | 'css' => 1, | 316 | 'css' => 1, |
312 | 'Mercurial' => 1, | 317 | 'Mercurial' => 1, |
313 | 'stuff' => 2, | 318 | 'sTuff' => 2, |
314 | '-exclude' => 1, | 319 | '-exclude' => 1, |
315 | '.hidden' => 1, | 320 | '.hidden' => 1, |
321 | 'hashtag' => 2, | ||
322 | 'tag1' => 1, | ||
323 | 'tag2' => 1, | ||
324 | 'tag3' => 1, | ||
325 | 'tag4' => 1, | ||
326 | 'ut' => 1, | ||
316 | ), | 327 | ), |
317 | self::$privateLinkDB->allTags() | 328 | self::$privateLinkDB->allTags() |
318 | ); | 329 | ); |
@@ -403,6 +414,11 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
403 | 1, | 414 | 1, |
404 | count(self::$publicLinkDB->filterHash($request)) | 415 | count(self::$publicLinkDB->filterHash($request)) |
405 | ); | 416 | ); |
417 | $request = smallHash('20150310_114633' . 8); | ||
418 | $this->assertEquals( | ||
419 | 1, | ||
420 | count(self::$publicLinkDB->filterHash($request)) | ||
421 | ); | ||
406 | } | 422 | } |
407 | 423 | ||
408 | /** | 424 | /** |
@@ -425,4 +441,23 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
425 | { | 441 | { |
426 | self::$publicLinkDB->filterHash(''); | 442 | self::$publicLinkDB->filterHash(''); |
427 | } | 443 | } |
444 | |||
445 | /** | ||
446 | * Test reorder with asc/desc parameter. | ||
447 | */ | ||
448 | public function testReorderLinksDesc() | ||
449 | { | ||
450 | self::$privateLinkDB->reorder('ASC'); | ||
451 | $linkIds = array(42, 4, 1, 0, 7, 6, 8, 41); | ||
452 | $cpt = 0; | ||
453 | foreach (self::$privateLinkDB as $key => $value) { | ||
454 | $this->assertEquals($linkIds[$cpt++], $key); | ||
455 | } | ||
456 | self::$privateLinkDB->reorder('DESC'); | ||
457 | $linkIds = array_reverse($linkIds); | ||
458 | $cpt = 0; | ||
459 | foreach (self::$privateLinkDB as $key => $value) { | ||
460 | $this->assertEquals($linkIds[$cpt++], $key); | ||
461 | } | ||
462 | } | ||
428 | } | 463 | } |