diff options
author | Arthur <arthur@hoa.ro> | 2016-01-06 19:57:42 +0100 |
---|---|---|
committer | Arthur <arthur@hoa.ro> | 2016-01-06 19:57:42 +0100 |
commit | 88c15abb2a2b24f05ca926c0ddbdec18a407e47d (patch) | |
tree | 90f783c69dc51866dc01dc34e740023bd1e0c4ec /tests/LinkDBTest.php | |
parent | a327d891b3a2762bb6aabba3a6572b077f6003c0 (diff) | |
parent | eefb636cea7acef9ddfd02a90749820f5fafc9f6 (diff) | |
download | Shaarli-88c15abb2a2b24f05ca926c0ddbdec18a407e47d.tar.gz Shaarli-88c15abb2a2b24f05ca926c0ddbdec18a407e47d.tar.zst Shaarli-88c15abb2a2b24f05ca926c0ddbdec18a407e47d.zip |
Merge pull request #424 from ArthurHoaro/search
Link filter refactoring
Diffstat (limited to 'tests/LinkDBTest.php')
-rw-r--r-- | tests/LinkDBTest.php | 229 |
1 files changed, 21 insertions, 208 deletions
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 7b22b270..3b1a2057 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php | |||
@@ -302,236 +302,49 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
302 | } | 302 | } |
303 | 303 | ||
304 | /** | 304 | /** |
305 | * Filter links using a tag | 305 | * Test real_url without redirector. |
306 | */ | ||
307 | public function testFilterOneTag() | ||
308 | { | ||
309 | $this->assertEquals( | ||
310 | 3, | ||
311 | sizeof(self::$publicLinkDB->filterTags('web', false)) | ||
312 | ); | ||
313 | |||
314 | $this->assertEquals( | ||
315 | 4, | ||
316 | sizeof(self::$privateLinkDB->filterTags('web', false)) | ||
317 | ); | ||
318 | } | ||
319 | |||
320 | /** | ||
321 | * Filter links using a tag - case-sensitive | ||
322 | */ | ||
323 | public function testFilterCaseSensitiveTag() | ||
324 | { | ||
325 | $this->assertEquals( | ||
326 | 0, | ||
327 | sizeof(self::$privateLinkDB->filterTags('mercurial', true)) | ||
328 | ); | ||
329 | |||
330 | $this->assertEquals( | ||
331 | 1, | ||
332 | sizeof(self::$privateLinkDB->filterTags('Mercurial', true)) | ||
333 | ); | ||
334 | } | ||
335 | |||
336 | /** | ||
337 | * Filter links using a tag combination | ||
338 | */ | ||
339 | public function testFilterMultipleTags() | ||
340 | { | ||
341 | $this->assertEquals( | ||
342 | 1, | ||
343 | sizeof(self::$publicLinkDB->filterTags('dev cartoon', false)) | ||
344 | ); | ||
345 | |||
346 | $this->assertEquals( | ||
347 | 2, | ||
348 | sizeof(self::$privateLinkDB->filterTags('dev cartoon', false)) | ||
349 | ); | ||
350 | } | ||
351 | |||
352 | /** | ||
353 | * Filter links using a non-existent tag | ||
354 | */ | ||
355 | public function testFilterUnknownTag() | ||
356 | { | ||
357 | $this->assertEquals( | ||
358 | 0, | ||
359 | sizeof(self::$publicLinkDB->filterTags('null', false)) | ||
360 | ); | ||
361 | } | ||
362 | |||
363 | /** | ||
364 | * Return links for a given day | ||
365 | */ | ||
366 | public function testFilterDay() | ||
367 | { | ||
368 | $this->assertEquals( | ||
369 | 2, | ||
370 | sizeof(self::$publicLinkDB->filterDay('20121206')) | ||
371 | ); | ||
372 | |||
373 | $this->assertEquals( | ||
374 | 3, | ||
375 | sizeof(self::$privateLinkDB->filterDay('20121206')) | ||
376 | ); | ||
377 | } | ||
378 | |||
379 | /** | ||
380 | * 404 - day not found | ||
381 | */ | ||
382 | public function testFilterUnknownDay() | ||
383 | { | ||
384 | $this->assertEquals( | ||
385 | 0, | ||
386 | sizeof(self::$publicLinkDB->filterDay('19700101')) | ||
387 | ); | ||
388 | |||
389 | $this->assertEquals( | ||
390 | 0, | ||
391 | sizeof(self::$privateLinkDB->filterDay('19700101')) | ||
392 | ); | ||
393 | } | ||
394 | |||
395 | /** | ||
396 | * Use an invalid date format | ||
397 | * @expectedException Exception | ||
398 | * @expectedExceptionMessageRegExp /Invalid date format/ | ||
399 | */ | ||
400 | public function testFilterInvalidDayWithChars() | ||
401 | { | ||
402 | self::$privateLinkDB->filterDay('Rainy day, dream away'); | ||
403 | } | ||
404 | |||
405 | /** | ||
406 | * Use an invalid date format | ||
407 | * @expectedException Exception | ||
408 | * @expectedExceptionMessageRegExp /Invalid date format/ | ||
409 | */ | ||
410 | public function testFilterInvalidDayDigits() | ||
411 | { | ||
412 | self::$privateLinkDB->filterDay('20'); | ||
413 | } | ||
414 | |||
415 | /** | ||
416 | * Retrieve a link entry with its hash | ||
417 | */ | ||
418 | public function testFilterSmallHash() | ||
419 | { | ||
420 | $links = self::$privateLinkDB->filterSmallHash('IuWvgA'); | ||
421 | |||
422 | $this->assertEquals( | ||
423 | 1, | ||
424 | sizeof($links) | ||
425 | ); | ||
426 | |||
427 | $this->assertEquals( | ||
428 | 'MediaGoblin', | ||
429 | $links['20130614_184135']['title'] | ||
430 | ); | ||
431 | |||
432 | } | ||
433 | |||
434 | /** | ||
435 | * No link for this hash | ||
436 | */ | ||
437 | public function testFilterUnknownSmallHash() | ||
438 | { | ||
439 | $this->assertEquals( | ||
440 | 0, | ||
441 | sizeof(self::$privateLinkDB->filterSmallHash('Iblaah')) | ||
442 | ); | ||
443 | } | ||
444 | |||
445 | /** | ||
446 | * Full-text search - result from a link's URL | ||
447 | */ | ||
448 | public function testFilterFullTextURL() | ||
449 | { | ||
450 | $this->assertEquals( | ||
451 | 2, | ||
452 | sizeof(self::$publicLinkDB->filterFullText('ars.userfriendly.org')) | ||
453 | ); | ||
454 | } | ||
455 | |||
456 | /** | ||
457 | * Full-text search - result from a link's title only | ||
458 | */ | 306 | */ |
459 | public function testFilterFullTextTitle() | 307 | public function testLinkRealUrlWithoutRedirector() |
460 | { | 308 | { |
461 | // use miscellaneous cases | 309 | $db = new LinkDB(self::$testDatastore, false, false); |
462 | $this->assertEquals( | 310 | foreach($db as $link) { |
463 | 2, | 311 | $this->assertEquals($link['url'], $link['real_url']); |
464 | sizeof(self::$publicLinkDB->filterFullText('userfriendly -')) | 312 | } |
465 | ); | ||
466 | $this->assertEquals( | ||
467 | 2, | ||
468 | sizeof(self::$publicLinkDB->filterFullText('UserFriendly -')) | ||
469 | ); | ||
470 | $this->assertEquals( | ||
471 | 2, | ||
472 | sizeof(self::$publicLinkDB->filterFullText('uSeRFrIendlY -')) | ||
473 | ); | ||
474 | |||
475 | // use miscellaneous case and offset | ||
476 | $this->assertEquals( | ||
477 | 2, | ||
478 | sizeof(self::$publicLinkDB->filterFullText('RFrIendL')) | ||
479 | ); | ||
480 | } | 313 | } |
481 | 314 | ||
482 | /** | 315 | /** |
483 | * Full-text search - result from the link's description only | 316 | * Test real_url with redirector. |
484 | */ | 317 | */ |
485 | public function testFilterFullTextDescription() | 318 | public function testLinkRealUrlWithRedirector() |
486 | { | 319 | { |
487 | $this->assertEquals( | 320 | $redirector = 'http://redirector.to?'; |
488 | 1, | 321 | $db = new LinkDB(self::$testDatastore, false, false, $redirector); |
489 | sizeof(self::$publicLinkDB->filterFullText('media publishing')) | 322 | foreach($db as $link) { |
490 | ); | 323 | $this->assertStringStartsWith($redirector, $link['real_url']); |
324 | } | ||
491 | } | 325 | } |
492 | 326 | ||
493 | /** | 327 | /** |
494 | * Full-text search - result from the link's tags only | 328 | * Test filter with string. |
495 | */ | 329 | */ |
496 | public function testFilterFullTextTags() | 330 | public function testFilterString() |
497 | { | 331 | { |
332 | $tags = 'dev cartoon'; | ||
498 | $this->assertEquals( | 333 | $this->assertEquals( |
499 | 2, | 334 | 2, |
500 | sizeof(self::$publicLinkDB->filterFullText('gnu')) | 335 | count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) |
501 | ); | 336 | ); |
502 | } | 337 | } |
503 | 338 | ||
504 | /** | 339 | /** |
505 | * Full-text search - result set from mixed sources | 340 | * Test filter with string. |
506 | */ | 341 | */ |
507 | public function testFilterFullTextMixed() | 342 | public function testFilterArray() |
508 | { | 343 | { |
344 | $tags = array('dev', 'cartoon'); | ||
509 | $this->assertEquals( | 345 | $this->assertEquals( |
510 | 2, | 346 | 2, |
511 | sizeof(self::$publicLinkDB->filterFullText('free software')) | 347 | count(self::$privateLinkDB->filter(LinkFilter::$FILTER_TAG, $tags, true, false)) |
512 | ); | 348 | ); |
513 | } | 349 | } |
514 | |||
515 | /** | ||
516 | * Test real_url without redirector. | ||
517 | */ | ||
518 | public function testLinkRealUrlWithoutRedirector() | ||
519 | { | ||
520 | $db = new LinkDB(self::$testDatastore, false, false); | ||
521 | foreach($db as $link) { | ||
522 | $this->assertEquals($link['url'], $link['real_url']); | ||
523 | } | ||
524 | } | ||
525 | |||
526 | /** | ||
527 | * Test real_url with redirector. | ||
528 | */ | ||
529 | public function testLinkRealUrlWithRedirector() | ||
530 | { | ||
531 | $redirector = 'http://redirector.to?'; | ||
532 | $db = new LinkDB(self::$testDatastore, false, false, $redirector); | ||
533 | foreach($db as $link) { | ||
534 | $this->assertStringStartsWith($redirector, $link['real_url']); | ||
535 | } | ||
536 | } | ||
537 | } | 350 | } |