diff options
author | ArthurHoaro <arthur@hoa.ro> | 2016-03-21 21:40:49 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2016-03-25 19:17:59 +0100 |
commit | 528a6f8a232c060faf024008e4f8a09b4aa8dabc (patch) | |
tree | 86cac78b7f4d3998bedd923da83145c37ec88ff4 /tests | |
parent | ee88a4bcc29da721cf43b750663aebeac4969517 (diff) | |
download | Shaarli-528a6f8a232c060faf024008e4f8a09b4aa8dabc.tar.gz Shaarli-528a6f8a232c060faf024008e4f8a09b4aa8dabc.tar.zst Shaarli-528a6f8a232c060faf024008e4f8a09b4aa8dabc.zip |
Refactor filter in LinkDB
* search type now carried by LinkDB in order to factorize code between different search sources.
* LinkDB->filter split in 3 method: filterSearch, filterHash, filterDay (we know what type of filter is needed).
* filterHash now throw a LinkNotFoundException if it doesn't exist: internal implementation choice, still displays a 404.
* Smallhash regex has been rewritten.
* Unit tests update
Diffstat (limited to 'tests')
-rw-r--r-- | tests/LinkDBTest.php | 56 | ||||
-rw-r--r-- | tests/LinkFilterTest.php | 7 | ||||
-rw-r--r-- | tests/Updater/UpdaterTest.php | 4 |
3 files changed, 57 insertions, 10 deletions
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index b6a273b3..52d31400 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php | |||
@@ -17,8 +17,20 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
17 | { | 17 | { |
18 | // datastore to test write operations | 18 | // datastore to test write operations |
19 | protected static $testDatastore = 'sandbox/datastore.php'; | 19 | protected static $testDatastore = 'sandbox/datastore.php'; |
20 | |||
21 | /** | ||
22 | * @var ReferenceLinkDB instance. | ||
23 | */ | ||
20 | protected static $refDB = null; | 24 | protected static $refDB = null; |
25 | |||
26 | /** | ||
27 | * @var LinkDB public LinkDB instance. | ||
28 | */ | ||
21 | protected static $publicLinkDB = null; | 29 | protected static $publicLinkDB = null; |
30 | |||
31 | /** | ||
32 | * @var LinkDB private LinkDB instance. | ||
33 | */ | ||
22 | protected static $privateLinkDB = null; | 34 | protected static $privateLinkDB = null; |
23 | 35 | ||
24 | /** | 36 | /** |
@@ -335,9 +347,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
335 | public function testFilterString() | 347 | public function testFilterString() |
336 | { | 348 | { |
337 | $tags = 'dev cartoon'; | 349 | $tags = 'dev cartoon'; |
350 | $request = array('searchtags' => $tags); | ||
338 | $this->assertEquals( | 351 | $this->assertEquals( |
339 | 2, | 352 | 2, |
340 | count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) | 353 | count(self::$privateLinkDB->filterSearch($request, true, false)) |
341 | ); | 354 | ); |
342 | } | 355 | } |
343 | 356 | ||
@@ -347,9 +360,10 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
347 | public function testFilterArray() | 360 | public function testFilterArray() |
348 | { | 361 | { |
349 | $tags = array('dev', 'cartoon'); | 362 | $tags = array('dev', 'cartoon'); |
363 | $request = array('searchtags' => $tags); | ||
350 | $this->assertEquals( | 364 | $this->assertEquals( |
351 | 2, | 365 | 2, |
352 | count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) | 366 | count(self::$privateLinkDB->filterSearch($request, true, false)) |
353 | ); | 367 | ); |
354 | } | 368 | } |
355 | 369 | ||
@@ -360,14 +374,48 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
360 | public function testHiddenTags() | 374 | public function testHiddenTags() |
361 | { | 375 | { |
362 | $tags = '.hidden'; | 376 | $tags = '.hidden'; |
377 | $request = array('searchtags' => $tags); | ||
363 | $this->assertEquals( | 378 | $this->assertEquals( |
364 | 1, | 379 | 1, |
365 | count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) | 380 | count(self::$privateLinkDB->filterSearch($request, true, false)) |
366 | ); | 381 | ); |
367 | 382 | ||
368 | $this->assertEquals( | 383 | $this->assertEquals( |
369 | 0, | 384 | 0, |
370 | count(self::$publicLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) | 385 | count(self::$publicLinkDB->filterSearch($request, true, false)) |
371 | ); | 386 | ); |
372 | } | 387 | } |
388 | |||
389 | /** | ||
390 | * Test filterHash() with a valid smallhash. | ||
391 | */ | ||
392 | public function testFilterHashValid() | ||
393 | { | ||
394 | $request = smallHash('20150310_114651'); | ||
395 | $this->assertEquals( | ||
396 | 1, | ||
397 | count(self::$publicLinkDB->filterHash($request)) | ||
398 | ); | ||
399 | } | ||
400 | |||
401 | /** | ||
402 | * Test filterHash() with an invalid smallhash. | ||
403 | * | ||
404 | * @expectedException LinkNotFoundException | ||
405 | */ | ||
406 | public function testFilterHashInValid1() | ||
407 | { | ||
408 | $request = 'blabla'; | ||
409 | self::$publicLinkDB->filterHash($request); | ||
410 | } | ||
411 | |||
412 | /** | ||
413 | * Test filterHash() with an empty smallhash. | ||
414 | * | ||
415 | * @expectedException LinkNotFoundException | ||
416 | */ | ||
417 | public function testFilterHashInValid() | ||
418 | { | ||
419 | self::$publicLinkDB->filterHash(''); | ||
420 | } | ||
373 | } | 421 | } |
diff --git a/tests/LinkFilterTest.php b/tests/LinkFilterTest.php index f991a9c9..1620bb78 100644 --- a/tests/LinkFilterTest.php +++ b/tests/LinkFilterTest.php | |||
@@ -165,13 +165,12 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase | |||
165 | 165 | ||
166 | /** | 166 | /** |
167 | * No link for this hash | 167 | * No link for this hash |
168 | * | ||
169 | * @expectedException LinkNotFoundException | ||
168 | */ | 170 | */ |
169 | public function testFilterUnknownSmallHash() | 171 | public function testFilterUnknownSmallHash() |
170 | { | 172 | { |
171 | $this->assertEquals( | 173 | self::$linkFilter->filter(LinkFilter::$FILTER_HASH, 'Iblaah'); |
172 | 0, | ||
173 | count(self::$linkFilter->filter(LinkFilter::$FILTER_HASH, 'Iblaah')) | ||
174 | ); | ||
175 | } | 174 | } |
176 | 175 | ||
177 | /** | 176 | /** |
diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index d865066b..a29d9067 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php | |||
@@ -236,9 +236,9 @@ class UpdaterTest extends PHPUnit_Framework_TestCase | |||
236 | $refDB = new ReferenceLinkDB(); | 236 | $refDB = new ReferenceLinkDB(); |
237 | $refDB->write(self::$testDatastore); | 237 | $refDB->write(self::$testDatastore); |
238 | $linkDB = new LinkDB(self::$testDatastore, true, false); | 238 | $linkDB = new LinkDB(self::$testDatastore, true, false); |
239 | $this->assertEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude')); | 239 | $this->assertEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); |
240 | $updater = new Updater(array(), self::$configFields, $linkDB, true); | 240 | $updater = new Updater(array(), self::$configFields, $linkDB, true); |
241 | $updater->updateMethodRenameDashTags(); | 241 | $updater->updateMethodRenameDashTags(); |
242 | $this->assertNotEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude')); | 242 | $this->assertNotEmpty($linkDB->filterSearch(array('searchtags' => 'exclude'))); |
243 | } | 243 | } |
244 | } | 244 | } |