diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-04-01 12:17:37 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2017-05-25 15:51:12 +0200 |
commit | 7d86f40bdb2135655b5b4fe8cbcc1ac102114f86 (patch) | |
tree | c70ac4ad89a4fc84b8e52114aca7d9755cc92086 /tests | |
parent | b64d83cd2b60b6851741787f8ce2ae2c93092841 (diff) | |
download | Shaarli-7d86f40bdb2135655b5b4fe8cbcc1ac102114f86.tar.gz Shaarli-7d86f40bdb2135655b5b4fe8cbcc1ac102114f86.tar.zst Shaarli-7d86f40bdb2135655b5b4fe8cbcc1ac102114f86.zip |
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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/LinkDBTest.php | 2 | ||||
-rw-r--r-- | tests/LinkFilterTest.php | 19 | ||||
-rw-r--r-- | tests/api/controllers/GetLinksTest.php | 4 | ||||
-rw-r--r-- | tests/api/controllers/InfoTest.php | 4 | ||||
-rw-r--r-- | tests/utils/ReferenceLinkDB.php | 26 |
5 files changed, 46 insertions, 9 deletions
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php index 1f62a34a..6fbf597a 100644 --- a/tests/LinkDBTest.php +++ b/tests/LinkDBTest.php | |||
@@ -448,7 +448,7 @@ class LinkDBTest extends PHPUnit_Framework_TestCase | |||
448 | public function testReorderLinksDesc() | 448 | public function testReorderLinksDesc() |
449 | { | 449 | { |
450 | self::$privateLinkDB->reorder('ASC'); | 450 | self::$privateLinkDB->reorder('ASC'); |
451 | $linkIds = array(42, 4, 1, 0, 7, 6, 8, 41); | 451 | $linkIds = array(42, 4, 9, 1, 0, 7, 6, 8, 41); |
452 | $cpt = 0; | 452 | $cpt = 0; |
453 | foreach (self::$privateLinkDB as $key => $value) { | 453 | foreach (self::$privateLinkDB as $key => $value) { |
454 | $this->assertEquals($linkIds[$cpt++], $key); | 454 | $this->assertEquals($linkIds[$cpt++], $key); |
diff --git a/tests/LinkFilterTest.php b/tests/LinkFilterTest.php index 37d5ca30..74162358 100644 --- a/tests/LinkFilterTest.php +++ b/tests/LinkFilterTest.php | |||
@@ -63,6 +63,12 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase | |||
63 | count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '')) | 63 | count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '')) |
64 | ); | 64 | ); |
65 | 65 | ||
66 | // Untagged only | ||
67 | $this->assertEquals( | ||
68 | self::$refDB->countUntaggedLinks(), | ||
69 | count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, false)) | ||
70 | ); | ||
71 | |||
66 | $this->assertEquals( | 72 | $this->assertEquals( |
67 | ReferenceLinkDB::$NB_LINKS_TOTAL, | 73 | ReferenceLinkDB::$NB_LINKS_TOTAL, |
68 | count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '')) | 74 | count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '')) |
@@ -146,7 +152,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase | |||
146 | public function testFilterDay() | 152 | public function testFilterDay() |
147 | { | 153 | { |
148 | $this->assertEquals( | 154 | $this->assertEquals( |
149 | 3, | 155 | 4, |
150 | count(self::$linkFilter->filter(LinkFilter::$FILTER_DAY, '20121206')) | 156 | count(self::$linkFilter->filter(LinkFilter::$FILTER_DAY, '20121206')) |
151 | ); | 157 | ); |
152 | } | 158 | } |
@@ -339,7 +345,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase | |||
339 | ); | 345 | ); |
340 | 346 | ||
341 | $this->assertEquals( | 347 | $this->assertEquals( |
342 | 7, | 348 | ReferenceLinkDB::$NB_LINKS_TOTAL - 1, |
343 | count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '-revolution')) | 349 | count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, '-revolution')) |
344 | ); | 350 | ); |
345 | } | 351 | } |
@@ -399,7 +405,7 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase | |||
399 | ); | 405 | ); |
400 | 406 | ||
401 | $this->assertEquals( | 407 | $this->assertEquals( |
402 | 7, | 408 | ReferenceLinkDB::$NB_LINKS_TOTAL - 1, |
403 | count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '-free')) | 409 | count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '-free')) |
404 | ); | 410 | ); |
405 | } | 411 | } |
@@ -429,6 +435,13 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase | |||
429 | 1, | 435 | 1, |
430 | count(self::$linkFilter->filter( | 436 | count(self::$linkFilter->filter( |
431 | LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, | 437 | LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, |
438 | array(false, 'PSR-2') | ||
439 | )) | ||
440 | ); | ||
441 | $this->assertEquals( | ||
442 | 1, | ||
443 | count(self::$linkFilter->filter( | ||
444 | LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT, | ||
432 | array($tags, '') | 445 | array($tags, '') |
433 | )) | 446 | )) |
434 | ); | 447 | ); |
diff --git a/tests/api/controllers/GetLinksTest.php b/tests/api/controllers/GetLinksTest.php index 10330cd9..f1b262bc 100644 --- a/tests/api/controllers/GetLinksTest.php +++ b/tests/api/controllers/GetLinksTest.php | |||
@@ -94,7 +94,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
94 | $this->assertEquals($this->refDB->countLinks(), count($data)); | 94 | $this->assertEquals($this->refDB->countLinks(), count($data)); |
95 | 95 | ||
96 | // Check order | 96 | // Check order |
97 | $order = [41, 8, 6, 7, 0, 1, 4, 42]; | 97 | $order = [41, 8, 6, 7, 0, 1, 9, 4, 42]; |
98 | $cpt = 0; | 98 | $cpt = 0; |
99 | foreach ($data as $link) { | 99 | foreach ($data as $link) { |
100 | $this->assertEquals(self::NB_FIELDS_LINK, count($link)); | 100 | $this->assertEquals(self::NB_FIELDS_LINK, count($link)); |
@@ -163,7 +163,7 @@ class GetLinksTest extends \PHPUnit_Framework_TestCase | |||
163 | $data = json_decode((string) $response->getBody(), true); | 163 | $data = json_decode((string) $response->getBody(), true); |
164 | $this->assertEquals($this->refDB->countLinks(), count($data)); | 164 | $this->assertEquals($this->refDB->countLinks(), count($data)); |
165 | // Check order | 165 | // Check order |
166 | $order = [41, 8, 6, 7, 0, 1, 4, 42]; | 166 | $order = [41, 8, 6, 7, 0, 1, 9, 4, 42]; |
167 | $cpt = 0; | 167 | $cpt = 0; |
168 | foreach ($data as $link) { | 168 | foreach ($data as $link) { |
169 | $this->assertEquals(self::NB_FIELDS_LINK, count($link)); | 169 | $this->assertEquals(self::NB_FIELDS_LINK, count($link)); |
diff --git a/tests/api/controllers/InfoTest.php b/tests/api/controllers/InfoTest.php index 4beef3f7..5d6a2329 100644 --- a/tests/api/controllers/InfoTest.php +++ b/tests/api/controllers/InfoTest.php | |||
@@ -80,7 +80,7 @@ class InfoTest extends \PHPUnit_Framework_TestCase | |||
80 | $this->assertEquals(200, $response->getStatusCode()); | 80 | $this->assertEquals(200, $response->getStatusCode()); |
81 | $data = json_decode((string) $response->getBody(), true); | 81 | $data = json_decode((string) $response->getBody(), true); |
82 | 82 | ||
83 | $this->assertEquals(8, $data['global_counter']); | 83 | $this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']); |
84 | $this->assertEquals(2, $data['private_counter']); | 84 | $this->assertEquals(2, $data['private_counter']); |
85 | $this->assertEquals('Shaarli', $data['settings']['title']); | 85 | $this->assertEquals('Shaarli', $data['settings']['title']); |
86 | $this->assertEquals('?', $data['settings']['header_link']); | 86 | $this->assertEquals('?', $data['settings']['header_link']); |
@@ -103,7 +103,7 @@ class InfoTest extends \PHPUnit_Framework_TestCase | |||
103 | $this->assertEquals(200, $response->getStatusCode()); | 103 | $this->assertEquals(200, $response->getStatusCode()); |
104 | $data = json_decode((string) $response->getBody(), true); | 104 | $data = json_decode((string) $response->getBody(), true); |
105 | 105 | ||
106 | $this->assertEquals(8, $data['global_counter']); | 106 | $this->assertEquals(\ReferenceLinkDB::$NB_LINKS_TOTAL, $data['global_counter']); |
107 | $this->assertEquals(2, $data['private_counter']); | 107 | $this->assertEquals(2, $data['private_counter']); |
108 | $this->assertEquals($title, $data['settings']['title']); | 108 | $this->assertEquals($title, $data['settings']['title']); |
109 | $this->assertEquals($headerLink, $data['settings']['header_link']); | 109 | $this->assertEquals($headerLink, $data['settings']['header_link']); |
diff --git a/tests/utils/ReferenceLinkDB.php b/tests/utils/ReferenceLinkDB.php index 36d58c68..29d63fac 100644 --- a/tests/utils/ReferenceLinkDB.php +++ b/tests/utils/ReferenceLinkDB.php | |||
@@ -4,7 +4,7 @@ | |||
4 | */ | 4 | */ |
5 | class ReferenceLinkDB | 5 | class ReferenceLinkDB |
6 | { | 6 | { |
7 | public static $NB_LINKS_TOTAL = 8; | 7 | public static $NB_LINKS_TOTAL = 9; |
8 | 8 | ||
9 | private $_links = array(); | 9 | private $_links = array(); |
10 | private $_publicCount = 0; | 10 | private $_publicCount = 0; |
@@ -38,6 +38,16 @@ class ReferenceLinkDB | |||
38 | ); | 38 | ); |
39 | 39 | ||
40 | $this->addLink( | 40 | $this->addLink( |
41 | 9, | ||
42 | 'PSR-2: Coding Style Guide', | ||
43 | 'http://www.php-fig.org/psr/psr-2/', | ||
44 | 'This guide extends and expands on PSR-1, the basic coding standard.', | ||
45 | 0, | ||
46 | DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_152312'), | ||
47 | '' | ||
48 | ); | ||
49 | |||
50 | $this->addLink( | ||
41 | 8, | 51 | 8, |
42 | 'Free as in Freedom 2.0 @website', | 52 | 'Free as in Freedom 2.0 @website', |
43 | 'https://static.fsf.org/nosvn/faif-2.0.pdf', | 53 | 'https://static.fsf.org/nosvn/faif-2.0.pdf', |
@@ -161,6 +171,20 @@ class ReferenceLinkDB | |||
161 | return $this->_privateCount; | 171 | return $this->_privateCount; |
162 | } | 172 | } |
163 | 173 | ||
174 | /** | ||
175 | * Returns the number of links without tag | ||
176 | */ | ||
177 | public function countUntaggedLinks() | ||
178 | { | ||
179 | $cpt = 0; | ||
180 | foreach ($this->_links as $link) { | ||
181 | if (empty($link['tags'])) { | ||
182 | ++$cpt; | ||
183 | } | ||
184 | } | ||
185 | return $cpt; | ||
186 | } | ||
187 | |||
164 | public function getLinks() | 188 | public function getLinks() |
165 | { | 189 | { |
166 | return $this->_links; | 190 | return $this->_links; |