Added filter class for tags
This commit is contained in:
@@ -48,8 +48,8 @@ abstract class Base extends PHPUnit_Framework_TestCase
|
||||
new Stopwatch
|
||||
);
|
||||
|
||||
$this->container['db']->logQueries = true;
|
||||
$this->container['logger'] = new Logger;
|
||||
$this->container['db']->getStatementHandler()->withLogging();
|
||||
$this->container['logger'] = new Logger();
|
||||
|
||||
$this->container['httpClient'] = $this
|
||||
->getMockBuilder('\Kanboard\Core\Http\Client')
|
||||
|
||||
@@ -202,4 +202,16 @@ class LexerTest extends Base
|
||||
|
||||
$this->assertSame($expected, $lexer->tokenize('६Δↈ五一'));
|
||||
}
|
||||
|
||||
public function testTokenizeWithMultipleValues()
|
||||
{
|
||||
$lexer = new Lexer();
|
||||
$lexer->addToken("/^(tag:)/", 'T_TAG');
|
||||
|
||||
$expected = array(
|
||||
'T_TAG' => array('tag 1', 'tag2'),
|
||||
);
|
||||
|
||||
$this->assertSame($expected, $lexer->tokenize('tag:"tag 1" tag:tag2'));
|
||||
}
|
||||
}
|
||||
|
||||
121
tests/units/Filter/TaskTagFilterTest.php
Normal file
121
tests/units/Filter/TaskTagFilterTest.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
use Kanboard\Filter\TaskTagFilter;
|
||||
use Kanboard\Model\ProjectModel;
|
||||
use Kanboard\Model\TaskCreationModel;
|
||||
use Kanboard\Model\TaskFinderModel;
|
||||
use Kanboard\Model\TaskTagModel;
|
||||
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
class TaskTagFilterTest extends Base
|
||||
{
|
||||
public function testWithMultipleMatches()
|
||||
{
|
||||
$taskFinderModel = new TaskFinderModel($this->container);
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
$taskTagModel = new TaskTagModel($this->container);
|
||||
$query = $taskFinderModel->getExtendedQuery();
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
|
||||
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
|
||||
$this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
|
||||
|
||||
$this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
|
||||
$this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
|
||||
|
||||
$filter = new TaskTagFilter();
|
||||
$filter->setDatabase($this->container['db']);
|
||||
$filter->withQuery($query);
|
||||
$filter->withValue('my tag 3');
|
||||
$filter->apply();
|
||||
|
||||
$tasks = $query->findAll();
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('test1', $tasks[0]['title']);
|
||||
$this->assertEquals('test2', $tasks[1]['title']);
|
||||
}
|
||||
|
||||
public function testWithSingleMatch()
|
||||
{
|
||||
$taskFinderModel = new TaskFinderModel($this->container);
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
$taskTagModel = new TaskTagModel($this->container);
|
||||
$query = $taskFinderModel->getExtendedQuery();
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
|
||||
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
|
||||
$this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
|
||||
|
||||
$this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
|
||||
$this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
|
||||
|
||||
$filter = new TaskTagFilter();
|
||||
$filter->setDatabase($this->container['db']);
|
||||
$filter->withQuery($query);
|
||||
$filter->withValue('my tag 2');
|
||||
$filter->apply();
|
||||
|
||||
$tasks = $query->findAll();
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('test1', $tasks[0]['title']);
|
||||
}
|
||||
|
||||
public function testWithNoMatch()
|
||||
{
|
||||
$taskFinderModel = new TaskFinderModel($this->container);
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
$taskTagModel = new TaskTagModel($this->container);
|
||||
$query = $taskFinderModel->getExtendedQuery();
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
|
||||
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
|
||||
$this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
|
||||
|
||||
$this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
|
||||
$this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
|
||||
|
||||
$filter = new TaskTagFilter();
|
||||
$filter->setDatabase($this->container['db']);
|
||||
$filter->withQuery($query);
|
||||
$filter->withValue('my tag 42');
|
||||
$filter->apply();
|
||||
|
||||
$tasks = $query->findAll();
|
||||
$this->assertCount(0, $tasks);
|
||||
}
|
||||
|
||||
public function testWithSameTagInMultipleProjects()
|
||||
{
|
||||
$taskFinderModel = new TaskFinderModel($this->container);
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
$taskTagModel = new TaskTagModel($this->container);
|
||||
$query = $taskFinderModel->getExtendedQuery();
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
|
||||
$this->assertEquals(2, $projectModel->create(array('name' => 'Test')));
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
|
||||
$this->assertEquals(2, $taskCreationModel->create(array('project_id' => 2, 'title' => 'test2')));
|
||||
|
||||
$this->assertTrue($taskTagModel->save(1, 1, array('My tag')));
|
||||
$this->assertTrue($taskTagModel->save(2, 2, array('My tag')));
|
||||
|
||||
$filter = new TaskTagFilter();
|
||||
$filter->setDatabase($this->container['db']);
|
||||
$filter->withQuery($query);
|
||||
$filter->withValue('my tag');
|
||||
$filter->apply();
|
||||
|
||||
$tasks = $query->findAll();
|
||||
$this->assertCount(2, $tasks);
|
||||
$this->assertEquals('test1', $tasks[0]['title']);
|
||||
$this->assertEquals('test2', $tasks[1]['title']);
|
||||
}
|
||||
}
|
||||
@@ -110,4 +110,18 @@ class TaskTagModelTest extends Base
|
||||
|
||||
$this->assertEquals($expected, $tags);
|
||||
}
|
||||
|
||||
public function testGetTagsForTasksWithEmptyList()
|
||||
{
|
||||
$projectModel = new ProjectModel($this->container);
|
||||
$taskCreationModel = new TaskCreationModel($this->container);
|
||||
$taskTagModel = new TaskTagModel($this->container);
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
|
||||
$this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
|
||||
|
||||
$tags = $taskTagModel->getTagsByTasks(array());
|
||||
$this->assertEquals(array(), $tags);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user