Add exclusion in tag search

* Searching '-mytag' will now exlude all shaares with 'mytag' tag.
  * All tags starting with a '-' are renamed without it (through the Updater).
  * Unit tests.

Minor code changes:

 * LinkDB->filter() can now take no parameters (get all link depending on logged status).
 * tagsStrToArray() is now static and filters blank tags.
This commit is contained in:
ArthurHoaro 2016-01-20 23:34:33 +01:00
parent 6e607ca613
commit 21979ff11c
7 changed files with 77 additions and 12 deletions

View file

@ -276,7 +276,8 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
'media' => 1,
'software' => 1,
'stallman' => 1,
'free' => 1
'free' => 1,
'-exclude' => 1,
),
self::$publicLinkDB->allTags()
);
@ -295,7 +296,8 @@ class LinkDBTest extends PHPUnit_Framework_TestCase
'html' => 1,
'w3c' => 1,
'css' => 1,
'Mercurial' => 1
'Mercurial' => 1,
'-exclude' => 1,
),
self::$privateLinkDB->allTags()
);

View file

@ -254,4 +254,20 @@ class LinkFilterTest extends PHPUnit_Framework_TestCase
count(self::$linkFilter->filter(LinkFilter::$FILTER_TEXT, 'free software'))
);
}
/**
* Tag search with exclusion.
*/
public function testTagFilterWithExclusion()
{
$this->assertEquals(
1,
count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, 'gnu -free'))
);
$this->assertEquals(
5,
count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '-free'))
);
}
}

View file

@ -13,6 +13,11 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
*/
private static $configFields;
/**
* @var string Path to test datastore.
*/
protected static $testDatastore = 'sandbox/datastore.php';
/**
* Executed before each test.
*/
@ -31,6 +36,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
'config' => array(
'CONFIG_FILE' => 'tests/Updater/config.php',
'DATADIR' => 'tests/Updater',
'PAGECACHE' => 'sandbox/pagecache',
'config1' => 'config1data',
'config2' => 'config2data',
)
@ -224,4 +230,16 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
include self::$configFields['config']['CONFIG_FILE'];
$this->assertEquals(self::$configFields['login'], $GLOBALS['login']);
}
public function testRenameDashTags()
{
$refDB = new ReferenceLinkDB();
$refDB->write(self::$testDatastore);
$linkDB = new LinkDB(self::$testDatastore, true, false);
$this->assertEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude'));
$updater = new Updater(array(), self::$configFields, $linkDB, true);
$updater->updateMethodRenameDashTags();
var_dump($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude'));
$this->assertNotEmpty($linkDB->filter(LinkFilter::$FILTER_TAG, 'exclude'));
}
}

View file

@ -19,7 +19,7 @@ class ReferenceLinkDB
'Richard Stallman and the Free Software Revolution',
0,
'20150310_114633',
'free gnu software stallman'
'free gnu software stallman -exclude'
);
$this->addLink(