Empty tag search will look for not tagged links
Fixes #784 From now, searching for tags with an empty value will return only not tagged links, with the search bar showing `x results [not tagged]`. Note that using the api, the searchtags request parameter must be set to `false` to get the same result. - [ ] Update API doc
This commit is contained in:
parent
b64d83cd2b
commit
7d86f40bdb
12 changed files with 115 additions and 36 deletions
tests
|
@ -448,7 +448,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
|
|||
public function testReorderLinksDesc()
|
||||
{
|
||||
self::$privateLinkDB->reorder('ASC');
|
||||
$linkIds = array(42, 4, 1, 0, 7, 6, 8, 41);
|
||||
$linkIds = array(42, 4, 9, 1, 0, 7, 6, 8, 41);
|
||||
$cpt = 0;
|
||||
foreach (self::$privateLinkDB as $key => $value) {
|
||||
$this->assertEquals($linkIds[$cpt++], $key);
|
||||
|
|
|
@ -63,6 +63,12 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
|
|||
count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, ''))
|
||||
);
|
||||
|
||||
// Untagged only
|
||||
$this->assertEquals(
|
||||
self::$refDB->countUntaggedLinks(),
|
||||
count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, false))
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
ReferenceLinkDB::$NB_LINKS_TOTAL,
|
||||
count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, ''))
|
||||
|
@ -146,7 +152,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
|
|||
public function testFilterDay()
|
||||
{
|
||||
$this->assertEquals(
|
||||
3,
|
||||
4,
|
||||
count(self::$linkFilter->filter(LinkFilter::$FILTER_DAY, '20121206'))
|
||||
);
|
||||
}
|
||||
|
@ -339,7 +345,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
|
|||
);
|
||||
|
||||
$this->assertEquals(
|
||||
7,
|
||||
ReferenceLinkDB::$NB_LINKS_TOTAL - 1,
|
||||
count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '-revolution'))
|
||||
);
|
||||
}
|
||||
|
@ -399,7 +405,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
|
|||
);
|
||||
|
||||
$this->assertEquals(
|
||||
7,
|
||||
ReferenceLinkDB::$NB_LINKS_TOTAL - 1,
|
||||
count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '-free'))
|
||||
);
|
||||
}
|
||||
|
@ -425,6 +431,13 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
|
|||
array('', $terms)
|
||||
))
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
count(self::$linkFilter->filter(
|
||||
LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT,
|
||||
array(false, 'PSR-2')
|
||||
))
|
||||
);
|
||||
$this->assertEquals(
|
||||
1,
|
||||
count(self::$linkFilter->filter(
|
||||
|
|
|
@ -94,7 +94,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals($this->refDB->countLinks(), count($data));
|
||||
|
||||
// Check order
|
||||
$order = [41, 8, 6, 7, 0, 1, 4, 42];
|
||||
$order = [41, 8, 6, 7, 0, 1, 9, 4, 42];
|
||||
$cpt = 0;
|
||||
foreach ($data as $link) {
|
||||
$this->assertEquals(self::NB_FIELDS_LINK, count($link));
|
||||
|
@ -163,7 +163,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase
|
|||
$data = json_decode((string) $response->getBody(), true);
|
||||
$this->assertEquals($this->refDB->countLinks(), count($data));
|
||||
// Check order
|
||||
$order = [41, 8, 6, 7, 0, 1, 4, 42];
|
||||
$order = [41, 8, 6, 7, 0, 1, 9, 4, 42];
|
||||
$cpt = 0;
|
||||
foreach ($data as $link) {
|
||||
$this->assertEquals(self::NB_FIELDS_LINK, count($link));
|
||||
|
|
|
@ -80,7 +80,7 @@ class InfoTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$data = json_decode((string) $response->getBody(), true);
|
||||
|
||||
$this->assertEquals(8, $data['global_counter']);
|
||||
$this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']);
|
||||
$this->assertEquals(2, $data['private_counter']);
|
||||
$this->assertEquals('Shaarli', $data['settings']['title']);
|
||||
$this->assertEquals('?', $data['settings']['header_link']);
|
||||
|
@ -103,7 +103,7 @@ class InfoTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$data = json_decode((string) $response->getBody(), true);
|
||||
|
||||
$this->assertEquals(8, $data['global_counter']);
|
||||
$this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']);
|
||||
$this->assertEquals(2, $data['private_counter']);
|
||||
$this->assertEquals($title, $data['settings']['title']);
|
||||
$this->assertEquals($headerLink, $data['settings']['header_link']);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
class ReferenceLinkDB
|
||||
{
|
||||
public static $NB_LINKS_TOTAL = 8;
|
||||
public static $NB_LINKS_TOTAL = 9;
|
||||
|
||||
private $_links = array();
|
||||
private $_publicCount = 0;
|
||||
|
@ -37,6 +37,16 @@ class ReferenceLinkDB
|
|||
'ut'
|
||||
);
|
||||
|
||||
$this->addLink(
|
||||
9,
|
||||
'PSR-2: Coding Style Guide',
|
||||
'http://www.php-fig.org/psr/psr-2/',
|
||||
'This guide extends and expands on PSR-1, the basic coding standard.',
|
||||
0,
|
||||
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_152312'),
|
||||
''
|
||||
);
|
||||
|
||||
$this->addLink(
|
||||
8,
|
||||
'Free as in Freedom 2.0 @website',
|
||||
|
@ -161,6 +171,20 @@ class ReferenceLinkDB
|
|||
return $this->_privateCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of links without tag
|
||||
*/
|
||||
public function countUntaggedLinks()
|
||||
{
|
||||
$cpt = 0;
|
||||
foreach ($this->_links as $link) {
|
||||
if (empty($link['tags'])) {
|
||||
++$cpt;
|
||||
}
|
||||
}
|
||||
return $cpt;
|
||||
}
|
||||
|
||||
public function getLinks()
|
||||
{
|
||||
return $this->_links;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue