diff options
Diffstat (limited to 'tests')
30 files changed, 1291 insertions, 1371 deletions
diff --git a/tests/units/Base.php b/tests/units/Base.php index 6af14ba5..5125ffb9 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -39,6 +39,8 @@ abstract class Base extends PHPUnit_Framework_TestCase $this->container->register(new Kanboard\ServiceProvider\ClassProvider); $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/Http/OAuth2Test.php b/tests/units/Core/Http/OAuth2Test.php index c68ae116..5a9c0ac1 100644 --- a/tests/units/Core/Http/OAuth2Test.php +++ b/tests/units/Core/Http/OAuth2Test.php @@ -10,7 +10,8 @@ class OAuth2Test extends Base { $oauth = new OAuth2($this->container); $oauth->createService('A', 'B', 'C', 'D', 'E', array('f', 'g')); - $this->assertEquals('D?response_type=code&client_id=A&redirect_uri=C&scope=f+g', $oauth->getAuthorizationUrl()); + $state = $oauth->getState(); + $this->assertEquals('D?response_type=code&client_id=A&redirect_uri=C&scope=f+g&state='.$state, $oauth->getAuthorizationUrl()); } public function testAuthHeader() @@ -27,12 +28,15 @@ class OAuth2Test extends Base public function testAccessToken() { + $oauth = new OAuth2($this->container); + $params = array( 'code' => 'something', 'client_id' => 'A', 'client_secret' => 'B', 'redirect_uri' => 'C', 'grant_type' => 'authorization_code', + 'state' => $oauth->getState(), ); $response = json_encode(array( @@ -46,7 +50,6 @@ class OAuth2Test extends Base ->with('E', $params, array('Accept: application/json')) ->will($this->returnValue($response)); - $oauth = new OAuth2($this->container); $oauth->createService('A', 'B', 'C', 'D', 'E', array('f', 'g')); $oauth->getAccessToken('something'); } 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/Core/TemplateTest.php b/tests/units/Core/TemplateTest.php index bd476c51..9584c831 100644 --- a/tests/units/Core/TemplateTest.php +++ b/tests/units/Core/TemplateTest.php @@ -8,35 +8,41 @@ class TemplateTest extends Base { public function testGetTemplateFile() { - $t = new Template($this->container['helper']); + $template = new Template($this->container['helper']); + + $this->assertStringEndsWith( + implode(DIRECTORY_SEPARATOR, array('app', 'Core', '..', 'Template', 'a', 'b.php')), + $template->getTemplateFile('a'.DIRECTORY_SEPARATOR.'b') + ); + $this->assertStringEndsWith( - 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'a'.DIRECTORY_SEPARATOR.'b.php', - $t->getTemplateFile('a'.DIRECTORY_SEPARATOR.'b') + implode(DIRECTORY_SEPARATOR, array('app', 'Core', '..', 'Template', 'a', 'b.php')), + $template->getTemplateFile('kanboard:a'.DIRECTORY_SEPARATOR.'b') ); } public function testGetPluginTemplateFile() { - $t = new Template($this->container['helper']); + $template = new Template($this->container['helper']); $this->assertStringEndsWith( - 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'Myplugin'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'a'.DIRECTORY_SEPARATOR.'b.php', - $t->getTemplateFile('myplugin:a'.DIRECTORY_SEPARATOR.'b') + implode(DIRECTORY_SEPARATOR, array('app', 'Core', '..', '..', 'plugins', 'Myplugin', 'Template', 'a', 'b.php')), + $template->getTemplateFile('myplugin:a'.DIRECTORY_SEPARATOR.'b') ); } public function testGetOverridedTemplateFile() { - $t = new Template($this->container['helper']); - $t->setTemplateOverride('a'.DIRECTORY_SEPARATOR.'b', 'myplugin:c'); + $template = new Template($this->container['helper']); + $template->setTemplateOverride('a'.DIRECTORY_SEPARATOR.'b', 'myplugin:c'); $this->assertStringEndsWith( - 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'Myplugin'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'c.php', - $t->getTemplateFile('a'.DIRECTORY_SEPARATOR.'b') + implode(DIRECTORY_SEPARATOR, array('app', 'Core', '..', '..', 'plugins', 'Myplugin', 'Template', 'c.php')), + $template->getTemplateFile('a'.DIRECTORY_SEPARATOR.'b') ); $this->assertStringEndsWith( - 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'d.php', - $t->getTemplateFile('d') + implode(DIRECTORY_SEPARATOR, array('app', 'Core', '..', 'Template', 'd.php')), + $template->getTemplateFile('d') ); } } diff --git a/tests/units/Filter/ProjectActivityCreationDateFilterTest.php b/tests/units/Filter/ProjectActivityCreationDateFilterTest.php new file mode 100644 index 00000000..d679f285 --- /dev/null +++ b/tests/units/Filter/ProjectActivityCreationDateFilterTest.php @@ -0,0 +1,117 @@ +<?php + +use Kanboard\Filter\ProjectActivityCreationDateFilter; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectActivity; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Task; + +require_once __DIR__.'/../Base.php'; + +class ProjectActivityCreationDateFilterTest extends Base +{ + public function testWithToday() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityCreationDateFilter('today'); + $filter->setDateParser($this->container['dateParser']); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(1, $events); + } + + public function testWithYesterday() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityCreationDateFilter('yesterday'); + $filter->setDateParser($this->container['dateParser']); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(0, $events); + } + + public function testWithIsoDate() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityCreationDateFilter(date('Y-m-d')); + $filter->setDateParser($this->container['dateParser']); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(1, $events); + } + + public function testWithOperatorAndIsoDate() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityCreationDateFilter('>='.date('Y-m-d')); + $filter->setDateParser($this->container['dateParser']); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(1, $events); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityCreationDateFilter('<'.date('Y-m-d')); + $filter->setDateParser($this->container['dateParser']); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(0, $events); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityCreationDateFilter('>'.date('Y-m-d')); + $filter->setDateParser($this->container['dateParser']); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(0, $events); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityCreationDateFilter('>='.date('Y-m-d')); + $filter->setDateParser($this->container['dateParser']); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(1, $events); + } +} diff --git a/tests/units/Filter/ProjectActivityCreatorFilterTest.php b/tests/units/Filter/ProjectActivityCreatorFilterTest.php new file mode 100644 index 00000000..99c70322 --- /dev/null +++ b/tests/units/Filter/ProjectActivityCreatorFilterTest.php @@ -0,0 +1,91 @@ +<?php + +use Kanboard\Filter\ProjectActivityCreatorFilter; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectActivity; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Task; + +require_once __DIR__.'/../Base.php'; + +class ProjectActivityCreatorFilterTest extends Base +{ + public function testWithUsername() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityCreatorFilter('admin'); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(1, $events); + } + + public function testWithAnotherUsername() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityCreatorFilter('John Doe'); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(0, $events); + } + + public function testWithCurrentUser() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityCreatorFilter('me'); + $filter->setCurrentUserId(1); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(1, $events); + } + + public function testWithAnotherCurrentUser() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityCreatorFilter('me'); + $filter->setCurrentUserId(2); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(0, $events); + } +} diff --git a/tests/units/Filter/ProjectActivityProjectIdFilterTest.php b/tests/units/Filter/ProjectActivityProjectIdFilterTest.php new file mode 100644 index 00000000..193852e1 --- /dev/null +++ b/tests/units/Filter/ProjectActivityProjectIdFilterTest.php @@ -0,0 +1,35 @@ +<?php + +use Kanboard\Filter\ProjectActivityProjectIdFilter; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectActivity; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Task; + +require_once __DIR__.'/../Base.php'; + +class ProjectActivityProjectIdFilterTest extends Base +{ + public function testFilterByProjectId() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + $query = $projectActivityModel->getQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'P2'))); + + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); + + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + + $filter = new ProjectActivityProjectIdFilter(1); + $filter->withQuery($query)->apply(); + $this->assertCount(1, $query->findAll()); + } +} diff --git a/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php b/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php new file mode 100644 index 00000000..e99d2e2f --- /dev/null +++ b/tests/units/Filter/ProjectActivityProjectIdsFilterTest.php @@ -0,0 +1,63 @@ +<?php + +use Kanboard\Filter\ProjectActivityProjectIdsFilter; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectActivity; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Task; + +require_once __DIR__.'/../Base.php'; + +class ProjectActivityProjectIdsFilterTest extends Base +{ + public function testFilterByProjectIds() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + $query = $projectActivityModel->getQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'P2'))); + $this->assertEquals(3, $projectModel->create(array('name' => 'P3'))); + + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); + $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 3))); + + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); + + $filter = new ProjectActivityProjectIdsFilter(array(1, 2)); + $filter->withQuery($query)->apply(); + $this->assertCount(2, $query->findAll()); + } + + public function testWithEmptyArgument() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + $query = $projectActivityModel->getQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'P2'))); + $this->assertEquals(3, $projectModel->create(array('name' => 'P3'))); + + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); + $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 3))); + + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, $taskFinder->getById(1))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, $taskFinder->getById(2))); + $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, Task::EVENT_CREATE, $taskFinder->getById(3))); + + $filter = new ProjectActivityProjectIdsFilter(array()); + $filter->withQuery($query)->apply(); + $this->assertCount(0, $query->findAll()); + } +} diff --git a/tests/units/Filter/ProjectActivityProjectNameFilterTest.php b/tests/units/Filter/ProjectActivityProjectNameFilterTest.php new file mode 100644 index 00000000..de9d7d59 --- /dev/null +++ b/tests/units/Filter/ProjectActivityProjectNameFilterTest.php @@ -0,0 +1,35 @@ +<?php + +use Kanboard\Filter\ProjectActivityProjectNameFilter; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectActivity; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Task; + +require_once __DIR__.'/../Base.php'; + +class ProjectActivityProjectNameFilterTest extends Base +{ + public function testFilterByProjectName() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + $query = $projectActivityModel->getQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'P2'))); + + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); + + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + + $filter = new ProjectActivityProjectNameFilter('P1'); + $filter->withQuery($query)->apply(); + $this->assertCount(1, $query->findAll()); + } +} diff --git a/tests/units/Filter/ProjectActivityTaskIdFilterTest.php b/tests/units/Filter/ProjectActivityTaskIdFilterTest.php new file mode 100644 index 00000000..646cab1b --- /dev/null +++ b/tests/units/Filter/ProjectActivityTaskIdFilterTest.php @@ -0,0 +1,34 @@ +<?php + +use Kanboard\Filter\ProjectActivityTaskIdFilter; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectActivity; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Task; + +require_once __DIR__.'/../Base.php'; + +class ProjectActivityTaskIdFilterTest extends Base +{ + public function testFilterByTaskId() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + $query = $projectActivityModel->getQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + + $filter = new ProjectActivityTaskIdFilter(1); + $filter->withQuery($query)->apply(); + $this->assertCount(1, $query->findAll()); + } +} diff --git a/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php b/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php new file mode 100644 index 00000000..b8df6338 --- /dev/null +++ b/tests/units/Filter/ProjectActivityTaskStatusFilterTest.php @@ -0,0 +1,49 @@ +<?php + +use Kanboard\Filter\ProjectActivityTaskStatusFilter; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectActivity; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Task; +use Kanboard\Model\TaskStatus; + +require_once __DIR__.'/../Base.php'; + +class ProjectActivityTaskStatusFilterTest extends Base +{ + public function testFilterByTaskStatus() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $taskStatus = new TaskStatus($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + + $this->assertTrue($taskStatus->close(1)); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityTaskStatusFilter('open'); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(1, $events); + $this->assertEquals(2, $events[0]['task_id']); + + $query = $projectActivityModel->getQuery(); + $filter = new ProjectActivityTaskStatusFilter('closed'); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(1, $events); + $this->assertEquals(1, $events[0]['task_id']); + } +} diff --git a/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php b/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php new file mode 100644 index 00000000..925a1ab2 --- /dev/null +++ b/tests/units/Filter/ProjectActivityTaskTitleFilterTest.php @@ -0,0 +1,79 @@ +<?php + +use Kanboard\Filter\ProjectActivityTaskTitleFilter; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectActivity; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Task; + +require_once __DIR__.'/../Base.php'; + +class ProjectActivityTaskTitleFilterTest extends Base +{ + public function testWithFullTitle() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + $query = $projectActivityModel->getQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', 'project_id' => 1))); + + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + + $filter = new ProjectActivityTaskTitleFilter('test2'); + $filter->withQuery($query)->apply(); + $this->assertCount(1, $query->findAll()); + } + + public function testWithPartialTitle() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + $query = $projectActivityModel->getQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', 'project_id' => 1))); + + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + + $filter = new ProjectActivityTaskTitleFilter('test'); + $filter->withQuery($query)->apply(); + $this->assertCount(2, $query->findAll()); + } + + public function testWithId() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + $query = $projectActivityModel->getQuery(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', 'project_id' => 1))); + + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + + $filter = new ProjectActivityTaskTitleFilter('#2'); + $filter->withQuery($query)->apply(); + + $events = $query->findAll(); + $this->assertCount(1, $events); + $this->assertEquals(2, $events[0]['task_id']); + } +} 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/Filter/TaskCommentFilterTest.php b/tests/units/Filter/TaskCommentFilterTest.php new file mode 100644 index 00000000..8d1b7f44 --- /dev/null +++ b/tests/units/Filter/TaskCommentFilterTest.php @@ -0,0 +1,52 @@ +<?php + +use Kanboard\Filter\TaskCommentFilter; +use Kanboard\Model\Comment; +use Kanboard\Model\Project; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; + +require_once __DIR__.'/../Base.php'; + +class TaskCommentFilterTest extends Base +{ + public function testMatch() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $commentModel = new Comment($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))); + $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'user_id' => 1, 'comment' => 'This is a test'))); + + $filter = new TaskCommentFilter(); + $filter->withQuery($query); + $filter->withValue('test'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + } + + public function testNoMatch() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $commentModel = new Comment($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))); + $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'user_id' => 1, 'comment' => 'This is a test'))); + + $filter = new TaskCommentFilter(); + $filter->withQuery($query); + $filter->withValue('foobar'); + $filter->apply(); + + $this->assertCount(0, $query->findAll()); + } +} diff --git a/tests/units/Filter/TaskCreatorFilterTest.php b/tests/units/Filter/TaskCreatorFilterTest.php new file mode 100644 index 00000000..1c344de7 --- /dev/null +++ b/tests/units/Filter/TaskCreatorFilterTest.php @@ -0,0 +1,159 @@ +<?php + +use Kanboard\Filter\TaskCreatorFilter; +use Kanboard\Model\Project; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\User; + +require_once __DIR__.'/../Base.php'; + +class TaskCreatorFilterTest 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, 'creator_id' => 1))); + + $filter = new TaskCreatorFilter(); + $filter->withQuery($query); + $filter->withValue(1); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $filter = new TaskCreatorFilter(); + $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, 'creator_id' => 1))); + + $filter = new TaskCreatorFilter(); + $filter->withQuery($query); + $filter->withValue('1'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $filter = new TaskCreatorFilter(); + $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, 'creator_id' => 1))); + + $filter = new TaskCreatorFilter(); + $filter->withQuery($query); + $filter->withValue('admin'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $filter = new TaskCreatorFilter(); + $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, 'creator_id' => 2))); + + $filter = new TaskCreatorFilter(); + $filter->withQuery($query); + $filter->withValue('foo bar'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $filter = new TaskCreatorFilter(); + $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 TaskCreatorFilter(); + $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, 'creator_id' => 1))); + + $filter = new TaskCreatorFilter(); + $filter->setCurrentUserId(1); + $filter->withQuery($query); + $filter->withValue('me'); + $filter->apply(); + + $this->assertCount(1, $query->findAll()); + + $filter = new TaskCreatorFilter(); + $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/Helper/ProjectActivityHelperTest.php b/tests/units/Helper/ProjectActivityHelperTest.php new file mode 100644 index 00000000..88b2d352 --- /dev/null +++ b/tests/units/Helper/ProjectActivityHelperTest.php @@ -0,0 +1,97 @@ +<?php + +use Kanboard\Helper\ProjectActivityHelper; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectActivity; +use Kanboard\Model\Task; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; + +require_once __DIR__.'/../Base.php'; + +class ProjectActivityHelperTest extends Base +{ + public function testGetProjectEvents() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 3, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); + + $helper = new ProjectActivityHelper($this->container); + $events = $helper->getProjectEvents(1); + + $this->assertCount(3, $events); + $this->assertEquals(3, $events[0]['task_id']); + $this->assertNotEmpty($events[0]['event_content']); + $this->assertNotEmpty($events[0]['event_title']); + $this->assertNotEmpty($events[0]['author']); + $this->assertInternalType('array', $events[0]['task']); + } + + public function testGetProjectsEvents() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'P2'))); + $this->assertEquals(3, $projectModel->create(array('name' => 'P3'))); + + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 2))); + $this->assertEquals(3, $taskCreation->create(array('title' => 'Test', 'project_id' => 3))); + + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(2, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + $this->assertNotFalse($projectActivityModel->createEvent(3, 3, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(3)))); + + $helper = new ProjectActivityHelper($this->container); + $events = $helper->getProjectsEvents(array(1, 2)); + + $this->assertCount(2, $events); + $this->assertEquals(2, $events[0]['task_id']); + $this->assertNotEmpty($events[0]['event_content']); + $this->assertNotEmpty($events[0]['event_title']); + $this->assertNotEmpty($events[0]['author']); + $this->assertInternalType('array', $events[0]['task']); + } + + public function testGetTaskEvents() + { + $taskFinder = new TaskFinder($this->container); + $taskCreation = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $projectActivityModel = new ProjectActivity($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + + $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1))); + + $this->assertNotFalse($projectActivityModel->createEvent(1, 1, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(1)))); + $this->assertNotFalse($projectActivityModel->createEvent(1, 2, 1, Task::EVENT_CREATE, array('task' => $taskFinder->getById(2)))); + + $helper = new ProjectActivityHelper($this->container); + $events = $helper->getTaskEvents(1); + + $this->assertCount(1, $events); + $this->assertEquals(1, $events[0]['task_id']); + $this->assertNotEmpty($events[0]['event_content']); + $this->assertNotEmpty($events[0]['event_title']); + $this->assertNotEmpty($events[0]['author']); + $this->assertInternalType('array', $events[0]['task']); + } +} diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php index 7ee6e8bb..9a9832b2 100644 --- a/tests/units/Helper/UserHelperTest.php +++ b/tests/units/Helper/UserHelperTest.php @@ -15,6 +15,7 @@ class UserHelperTest extends Base $helper = new UserHelper($this->container); $this->assertEquals('CN', $helper->getInitials('chuck norris')); + $this->assertEquals('CN', $helper->getInitials('chuck norris #2')); $this->assertEquals('A', $helper->getInitials('admin')); } diff --git a/tests/units/Model/ProjectActivityTest.php b/tests/units/Model/ProjectActivityTest.php index 27ea039d..a624cd86 100644 --- a/tests/units/Model/ProjectActivityTest.php +++ b/tests/units/Model/ProjectActivityTest.php @@ -10,90 +10,51 @@ use Kanboard\Model\Project; class ProjectActivityTest extends Base { - public function testDecode() - { - $e = new ProjectActivity($this->container); - $input = array('test'); - $serialized = serialize($input); - $json = json_encode($input); - - $this->assertEquals($input, $e->decode($serialized)); - $this->assertEquals($input, $e->decode($json)); - } - public function testCreation() { - $e = new ProjectActivity($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $projectActivity = new ProjectActivity($this->container); + $taskCreation = new TaskCreation($this->container); + $taskFinder = new TaskFinder($this->container); + $projectModel = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); - $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1))); + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Task #1', 'project_id' => 1))); + $this->assertEquals(2, $taskCreation->create(array('title' => 'Task #2', 'project_id' => 1))); - $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1)))); - $this->assertTrue($e->createEvent(1, 2, 1, Task::EVENT_UPDATE, array('task' => $tf->getById(2)))); - $this->assertFalse($e->createEvent(1, 1, 0, Task::EVENT_OPEN, array('task' => $tf->getbyId(1)))); + $this->assertTrue($projectActivity->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $taskFinder->getbyId(1)))); + $this->assertTrue($projectActivity->createEvent(1, 2, 1, Task::EVENT_UPDATE, array('task' => $taskFinder->getById(2)))); + $this->assertFalse($projectActivity->createEvent(1, 1, 0, Task::EVENT_OPEN, array('task' => $taskFinder->getbyId(1)))); - $events = $e->getProject(1); + $events = $projectActivity->getQuery()->desc('id')->findAll(); - $this->assertNotEmpty($events); - $this->assertTrue(is_array($events)); - $this->assertEquals(2, count($events)); + $this->assertCount(2, $events); $this->assertEquals(time(), $events[0]['date_creation'], '', 1); $this->assertEquals(Task::EVENT_UPDATE, $events[0]['event_name']); $this->assertEquals(Task::EVENT_CLOSE, $events[1]['event_name']); } - public function testFetchAllContent() - { - $e = new ProjectActivity($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); - - $nb_events = 80; - - for ($i = 0; $i < $nb_events; $i++) { - $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_UPDATE, array('task' => $tf->getbyId(1)))); - } - - $events = $e->getProject(1); - - $this->assertNotEmpty($events); - $this->assertTrue(is_array($events)); - $this->assertEquals(50, count($events)); - $this->assertEquals('admin', $events[0]['author']); - $this->assertNotEmpty($events[0]['event_title']); - $this->assertNotEmpty($events[0]['event_content']); - } - public function testCleanup() { - $e = new ProjectActivity($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $projectActivity = new ProjectActivity($this->container); + $taskCreation = new TaskCreation($this->container); + $taskFinder = new TaskFinder($this->container); + $projectModel = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); + $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1'))); + $this->assertEquals(1, $taskCreation->create(array('title' => 'Task #1', 'project_id' => 1))); $max = 15; $nb_events = 100; - $task = $tf->getbyId(1); + $task = $taskFinder->getbyId(1); for ($i = 0; $i < $nb_events; $i++) { - $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $task))); + $this->assertTrue($projectActivity->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $task))); } $this->assertEquals($nb_events, $this->container['db']->table('project_activities')->count()); - $e->cleanup($max); + $projectActivity->cleanup($max); - $events = $e->getProject(1); + $events = $projectActivity->getQuery()->desc('id')->findAll(); $this->assertNotEmpty($events); $this->assertCount($max, $events); diff --git a/tests/units/Model/ProjectFileTest.php b/tests/units/Model/ProjectFileTest.php index d9b37fbe..0d7a9377 100644 --- a/tests/units/Model/ProjectFileTest.php +++ b/tests/units/Model/ProjectFileTest.php @@ -278,7 +278,7 @@ class ProjectFileTest extends Base $fileModel = $this ->getMockBuilder('\Kanboard\Model\ProjectFile') ->setConstructorArgs(array($this->container)) - ->setMethods(array('generateThumbnailFromFile')) + ->setMethods(array('generateThumbnailFromData')) ->getMock(); $projectModel = new Project($this->container); @@ -288,7 +288,7 @@ class ProjectFileTest extends Base $fileModel ->expects($this->once()) - ->method('generateThumbnailFromFile'); + ->method('generateThumbnailFromData'); $this->container['objectStorage'] ->expects($this->once()) 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/TaskFileTest.php b/tests/units/Model/TaskFileTest.php index b900e8f3..e44e092d 100644 --- a/tests/units/Model/TaskFileTest.php +++ b/tests/units/Model/TaskFileTest.php @@ -331,7 +331,7 @@ class TaskFileTest extends Base $fileModel = $this ->getMockBuilder('\Kanboard\Model\TaskFile') ->setConstructorArgs(array($this->container)) - ->setMethods(array('generateThumbnailFromFile')) + ->setMethods(array('generateThumbnailFromData')) ->getMock(); $projectModel = new Project($this->container); @@ -343,7 +343,7 @@ class TaskFileTest extends Base $fileModel ->expects($this->once()) - ->method('generateThumbnailFromFile'); + ->method('generateThumbnailFromData'); $this->container['objectStorage'] ->expects($this->once()) 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); - } -} diff --git a/tests/units/Model/UserNotificationFilterTest.php b/tests/units/Model/UserNotificationFilterTest.php index 0b5f1d98..924f0883 100644 --- a/tests/units/Model/UserNotificationFilterTest.php +++ b/tests/units/Model/UserNotificationFilterTest.php @@ -26,10 +26,11 @@ class UserNotificationFilterTest extends Base $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); + $this->assertEquals(3, $p->create(array('name' => 'UnitTest3'))); $this->assertEmpty($nf->getSelectedProjects(1)); - $nf->saveSelectedProjects(1, array(1, 2)); - $this->assertEquals(array(1, 2), $nf->getSelectedProjects(1)); + $this->assertTrue($nf->saveSelectedProjects(1, array(1, 2, 3))); + $this->assertEquals(array(1, 2, 3), $nf->getSelectedProjects(1)); } public function testSaveUserFilter() diff --git a/tests/units/User/Avatar/LetterAvatarProviderTest.php b/tests/units/User/Avatar/LetterAvatarProviderTest.php index 0c1bfc4b..39e51c98 100644 --- a/tests/units/User/Avatar/LetterAvatarProviderTest.php +++ b/tests/units/User/Avatar/LetterAvatarProviderTest.php @@ -23,7 +23,7 @@ class LetterAvatarProviderTest extends Base { $provider = new LetterAvatarProvider($this->container); $user = array('id' => 123, 'name' => 'Kanboard Admin', 'username' => 'bob', 'email' => ''); - $expected = '<div class="avatar-letter" style="background-color: rgb(187, 224, 108)" title="Kanboard Admin">KA</div>'; + $expected = '<div class="avatar-letter" style="background-color: rgb(131, 224, 108)" title="Kanboard Admin">KA</div>'; $this->assertEquals($expected, $provider->render($user, 48)); } @@ -31,7 +31,7 @@ class LetterAvatarProviderTest extends Base { $provider = new LetterAvatarProvider($this->container); $user = array('id' => 123, 'name' => '', 'username' => 'admin', 'email' => ''); - $expected = '<div class="avatar-letter" style="background-color: rgb(210, 97, 45)" title="admin">A</div>'; + $expected = '<div class="avatar-letter" style="background-color: rgb(134, 45, 132)" title="admin">A</div>'; $this->assertEquals($expected, $provider->render($user, 48)); } } |