diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-04-09 22:42:17 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-04-09 22:42:17 -0400 |
commit | 11858be4e8d5aba983700c6cba1c4d0a33ea8e9d (patch) | |
tree | 38427e86d52185df95e2b891e4bcd50aeb56eeb9 /tests | |
parent | 42813d702d1c3e5659301bc771f8dbb37a6d15cd (diff) |
Filter refactoring
Diffstat (limited to 'tests')
-rw-r--r-- | tests/units/Base.php | 1 | ||||
-rw-r--r-- | tests/units/Core/Filter/LexerBuilderTest.php | 106 | ||||
-rw-r--r-- | tests/units/Core/Filter/LexerTest.php | 100 | ||||
-rw-r--r-- | tests/units/Core/Filter/OrCriteriaTest.php | 58 | ||||
-rw-r--r-- | tests/units/Core/LexerTest.php | 468 | ||||
-rw-r--r-- | tests/units/Filter/TaskAssigneeFilterTest.php | 159 | ||||
-rw-r--r-- | tests/units/Formatter/TaskFilterCalendarFormatterTest.php | 21 | ||||
-rw-r--r-- | tests/units/Formatter/TaskFilterGanttFormatterTest.php | 24 | ||||
-rw-r--r-- | tests/units/Formatter/TaskFilterICalendarFormatterTest.php | 74 | ||||
-rw-r--r-- | tests/units/Model/SubtaskTimeTrackingTest.php | 77 | ||||
-rw-r--r-- | tests/units/Model/TaskFilterTest.php | 624 |
11 files changed, 424 insertions, 1288 deletions
diff --git a/tests/units/Base.php b/tests/units/Base.php index 563035f6..5125ffb9 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -40,6 +40,7 @@ abstract class Base extends PHPUnit_Framework_TestCase $this->container->register(new Kanboard\ServiceProvider\NotificationProvider); $this->container->register(new Kanboard\ServiceProvider\RouteProvider); $this->container->register(new Kanboard\ServiceProvider\AvatarProvider); + $this->container->register(new Kanboard\ServiceProvider\FilterProvider); $this->container['dispatcher'] = new TraceableEventDispatcher( new EventDispatcher, diff --git a/tests/units/Core/Filter/LexerBuilderTest.php b/tests/units/Core/Filter/LexerBuilderTest.php new file mode 100644 index 00000000..ac5315bb --- /dev/null +++ b/tests/units/Core/Filter/LexerBuilderTest.php @@ -0,0 +1,106 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Filter\LexerBuilder; +use Kanboard\Filter\TaskAssigneeFilter; +use Kanboard\Filter\TaskTitleFilter; +use Kanboard\Model\Project; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; + +class LexerBuilderTest extends Base +{ + public function testBuilderThatReturnResult() + { + $project = new Project($this->container); + $taskCreation = new TaskCreation($this->container); + $taskFinder = new TaskFinder($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(1, $project->create(array('name' => 'Project'))); + $this->assertNotFalse($taskCreation->create(array('project_id' => 1, 'title' => 'Test'))); + + $builder = new LexerBuilder(); + $builder->withFilter(new TaskAssigneeFilter()); + $builder->withFilter(new TaskTitleFilter(), true); + $builder->withQuery($query); + $tasks = $builder->build('assignee:nobody')->toArray(); + + $this->assertCount(1, $tasks); + $this->assertEquals('Test', $tasks[0]['title']); + } + + public function testBuilderThatReturnNothing() + { + $project = new Project($this->container); + $taskCreation = new TaskCreation($this->container); + $taskFinder = new TaskFinder($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(1, $project->create(array('name' => 'Project'))); + $this->assertNotFalse($taskCreation->create(array('project_id' => 1, 'title' => 'Test'))); + + $builder = new LexerBuilder(); + $builder->withFilter(new TaskAssigneeFilter()); + $builder->withFilter(new TaskTitleFilter(), true); + $builder->withQuery($query); + $tasks = $builder->build('something')->toArray(); + + $this->assertCount(0, $tasks); + } + + public function testBuilderWithEmptyInput() + { + $project = new Project($this->container); + $taskCreation = new TaskCreation($this->container); + $taskFinder = new TaskFinder($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(1, $project->create(array('name' => 'Project'))); + $this->assertNotFalse($taskCreation->create(array('project_id' => 1, 'title' => 'Test'))); + + $builder = new LexerBuilder(); + $builder->withFilter(new TaskAssigneeFilter()); + $builder->withFilter(new TaskTitleFilter(), true); + $builder->withQuery($query); + $tasks = $builder->build('')->toArray(); + + $this->assertCount(1, $tasks); + } + + public function testBuilderWithMultipleMatches() + { + $project = new Project($this->container); + $taskCreation = new TaskCreation($this->container); + $taskFinder = new TaskFinder($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(1, $project->create(array('name' => 'Project'))); + $this->assertNotFalse($taskCreation->create(array('project_id' => 1, 'title' => 'ABC', 'owner_id' => 1))); + $this->assertNotFalse($taskCreation->create(array('project_id' => 1, 'title' => 'DEF'))); + + $builder = new LexerBuilder(); + $builder->withFilter(new TaskAssigneeFilter()); + $builder->withFilter(new TaskTitleFilter(), true); + $builder->withQuery($query); + $tasks = $builder->build('assignee:nobody assignee:1')->toArray(); + + $this->assertCount(2, $tasks); + } + + public function testClone() + { + $taskFinder = new TaskFinder($this->container); + $query = $taskFinder->getExtendedQuery(); + + $builder = new LexerBuilder(); + $builder->withFilter(new TaskAssigneeFilter()); + $builder->withFilter(new TaskTitleFilter()); + $builder->withQuery($query); + + $clone = clone($builder); + $this->assertFalse($builder === $clone); + $this->assertFalse($builder->build('test')->getQuery() === $clone->build('test')->getQuery()); + } +} diff --git a/tests/units/Core/Filter/LexerTest.php b/tests/units/Core/Filter/LexerTest.php new file mode 100644 index 00000000..3f3e368e --- /dev/null +++ b/tests/units/Core/Filter/LexerTest.php @@ -0,0 +1,100 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Filter\Lexer; + +class LexerTest extends Base +{ + public function testTokenizeWithNoDefaultToken() + { + $lexer = new Lexer(); + $this->assertSame(array(), $lexer->tokenize('This is Kanboard')); + } + + public function testTokenizeWithDefaultToken() + { + $lexer = new Lexer(); + $lexer->setDefaultToken('myDefaultToken'); + + $expected = array( + 'myDefaultToken' => array('This is Kanboard'), + ); + + $this->assertSame($expected, $lexer->tokenize('This is Kanboard')); + } + + public function testTokenizeWithCustomToken() + { + $lexer = new Lexer(); + $lexer->addToken("/^(assignee:)/", 'T_USER'); + + $expected = array( + 'T_USER' => array('admin'), + ); + + $this->assertSame($expected, $lexer->tokenize('assignee:admin something else')); + } + + public function testTokenizeWithCustomTokenAndDefaultToken() + { + $lexer = new Lexer(); + $lexer->setDefaultToken('myDefaultToken'); + $lexer->addToken("/^(assignee:)/", 'T_USER'); + + $expected = array( + 'T_USER' => array('admin'), + 'myDefaultToken' => array('something else'), + ); + + $this->assertSame($expected, $lexer->tokenize('assignee:admin something else')); + } + + public function testTokenizeWithQuotedString() + { + $lexer = new Lexer(); + $lexer->addToken("/^(assignee:)/", 'T_USER'); + + $expected = array( + 'T_USER' => array('Foo Bar'), + ); + + $this->assertSame($expected, $lexer->tokenize('assignee:"Foo Bar" something else')); + } + + public function testTokenizeWithNumber() + { + $lexer = new Lexer(); + $lexer->setDefaultToken('myDefaultToken'); + + $expected = array( + 'myDefaultToken' => array('#123'), + ); + + $this->assertSame($expected, $lexer->tokenize('#123')); + } + + public function testTokenizeWithStringDate() + { + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_DATE'); + + $expected = array( + 'T_DATE' => array('today'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:today something else')); + } + + public function testTokenizeWithIsoDate() + { + $lexer = new Lexer(); + $lexer->addToken("/^(date:)/", 'T_DATE'); + + $expected = array( + 'T_DATE' => array('<=2016-01-01'), + ); + + $this->assertSame($expected, $lexer->tokenize('date:<=2016-01-01 something else')); + } +} diff --git a/tests/units/Core/Filter/OrCriteriaTest.php b/tests/units/Core/Filter/OrCriteriaTest.php new file mode 100644 index 00000000..787d3461 --- /dev/null +++ b/tests/units/Core/Filter/OrCriteriaTest.php @@ -0,0 +1,58 @@ +<?php + +use Kanboard\Core\Filter\OrCriteria; +use Kanboard\Filter\TaskAssigneeFilter; +use Kanboard\Filter\TaskTitleFilter; +use Kanboard\Model\Project; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\User; + +require_once __DIR__.'/../../Base.php'; + +class OrCriteriaTest extends Base +{ + public function testWithSameFilter() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $userModel = new User($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 2))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 1))); + + $criteria = new OrCriteria(); + $criteria->withQuery($query); + $criteria->withFilter(TaskAssigneeFilter::getInstance(1)); + $criteria->withFilter(TaskAssigneeFilter::getInstance(2)); + $criteria->apply(); + + $this->assertCount(2, $query->findAll()); + } + + public function testWithDifferentFilter() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $userModel = new User($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'ABC', 'project_id' => 1, 'owner_id' => 2))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'DEF', 'project_id' => 1, 'owner_id' => 1))); + + $criteria = new OrCriteria(); + $criteria->withQuery($query); + $criteria->withFilter(TaskAssigneeFilter::getInstance(1)); + $criteria->withFilter(TaskTitleFilter::getInstance('ABC')); + $criteria->apply(); + + $this->assertCount(2, $query->findAll()); + } +} diff --git a/tests/units/Core/LexerTest.php b/tests/units/Core/LexerTest.php deleted file mode 100644 index 55370aab..00000000 --- a/tests/units/Core/LexerTest.php +++ /dev/null @@ -1,468 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Core\Lexer; - -class LexerTest extends Base -{ - public function testSwimlaneQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'swimlane:', 'token' => 'T_SWIMLANE'), array('match' => 'Version 42', 'token' => 'T_STRING')), - $lexer->tokenize('swimlane:"Version 42"') - ); - - $this->assertEquals( - array(array('match' => 'swimlane:', 'token' => 'T_SWIMLANE'), array('match' => 'v3', 'token' => 'T_STRING')), - $lexer->tokenize('swimlane:v3') - ); - - $this->assertEquals( - array('T_SWIMLANE' => array('v3')), - $lexer->map($lexer->tokenize('swimlane:v3')) - ); - - $this->assertEquals( - array('T_SWIMLANE' => array('Version 42', 'v3')), - $lexer->map($lexer->tokenize('swimlane:"Version 42" swimlane:v3')) - ); - } - - public function testAssigneeQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'assignee:', 'token' => 'T_ASSIGNEE'), array('match' => 'me', 'token' => 'T_STRING')), - $lexer->tokenize('assignee:me') - ); - - $this->assertEquals( - array(array('match' => 'assignee:', 'token' => 'T_ASSIGNEE'), array('match' => 'everybody', 'token' => 'T_STRING')), - $lexer->tokenize('assignee:everybody') - ); - - $this->assertEquals( - array(array('match' => 'assignee:', 'token' => 'T_ASSIGNEE'), array('match' => 'nobody', 'token' => 'T_STRING')), - $lexer->tokenize('assignee:nobody') - ); - - $this->assertEquals( - array('T_ASSIGNEE' => array('nobody')), - $lexer->map($lexer->tokenize('assignee:nobody')) - ); - - $this->assertEquals( - array('T_ASSIGNEE' => array('John Doe', 'me')), - $lexer->map($lexer->tokenize('assignee:"John Doe" assignee:me')) - ); - } - - public function testColorQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'color:', 'token' => 'T_COLOR'), array('match' => 'Blue', 'token' => 'T_STRING')), - $lexer->tokenize('color:Blue') - ); - - $this->assertEquals( - array(array('match' => 'color:', 'token' => 'T_COLOR'), array('match' => 'Dark Grey', 'token' => 'T_STRING')), - $lexer->tokenize('color:"Dark Grey"') - ); - - $this->assertEquals( - array('T_COLOR' => array('Blue')), - $lexer->map($lexer->tokenize('color:Blue')) - ); - - $this->assertEquals( - array('T_COLOR' => array('Dark Grey')), - $lexer->map($lexer->tokenize('color:"Dark Grey"')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('color: ')) - ); - } - - public function testCategoryQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'category:', 'token' => 'T_CATEGORY'), array('match' => 'Feature Request', 'token' => 'T_STRING')), - $lexer->tokenize('category:"Feature Request"') - ); - - $this->assertEquals( - array('T_CATEGORY' => array('Feature Request')), - $lexer->map($lexer->tokenize('category:"Feature Request"')) - ); - - $this->assertEquals( - array('T_CATEGORY' => array('Feature Request', 'Bug')), - $lexer->map($lexer->tokenize('category:"Feature Request" category:Bug')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('category: ')) - ); - } - - public function testLinkQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'link:', 'token' => 'T_LINK'), array('match' => 'is a milestone of', 'token' => 'T_STRING')), - $lexer->tokenize('link:"is a milestone of"') - ); - - $this->assertEquals( - array('T_LINK' => array('is a milestone of')), - $lexer->map($lexer->tokenize('link:"is a milestone of"')) - ); - - $this->assertEquals( - array('T_LINK' => array('is a milestone of', 'fixes')), - $lexer->map($lexer->tokenize('link:"is a milestone of" link:fixes')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('link: ')) - ); - } - - public function testColumnQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'column:', 'token' => 'T_COLUMN'), array('match' => 'Feature Request', 'token' => 'T_STRING')), - $lexer->tokenize('column:"Feature Request"') - ); - - $this->assertEquals( - array('T_COLUMN' => array('Feature Request')), - $lexer->map($lexer->tokenize('column:"Feature Request"')) - ); - - $this->assertEquals( - array('T_COLUMN' => array('Feature Request', 'Bug')), - $lexer->map($lexer->tokenize('column:"Feature Request" column:Bug')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('column: ')) - ); - } - - public function testProjectQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'project:', 'token' => 'T_PROJECT'), array('match' => 'My project', 'token' => 'T_STRING')), - $lexer->tokenize('project:"My project"') - ); - - $this->assertEquals( - array('T_PROJECT' => array('My project')), - $lexer->map($lexer->tokenize('project:"My project"')) - ); - - $this->assertEquals( - array('T_PROJECT' => array('My project', 'plop')), - $lexer->map($lexer->tokenize('project:"My project" project:plop')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('project: ')) - ); - } - - public function testStatusQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'status:', 'token' => 'T_STATUS'), array('match' => 'open', 'token' => 'T_STRING')), - $lexer->tokenize('status:open') - ); - - $this->assertEquals( - array(array('match' => 'status:', 'token' => 'T_STATUS'), array('match' => 'closed', 'token' => 'T_STRING')), - $lexer->tokenize('status:closed') - ); - - $this->assertEquals( - array('T_STATUS' => 'open'), - $lexer->map($lexer->tokenize('status:open')) - ); - - $this->assertEquals( - array('T_STATUS' => 'closed'), - $lexer->map($lexer->tokenize('status:closed')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('status: ')) - ); - } - - public function testReferenceQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'ref:', 'token' => 'T_REFERENCE'), array('match' => '123', 'token' => 'T_STRING')), - $lexer->tokenize('ref:123') - ); - - $this->assertEquals( - array(array('match' => 'reference:', 'token' => 'T_REFERENCE'), array('match' => '456', 'token' => 'T_STRING')), - $lexer->tokenize('reference:456') - ); - - $this->assertEquals( - array('T_REFERENCE' => '123'), - $lexer->map($lexer->tokenize('reference:123')) - ); - - $this->assertEquals( - array('T_REFERENCE' => '456'), - $lexer->map($lexer->tokenize('ref:456')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('ref: ')) - ); - } - - public function testDescriptionQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'description:', 'token' => 'T_DESCRIPTION'), array('match' => 'my text search', 'token' => 'T_STRING')), - $lexer->tokenize('description:"my text search"') - ); - - $this->assertEquals( - array('T_DESCRIPTION' => 'my text search'), - $lexer->map($lexer->tokenize('description:"my text search"')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('description: ')) - ); - } - - public function testDueDateQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('due:2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '<2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('due:<2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '>2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('due:>2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '<=2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('due:<=2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => '>=2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('due:>=2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => 'yesterday', 'token' => 'T_DATE')), - $lexer->tokenize('due:yesterday') - ); - - $this->assertEquals( - array(array('match' => 'due:', 'token' => 'T_DUE'), array('match' => 'tomorrow', 'token' => 'T_DATE')), - $lexer->tokenize('due:tomorrow') - ); - - $this->assertEquals( - array(), - $lexer->tokenize('due:#2015-05-01') - ); - - $this->assertEquals( - array(), - $lexer->tokenize('due:01-05-1024') - ); - - $this->assertEquals( - array('T_DUE' => '2015-05-01'), - $lexer->map($lexer->tokenize('due:2015-05-01')) - ); - - $this->assertEquals( - array('T_DUE' => '<2015-05-01'), - $lexer->map($lexer->tokenize('due:<2015-05-01')) - ); - - $this->assertEquals( - array('T_DUE' => 'today'), - $lexer->map($lexer->tokenize('due:today')) - ); - } - - public function testModifiedQuery() - { - $lexer = new Lexer; - - $this->assertEquals( - array(array('match' => 'modified:', 'token' => 'T_UPDATED'), array('match' => '2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('modified:2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'modified:', 'token' => 'T_UPDATED'), array('match' => '<2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('modified:<2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'modified:', 'token' => 'T_UPDATED'), array('match' => '>2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('modified:>2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'updated:', 'token' => 'T_UPDATED'), array('match' => '<=2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('updated:<=2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'updated:', 'token' => 'T_UPDATED'), array('match' => '>=2015-05-01', 'token' => 'T_DATE')), - $lexer->tokenize('updated:>=2015-05-01') - ); - - $this->assertEquals( - array(array('match' => 'updated:', 'token' => 'T_UPDATED'), array('match' => 'yesterday', 'token' => 'T_DATE')), - $lexer->tokenize('updated:yesterday') - ); - - $this->assertEquals( - array(array('match' => 'updated:', 'token' => 'T_UPDATED'), array('match' => 'tomorrow', 'token' => 'T_DATE')), - $lexer->tokenize('updated:tomorrow') - ); - - $this->assertEquals( - array(), - $lexer->tokenize('updated:#2015-05-01') - ); - - $this->assertEquals( - array(), - $lexer->tokenize('modified:01-05-1024') - ); - - $this->assertEquals( - array('T_UPDATED' => '2015-05-01'), - $lexer->map($lexer->tokenize('modified:2015-05-01')) - ); - - $this->assertEquals( - array('T_UPDATED' => '<2015-05-01'), - $lexer->map($lexer->tokenize('modified:<2015-05-01')) - ); - - $this->assertEquals( - array('T_UPDATED' => 'today'), - $lexer->map($lexer->tokenize('modified:today')) - ); - } - - public function testMultipleCriterias() - { - $lexer = new Lexer; - - $this->assertEquals( - array('T_COLOR' => array('Dark Grey'), 'T_ASSIGNEE' => array('Fred G'), 'T_TITLE' => 'my task title'), - $lexer->map($lexer->tokenize('color:"Dark Grey" assignee:"Fred G" my task title')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title', 'T_COLOR' => array('yellow')), - $lexer->map($lexer->tokenize('my title color:yellow')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title', 'T_DUE' => '2015-04-01'), - $lexer->map($lexer->tokenize('my title due:2015-04-01')) - ); - - $this->assertEquals( - array('T_TITLE' => 'awesome', 'T_DUE' => '<=2015-04-01'), - $lexer->map($lexer->tokenize('due:<=2015-04-01 awesome')) - ); - - $this->assertEquals( - array('T_TITLE' => 'awesome', 'T_DUE' => 'today'), - $lexer->map($lexer->tokenize('due:today awesome')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title', 'T_COLOR' => array('yellow'), 'T_DUE' => '2015-04-01'), - $lexer->map($lexer->tokenize('my title color:yellow due:2015-04-01')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title', 'T_COLOR' => array('yellow'), 'T_DUE' => '2015-04-01', 'T_ASSIGNEE' => array('John Doe')), - $lexer->map($lexer->tokenize('my title color:yellow due:2015-04-01 assignee:"John Doe"')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title'), - $lexer->map($lexer->tokenize('my title color:')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title'), - $lexer->map($lexer->tokenize('my title color:assignee:')) - ); - - $this->assertEquals( - array('T_TITLE' => 'my title'), - $lexer->map($lexer->tokenize('my title ')) - ); - - $this->assertEquals( - array('T_TITLE' => '#123'), - $lexer->map($lexer->tokenize('#123')) - ); - - $this->assertEquals( - array(), - $lexer->map($lexer->tokenize('color:assignee:')) - ); - } -} diff --git a/tests/units/Filter/TaskAssigneeFilterTest.php b/tests/units/Filter/TaskAssigneeFilterTest.php new file mode 100644 index 00000000..356342c5 --- /dev/null +++ b/tests/units/Filter/TaskAssigneeFilterTest.php @@ -0,0 +1,159 @@ +<?php + +use Kanboard\Filter\TaskAssigneeFilter; +use Kanboard\Model\Project; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\User; + +require_once __DIR__.'/../Base.php'; + +class TaskAssigneeFilterTest extends Base +{ + public function testWithIntegerAssigneeId() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 1))); + + $filter = new TaskAssigneeFilter(); + $filter->withQuery($query); + $filter->withValue(1); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $filter = new TaskAssigneeFilter(); + $filter->withQuery($query); + $filter->withValue(123); + $filter->apply(); + + $this->assertCount(0, $query->findAll()); + } + + public function testWithStringAssigneeId() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 1))); + + $filter = new TaskAssigneeFilter(); + $filter->withQuery($query); + $filter->withValue('1'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $filter = new TaskAssigneeFilter(); + $filter->withQuery($query); + $filter->withValue("123"); + $filter->apply(); + + $this->assertCount(0, $query->findAll()); + } + + public function testWithUsername() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 1))); + + $filter = new TaskAssigneeFilter(); + $filter->withQuery($query); + $filter->withValue('admin'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $filter = new TaskAssigneeFilter(); + $filter->withQuery($query); + $filter->withValue('foobar'); + $filter->apply(); + + $this->assertCount(0, $query->findAll()); + } + + public function testWithName() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $userModel = new User($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 2))); + + $filter = new TaskAssigneeFilter(); + $filter->withQuery($query); + $filter->withValue('foo bar'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $filter = new TaskAssigneeFilter(); + $filter->withQuery($query); + $filter->withValue('bob'); + $filter->apply(); + + $this->assertCount(0, $query->findAll()); + } + + public function testWithNobody() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + + $filter = new TaskAssigneeFilter(); + $filter->withQuery($query); + $filter->withValue('nobody'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + } + + public function testWithCurrentUser() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $query = $taskFinder->getExtendedQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 1))); + + $filter = new TaskAssigneeFilter(); + $filter->setCurrentUserId(1); + $filter->withQuery($query); + $filter->withValue('me'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $filter = new TaskAssigneeFilter(); + $filter->setCurrentUserId(2); + $filter->withQuery($query); + $filter->withValue('me'); + $filter->apply(); + + $this->assertCount(0, $query->findAll()); + } +} diff --git a/tests/units/Formatter/TaskFilterCalendarFormatterTest.php b/tests/units/Formatter/TaskFilterCalendarFormatterTest.php deleted file mode 100644 index 09dd0de6..00000000 --- a/tests/units/Formatter/TaskFilterCalendarFormatterTest.php +++ /dev/null @@ -1,21 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Formatter\TaskFilterCalendarFormatter; - -class TaskFilterCalendarFormatterTest extends Base -{ - public function testCopy() - { - $tf = new TaskFilterCalendarFormatter($this->container); - $filter1 = $tf->create()->setFullDay(); - $filter2 = $tf->copy(); - - $this->assertTrue($filter1 !== $filter2); - $this->assertTrue($filter1->query !== $filter2->query); - $this->assertTrue($filter1->query->condition !== $filter2->query->condition); - $this->assertTrue($filter1->isFullDay()); - $this->assertFalse($filter2->isFullDay()); - } -} diff --git a/tests/units/Formatter/TaskFilterGanttFormatterTest.php b/tests/units/Formatter/TaskFilterGanttFormatterTest.php deleted file mode 100644 index 14804784..00000000 --- a/tests/units/Formatter/TaskFilterGanttFormatterTest.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Formatter\TaskFilterGanttFormatter; -use Kanboard\Model\Project; -use Kanboard\Model\TaskCreation; -use Kanboard\Core\DateParser; - -class TaskFilterGanttFormatterTest extends Base -{ - public function testFormat() - { - $dp = new DateParser($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilterGanttFormatter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1'))); - - $this->assertNotEmpty($tf->search('status:open')->format()); - } -} diff --git a/tests/units/Formatter/TaskFilterICalendarFormatterTest.php b/tests/units/Formatter/TaskFilterICalendarFormatterTest.php deleted file mode 100644 index 6de9cf0f..00000000 --- a/tests/units/Formatter/TaskFilterICalendarFormatterTest.php +++ /dev/null @@ -1,74 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Eluceo\iCal\Component\Calendar; -use Kanboard\Formatter\TaskFilterICalendarFormatter; -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Model\TaskCreation; -use Kanboard\Core\DateParser; -use Kanboard\Model\Config; - -class TaskFilterICalendarFormatterTest extends Base -{ - public function testIcalEventsWithCreatorAndDueDate() - { - $dp = new DateParser($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilterICalendarFormatter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1', 'creator_id' => 1, 'date_due' => $dp->getTimestampFromIsoFormat('-2 days')))); - - $ics = $tf->create() - ->filterByDueDateRange(strtotime('-1 month'), strtotime('+1 month')) - ->setFullDay() - ->setCalendar(new Calendar('Kanboard')) - ->setColumns('date_due') - ->addFullDayEvents() - ->format(); - - $this->assertContains('UID:task-#1-date_due', $ics); - $this->assertContains('DTSTART;TZID=UTC;VALUE=DATE:'.date('Ymd', strtotime('-2 days')), $ics); - $this->assertContains('DTEND;TZID=UTC;VALUE=DATE:'.date('Ymd', strtotime('-2 days')), $ics); - $this->assertContains('URL:http://localhost/?controller=task&action=show&task_id=1&project_id=1', $ics); - $this->assertContains('SUMMARY:#1 task1', $ics); - $this->assertContains('ATTENDEE:MAILTO:admin@kanboard.local', $ics); - $this->assertContains('X-MICROSOFT-CDO-ALLDAYEVENT:TRUE', $ics); - } - - public function testIcalEventsWithAssigneeAndDueDate() - { - $dp = new DateParser($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilterICalendarFormatter($this->container); - $u = new User($this->container); - $c = new Config($this->container); - - $this->assertNotFalse($c->save(array('application_url' => 'http://kb/'))); - $this->assertEquals('http://kb/', $c->get('application_url')); - - $this->assertNotFalse($u->update(array('id' => 1, 'email' => 'bob@localhost'))); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1', 'owner_id' => 1, 'date_due' => $dp->getTimestampFromIsoFormat('+5 days')))); - - $ics = $tf->create() - ->filterByDueDateRange(strtotime('-1 month'), strtotime('+1 month')) - ->setFullDay() - ->setCalendar(new Calendar('Kanboard')) - ->setColumns('date_due') - ->addFullDayEvents() - ->format(); - - $this->assertContains('UID:task-#1-date_due', $ics); - $this->assertContains('DTSTART;TZID=UTC;VALUE=DATE:'.date('Ymd', strtotime('+5 days')), $ics); - $this->assertContains('DTEND;TZID=UTC;VALUE=DATE:'.date('Ymd', strtotime('+5 days')), $ics); - $this->assertContains('URL:http://kb/?controller=task&action=show&task_id=1&project_id=1', $ics); - $this->assertContains('SUMMARY:#1 task1', $ics); - $this->assertContains('ORGANIZER;CN=admin:MAILTO:bob@localhost', $ics); - $this->assertContains('X-MICROSOFT-CDO-ALLDAYEVENT:TRUE', $ics); - } -} diff --git a/tests/units/Model/SubtaskTimeTrackingTest.php b/tests/units/Model/SubtaskTimeTrackingTest.php index 9fa8d5b0..2545dcb2 100644 --- a/tests/units/Model/SubtaskTimeTrackingTest.php +++ b/tests/units/Model/SubtaskTimeTrackingTest.php @@ -240,81 +240,4 @@ class SubtaskTimeTrackingTest extends Base $this->assertEquals(0, $task['time_estimated']); $this->assertEquals(0, $task['time_spent']); } - - public function testGetCalendarEvents() - { - $tf = new TaskFinder($this->container); - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $st = new SubtaskTimeTracking($this->container); - $p = new Project($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); - $this->assertEquals(2, $tc->create(array('title' => 'test 1', 'project_id' => 2))); - - $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); - $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1))); - $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 1))); - - $this->assertEquals(4, $s->create(array('title' => 'subtask #4', 'task_id' => 2))); - $this->assertEquals(5, $s->create(array('title' => 'subtask #5', 'task_id' => 2))); - $this->assertEquals(6, $s->create(array('title' => 'subtask #6', 'task_id' => 2))); - $this->assertEquals(7, $s->create(array('title' => 'subtask #7', 'task_id' => 2))); - $this->assertEquals(8, $s->create(array('title' => 'subtask #8', 'task_id' => 2))); - - // Slot start before and finish inside the calendar time range - $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 1, 'start' => strtotime('-1 day'), 'end' => strtotime('+1 hour'))); - - // Slot start inside time range and finish after the time range - $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 2, 'start' => strtotime('+1 hour'), 'end' => strtotime('+2 days'))); - - // Start before time range and finish inside time range - $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 3, 'start' => strtotime('-1 day'), 'end' => strtotime('+1.5 days'))); - - // Start and finish inside time range - $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 4, 'start' => strtotime('+1 hour'), 'end' => strtotime('+2 hours'))); - - // Start and finish after the time range - $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 5, 'start' => strtotime('+2 days'), 'end' => strtotime('+3 days'))); - - // Start and finish before the time range - $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 6, 'start' => strtotime('-2 days'), 'end' => strtotime('-1 day'))); - - // Start before time range and not finished - $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 7, 'start' => strtotime('-1 day'))); - - // Start inside time range and not finish - $this->container['db']->table(SubtaskTimeTracking::TABLE)->insert(array('user_id' => 1, 'subtask_id' => 8, 'start' => strtotime('+3200 seconds'))); - - $timesheet = $st->getUserTimesheet(1); - $this->assertNotEmpty($timesheet); - $this->assertCount(8, $timesheet); - - $events = $st->getUserCalendarEvents(1, date('Y-m-d'), date('Y-m-d', strtotime('+2 day'))); - $this->assertNotEmpty($events); - $this->assertCount(6, $events); - $this->assertEquals(1, $events[0]['subtask_id']); - $this->assertEquals(2, $events[1]['subtask_id']); - $this->assertEquals(3, $events[2]['subtask_id']); - $this->assertEquals(4, $events[3]['subtask_id']); - $this->assertEquals(7, $events[4]['subtask_id']); - $this->assertEquals(8, $events[5]['subtask_id']); - - $events = $st->getProjectCalendarEvents(1, date('Y-m-d'), date('Y-m-d', strtotime('+2 days'))); - $this->assertNotEmpty($events); - $this->assertCount(3, $events); - $this->assertEquals(1, $events[0]['subtask_id']); - $this->assertEquals(2, $events[1]['subtask_id']); - $this->assertEquals(3, $events[2]['subtask_id']); - - $events = $st->getProjectCalendarEvents(2, date('Y-m-d'), date('Y-m-d', strtotime('+2 days'))); - $this->assertNotEmpty($events); - $this->assertCount(3, $events); - $this->assertEquals(4, $events[0]['subtask_id']); - $this->assertEquals(7, $events[1]['subtask_id']); - $this->assertEquals(8, $events[2]['subtask_id']); - } } diff --git a/tests/units/Model/TaskFilterTest.php b/tests/units/Model/TaskFilterTest.php deleted file mode 100644 index 9e291c31..00000000 --- a/tests/units/Model/TaskFilterTest.php +++ /dev/null @@ -1,624 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Model\Project; -use Kanboard\Model\User; -use Kanboard\Model\TaskFilter; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskLink; -use Kanboard\Core\DateParser; -use Kanboard\Model\Category; -use Kanboard\Model\Subtask; -use Kanboard\Model\Swimlane; - -class TaskFilterTest extends Base -{ - public function testSearchWithEmptyResult() - { - $dp = new DateParser($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'date_due' => $dp->getTimestampFromIsoFormat('-2 days')))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'date_due' => $dp->getTimestampFromIsoFormat('+1 day')))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work', 'date_due' => $dp->getTimestampFromIsoFormat('-1 day')))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'youpi', 'date_due' => $dp->getTimestampFromIsoFormat(time())))); - - $this->assertEmpty($tf->search('search something')->findAll()); - } - - public function testSearchWithEmptyInput() - { - $dp = new DateParser($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'date_due' => $dp->getTimestampFromIsoFormat('-2 days')))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'date_due' => $dp->getTimestampFromIsoFormat('+1 day')))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work', 'date_due' => $dp->getTimestampFromIsoFormat('-1 day')))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'youpi', 'date_due' => $dp->getTimestampFromIsoFormat(time())))); - - $result = $tf->search('')->findAll(); - $this->assertNotEmpty($result); - $this->assertCount(4, $result); - } - - public function testSearchById() - { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task 43'))); - - $tf->search('#2'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task2', $tasks[0]['title']); - - $tf->search('1'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task1', $tasks[0]['title']); - - $tf->search('something'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - - $tf->search('#'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - - $tf->search('#abcd'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - - $tf->search('task1'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task1', $tasks[0]['title']); - - $tf->search('43'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task 43', $tasks[0]['title']); - } - - public function testSearchWithReference() - { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2', 'reference' => 123))); - - $tf->search('ref:123'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task2', $tasks[0]['title']); - - $tf->search('reference:123'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task2', $tasks[0]['title']); - - $tf->search('ref:plop'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - - $tf->search('ref:'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - } - - public function testSearchWithStatus() - { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'is_active' => 0))); - - $tf->search('status:open'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(2, $tasks); - - $tf->search('status:plop'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(3, $tasks); - - $tf->search('status:closed'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - } - - public function testSearchWithDescription() - { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2', 'description' => '**something to do**'))); - - $tf->search('description:"something"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task2', $tasks[0]['title']); - - $tf->search('description:"rainy day"'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - } - - public function testSearchWithCategory() - { - $p = new Project($this->container); - $c = new Category($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $c->create(array('name' => 'Feature request', 'project_id' => 1))); - $this->assertEquals(2, $c->create(array('name' => 'hé hé', 'project_id' => 1))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2', 'category_id' => 1))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task3', 'category_id' => 2))); - - $tf->search('category:"Feature request"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task2', $tasks[0]['title']); - $this->assertEquals('Feature request', $tasks[0]['category_name']); - - $tf->search('category:"hé hé"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task3', $tasks[0]['title']); - $this->assertEquals('hé hé', $tasks[0]['category_name']); - - $tf->search('category:"Feature request" category:"hé hé"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(2, $tasks); - $this->assertEquals('task2', $tasks[0]['title']); - $this->assertEquals('Feature request', $tasks[0]['category_name']); - $this->assertEquals('task3', $tasks[1]['title']); - $this->assertEquals('hé hé', $tasks[1]['category_name']); - - $tf->search('category:none'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task1', $tasks[0]['title']); - $this->assertEquals('', $tasks[0]['category_name']); - - $tf->search('category:"not found"'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - } - - public function testSearchWithProject() - { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'My project A'))); - $this->assertEquals(2, $p->create(array('name' => 'My project B'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1'))); - $this->assertNotFalse($tc->create(array('project_id' => 2, 'title' => 'task2'))); - - $tf->search('project:"My project A"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task1', $tasks[0]['title']); - $this->assertEquals('My project A', $tasks[0]['project_name']); - - $tf->search('project:2'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task2', $tasks[0]['title']); - $this->assertEquals('My project B', $tasks[0]['project_name']); - - $tf->search('project:"My project A" project:"my project b"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(2, $tasks); - $this->assertEquals('task1', $tasks[0]['title']); - $this->assertEquals('My project A', $tasks[0]['project_name']); - $this->assertEquals('task2', $tasks[1]['title']); - $this->assertEquals('My project B', $tasks[1]['project_name']); - - $tf->search('project:"not found"'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - } - - public function testSearchWithSwimlane() - { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilter($this->container); - $s = new Swimlane($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'My project A'))); - $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Version 1.1'))); - $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'Version 1.2'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1', 'swimlane_id' => 1))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2', 'swimlane_id' => 2))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task3', 'swimlane_id' => 0))); - - $tf->search('swimlane:"Version 1.1"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task1', $tasks[0]['title']); - $this->assertEquals('Version 1.1', $tasks[0]['swimlane_name']); - - $tf->search('swimlane:"versioN 1.2"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task2', $tasks[0]['title']); - $this->assertEquals('Version 1.2', $tasks[0]['swimlane_name']); - - $tf->search('swimlane:"Default swimlane"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task3', $tasks[0]['title']); - $this->assertEquals('Default swimlane', $tasks[0]['default_swimlane']); - $this->assertEquals('', $tasks[0]['swimlane_name']); - - $tf->search('swimlane:default'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task3', $tasks[0]['title']); - $this->assertEquals('Default swimlane', $tasks[0]['default_swimlane']); - $this->assertEquals('', $tasks[0]['swimlane_name']); - - $tf->search('swimlane:"Version 1.1" swimlane:"Version 1.2"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(2, $tasks); - $this->assertEquals('task1', $tasks[0]['title']); - $this->assertEquals('Version 1.1', $tasks[0]['swimlane_name']); - $this->assertEquals('task2', $tasks[1]['title']); - $this->assertEquals('Version 1.2', $tasks[1]['swimlane_name']); - - $tf->search('swimlane:"not found"'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - } - - public function testSearchWithColumn() - { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'My project A'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2', 'column_id' => 3))); - - $tf->search('column:Backlog'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task1', $tasks[0]['title']); - $this->assertEquals('Backlog', $tasks[0]['column_name']); - - $tf->search('column:backlog column:"Work in progress"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(2, $tasks); - $this->assertEquals('task1', $tasks[0]['title']); - $this->assertEquals('Backlog', $tasks[0]['column_name']); - $this->assertEquals('task2', $tasks[1]['title']); - $this->assertEquals('Work in progress', $tasks[1]['column_name']); - - $tf->search('column:"not found"'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - } - - public function testSearchWithDueDate() - { - $dp = new DateParser($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'date_due' => $dp->getTimestampFromIsoFormat('-2 days')))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'date_due' => $dp->getTimestampFromIsoFormat('+1 day')))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work', 'date_due' => $dp->getTimestampFromIsoFormat('-1 day')))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'youpi', 'date_due' => $dp->getTimestampFromIsoFormat(time())))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'no due date'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'due date at 0', 'date_due' => 0))); - - $tf->search('due:>'.date('Y-m-d')); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('my task title is amazing', $tasks[0]['title']); - - $tf->search('due:>='.date('Y-m-d')); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(2, $tasks); - $this->assertEquals('my task title is amazing', $tasks[0]['title']); - $this->assertEquals('youpi', $tasks[1]['title']); - - $tf->search('due:<'.date('Y-m-d')); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(2, $tasks); - $this->assertEquals('my task title is awesome', $tasks[0]['title']); - $this->assertEquals('Bob at work', $tasks[1]['title']); - - $tf->search('due:<='.date('Y-m-d')); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(3, $tasks); - $this->assertEquals('my task title is awesome', $tasks[0]['title']); - $this->assertEquals('Bob at work', $tasks[1]['title']); - $this->assertEquals('youpi', $tasks[2]['title']); - - $tf->search('due:tomorrow'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('my task title is amazing', $tasks[0]['title']); - - $tf->search('due:yesterday'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('Bob at work', $tasks[0]['title']); - - $tf->search('due:today'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('youpi', $tasks[0]['title']); - } - - public function testSearchWithColor() - { - $p = new Project($this->container); - $u = new User($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Bob Ryan'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'color_id' => 'light_green'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'color_id' => 'blue'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work'))); - - $tf->search('color:"Light Green"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('my task title is awesome', $tasks[0]['title']); - - $tf->search('color:"Light Green" amazing'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - - $tf->search('color:"plop'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - - $tf->search('color:unknown'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(3, $tasks); - - $tf->search('color:blue amazing'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('my task title is amazing', $tasks[0]['title']); - - $tf->search('color:blue color:Yellow'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(2, $tasks); - $this->assertEquals('my task title is amazing', $tasks[0]['title']); - $this->assertEquals('Bob at work', $tasks[1]['title']); - } - - public function testSearchWithAssignee() - { - $p = new Project($this->container); - $u = new User($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Bob Ryan'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'owner_id' => 1))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'owner_id' => 0))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work', 'owner_id' => 2))); - - $tf->search('assignee:john'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - - $tf->search('assignee:admin my task title'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('my task title is awesome', $tasks[0]['title']); - - $tf->search('my task title'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(2, $tasks); - $this->assertEquals('my task title is awesome', $tasks[0]['title']); - $this->assertEquals('my task title is amazing', $tasks[1]['title']); - - $tf->search('my task title assignee:nobody'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('my task title is amazing', $tasks[0]['title']); - - $tf->search('assignee:"Bob ryan" assignee:nobody'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(2, $tasks); - $this->assertEquals('my task title is amazing', $tasks[0]['title']); - $this->assertEquals('Bob at work', $tasks[1]['title']); - } - - public function testSearchWithAssigneeIncludingSubtasks() - { - $p = new Project($this->container); - $u = new User($this->container); - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Paul Ryan'))); - - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'task1', 'owner_id' => 2))); - $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'status' => 1, 'user_id' => 0))); - - $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'task2', 'owner_id' => 0))); - $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 2, 'status' => 1, 'user_id' => 2))); - - $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'task3', 'owner_id' => 0))); - $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 3, 'user_id' => 1))); - - $tf->search('assignee:bob'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(2, $tasks); - $this->assertEquals('task1', $tasks[0]['title']); - $this->assertEquals('task2', $tasks[1]['title']); - - $tf->search('assignee:"Paul Ryan"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(2, $tasks); - $this->assertEquals('task1', $tasks[0]['title']); - $this->assertEquals('task2', $tasks[1]['title']); - - $tf->search('assignee:nobody'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(2, $tasks); - $this->assertEquals('task2', $tasks[0]['title']); - $this->assertEquals('task3', $tasks[1]['title']); - - $tf->search('assignee:admin'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('task3', $tasks[0]['title']); - } - - public function testSearchWithLink() - { - $p = new Project($this->container); - $u = new User($this->container); - $tc = new TaskCreation($this->container); - $tl = new TaskLink($this->container); - $tf = new TaskFilter($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Bob Ryan'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'color_id' => 'light_green'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'color_id' => 'blue'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work'))); - $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'I have a bad feeling about that'))); - $this->assertEquals(1, $tl->create(1, 2, 9)); // #1 is a milestone of #2 - $this->assertEquals(3, $tl->create(2, 1, 2)); // #2 blocks #1 - $this->assertEquals(5, $tl->create(3, 2, 2)); // #3 blocks #2 - - $tf->search('link:"is a milestone of"'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('my task title is awesome', $tasks[0]['title']); - - $tf->search('link:"is a milestone of" amazing'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - - $tf->search('link:"unknown"'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - - $tf->search('link:unknown'); - $tasks = $tf->findAll(); - $this->assertEmpty($tasks); - - $tf->search('link:blocks amazing'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(1, $tasks); - $this->assertEquals('my task title is amazing', $tasks[0]['title']); - - $tf->search('link:"is a milestone of" link:blocks'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(3, $tasks); - $this->assertEquals('my task title is awesome', $tasks[0]['title']); - $this->assertEquals('my task title is amazing', $tasks[1]['title']); - $this->assertEquals('Bob at work', $tasks[2]['title']); - - $tf->search('link:"is a milestone of" link:blocks link:unknown'); - $tasks = $tf->findAll(); - $this->assertNotEmpty($tasks); - $this->assertCount(3, $tasks); - $this->assertEquals('my task title is awesome', $tasks[0]['title']); - $this->assertEquals('my task title is amazing', $tasks[1]['title']); - $this->assertEquals('Bob at work', $tasks[2]['title']); - } - - public function testCopy() - { - $tf = new TaskFilter($this->container); - $filter1 = $tf->create(); - $filter2 = $tf->copy(); - - $this->assertTrue($filter1 !== $filter2); - $this->assertTrue($filter1->query !== $filter2->query); - $this->assertTrue($filter1->query->condition !== $filter2->query->condition); - } -} |