summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/AclTest.php264
-rw-r--r--tests/units/ActionTaskAssignColorCategoryTest.php22
-rw-r--r--tests/units/ActionTaskAssignColorColumnTest.php41
-rw-r--r--tests/units/ActionTaskAssignColorUserTest.php20
-rw-r--r--tests/units/ActionTaskAssignCurrentUserTest.php28
-rw-r--r--tests/units/ActionTaskAssignSpecificUserTest.php22
-rw-r--r--tests/units/ActionTaskCloseTest.php32
-rw-r--r--tests/units/ActionTaskDuplicateAnotherProjectTest.php25
-rw-r--r--tests/units/ActionTaskMoveAnotherProjectTest.php24
-rw-r--r--tests/units/ActionTaskUpdateStartDateTest.php46
-rw-r--r--tests/units/ActionTest.php180
-rw-r--r--tests/units/AppHelperTest.php38
-rw-r--r--tests/units/AssetHelperTest.php21
-rw-r--r--tests/units/Base.php99
-rw-r--r--tests/units/BitbucketWebhookTest.php65
-rw-r--r--tests/units/BoardTest.php217
-rw-r--r--tests/units/CategoryTest.php27
-rw-r--r--tests/units/CommentTest.php47
-rw-r--r--tests/units/ConfigTest.php30
-rw-r--r--tests/units/DateParserTest.php50
-rw-r--r--tests/units/DatetimeHelperTest.php44
-rw-r--r--tests/units/FileHelperText.php15
-rw-r--r--tests/units/FileTest.php31
-rw-r--r--tests/units/GitlabWebhookTest.php119
-rw-r--r--tests/units/HourlyRate.php43
-rw-r--r--tests/units/LinkTest.php173
-rw-r--r--tests/units/MailgunTest.php71
-rw-r--r--tests/units/NotificationTest.php336
-rw-r--r--tests/units/PostmarkTest.php106
-rw-r--r--tests/units/ProjectActivityTest.php50
-rw-r--r--tests/units/ProjectDailySummary.php84
-rw-r--r--tests/units/ProjectDuplicationTest.php359
-rw-r--r--tests/units/ProjectPermissionTest.php196
-rw-r--r--tests/units/ProjectTest.php173
-rw-r--r--tests/units/SendgridWebhookTest.php107
-rw-r--r--tests/units/SubtaskTest.php127
-rw-r--r--tests/units/SubtaskTimeTrackingTest.php231
-rw-r--r--tests/units/SwimlaneTest.php409
-rw-r--r--tests/units/TaskCreationTest.php358
-rw-r--r--tests/units/TaskDuplicationTest.php563
-rw-r--r--tests/units/TaskExportTest.php24
-rw-r--r--tests/units/TaskFinderTest.php15
-rw-r--r--tests/units/TaskLinkTest.php185
-rw-r--r--tests/units/TaskModificationTest.php253
-rw-r--r--tests/units/TaskPermissionTest.php43
-rw-r--r--tests/units/TaskPositionTest.php600
-rw-r--r--tests/units/TaskStatusTest.php77
-rw-r--r--tests/units/TaskTest.php632
-rw-r--r--tests/units/TextHelperTest.php64
-rw-r--r--tests/units/TimeTrackingTest.php46
-rw-r--r--tests/units/TimetableTest.php256
-rw-r--r--tests/units/ToolTest.php15
-rw-r--r--tests/units/UrlHelperTest.php64
-rw-r--r--tests/units/UserSessionTest.php45
-rw-r--r--tests/units/UserTest.php84
-rw-r--r--tests/units/WebhookTest.php112
56 files changed, 6186 insertions, 1222 deletions
diff --git a/tests/units/AclTest.php b/tests/units/AclTest.php
index 83351616..20101d47 100644
--- a/tests/units/AclTest.php
+++ b/tests/units/AclTest.php
@@ -2,111 +2,223 @@
require_once __DIR__.'/Base.php';
+use Core\Session;
use Model\Acl;
+use Model\Project;
+use Model\ProjectPermission;
+use Model\User;
class AclTest extends Base
{
- public function testAllowedAction()
+ public function testMatchAcl()
{
$acl_rules = array(
'controller1' => array('action1', 'action3'),
+ 'controller3' => '*',
+ 'controller5' => '-',
+ 'controller6' => array(),
);
- $acl = new Acl($this->registry);
- $this->assertTrue($acl->isAllowedAction($acl_rules, 'controller1', 'action1'));
- $this->assertTrue($acl->isAllowedAction($acl_rules, 'controller1', 'action3'));
- $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller1', 'action2'));
- $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller2', 'action2'));
- $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller2', 'action3'));
+ $acl = new Acl($this->container);
+ $this->assertTrue($acl->matchAcl($acl_rules, 'controller1', 'aCtiOn1'));
+ $this->assertTrue($acl->matchAcl($acl_rules, 'controller1', 'action1'));
+ $this->assertTrue($acl->matchAcl($acl_rules, 'controller1', 'action3'));
+ $this->assertFalse($acl->matchAcl($acl_rules, 'controller1', 'action2'));
+ $this->assertFalse($acl->matchAcl($acl_rules, 'controller2', 'action2'));
+ $this->assertFalse($acl->matchAcl($acl_rules, 'controller2', 'action3'));
+ $this->assertTrue($acl->matchAcl($acl_rules, 'controller3', 'anything'));
+ $this->assertFalse($acl->matchAcl($acl_rules, 'controller4', 'anything'));
+ $this->assertFalse($acl->matchAcl($acl_rules, 'controller5', 'anything'));
+ $this->assertFalse($acl->matchAcl($acl_rules, 'controller6', 'anything'));
}
- public function testIsAdmin()
+ public function testPublicActions()
{
- $acl = new Acl($this->registry);
+ $acl = new Acl($this->container);
+ $this->assertTrue($acl->isPublicAction('board', 'readonly'));
+ $this->assertFalse($acl->isPublicAction('board', 'show'));
+ $this->assertTrue($acl->isPublicAction('app', 'colors'));
+ }
- $_SESSION = array();
- $this->assertFalse($acl->isAdminUser());
+ public function testAdminActions()
+ {
+ $acl = new Acl($this->container);
+ $this->assertFalse($acl->isAdminAction('board', 'show'));
+ $this->assertFalse($acl->isAdminAction('task', 'show'));
+ $this->assertTrue($acl->isAdminAction('config', 'api'));
+ $this->assertTrue($acl->isAdminAction('config', 'anything'));
+ $this->assertTrue($acl->isAdminAction('config', 'anything'));
+ $this->assertTrue($acl->isAdminAction('user', 'save'));
+ }
- $_SESSION = array('user' => array());
- $this->assertFalse($acl->isAdminUser());
+ public function testManagerActions()
+ {
+ $acl = new Acl($this->container);
+ $this->assertFalse($acl->isManagerAction('board', 'readonly'));
+ $this->assertFalse($acl->isManagerAction('project', 'remove'));
+ $this->assertFalse($acl->isManagerAction('project', 'show'));
+ $this->assertTrue($acl->isManagerAction('project', 'disable'));
+ $this->assertTrue($acl->isManagerAction('category', 'index'));
+ $this->assertTrue($acl->isManagerAction('project', 'users'));
+ $this->assertFalse($acl->isManagerAction('app', 'index'));
+ }
- $_SESSION = array('user' => array('is_admin' => '1'));
- $this->assertFalse($acl->isAdminUser());
+ public function testPageAccessNoSession()
+ {
+ $acl = new Acl($this->container);
+ $this->assertFalse($acl->isAllowed('board', 'readonly'));
+ $this->assertFalse($acl->isAllowed('task', 'show'));
+ $this->assertFalse($acl->isAllowed('config', 'application'));
+ $this->assertFalse($acl->isAllowed('project', 'users'));
+ $this->assertFalse($acl->isAllowed('task', 'remove'));
+ $this->assertTrue($acl->isAllowed('app', 'index'));
+ }
- $_SESSION = array('user' => array('is_admin' => false));
- $this->assertFalse($acl->isAdminUser());
+ public function testPageAccessEmptySession()
+ {
+ $acl = new Acl($this->container);
+ $session = new Session;
- $_SESSION = array('user' => array('is_admin' => '2'));
- $this->assertFalse($acl->isAdminUser());
+ $session['user'] = array();
- $_SESSION = array('user' => array('is_admin' => true));
- $this->assertTrue($acl->isAdminUser());
+ $this->assertFalse($acl->isAllowed('board', 'readonly'));
+ $this->assertFalse($acl->isAllowed('task', 'show'));
+ $this->assertFalse($acl->isAllowed('config', 'application'));
+ $this->assertFalse($acl->isAllowed('project', 'users'));
+ $this->assertFalse($acl->isAllowed('task', 'remove'));
+ $this->assertTrue($acl->isAllowed('app', 'index'));
}
- public function testIsUser()
+ public function testPageAccessAdminUser()
{
- $acl = new Acl($this->registry);
+ $acl = new Acl($this->container);
+ $session = new Session;
- $_SESSION = array();
- $this->assertFalse($acl->isRegularUser());
+ $session['user'] = array(
+ 'is_admin' => true,
+ );
- $_SESSION = array('user' => array());
- $this->assertFalse($acl->isRegularUser());
+ $this->assertTrue($acl->isAllowed('board', 'readonly'));
+ $this->assertTrue($acl->isAllowed('task', 'readonly'));
+ $this->assertTrue($acl->isAllowed('webhook', 'github'));
+ $this->assertTrue($acl->isAllowed('task', 'show'));
+ $this->assertTrue($acl->isAllowed('task', 'update'));
+ $this->assertTrue($acl->isAllowed('project', 'show'));
+ $this->assertTrue($acl->isAllowed('config', 'application'));
+ $this->assertTrue($acl->isAllowed('project', 'users'));
+ $this->assertTrue($acl->isAllowed('category', 'edit'));
+ $this->assertTrue($acl->isAllowed('task', 'remove'));
+ $this->assertTrue($acl->isAllowed('app', 'index'));
+ }
- $_SESSION = array('user' => array('is_admin' => true));
- $this->assertFalse($acl->isRegularUser());
+ public function testPageAccessManager()
+ {
+ $acl = new Acl($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $u = new User($this->container);
+ $session = new Session;
+
+ // We create our user
+ $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
+
+ // We create a project and set our user as project manager
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest'), 2, true));
+ $this->assertTrue($pp->isMember(1, 2));
+ $this->assertTrue($pp->isManager(1, 2));
+
+ // We fake a session for him
+ $session['user'] = array(
+ 'id' => 2,
+ 'is_admin' => false,
+ );
- $_SESSION = array('user' => array('is_admin' => true));
- $this->assertFalse($acl->isRegularUser());
+ $this->assertTrue($acl->isAllowed('board', 'readonly', 1));
+ $this->assertTrue($acl->isAllowed('task', 'readonly', 1));
+ $this->assertTrue($acl->isAllowed('webhook', 'github', 1));
+ $this->assertTrue($acl->isAllowed('task', 'show', 1));
+ $this->assertFalse($acl->isAllowed('task', 'show', 2));
+ $this->assertTrue($acl->isAllowed('task', 'update', 1));
+ $this->assertTrue($acl->isAllowed('project', 'show', 1));
+ $this->assertFalse($acl->isAllowed('config', 'application', 1));
+ $this->assertTrue($acl->isAllowed('project', 'users', 1));
+ $this->assertFalse($acl->isAllowed('project', 'users', 2));
+ $this->assertTrue($acl->isAllowed('category', 'edit', 1));
+ $this->assertTrue($acl->isAllowed('task', 'remove', 1));
+ $this->assertTrue($acl->isAllowed('app', 'index', 1));
+ }
- $_SESSION = array('user' => array('is_admin' => '2'));
- $this->assertFalse($acl->isRegularUser());
+ public function testPageAccessMember()
+ {
+ $acl = new Acl($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $u = new User($this->container);
+
+ // We create our user
+ $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
+
+ // We create a project and set our user as member
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
+ $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+ $this->assertTrue($pp->addMember(1, 2));
+ $this->assertTrue($pp->isMember(1, 2));
+ $this->assertFalse($pp->isManager(1, 2));
+
+ $session = new Session;
+
+ $session['user'] = array(
+ 'id' => 2,
+ 'is_admin' => false,
+ );
- $_SESSION = array('user' => array('is_admin' => false));
- $this->assertTrue($acl->isRegularUser());
+ $this->assertTrue($acl->isAllowed('board', 'readonly', 1));
+ $this->assertTrue($acl->isAllowed('task', 'readonly', 1));
+ $this->assertTrue($acl->isAllowed('webhook', 'github', 1));
+ $this->assertFalse($acl->isAllowed('board', 'show', 2));
+ $this->assertTrue($acl->isAllowed('board', 'show', 1));
+ $this->assertFalse($acl->isAllowed('task', 'show', 2));
+ $this->assertTrue($acl->isAllowed('task', 'show', 1));
+ $this->assertTrue($acl->isAllowed('task', 'update', 1));
+ $this->assertTrue($acl->isAllowed('project', 'show', 1));
+ $this->assertFalse($acl->isAllowed('config', 'application', 1));
+ $this->assertFalse($acl->isAllowed('project', 'users', 1));
+ $this->assertTrue($acl->isAllowed('task', 'remove', 1));
+ $this->assertFalse($acl->isAllowed('task', 'remove', 2));
+ $this->assertTrue($acl->isAllowed('app', 'index', 1));
}
- public function testIsPageAllowed()
+ public function testPageAccessNotMember()
{
- $acl = new Acl($this->registry);
-
- // Public access
- $_SESSION = array();
- $this->assertFalse($acl->isPageAccessAllowed('user', 'create'));
- $this->assertFalse($acl->isPageAccessAllowed('user', 'save'));
- $this->assertFalse($acl->isPageAccessAllowed('user', 'remove'));
- $this->assertFalse($acl->isPageAccessAllowed('user', 'confirm'));
- $this->assertFalse($acl->isPageAccessAllowed('app', 'index'));
- $this->assertFalse($acl->isPageAccessAllowed('user', 'index'));
- $this->assertTrue($acl->isPageAccessAllowed('user', 'login'));
- $this->assertTrue($acl->isPageAccessAllowed('user', 'check'));
- $this->assertTrue($acl->isPageAccessAllowed('webhook', 'task'));
- $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly'));
-
- // Regular user
- $_SESSION = array('user' => array('is_admin' => false));
- $this->assertFalse($acl->isPageAccessAllowed('user', 'create'));
- $this->assertFalse($acl->isPageAccessAllowed('user', 'save'));
- $this->assertFalse($acl->isPageAccessAllowed('user', 'remove'));
- $this->assertFalse($acl->isPageAccessAllowed('user', 'confirm'));
- $this->assertTrue($acl->isPageAccessAllowed('app', 'index'));
- $this->assertFalse($acl->isPageAccessAllowed('user', 'index'));
- $this->assertTrue($acl->isPageAccessAllowed('user', 'login'));
- $this->assertTrue($acl->isPageAccessAllowed('user', 'check'));
- $this->assertTrue($acl->isPageAccessAllowed('webhook', 'task'));
- $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly'));
-
- // Admin user
- $_SESSION = array('user' => array('is_admin' => true));
- $this->assertTrue($acl->isPageAccessAllowed('user', 'create'));
- $this->assertTrue($acl->isPageAccessAllowed('user', 'save'));
- $this->assertTrue($acl->isPageAccessAllowed('user', 'remove'));
- $this->assertTrue($acl->isPageAccessAllowed('user', 'confirm'));
- $this->assertTrue($acl->isPageAccessAllowed('app', 'index'));
- $this->assertTrue($acl->isPageAccessAllowed('user', 'index'));
- $this->assertTrue($acl->isPageAccessAllowed('user', 'login'));
- $this->assertTrue($acl->isPageAccessAllowed('user', 'check'));
- $this->assertTrue($acl->isPageAccessAllowed('task', 'add'));
- $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly'));
+ $acl = new Acl($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $u = new User($this->container);
+
+ // We create our user
+ $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
+
+ // We create a project and set our user as member
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
+ $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+ $this->assertFalse($pp->isMember(1, 2));
+ $this->assertFalse($pp->isManager(1, 2));
+
+ $session = new Session;
+
+ $session['user'] = array(
+ 'id' => 2,
+ 'is_admin' => false,
+ );
+
+ $this->assertFalse($acl->isAllowed('board', 'show', 2));
+ $this->assertFalse($acl->isAllowed('board', 'show', 1));
+ $this->assertFalse($acl->isAllowed('task', 'show', 1));
+ $this->assertFalse($acl->isAllowed('task', 'update', 1));
+ $this->assertFalse($acl->isAllowed('project', 'show', 1));
+ $this->assertFalse($acl->isAllowed('config', 'application', 1));
+ $this->assertFalse($acl->isAllowed('project', 'users', 1));
+ $this->assertFalse($acl->isAllowed('task', 'remove', 1));
+ $this->assertTrue($acl->isAllowed('app', 'index', 1));
}
}
diff --git a/tests/units/ActionTaskAssignColorCategoryTest.php b/tests/units/ActionTaskAssignColorCategoryTest.php
index b7d99dae..c9665268 100644
--- a/tests/units/ActionTaskAssignColorCategoryTest.php
+++ b/tests/units/ActionTaskAssignColorCategoryTest.php
@@ -3,15 +3,17 @@
require_once __DIR__.'/Base.php';
use Model\Task;
+use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
use Model\Category;
+use Event\GenericEvent;
class ActionTaskAssignColorCategory extends Base
{
public function testBadProject()
{
- $action = new Action\TaskAssignColorCategory($this->registry, 3, Task::EVENT_CREATE_UPDATE);
+ $action = new Action\TaskAssignColorCategory($this->container, 3, Task::EVENT_CREATE_UPDATE);
$event = array(
'project_id' => 2,
@@ -20,25 +22,25 @@ class ActionTaskAssignColorCategory extends Base
);
$this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
{
- $action = new Action\TaskAssignColorCategory($this->registry, 1, Task::EVENT_CREATE_UPDATE);
+ $action = new Action\TaskAssignColorCategory($this->container, 1, Task::EVENT_CREATE_UPDATE);
$action->setParam('category_id', 1);
$action->setParam('color_id', 'blue');
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $c = new Category($this->registry);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $c->create(array('name' => 'c1')));
$this->assertEquals(2, $c->create(array('name' => 'c2')));
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green', 'category_id' => 2)));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green', 'category_id' => 2)));
// We create an event but we don't do anything
$event = array(
@@ -50,7 +52,7 @@ class ActionTaskAssignColorCategory extends Base
);
// Our event should NOT be executed
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
// Our task should be assigned to the ategory_id=1 and have the green color
$task = $tf->getById(1);
@@ -68,7 +70,7 @@ class ActionTaskAssignColorCategory extends Base
);
// Our event should be executed
- $this->assertTrue($action->execute($event));
+ $this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should have the blue color
$task = $tf->getById(1);
diff --git a/tests/units/ActionTaskAssignColorColumnTest.php b/tests/units/ActionTaskAssignColorColumnTest.php
new file mode 100644
index 00000000..363bb05c
--- /dev/null
+++ b/tests/units/ActionTaskAssignColorColumnTest.php
@@ -0,0 +1,41 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Event\GenericEvent;
+use Model\Task;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\Project;
+
+class ActionTaskAssignColorColumnTest extends Base
+{
+ public function testColorChange()
+ {
+ $action = new Action\TaskAssignColorColumn($this->container, 1, Task::EVENT_MOVE_COLUMN);
+ $action->setParam('column_id', 2);
+ $action->setParam('color_id', 'green');
+
+ // We create a task in the first column
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'yellow')));
+
+ $event = array(
+ 'project_id' => 1,
+ 'task_id' => 1,
+ 'column_id' => 2,
+ 'color_id' => 'green',
+ );
+
+ // Our event should be executed
+ $this->assertTrue($action->execute(new GenericEvent($event)));
+
+ // Our task should have color green
+ $task = $tf->getById(1);
+ $this->assertEquals('green', $task['color_id']);
+ }
+}
diff --git a/tests/units/ActionTaskAssignColorUserTest.php b/tests/units/ActionTaskAssignColorUserTest.php
index 61600fdc..c1bf3a34 100644
--- a/tests/units/ActionTaskAssignColorUserTest.php
+++ b/tests/units/ActionTaskAssignColorUserTest.php
@@ -3,14 +3,16 @@
require_once __DIR__.'/Base.php';
use Model\Task;
+use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
+use Event\GenericEvent;
class ActionTaskAssignColorUser extends Base
{
public function testBadProject()
{
- $action = new Action\TaskAssignColorUser($this->registry, 3, Task::EVENT_CREATE);
+ $action = new Action\TaskAssignColorUser($this->container, 3, Task::EVENT_CREATE);
$event = array(
'project_id' => 2,
@@ -19,21 +21,21 @@ class ActionTaskAssignColorUser extends Base
);
$this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
{
- $action = new Action\TaskAssignColorUser($this->registry, 1, Task::EVENT_ASSIGNEE_CHANGE);
+ $action = new Action\TaskAssignColorUser($this->container, 1, Task::EVENT_ASSIGNEE_CHANGE);
$action->setParam('user_id', 1);
$action->setParam('color_id', 'blue');
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green')));
// We change the assignee
$event = array(
@@ -43,7 +45,7 @@ class ActionTaskAssignColorUser extends Base
);
// Our event should NOT be executed
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
// Our task should be assigned to nobody and have the green color
$task = $tf->getById(1);
@@ -59,7 +61,7 @@ class ActionTaskAssignColorUser extends Base
);
// Our event should be executed
- $this->assertTrue($action->execute($event));
+ $this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be assigned to nobody and have the blue color
$task = $tf->getById(1);
diff --git a/tests/units/ActionTaskAssignCurrentUserTest.php b/tests/units/ActionTaskAssignCurrentUserTest.php
index edc2577c..f32fc77c 100644
--- a/tests/units/ActionTaskAssignCurrentUserTest.php
+++ b/tests/units/ActionTaskAssignCurrentUserTest.php
@@ -2,16 +2,18 @@
require_once __DIR__.'/Base.php';
+use Event\GenericEvent;
use Model\Task;
+use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
-use Model\Acl;
+use Model\UserSession;
class ActionTaskAssignCurrentUser extends Base
{
public function testBadProject()
{
- $action = new Action\TaskAssignCurrentUser($this->registry, 3, Task::EVENT_CREATE);
+ $action = new Action\TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE);
$action->setParam('column_id', 5);
$event = array(
@@ -21,12 +23,12 @@ class ActionTaskAssignCurrentUser extends Base
);
$this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testBadColumn()
{
- $action = new Action\TaskAssignCurrentUser($this->registry, 3, Task::EVENT_CREATE);
+ $action = new Action\TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE);
$action->setParam('column_id', 5);
$event = array(
@@ -35,26 +37,26 @@ class ActionTaskAssignCurrentUser extends Base
'column_id' => 3,
);
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
{
- $action = new Action\TaskAssignCurrentUser($this->registry, 1, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskAssignCurrentUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
$_SESSION = array(
'user' => array('id' => 5)
);
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $a = new Acl($this->registry);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $us = new UserSession($this->container);
- $this->assertEquals(5, $a->getUserId());
+ $this->assertEquals(5, $us->getId());
$this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
// We create an event to move the task to the 2nd column
$event = array(
@@ -64,7 +66,7 @@ class ActionTaskAssignCurrentUser extends Base
);
// Our event should be executed
- $this->assertTrue($action->execute($event));
+ $this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be assigned to the user 5 (from the session)
$task = $tf->getById(1);
diff --git a/tests/units/ActionTaskAssignSpecificUserTest.php b/tests/units/ActionTaskAssignSpecificUserTest.php
index 8795d5fb..ac054ba6 100644
--- a/tests/units/ActionTaskAssignSpecificUserTest.php
+++ b/tests/units/ActionTaskAssignSpecificUserTest.php
@@ -2,7 +2,9 @@
require_once __DIR__.'/Base.php';
+use Event\GenericEvent;
use Model\Task;
+use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
@@ -10,7 +12,7 @@ class ActionTaskAssignSpecificUser extends Base
{
public function testBadProject()
{
- $action = new Action\TaskAssignSpecificUser($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskAssignSpecificUser($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -20,12 +22,12 @@ class ActionTaskAssignSpecificUser extends Base
);
$this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testBadColumn()
{
- $action = new Action\TaskAssignSpecificUser($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskAssignSpecificUser($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -34,21 +36,21 @@ class ActionTaskAssignSpecificUser extends Base
'column_id' => 3,
);
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
{
- $action = new Action\TaskAssignSpecificUser($this->registry, 1, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskAssignSpecificUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
$action->setParam('user_id', 1);
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
// We create an event to move the task to the 2nd column
$event = array(
@@ -58,7 +60,7 @@ class ActionTaskAssignSpecificUser extends Base
);
// Our event should be executed
- $this->assertTrue($action->execute($event));
+ $this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be assigned to the user 1
$task = $tf->getById(1);
diff --git a/tests/units/ActionTaskCloseTest.php b/tests/units/ActionTaskCloseTest.php
index 6c8e4cf1..7f2c42de 100644
--- a/tests/units/ActionTaskCloseTest.php
+++ b/tests/units/ActionTaskCloseTest.php
@@ -2,16 +2,18 @@
require_once __DIR__.'/Base.php';
+use Event\GenericEvent;
use Model\Task;
+use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
-use Model\GithubWebhook;
+use Integration\GithubWebhook;
class ActionTaskCloseTest extends Base
{
public function testExecutable()
{
- $action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -22,7 +24,7 @@ class ActionTaskCloseTest extends Base
$this->assertTrue($action->isExecutable($event));
- $action = new Action\TaskClose($this->registry, 3, GithubWebhook::EVENT_COMMIT);
+ $action = new Action\TaskClose($this->container, 3, GithubWebhook::EVENT_COMMIT);
$event = array(
'project_id' => 3,
@@ -34,7 +36,7 @@ class ActionTaskCloseTest extends Base
public function testBadEvent()
{
- $action = new Action\TaskClose($this->registry, 3, Task::EVENT_UPDATE);
+ $action = new Action\TaskClose($this->container, 3, Task::EVENT_UPDATE);
$action->setParam('column_id', 5);
$event = array(
@@ -44,12 +46,12 @@ class ActionTaskCloseTest extends Base
);
$this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testBadProject()
{
- $action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -59,12 +61,12 @@ class ActionTaskCloseTest extends Base
);
$this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testBadColumn()
{
- $action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -73,20 +75,20 @@ class ActionTaskCloseTest extends Base
'column_id' => 3,
);
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
{
- $action = new Action\TaskClose($this->registry, 1, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskClose($this->container, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
// We create an event to move the task to the 2nd column
$event = array(
@@ -96,7 +98,7 @@ class ActionTaskCloseTest extends Base
);
// Our event should be executed
- $this->assertTrue($action->execute($event));
+ $this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be closed
$task = $tf->getById(1);
diff --git a/tests/units/ActionTaskDuplicateAnotherProjectTest.php b/tests/units/ActionTaskDuplicateAnotherProjectTest.php
index 6fb3c8d8..10c7c36a 100644
--- a/tests/units/ActionTaskDuplicateAnotherProjectTest.php
+++ b/tests/units/ActionTaskDuplicateAnotherProjectTest.php
@@ -2,7 +2,9 @@
require_once __DIR__.'/Base.php';
+use Event\GenericEvent;
use Model\Task;
+use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
@@ -10,7 +12,7 @@ class ActionTaskDuplicateAnotherProject extends Base
{
public function testBadProject()
{
- $action = new Action\TaskDuplicateAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskDuplicateAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -20,12 +22,12 @@ class ActionTaskDuplicateAnotherProject extends Base
);
$this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testBadColumn()
{
- $action = new Action\TaskDuplicateAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskDuplicateAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -34,20 +36,20 @@ class ActionTaskDuplicateAnotherProject extends Base
'column_id' => 3,
);
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
{
- $action = new Action\TaskDuplicateAnotherProject($this->registry, 1, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskDuplicateAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN);
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $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(2, $p->create(array('name' => 'project 2')));
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
// We create an event to move the task to the 2nd column
$event = array(
@@ -59,7 +61,7 @@ class ActionTaskDuplicateAnotherProject extends Base
// Our event should NOT be executed because we define the same project
$action->setParam('column_id', 2);
$action->setParam('project_id', 1);
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
// Our task should be assigned to the project 1
$task = $tf->getById(1);
@@ -76,7 +78,8 @@ class ActionTaskDuplicateAnotherProject extends Base
// Our event should be executed because we define a different project
$action->setParam('column_id', 2);
$action->setParam('project_id', 2);
- $this->assertTrue($action->execute($event));
+ $this->assertTrue($action->hasRequiredCondition($event));
+ $this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be assigned to the project 1
$task = $tf->getById(1);
diff --git a/tests/units/ActionTaskMoveAnotherProjectTest.php b/tests/units/ActionTaskMoveAnotherProjectTest.php
index 903cc392..3f0c3de6 100644
--- a/tests/units/ActionTaskMoveAnotherProjectTest.php
+++ b/tests/units/ActionTaskMoveAnotherProjectTest.php
@@ -2,7 +2,9 @@
require_once __DIR__.'/Base.php';
+use Event\GenericEvent;
use Model\Task;
+use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
@@ -10,7 +12,7 @@ class ActionTaskMoveAnotherProject extends Base
{
public function testBadProject()
{
- $action = new Action\TaskMoveAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskMoveAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -20,12 +22,12 @@ class ActionTaskMoveAnotherProject extends Base
);
$this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testBadColumn()
{
- $action = new Action\TaskMoveAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskMoveAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -34,20 +36,20 @@ class ActionTaskMoveAnotherProject extends Base
'column_id' => 3,
);
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
}
public function testExecute()
{
- $action = new Action\TaskMoveAnotherProject($this->registry, 1, Task::EVENT_MOVE_COLUMN);
+ $action = new Action\TaskMoveAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN);
// We create a task in the first column
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $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(2, $p->create(array('name' => 'project 2')));
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
// We create an event to move the task to the 2nd column
$event = array(
@@ -59,7 +61,7 @@ class ActionTaskMoveAnotherProject extends Base
// Our event should NOT be executed because we define the same project
$action->setParam('column_id', 2);
$action->setParam('project_id', 1);
- $this->assertFalse($action->execute($event));
+ $this->assertFalse($action->execute(new GenericEvent($event)));
// Our task should be assigned to the project 1
$task = $tf->getById(1);
@@ -76,7 +78,7 @@ class ActionTaskMoveAnotherProject extends Base
// Our event should be executed because we define a different project
$action->setParam('column_id', 2);
$action->setParam('project_id', 2);
- $this->assertTrue($action->execute($event));
+ $this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be assigned to the project 2
$task = $tf->getById(1);
diff --git a/tests/units/ActionTaskUpdateStartDateTest.php b/tests/units/ActionTaskUpdateStartDateTest.php
new file mode 100644
index 00000000..da36551d
--- /dev/null
+++ b/tests/units/ActionTaskUpdateStartDateTest.php
@@ -0,0 +1,46 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Event\GenericEvent;
+use Model\Task;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\Project;
+use Integration\GithubWebhook;
+
+class ActionTaskUpdateStartDateTest extends Base
+{
+ public function testExecute()
+ {
+ $action = new Action\TaskUpdateStartDate($this->container, 1, Task::EVENT_MOVE_COLUMN);
+ $action->setParam('column_id', 2);
+
+ // We create a task in the first column
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+
+ // The start date must be empty
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEmpty($task['date_started']);
+
+ // We create an event to move the task to the 2nd column
+ $event = array(
+ 'project_id' => 1,
+ 'task_id' => 1,
+ 'column_id' => 2,
+ );
+
+ // Our event should be executed
+ $this->assertTrue($action->execute(new GenericEvent($event)));
+
+ // Our task should be closed
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(time(), $task['date_started'], '', 2);
+ }
+}
diff --git a/tests/units/ActionTest.php b/tests/units/ActionTest.php
index aa923445..67957a26 100644
--- a/tests/units/ActionTest.php
+++ b/tests/units/ActionTest.php
@@ -6,25 +6,28 @@ use Model\Action;
use Model\Project;
use Model\Board;
use Model\Task;
+use Model\TaskPosition;
+use Model\TaskCreation;
use Model\TaskFinder;
use Model\Category;
+use Integration\GithubWebhook;
class ActionTest extends Base
{
- public function testFetchActions()
+ public function testSingleAction()
{
- $action = new Action($this->registry);
- $board = new Board($this->registry);
- $project = new Project($this->registry);
+ $tp = new TaskPosition($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $board = new Board($this->container);
+ $project = new Project($this->container);
+ $action = new Action($this->container);
+ // We create a project
$this->assertEquals(1, $project->create(array('name' => 'unit_test')));
- // We should have nothing
- $this->assertEmpty($action->getAll());
- $this->assertEmpty($action->getAllByProject(1));
-
// We create a new action
- $this->assertTrue($action->create(array(
+ $this->assertEquals(1, $action->create(array(
'project_id' => 1,
'event_name' => Task::EVENT_MOVE_COLUMN,
'action_name' => 'TaskClose',
@@ -33,33 +36,8 @@ class ActionTest extends Base
)
)));
- // We should have our action
- $this->assertNotEmpty($action->getAll());
- $this->assertEquals($action->getAll(), $action->getAllByProject(1));
-
- $actions = $action->getAll();
-
- $this->assertEquals(1, count($actions));
- $this->assertEquals(1, $actions[0]['project_id']);
- $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']);
- $this->assertEquals('TaskClose', $actions[0]['action_name']);
- $this->assertEquals('column_id', $actions[0]['params'][0]['name']);
- $this->assertEquals(4, $actions[0]['params'][0]['value']);
- }
-
- public function testEventMoveColumn()
- {
- $task = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $board = new Board($this->registry);
- $project = new Project($this->registry);
- $action = new Action($this->registry);
-
- // We create a project
- $this->assertEquals(1, $project->create(array('name' => 'unit_test')));
-
// We create a task
- $this->assertEquals(1, $task->create(array(
+ $this->assertEquals(1, $tc->create(array(
'title' => 'unit_test',
'project_id' => 1,
'owner_id' => 1,
@@ -67,17 +45,7 @@ class ActionTest extends Base
'column_id' => 1,
)));
- // We create a new action
- $this->assertTrue($action->create(array(
- 'project_id' => 1,
- 'event_name' => Task::EVENT_MOVE_COLUMN,
- 'action_name' => 'TaskClose',
- 'params' => array(
- 'column_id' => 4,
- )
- )));
-
- // We bind events
+ // We attach events
$action->attachEvents();
// Our task should be open
@@ -86,10 +54,7 @@ class ActionTest extends Base
$this->assertEquals(1, $t1['column_id']);
// We move our task
- $task->movePosition(1, 1, 4, 1);
-
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
- $this->assertFalse($this->registry->shared('event')->isEventTriggered(Task::EVENT_UPDATE));
+ $tp->movePosition(1, 1, 4, 1);
// Our task should be closed
$t1 = $tf->getById(1);
@@ -97,77 +62,80 @@ class ActionTest extends Base
$this->assertEquals(0, $t1['is_active']);
}
- public function testExecuteMultipleActions()
+ public function testMultipleActions()
{
- $task = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $board = new Board($this->registry);
- $project = new Project($this->registry);
- $action = new Action($this->registry);
+ $tp = new TaskPosition($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $b = new Board($this->container);
+ $p = new Project($this->container);
+ $a = new Action($this->container);
+ $c = new Category($this->container);
+ $g = new GithubWebhook($this->container);
- // We create 2 projects
- $this->assertEquals(1, $project->create(array('name' => 'unit_test1')));
- $this->assertEquals(2, $project->create(array('name' => 'unit_test2')));
+ // We create a project
+ $this->assertEquals(1, $p->create(array('name' => 'unit_test')));
+ $this->assertEquals(1, $c->create(array('name' => 'unit_test')));
- // We create a task
- $this->assertEquals(1, $task->create(array(
- 'title' => 'unit_test',
+ // We create a new action
+ $this->assertEquals(1, $a->create(array(
'project_id' => 1,
- 'owner_id' => 1,
- 'color_id' => 'red',
- 'column_id' => 1,
+ 'event_name' => GithubWebhook::EVENT_ISSUE_OPENED,
+ 'action_name' => 'TaskCreation',
+ 'params' => array()
)));
- // We create 2 actions
- $this->assertTrue($action->create(array(
+ $this->assertEquals(2, $a->create(array(
'project_id' => 1,
- 'event_name' => Task::EVENT_CLOSE,
- 'action_name' => 'TaskDuplicateAnotherProject',
+ 'event_name' => GithubWebhook::EVENT_ISSUE_LABEL_CHANGE,
+ 'action_name' => 'TaskAssignCategoryLabel',
'params' => array(
- 'column_id' => 4,
- 'project_id' => 2,
+ 'label' => 'bug',
+ 'category_id' => 1,
)
)));
- $this->assertTrue($action->create(array(
+ $this->assertEquals(3, $a->create(array(
'project_id' => 1,
- 'event_name' => Task::EVENT_MOVE_COLUMN,
- 'action_name' => 'TaskClose',
+ 'event_name' => Task::EVENT_CREATE_UPDATE,
+ 'action_name' => 'TaskAssignColorCategory',
'params' => array(
- 'column_id' => 4,
+ 'color_id' => 'red',
+ 'category_id' => 1,
)
)));
- // We bind events
- $action->attachEvents();
-
- // Events should be attached
- $this->assertTrue($this->registry->shared('event')->hasListener(Task::EVENT_CLOSE, 'Action\TaskDuplicateAnotherProject'));
- $this->assertTrue($this->registry->shared('event')->hasListener(Task::EVENT_MOVE_COLUMN, 'Action\TaskClose'));
-
- // Our task should be open, linked to the first project and in the first column
- $t1 = $tf->getById(1);
- $this->assertEquals(1, $t1['is_active']);
- $this->assertEquals(1, $t1['column_id']);
- $this->assertEquals(1, $t1['project_id']);
-
- // We move our task
- $task->movePosition(1, 1, 4, 1);
-
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CLOSE));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
-
- // Our task should be closed
- $t1 = $tf->getById(1);
- $this->assertEquals(4, $t1['column_id']);
- $this->assertEquals(0, $t1['is_active']);
-
- // Our task should be duplicated to the 2nd project
- $t2 = $tf->getById(2);
- $this->assertNotEmpty($t2);
- $this->assertNotEquals(4, $t2['column_id']);
- $this->assertEquals(1, $t2['is_active']);
- $this->assertEquals(2, $t2['project_id']);
- $this->assertEquals('unit_test', $t2['title']);
+ // We attach events
+ $a->attachEvents();
+ $g->setProjectId(1);
+
+ // We create a Github issue
+ $issue = array(
+ 'number' => 123,
+ 'title' => 'Bugs everywhere',
+ 'body' => 'There is a bug!',
+ 'html_url' => 'http://localhost/',
+ );
+
+ $this->assertTrue($g->handleIssueOpened($issue));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals('yellow', $task['color_id']);
+
+ // We assign a label to our issue
+ $label = array(
+ 'name' => 'bug',
+ );
+
+ $this->assertTrue($g->handleIssueLabeled($issue, $label));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+ $this->assertEquals(1, $task['category_id']);
+ $this->assertEquals('red', $task['color_id']);
}
}
diff --git a/tests/units/AppHelperTest.php b/tests/units/AppHelperTest.php
new file mode 100644
index 00000000..ad4bc151
--- /dev/null
+++ b/tests/units/AppHelperTest.php
@@ -0,0 +1,38 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Core\Session;
+use Helper\App;
+use Model\Config;
+
+class AppHelperTest extends Base
+{
+ public function testJsLang()
+ {
+ $h = new App($this->container);
+ $this->assertEquals('en', $h->jsLang());
+ }
+
+ public function testTimezone()
+ {
+ $h = new App($this->container);
+ $this->assertEquals('UTC', $h->getTimezone());
+ }
+
+ public function testFlashMessage()
+ {
+ $h = new App($this->container);
+ $s = new Session;
+
+ $this->assertEmpty($h->flashMessage());
+ $s->flash('test & test');
+ $this->assertEquals('<div class="alert alert-success alert-fade-out">test &amp; test</div>', $h->flashMessage());
+ $this->assertEmpty($h->flashMessage());
+
+ $this->assertEmpty($h->flashMessage());
+ $s->flashError('test & test');
+ $this->assertEquals('<div class="alert alert-error">test &amp; test</div>', $h->flashMessage());
+ $this->assertEmpty($h->flashMessage());
+ }
+}
diff --git a/tests/units/AssetHelperTest.php b/tests/units/AssetHelperTest.php
new file mode 100644
index 00000000..1143ce1f
--- /dev/null
+++ b/tests/units/AssetHelperTest.php
@@ -0,0 +1,21 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Helper\Asset;
+use Model\Config;
+
+class AssetHelperTest extends Base
+{
+ public function testCustomCss()
+ {
+ $h = new Asset($this->container);
+ $c = new Config($this->container);
+
+ $this->assertEmpty($h->customCss());
+
+ $this->assertTrue($c->save(array('application_stylesheet' => 'p { color: red }')));
+
+ $this->assertEquals('<style>p { color: red }</style>', $h->customCss());
+ }
+}
diff --git a/tests/units/Base.php b/tests/units/Base.php
index 3a46a4ae..bc6518fb 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -1,32 +1,81 @@
<?php
-require __DIR__.'/../../app/Core/Loader.php';
-require __DIR__.'/../../app/helpers.php';
-require __DIR__.'/../../app/functions.php';
+require __DIR__.'/../../vendor/autoload.php';
require __DIR__.'/../../app/constants.php';
-use Core\Loader;
-use Core\Registry;
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
+use Symfony\Component\Stopwatch\Stopwatch;
+use SimpleLogger\Logger;
+use SimpleLogger\File;
-if (version_compare(PHP_VERSION, '5.5.0', '<')) {
- require __DIR__.'/../../vendor/password.php';
+date_default_timezone_set('UTC');
+
+class FakeEmailClient
+{
+ public $email;
+ public $name;
+ public $subject;
+ public $html;
+
+ public function send($email, $name, $subject, $html)
+ {
+ $this->email = $email;
+ $this->name = $name;
+ $this->subject = $subject;
+ $this->html = $html;
+ }
}
-date_default_timezone_set('UTC');
+class FakeHttpClient
+{
+ private $url = '';
+ private $data = array();
+ private $headers = array();
+
+ public function getUrl()
+ {
+ return $this->url;
+ }
+
+ public function getData()
+ {
+ return $this->data;
+ }
+
+ public function getHeaders()
+ {
+ return $this->headers;
+ }
+
+ public function toPrettyJson()
+ {
+ return json_encode($this->data, JSON_PRETTY_PRINT);
+ }
-$loader = new Loader;
-$loader->setPath('app');
-$loader->setPath('vendor');
-$loader->execute();
+ public function postJson($url, array $data, array $headers = array())
+ {
+ $this->url = $url;
+ $this->data = $data;
+ $this->headers = $headers;
+ return true;
+ }
+
+ public function postForm($url, array $data, array $headers = array())
+ {
+ $this->url = $url;
+ $this->data = $data;
+ $this->headers = $headers;
+ return true;
+ }
+}
abstract class Base extends PHPUnit_Framework_TestCase
{
+ protected $container;
+
public function setUp()
{
- $this->registry = new Registry;
- $this->registry->db = function() { return setup_db(); };
- $this->registry->event = function() { return setup_events(); };
-
if (DB_DRIVER === 'mysql') {
$pdo = new PDO('mysql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
$pdo->exec('DROP DATABASE '.DB_NAME);
@@ -39,10 +88,26 @@ abstract class Base extends PHPUnit_Framework_TestCase
$pdo->exec('CREATE DATABASE '.DB_NAME.' WITH OWNER '.DB_USERNAME);
$pdo = null;
}
+
+ $this->container = new Pimple\Container;
+ $this->container->register(new ServiceProvider\DatabaseProvider);
+ $this->container->register(new ServiceProvider\ClassProvider);
+
+ $this->container['dispatcher'] = new TraceableEventDispatcher(
+ new EventDispatcher,
+ new Stopwatch
+ );
+
+ $this->container['db']->log_queries = true;
+
+ $this->container['logger'] = new Logger;
+ $this->container['logger']->setLogger(new File('/dev/null'));
+ $this->container['httpClient'] = new FakeHttpClient;
+ $this->container['emailClient'] = new FakeEmailClient;
}
public function tearDown()
{
- $this->registry->shared('db')->closeConnection();
+ $this->container['db']->closeConnection();
}
}
diff --git a/tests/units/BitbucketWebhookTest.php b/tests/units/BitbucketWebhookTest.php
new file mode 100644
index 00000000..cb33b595
--- /dev/null
+++ b/tests/units/BitbucketWebhookTest.php
@@ -0,0 +1,65 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Integration\BitbucketWebhook;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\Project;
+
+class BitbucketWebhookTest extends Base
+{
+ private $post_payload = '{"repository": {"website": "", "fork": false, "name": "webhooks", "scm": "git", "owner": "minicoders", "absolute_url": "/minicoders/webhooks/", "slug": "webhooks", "is_private": true}, "truncated": false, "commits": [{"node": "28569937627f", "files": [{"type": "added", "file": "README.md"}], "raw_author": "Frederic Guillot <fred@localhost>", "utctimestamp": "2015-02-09 00:57:45+00:00", "author": "Frederic Guillot", "timestamp": "2015-02-09 01:57:45", "raw_node": "28569937627fb406eeda9376a02b39581a974d4f", "parents": [], "branch": "master", "message": "first commit\\n", "revision": null, "size": -1}, {"node": "285699376274", "files": [{"type": "added", "file": "README.md"}], "raw_author": "Frederic Guillot <fred@localhost>", "utctimestamp": "2015-02-09 00:57:45+00:00", "author": "Frederic Guillot", "timestamp": "2015-02-09 01:57:45", "raw_node": "28569937627fb406eeda9376a02b39581a974d4f", "parents": [], "branch": "master", "message": "Fix #2\\n", "revision": null, "size": -1}], "canon_url": "https://bitbucket.org", "user": "minicoders"}';
+
+ public function testHandleCommit()
+ {
+ $g = new BitbucketWebhook($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $g->setProjectId(1);
+
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_COMMIT, function() {});
+
+ $event = json_decode($this->post_payload, true);
+
+ // No task
+ $this->assertFalse($g->handleCommit($event['commits'][0]));
+
+ // Create task with the wrong id
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertFalse($g->handleCommit($event['commits'][1]));
+
+ // Create task with the right id
+ $this->assertEquals(2, $tc->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($g->handleCommit($event['commits'][1]));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(BitbucketWebhook::EVENT_COMMIT.'.closure', $called);
+ }
+
+ public function testParsePayload()
+ {
+ $g = new BitbucketWebhook($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_COMMIT, function() {});
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+
+ $g->setProjectId(1);
+
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = json_decode($this->post_payload, true);
+ $this->assertTrue($g->parsePayload($event));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(BitbucketWebhook::EVENT_COMMIT.'.closure', $called);
+ }
+}
diff --git a/tests/units/BoardTest.php b/tests/units/BoardTest.php
index cdf23a82..ebd4f655 100644
--- a/tests/units/BoardTest.php
+++ b/tests/units/BoardTest.php
@@ -5,14 +5,17 @@ require_once __DIR__.'/Base.php';
use Model\Project;
use Model\Board;
use Model\Config;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\Swimlane;
class BoardTest extends Base
{
public function testCreation()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
- $c = new Config($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
+ $c = new Config($this->container);
// Default columns
@@ -43,22 +46,113 @@ class BoardTest extends Base
public function testGetBoard()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
- $board = $b->get(1);
+ $board = $b->getBoard(1);
$this->assertNotEmpty($board);
- $this->assertEquals(4, count($board));
- $this->assertTrue(array_key_exists('tasks', $board[2]));
- $this->assertTrue(array_key_exists('title', $board[2]));
+ $this->assertEquals(1, count($board));
+ $this->assertEquals(5, count($board[0]));
+ $this->assertTrue(array_key_exists('name', $board[0]));
+ $this->assertTrue(array_key_exists('columns', $board[0]));
+ $this->assertTrue(array_key_exists('tasks', $board[0]['columns'][2]));
+ $this->assertTrue(array_key_exists('title', $board[0]['columns'][2]));
+ }
+
+ public function testGetBoardWithSwimlane()
+ {
+ $b = new Board($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $s->create(1, 'test 1'));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 3)));
+ $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+ $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 3)));
+ $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 4)));
+ $this->assertEquals(6, $tc->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 4, 'swimlane_id' => 1)));
+
+ $board = $b->getBoard(1);
+ $this->assertNotEmpty($board);
+ $this->assertEquals(2, count($board));
+ $this->assertEquals(5, count($board[0]));
+ $this->assertTrue(array_key_exists('nb_tasks', $board[0]));
+ $this->assertTrue(array_key_exists('name', $board[0]));
+ $this->assertTrue(array_key_exists('columns', $board[0]));
+ $this->assertTrue(array_key_exists('tasks', $board[0]['columns'][2]));
+ $this->assertTrue(array_key_exists('title', $board[0]['columns'][2]));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(1, $board[0]['columns'][0]['tasks'][0]['id']);
+ $this->assertEquals(1, $board[0]['columns'][0]['tasks'][0]['column_id']);
+ $this->assertEquals(1, $board[0]['columns'][0]['tasks'][0]['position']);
+ $this->assertEquals(0, $board[0]['columns'][0]['tasks'][0]['swimlane_id']);
+
+ $task = $tf->getById(2);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(3, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(2, $board[0]['columns'][2]['tasks'][0]['id']);
+ $this->assertEquals(3, $board[0]['columns'][2]['tasks'][0]['column_id']);
+ $this->assertEquals(1, $board[0]['columns'][2]['tasks'][0]['position']);
+ $this->assertEquals(0, $board[0]['columns'][2]['tasks'][0]['swimlane_id']);
+
+ $task = $tf->getById(3);
+ $this->assertEquals(3, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['swimlane_id']);
+ $this->assertEquals(3, $board[1]['columns'][1]['tasks'][0]['id']);
+ $this->assertEquals(2, $board[1]['columns'][1]['tasks'][0]['column_id']);
+ $this->assertEquals(1, $board[1]['columns'][1]['tasks'][0]['position']);
+ $this->assertEquals(1, $board[1]['columns'][1]['tasks'][0]['swimlane_id']);
+
+ $task = $tf->getById(4);
+ $this->assertEquals(4, $task['id']);
+ $this->assertEquals(3, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(4, $board[0]['columns'][2]['tasks'][1]['id']);
+ $this->assertEquals(3, $board[0]['columns'][2]['tasks'][1]['column_id']);
+ $this->assertEquals(2, $board[0]['columns'][2]['tasks'][1]['position']);
+ $this->assertEquals(0, $board[0]['columns'][2]['tasks'][1]['swimlane_id']);
+
+ $task = $tf->getById(5);
+ $this->assertEquals(5, $task['id']);
+ $this->assertEquals(4, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(5, $board[0]['columns'][3]['tasks'][0]['id']);
+ $this->assertEquals(4, $board[0]['columns'][3]['tasks'][0]['column_id']);
+ $this->assertEquals(1, $board[0]['columns'][3]['tasks'][0]['position']);
+ $this->assertEquals(0, $board[0]['columns'][3]['tasks'][0]['swimlane_id']);
+
+ $task = $tf->getById(6);
+ $this->assertEquals(6, $task['id']);
+ $this->assertEquals(4, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['swimlane_id']);
+ $this->assertEquals(6, $board[1]['columns'][3]['tasks'][0]['id']);
+ $this->assertEquals(4, $board[1]['columns'][3]['tasks'][0]['column_id']);
+ $this->assertEquals(1, $board[1]['columns'][3]['tasks'][0]['position']);
+ $this->assertEquals(1, $board[1]['columns'][3]['tasks'][0]['swimlane_id']);
}
public function testGetColumn()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
@@ -72,8 +166,8 @@ class BoardTest extends Base
public function testRemoveColumn()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
$this->assertTrue($b->removeColumn(3));
@@ -86,8 +180,8 @@ class BoardTest extends Base
public function testUpdateColumn()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
@@ -107,12 +201,12 @@ class BoardTest extends Base
public function testAddColumn()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
- $this->assertTrue($b->addColumn(1, 'another column'));
- $this->assertTrue($b->addColumn(1, 'one more', 3));
+ $this->assertNotFalse($b->addColumn(1, 'another column'));
+ $this->assertNotFalse($b->addColumn(1, 'one more', 3, 'one more description'));
$columns = $b->getColumns(1);
$this->assertTrue(is_array($columns));
@@ -125,12 +219,13 @@ class BoardTest extends Base
$this->assertEquals('one more', $columns[5]['title']);
$this->assertEquals(3, $columns[5]['task_limit']);
$this->assertEquals(6, $columns[5]['position']);
+ $this->assertEquals('one more description', $columns[5]['description']);
}
public function testMoveColumns()
{
- $p = new Project($this->registry);
- $b = new Board($this->registry);
+ $p = new Project($this->container);
+ $b = new Board($this->container);
// We create 2 projects
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
@@ -194,4 +289,84 @@ class BoardTest extends Base
$this->assertEquals(4, $columns[3]['position']);
$this->assertEquals($columns_id[3], $columns[3]['id']);
}
+
+ public function testMoveUpAndRemoveColumn()
+ {
+ $p = new Project($this->container);
+ $b = new Board($this->container);
+
+ // We create a project
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
+
+ // We remove the second column
+ $this->assertTrue($b->removeColumn(2));
+
+ $columns = $b->getColumns(1);
+ $this->assertNotEmpty($columns);
+ $this->assertCount(3, $columns);
+
+ $this->assertEquals(1, $columns[0]['position']);
+ $this->assertEquals(3, $columns[1]['position']);
+ $this->assertEquals(4, $columns[2]['position']);
+
+ $this->assertEquals(1, $columns[0]['id']);
+ $this->assertEquals(3, $columns[1]['id']);
+ $this->assertEquals(4, $columns[2]['id']);
+
+ // We move up the second column
+ $this->assertTrue($b->moveUp(1, $columns[1]['id']));
+
+ // Check the new positions
+ $columns = $b->getColumns(1);
+ $this->assertNotEmpty($columns);
+ $this->assertCount(3, $columns);
+
+ $this->assertEquals(1, $columns[0]['position']);
+ $this->assertEquals(2, $columns[1]['position']);
+ $this->assertEquals(3, $columns[2]['position']);
+
+ $this->assertEquals(3, $columns[0]['id']);
+ $this->assertEquals(1, $columns[1]['id']);
+ $this->assertEquals(4, $columns[2]['id']);
+ }
+
+ public function testMoveDownAndRemoveColumn()
+ {
+ $p = new Project($this->container);
+ $b = new Board($this->container);
+
+ // We create a project
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
+
+ // We remove the second column
+ $this->assertTrue($b->removeColumn(2));
+
+ $columns = $b->getColumns(1);
+ $this->assertNotEmpty($columns);
+ $this->assertCount(3, $columns);
+
+ $this->assertEquals(1, $columns[0]['position']);
+ $this->assertEquals(3, $columns[1]['position']);
+ $this->assertEquals(4, $columns[2]['position']);
+
+ $this->assertEquals(1, $columns[0]['id']);
+ $this->assertEquals(3, $columns[1]['id']);
+ $this->assertEquals(4, $columns[2]['id']);
+
+ // We move up the second column
+ $this->assertTrue($b->moveDown(1, $columns[0]['id']));
+
+ // Check the new positions
+ $columns = $b->getColumns(1);
+ $this->assertNotEmpty($columns);
+ $this->assertCount(3, $columns);
+
+ $this->assertEquals(1, $columns[0]['position']);
+ $this->assertEquals(2, $columns[1]['position']);
+ $this->assertEquals(3, $columns[2]['position']);
+
+ $this->assertEquals(3, $columns[0]['id']);
+ $this->assertEquals(1, $columns[1]['id']);
+ $this->assertEquals(4, $columns[2]['id']);
+ }
}
diff --git a/tests/units/CategoryTest.php b/tests/units/CategoryTest.php
index ef061419..638f3fe4 100644
--- a/tests/units/CategoryTest.php
+++ b/tests/units/CategoryTest.php
@@ -3,6 +3,7 @@
require_once __DIR__.'/Base.php';
use Model\Task;
+use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
use Model\Category;
@@ -12,15 +13,15 @@ class CategoryTest extends Base
{
public function testCreation()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $c = new Category($this->registry);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1)));
- $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));
$task = $tf->getById(1);
$this->assertTrue(is_array($task));
@@ -31,19 +32,25 @@ class CategoryTest extends Base
$this->assertEquals(2, $category['id']);
$this->assertEquals('Category #2', $category['name']);
$this->assertEquals(1, $category['project_id']);
+
+ $this->assertEquals(2, $c->getIdByName(1, 'Category #2'));
+ $this->assertEquals(0, $c->getIdByName(2, 'Category #2'));
+
+ $this->assertEquals('Category #2', $c->getNameById(2));
+ $this->assertEquals('', $c->getNameById(23));
}
public function testRemove()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $c = new Category($this->registry);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $c->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertEquals(2, $c->create(array('name' => 'Category #2', 'project_id' => 1)));
- $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'category_id' => 2)));
$task = $tf->getById(1);
$this->assertTrue(is_array($task));
diff --git a/tests/units/CommentTest.php b/tests/units/CommentTest.php
index 31c46996..36ff1352 100644
--- a/tests/units/CommentTest.php
+++ b/tests/units/CommentTest.php
@@ -3,6 +3,7 @@
require_once __DIR__.'/Base.php';
use Model\Task;
+use Model\TaskCreation;
use Model\Project;
use Model\Comment;
@@ -10,13 +11,13 @@ class CommentTest extends Base
{
public function testCreate()
{
- $c = new Comment($this->registry);
- $t = new Task($this->registry);
- $p = new Project($this->registry);
+ $c = new Comment($this->container);
+ $tc = new TaskCreation($this->container);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
- $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
$comment = $c->getById(1);
@@ -30,15 +31,15 @@ class CommentTest extends Base
public function testGetAll()
{
- $c = new Comment($this->registry);
- $t = new Task($this->registry);
- $p = new Project($this->registry);
+ $c = new Comment($this->container);
+ $tc = new TaskCreation($this->container);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
- $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
- $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1)));
- $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+ $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1)));
+ $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1)));
$comments = $c->getAll(1);
@@ -53,13 +54,13 @@ class CommentTest extends Base
public function testUpdate()
{
- $c = new Comment($this->registry);
- $t = new Task($this->registry);
- $p = new Project($this->registry);
+ $c = new Comment($this->container);
+ $tc = new TaskCreation($this->container);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
- $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
$this->assertTrue($c->update(array('id' => 1, 'comment' => 'bla')));
$comment = $c->getById(1);
@@ -69,12 +70,12 @@ class CommentTest extends Base
public function validateRemove()
{
- $c = new Comment($this->registry);
- $t = new Task($this->registry);
- $p = new Project($this->registry);
+ $c = new Comment($this->container);
+ $tc = new TaskCreation($this->container);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
$this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
$this->assertTrue($c->remove(1));
@@ -84,7 +85,7 @@ class CommentTest extends Base
public function testValidateCreation()
{
- $c = new Comment($this->registry);
+ $c = new Comment($this->container);
$result = $c->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla'));
$this->assertTrue($result[0]);
@@ -113,7 +114,7 @@ class CommentTest extends Base
public function testValidateModification()
{
- $c = new Comment($this->registry);
+ $c = new Comment($this->container);
$result = $c->validateModification(array('id' => 1, 'comment' => 'bla'));
$this->assertTrue($result[0]);
diff --git a/tests/units/ConfigTest.php b/tests/units/ConfigTest.php
index 4992092b..b630f284 100644
--- a/tests/units/ConfigTest.php
+++ b/tests/units/ConfigTest.php
@@ -3,12 +3,13 @@
require_once __DIR__.'/Base.php';
use Model\Config;
+use Core\Session;
class ConfigTest extends Base
{
public function testDefaultValues()
{
- $c = new Config($this->registry);
+ $c = new Config($this->container);
$this->assertEquals('en_US', $c->get('application_language'));
$this->assertEquals('UTC', $c->get('application_timezone'));
@@ -23,10 +24,35 @@ class ConfigTest extends Base
public function testGet()
{
- $c = new Config($this->registry);
+ $c = new Config($this->container);
$this->assertEquals('', $c->get('board_columns'));
$this->assertEquals('test', $c->get('board_columns', 'test'));
$this->assertEquals(0, $c->get('board_columns', 0));
}
+
+ public function testGetWithSession()
+ {
+ $this->container['session'] = new Session;
+ $c = new Config($this->container);
+
+ session_id('test');
+
+ $this->assertTrue(Session::isOpen());
+
+ $this->assertEquals('', $c->get('board_columns'));
+ $this->assertEquals('test', $c->get('board_columns', 'test'));
+
+ $this->container['session']['config'] = array(
+ 'board_columns' => 'foo',
+ 'empty_value' => 0
+ );
+
+ $this->assertEquals('foo', $c->get('board_columns'));
+ $this->assertEquals('foo', $c->get('board_columns', 'test'));
+ $this->assertEquals('test', $c->get('empty_value', 'test'));
+
+ session_id('');
+ unset($this->container['session']);
+ }
}
diff --git a/tests/units/DateParserTest.php b/tests/units/DateParserTest.php
index 68addf3f..9403063b 100644
--- a/tests/units/DateParserTest.php
+++ b/tests/units/DateParserTest.php
@@ -6,9 +6,37 @@ use Model\DateParser;
class DateParserTest extends Base
{
+ public function testDateRange()
+ {
+ $d = new DateParser($this->container);
+
+ $this->assertTrue($d->withinDateRange(new DateTime('2015-03-14 15:30:00'), new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 16:00:00')));
+ $this->assertFalse($d->withinDateRange(new DateTime('2015-03-14 15:30:00'), new DateTime('2015-03-14 16:00:00'), new DateTime('2015-03-14 17:00:00')));
+ }
+
+ public function testRoundSeconds()
+ {
+ $d = new DateParser($this->container);
+ $this->assertEquals('16:30', date('H:i', $d->getRoundedSeconds(strtotime('16:28'))));
+ $this->assertEquals('16:00', date('H:i', $d->getRoundedSeconds(strtotime('16:02'))));
+ $this->assertEquals('16:15', date('H:i', $d->getRoundedSeconds(strtotime('16:14'))));
+ $this->assertEquals('17:00', date('H:i', $d->getRoundedSeconds(strtotime('16:58'))));
+ }
+
+ public function testGetHours()
+ {
+ $d = new DateParser($this->container);
+
+ $this->assertEquals(1, $d->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 16:00:00')));
+ $this->assertEquals(2.5, $d->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 17:30:00')));
+ $this->assertEquals(2.75, $d->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 17:45:00')));
+ $this->assertEquals(3, $d->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 17:58:00')));
+ $this->assertEquals(3, $d->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 11:58:00')));
+ }
+
public function testValidDate()
{
- $d = new DateParser($this->registry);
+ $d = new DateParser($this->container);
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('2014-03-05', 'Y-m-d')));
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('2014_03_05', 'Y_m_d')));
@@ -23,10 +51,28 @@ class DateParserTest extends Base
public function testGetTimestamp()
{
- $d = new DateParser($this->registry);
+ $d = new DateParser($this->container);
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('2014-03-05')));
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('2014_03_05')));
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('03/05/2014')));
}
+
+ public function testConvert()
+ {
+ $d = new DateParser($this->container);
+
+ $values = array(
+ 'date_due' => '2015-01-25',
+ 'date_started' => '2015_01_25',
+ );
+
+ $d->convert($values, array('date_due', 'date_started'));
+
+ $this->assertEquals(mktime(0, 0, 0, 1, 25, 2015), $values['date_due']);
+ $this->assertEquals('2015-01-25', date('Y-m-d', $values['date_due']));
+
+ $this->assertEquals(mktime(0, 0, 0, 1, 25, 2015), $values['date_started']);
+ $this->assertEquals('2015-01-25', date('Y-m-d', $values['date_started']));
+ }
}
diff --git a/tests/units/DatetimeHelperTest.php b/tests/units/DatetimeHelperTest.php
new file mode 100644
index 00000000..2746beed
--- /dev/null
+++ b/tests/units/DatetimeHelperTest.php
@@ -0,0 +1,44 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Helper\Datetime;
+
+class DatetimeHelperTest extends Base
+{
+ public function testGetDayHours()
+ {
+ $h = new Datetime($this->container);
+
+ $slots = $h->getDayHours();
+
+ $this->assertNotEmpty($slots);
+ $this->assertCount(48, $slots);
+ $this->assertArrayHasKey('00:00', $slots);
+ $this->assertArrayHasKey('00:30', $slots);
+ $this->assertArrayHasKey('01:00', $slots);
+ $this->assertArrayHasKey('01:30', $slots);
+ $this->assertArrayHasKey('23:30', $slots);
+ $this->assertArrayNotHasKey('24:00', $slots);
+ }
+
+ public function testGetWeekDays()
+ {
+ $h = new Datetime($this->container);
+
+ $slots = $h->getWeekDays();
+
+ $this->assertNotEmpty($slots);
+ $this->assertCount(7, $slots);
+ $this->assertContains('Monday', $slots);
+ $this->assertContains('Sunday', $slots);
+ }
+
+ public function testGetWeekDay()
+ {
+ $h = new Datetime($this->container);
+
+ $this->assertEquals('Monday', $h->getWeekDay(1));
+ $this->assertEquals('Sunday', $h->getWeekDay(7));
+ }
+}
diff --git a/tests/units/FileHelperText.php b/tests/units/FileHelperText.php
new file mode 100644
index 00000000..ce04fdbd
--- /dev/null
+++ b/tests/units/FileHelperText.php
@@ -0,0 +1,15 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Helper\File;
+
+class FileHelperTest extends Base
+{
+ public function testIcon()
+ {
+ $h = new File($this->container);
+ $this->assertEquals('fa-file-image-o', $h->icon('test.png'));
+ $this->assertEquals('fa-file-o', $h->icon('test'));
+ }
+}
diff --git a/tests/units/FileTest.php b/tests/units/FileTest.php
new file mode 100644
index 00000000..5e882fdb
--- /dev/null
+++ b/tests/units/FileTest.php
@@ -0,0 +1,31 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Task;
+use Model\File;
+use Model\TaskCreation;
+use Model\Project;
+
+class FileTest extends Base
+{
+ public function testCreationFileNameTooLong()
+ {
+ $p = new Project($this->container);
+ $f = new File($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->assertTrue($f->create(1, 'test', '/tmp/foo', false, 10));
+ $this->assertTrue($f->create(1, str_repeat('a', 1000), '/tmp/foo', false, 10));
+
+ $files = $f->getAll(1);
+ $this->assertNotEmpty($files);
+ $this->assertCount(2, $files);
+
+ $this->assertEquals(str_repeat('a', 255), $files[0]['name']);
+ $this->assertEquals('test', $files[1]['name']);
+ }
+}
diff --git a/tests/units/GitlabWebhookTest.php b/tests/units/GitlabWebhookTest.php
new file mode 100644
index 00000000..cea4e839
--- /dev/null
+++ b/tests/units/GitlabWebhookTest.php
@@ -0,0 +1,119 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Integration\GitlabWebhook;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\Project;
+
+class GitlabWebhookTest extends Base
+{
+ private $push_payload = '{"before":"9187f41ba34a2b40d41c50ed4b624ce374c5e583","after":"b3caaee62ad27dc31497946065ac18299784aee4","ref":"refs/heads/master","user_id":74067,"user_name":"Fred","project_id":124474,"repository":{"name":"kanboard","url":"git@gitlab.com:minicoders/kanboard.git","description":"Test repo","homepage":"https://gitlab.com/minicoders/kanboard"},"commits":[{"id":"b3caaee62ad27dc31497946065ac18299784aee4","message":"Fix bug #2\n","timestamp":"2014-12-28T20:31:48-05:00","url":"https://gitlab.com/minicoders/kanboard/commit/b3caaee62ad27dc31497946065ac18299784aee4","author":{"name":"Frédéric Guillot","email":"git@localhost"}}],"total_commits_count":1}';
+ private $issue_open_payload = '{"object_kind":"issue","user":{"name":"Fred","username":"minicoders","avatar_url":"https://secure.gravatar.com/avatar/3c44936e5a56f80711bff14987d2733f?s=40\u0026d=identicon"},"object_attributes":{"id":103356,"title":"Test Webhook","assignee_id":null,"author_id":74067,"project_id":124474,"created_at":"2014-12-29 01:24:24 UTC","updated_at":"2014-12-29 01:24:24 UTC","position":0,"branch_name":null,"description":"- test1\r\n- test2","milestone_id":null,"state":"opened","iid":1,"url":"https://gitlab.com/minicoders/kanboard/issues/1","action":"open"}}';
+ private $issue_closed_payload = '{"object_kind":"issue","user":{"name":"Fred","username":"minicoders","avatar_url":"https://secure.gravatar.com/avatar/3c44936e5a56f80711bff14987d2733f?s=40\u0026d=identicon"},"object_attributes":{"id":103361,"title":"uu","assignee_id":null,"author_id":74067,"project_id":124474,"created_at":"2014-12-29 01:28:44 UTC","updated_at":"2014-12-29 01:34:47 UTC","position":0,"branch_name":null,"description":"","milestone_id":null,"state":"closed","iid":4,"url":"https://gitlab.com/minicoders/kanboard/issues/4","action":"update"}}';
+
+ public function testGetEventType()
+ {
+ $g = new GitlabWebhook($this->container);
+
+ $this->assertEquals(GitlabWebhook::TYPE_PUSH, $g->getType(json_decode($this->push_payload, true)));
+ $this->assertEquals(GitlabWebhook::TYPE_ISSUE, $g->getType(json_decode($this->issue_open_payload, true)));
+ $this->assertEquals(GitlabWebhook::TYPE_ISSUE, $g->getType(json_decode($this->issue_closed_payload, true)));
+ $this->assertEquals('', $g->getType(array()));
+ }
+
+ public function testHandleCommit()
+ {
+ $g = new GitlabWebhook($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $g->setProjectId(1);
+
+ $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_COMMIT, function() {});
+
+ $event = json_decode($this->push_payload, true);
+
+ // No task
+ $this->assertFalse($g->handleCommit($event['commits'][0]));
+
+ // Create task with the wrong id
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertFalse($g->handleCommit($event['commits'][0]));
+
+ // Create task with the right id
+ $this->assertEquals(2, $tc->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($g->handleCommit($event['commits'][0]));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(GitlabWebhook::EVENT_COMMIT.'.closure', $called);
+ }
+
+ public function testHandleIssueOpened()
+ {
+ $g = new GitlabWebhook($this->container);
+ $g->setProjectId(1);
+
+ $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_OPENED, array($this, 'onOpen'));
+
+ $event = json_decode($this->issue_open_payload, true);
+ $this->assertTrue($g->handleIssueOpened($event['object_attributes']));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(GitlabWebhook::EVENT_ISSUE_OPENED.'.GitlabWebhookTest::onOpen', $called);
+ }
+
+ public function testHandleIssueClosed()
+ {
+ $g = new GitlabWebhook($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $g->setProjectId(1);
+
+ $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_CLOSED, array($this, 'onClose'));
+
+ $event = json_decode($this->issue_closed_payload, true);
+
+ // Issue not there
+ $this->assertFalse($g->handleIssueClosed($event['object_attributes']));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+
+ // Create a task with the issue reference
+ $this->assertEquals(1, $tc->create(array('title' => 'A', 'project_id' => 1, 'reference' => 103361)));
+ $task = $tf->getByReference(1, 103361);
+ $this->assertNotEmpty($task);
+
+ $task = $tf->getByReference(2, 103361);
+ $this->assertEmpty($task);
+
+ $this->assertTrue($g->handleIssueClosed($event['object_attributes']));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(GitlabWebhook::EVENT_ISSUE_CLOSED.'.GitlabWebhookTest::onClose', $called);
+ }
+
+ public function onOpen($event)
+ {
+ $data = $event->getAll();
+ $this->assertEquals(1, $data['project_id']);
+ $this->assertEquals(103356, $data['reference']);
+ $this->assertEquals('Test Webhook', $data['title']);
+ $this->assertEquals("- test1\r\n- test2\n\n[Gitlab Issue](https://gitlab.com/minicoders/kanboard/issues/1)", $data['description']);
+ }
+
+ public function onClose($event)
+ {
+ $data = $event->getAll();
+ $this->assertEquals(1, $data['project_id']);
+ $this->assertEquals(1, $data['task_id']);
+ $this->assertEquals(103361, $data['reference']);
+ }
+}
diff --git a/tests/units/HourlyRate.php b/tests/units/HourlyRate.php
new file mode 100644
index 00000000..5daf0446
--- /dev/null
+++ b/tests/units/HourlyRate.php
@@ -0,0 +1,43 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\User;
+use Model\HourlyRate;
+
+class HourlyRateTest extends Base
+{
+ public function testCreation()
+ {
+ $hr = new HourlyRate($this->container);
+ $this->assertEquals(1, $hr->create(1, 32.4, 'EUR', '2015-01-01'));
+ $this->assertEquals(2, $hr->create(1, 42, 'CAD', '2015-02-01'));
+
+ $rates = $hr->getAllByUser(0);
+ $this->assertEmpty($rates);
+
+ $rates = $hr->getAllByUser(1);
+ $this->assertNotEmpty($rates);
+ $this->assertCount(2, $rates);
+
+ $this->assertEquals(42, $rates[0]['rate']);
+ $this->assertEquals('CAD', $rates[0]['currency']);
+ $this->assertEquals('2015-02-01', date('Y-m-d', $rates[0]['date_effective']));
+
+ $this->assertEquals(32.4, $rates[1]['rate']);
+ $this->assertEquals('EUR', $rates[1]['currency']);
+ $this->assertEquals('2015-01-01', date('Y-m-d', $rates[1]['date_effective']));
+
+ $this->assertEquals(0, $hr->getCurrentRate(0));
+ $this->assertEquals(42, $hr->getCurrentRate(1));
+
+ $this->assertTrue($hr->remove(2));
+ $this->assertEquals(32.4, $hr->getCurrentRate(1));
+
+ $this->assertTrue($hr->remove(1));
+ $this->assertEquals(0, $hr->getCurrentRate(1));
+
+ $rates = $hr->getAllByUser(1);
+ $this->assertEmpty($rates);
+ }
+}
diff --git a/tests/units/LinkTest.php b/tests/units/LinkTest.php
new file mode 100644
index 00000000..45e9796c
--- /dev/null
+++ b/tests/units/LinkTest.php
@@ -0,0 +1,173 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Link;
+
+class LinkTest extends Base
+{
+ public function testCreateLink()
+ {
+ $l = new Link($this->container);
+
+ $this->assertNotFalse($l->create('Link A'));
+ $this->assertFalse($l->create('Link A'));
+ $this->assertNotFalse($l->create('Link B', 'Link C'));
+
+ $links = $l->getAll();
+ $this->assertNotEmpty($links);
+ $this->assertCount(14, $links);
+
+ $link = $l->getByLabel('Link A');
+ $this->assertNotEmpty($link);
+ $this->assertEquals('Link A', $link['label']);
+ $this->assertEquals(0, $link['opposite_id']);
+
+ $link1 = $l->getByLabel('Link B');
+ $this->assertNotEmpty($link1);
+ $this->assertEquals('Link B', $link1['label']);
+ $this->assertNotEmpty($link1['opposite_id']);
+
+ $link2 = $l->getByLabel('Link C');
+ $this->assertNotEmpty($link2);
+ $this->assertEquals('Link C', $link2['label']);
+ $this->assertNotEmpty($link2['opposite_id']);
+
+ $this->assertNotEquals($link1['opposite_id'], $link2['opposite_id']);
+ }
+
+ public function testGetOppositeLinkId()
+ {
+ $l = new Link($this->container);
+
+ $this->assertNotFalse($l->create('Link A'));
+ $this->assertNotFalse($l->create('Link B', 'Link C'));
+
+ $this->assertEquals(1, $l->getOppositeLinkId(1));
+ $this->assertEquals(3, $l->getOppositeLinkId(2));
+ $this->assertEquals(2, $l->getOppositeLinkId(3));
+ }
+
+ public function testUpdate()
+ {
+ $l = new Link($this->container);
+
+ $this->assertTrue($l->update(array('id' => 2, 'label' => 'test', 'opposite_id' => 0)));
+
+ $link = $l->getById(2);
+ $this->assertNotEmpty($link);
+ $this->assertEquals('test', $link['label']);
+ $this->assertEquals(0, $link['opposite_id']);
+ }
+
+ public function testRemove()
+ {
+ $l = new Link($this->container);
+
+ $link = $l->getById(3);
+ $this->assertNotEmpty($link);
+ $this->assertEquals('is blocked by', $link['label']);
+ $this->assertEquals(2, $link['opposite_id']);
+
+ $this->assertTrue($l->remove(2));
+
+ $link = $l->getById(2);
+ $this->assertEmpty($link);
+
+ $link = $l->getById(3);
+ $this->assertNotEmpty($link);
+ $this->assertEquals('is blocked by', $link['label']);
+ $this->assertEquals(0, $link['opposite_id']);
+ }
+
+ public function testGetMergedList()
+ {
+ $l = new Link($this->container);
+ $links = $l->getMergedList();
+
+ $this->assertNotEmpty($links);
+ $this->assertCount(11, $links);
+ $this->assertEquals('blocks', $links[1]['label']);
+ $this->assertEquals('is blocked by', $links[1]['opposite_label']);
+ }
+
+ public function testGetList()
+ {
+ $l = new Link($this->container);
+ $links = $l->getList();
+
+ $this->assertNotEmpty($links);
+ $this->assertCount(12, $links);
+ $this->assertEquals('', $links[0]);
+ $this->assertEquals('relates to', $links[1]);
+
+ $links = $l->getList(1);
+
+ $this->assertNotEmpty($links);
+ $this->assertCount(11, $links);
+ $this->assertEquals('', $links[0]);
+ $this->assertArrayNotHasKey(1, $links);
+ $this->assertEquals('blocks', $links[2]);
+
+ $links = $l->getList(1, false);
+
+ $this->assertNotEmpty($links);
+ $this->assertCount(10, $links);
+ $this->assertArrayNotHasKey(0, $links);
+ $this->assertArrayNotHasKey(1, $links);
+ $this->assertEquals('blocks', $links[2]);
+
+ $links = $l->getList(0, false);
+
+ $this->assertNotEmpty($links);
+ $this->assertCount(11, $links);
+ $this->assertArrayNotHasKey(0, $links);
+ $this->assertEquals('relates to', $links[1]);
+ }
+
+ public function testValidateCreation()
+ {
+ $l = new Link($this->container);
+
+ $r = $l->validateCreation(array('label' => 'a'));
+ $this->assertTrue($r[0]);
+
+ $r = $l->validateCreation(array('label' => 'a', 'opposite_label' => 'b'));
+ $this->assertTrue($r[0]);
+
+ $r = $l->validateCreation(array('label' => 'relates to'));
+ $this->assertFalse($r[0]);
+
+ $r = $l->validateCreation(array('label' => 'a', 'opposite_label' => 'a'));
+ $this->assertFalse($r[0]);
+
+ $r = $l->validateCreation(array('label' => ''));
+ $this->assertFalse($r[0]);
+ }
+
+ public function testValidateModification()
+ {
+ $l = new Link($this->container);
+
+ $r = $l->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => 0));
+ $this->assertTrue($r[0]);
+
+ $r = $l->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => '1'));
+ $this->assertTrue($r[0]);
+
+ $r = $l->validateModification(array('id' => 20, 'label' => 'relates to', 'opposite_id' => '1'));
+ $this->assertFalse($r[0]);
+
+ $r = $l->validateModification(array('id' => 20, 'label' => '', 'opposite_id' => '1'));
+ $this->assertFalse($r[0]);
+
+ $r = $l->validateModification(array('label' => '', 'opposite_id' => '1'));
+ $this->assertFalse($r[0]);
+
+ $r = $l->validateModification(array('id' => 20, 'opposite_id' => '1'));
+ $this->assertFalse($r[0]);
+
+ $r = $l->validateModification(array('label' => 'test'));
+ $this->assertFalse($r[0]);
+ }
+}
diff --git a/tests/units/MailgunTest.php b/tests/units/MailgunTest.php
new file mode 100644
index 00000000..b33a66fe
--- /dev/null
+++ b/tests/units/MailgunTest.php
@@ -0,0 +1,71 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Integration\Mailgun;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\Project;
+use Model\ProjectPermission;
+use Model\User;
+
+class MailgunTest extends Base
+{
+ public function testSendEmail()
+ {
+ $pm = new Mailgun($this->container);
+ $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob');
+
+ $this->assertStringStartsWith('https://api.mailgun.net/v3/', $this->container['httpClient']->getUrl());
+
+ $data = $this->container['httpClient']->getData();
+
+ $this->assertArrayHasKey('from', $data);
+ $this->assertArrayHasKey('to', $data);
+ $this->assertArrayHasKey('subject', $data);
+ $this->assertArrayHasKey('html', $data);
+
+ $this->assertEquals('Me <test@localhost>', $data['to']);
+ $this->assertEquals('Bob <notifications@kanboard.local>', $data['from']);
+ $this->assertEquals('Test', $data['subject']);
+ $this->assertEquals('Content', $data['html']);
+ }
+
+ public function testHandlePayload()
+ {
+ $w = new Mailgun($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $u = new User($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost')));
+
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
+
+ // Empty payload
+ $this->assertFalse($w->receiveEmail(array()));
+
+ // Unknown user
+ $this->assertFalse($w->receiveEmail(array('sender' => 'a@b.c', 'subject' => 'Email task', 'recipient' => 'foobar', 'stripped-text' => 'boo')));
+
+ // Project not found
+ $this->assertFalse($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test@localhost', 'stripped-text' => 'boo')));
+
+ // User is not member
+ $this->assertFalse($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo')));
+ $this->assertTrue($pp->addMember(2, 2));
+
+ // The task must be created
+ $this->assertTrue($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo')));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('Email task', $task['title']);
+ $this->assertEquals('boo', $task['description']);
+ $this->assertEquals(2, $task['creator_id']);
+ }
+}
diff --git a/tests/units/NotificationTest.php b/tests/units/NotificationTest.php
index de0ea9d9..5a7a782c 100644
--- a/tests/units/NotificationTest.php
+++ b/tests/units/NotificationTest.php
@@ -2,46 +2,200 @@
require_once __DIR__.'/Base.php';
+use Model\TaskFinder;
+use Model\TaskCreation;
+use Model\Subtask;
+use Model\Comment;
use Model\User;
+use Model\File;
use Model\Project;
use Model\ProjectPermission;
use Model\Notification;
+use Subscriber\NotificationSubscriber;
class NotificationTest extends Base
{
- public function testGetUsersWithNotification()
+ public function testFilterNone()
{
- $u = new User($this->registry);
- $p = new Project($this->registry);
- $n = new Notification($this->registry);
- $pp = new ProjectPermission($this->registry);
+ $u = new User($this->container);
+ $n = new Notification($this->container);
+
+ $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => Notification::FILTER_NONE)));
+ $this->assertTrue($n->filterNone($u->getById(2), array()));
+
+ $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_BOTH)));
+ $this->assertFalse($n->filterNone($u->getById(3), array()));
+ }
+
+ public function testFilterCreator()
+ {
+ $u = new User($this->container);
+ $n = new Notification($this->container);
+
+ $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => Notification::FILTER_CREATOR)));
+ $this->assertTrue($n->filterCreator($u->getById(2), array('task' => array('creator_id' => 2))));
+
+ $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_CREATOR)));
+ $this->assertFalse($n->filterCreator($u->getById(3), array('task' => array('creator_id' => 1))));
+
+ $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => Notification::FILTER_NONE)));
+ $this->assertFalse($n->filterCreator($u->getById(4), array('task' => array('creator_id' => 2))));
+ }
+
+ public function testFilterAssignee()
+ {
+ $u = new User($this->container);
+ $n = new Notification($this->container);
+
+ $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => Notification::FILTER_ASSIGNEE)));
+ $this->assertTrue($n->filterAssignee($u->getById(2), array('task' => array('owner_id' => 2))));
+
+ $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_ASSIGNEE)));
+ $this->assertFalse($n->filterAssignee($u->getById(3), array('task' => array('owner_id' => 1))));
+
+ $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => Notification::FILTER_NONE)));
+ $this->assertFalse($n->filterAssignee($u->getById(4), array('task' => array('owner_id' => 2))));
+ }
+
+ public function testFilterBoth()
+ {
+ $u = new User($this->container);
+ $n = new Notification($this->container);
+
+ $this->assertEquals(2, $u->create(array('username' => 'user1', 'notifications_filter' => Notification::FILTER_BOTH)));
+ $this->assertTrue($n->filterBoth($u->getById(2), array('task' => array('owner_id' => 2, 'creator_id' => 1))));
+ $this->assertTrue($n->filterBoth($u->getById(2), array('task' => array('owner_id' => 0, 'creator_id' => 2))));
+
+ $this->assertEquals(3, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_BOTH)));
+ $this->assertFalse($n->filterBoth($u->getById(3), array('task' => array('owner_id' => 1, 'creator_id' => 1))));
+ $this->assertFalse($n->filterBoth($u->getById(3), array('task' => array('owner_id' => 2, 'creator_id' => 1))));
+
+ $this->assertEquals(4, $u->create(array('username' => 'user3', 'notifications_filter' => Notification::FILTER_NONE)));
+ $this->assertFalse($n->filterBoth($u->getById(4), array('task' => array('owner_id' => 2, 'creator_id' => 1))));
+ }
+
+ public function testFilterProject()
+ {
+ $u = new User($this->container);
+ $n = new Notification($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
+ $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+
+ // No project selected
+ $this->assertTrue($n->filterProject($u->getById(1), array()));
+
+ // User that select only some projects
+ $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_NONE)));
+ $n->saveSettings(2, array('notifications_enabled' => 1, 'projects' => array(2 => true)));
+
+ $this->assertFalse($n->filterProject($u->getById(2), array('task' => array('project_id' => 1))));
+ $this->assertTrue($n->filterProject($u->getById(2), array('task' => array('project_id' => 2))));
+ }
+
+ public function testFilterUserWithNoFilter()
+ {
+ $u = new User($this->container);
+ $n = new Notification($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_NONE)));
+
+ $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1))));
+ }
+
+ public function testFilterUserWithAssigneeFilter()
+ {
+ $u = new User($this->container);
+ $n = new Notification($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_ASSIGNEE)));
+
+ $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'owner_id' => 2))));
+ $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'owner_id' => 1))));
+ }
+
+ public function testFilterUserWithCreatorFilter()
+ {
+ $u = new User($this->container);
+ $n = new Notification($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_CREATOR)));
+
+ $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2))));
+ $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 1))));
+ }
+
+ public function testFilterUserWithBothFilter()
+ {
+ $u = new User($this->container);
+ $n = new Notification($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_BOTH)));
+
+ $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2, 'owner_id' => 3))));
+ $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 0, 'owner_id' => 2))));
+ $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 4, 'owner_id' => 1))));
+ $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 5, 'owner_id' => 0))));
+ }
+
+ public function testFilterUserWithBothFilterAndProjectSelected()
+ {
+ $u = new User($this->container);
+ $n = new Notification($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
+ $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+
+ $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => Notification::FILTER_BOTH)));
+
+ $n->saveSettings(2, array('notifications_enabled' => 1, 'projects' => array(2 => true)));
+
+ $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2, 'owner_id' => 3))));
+ $this->assertFalse($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 0, 'owner_id' => 2))));
+
+ $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 2, 'owner_id' => 3))));
+ $this->assertTrue($n->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 0, 'owner_id' => 2))));
+ }
+
+ public function testGetProjectMembersWithNotifications()
+ {
+ $u = new User($this->container);
+ $p = new Project($this->container);
+ $n = new Notification($this->container);
+ $pp = new ProjectPermission($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
// Email + Notifications enabled
- $this->assertTrue($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
+ $this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
// No email + Notifications enabled
- $this->assertTrue($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
+ $this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
// Email + Notifications enabled
- $this->assertTrue($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
+ $this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
// No email + notifications disabled
- $this->assertTrue($u->create(array('username' => 'user4')));
+ $this->assertNotFalse($u->create(array('username' => 'user4')));
// Nobody is member of any projects
- $this->assertEmpty($pp->getAllowedUsers(1));
- $this->assertEmpty($n->getUsersWithNotification(1));
+ $this->assertEmpty($pp->getMembers(1));
+ $this->assertEmpty($n->getUsersWithNotificationEnabled(1));
// We allow all users to be member of our projects
- $this->assertTrue($pp->allowUser(1, 1));
- $this->assertTrue($pp->allowUser(1, 2));
- $this->assertTrue($pp->allowUser(1, 3));
- $this->assertTrue($pp->allowUser(1, 4));
+ $this->assertTrue($pp->addMember(1, 1));
+ $this->assertTrue($pp->addMember(1, 2));
+ $this->assertTrue($pp->addMember(1, 3));
+ $this->assertTrue($pp->addMember(1, 4));
- $this->assertNotEmpty($pp->getAllowedUsers(1));
- $users = $n->getUsersWithNotification(1);
+ $this->assertNotEmpty($pp->getMembers(1));
+ $users = $n->getUsersWithNotificationEnabled(1);
$this->assertNotEmpty($users);
$this->assertEquals(2, count($users));
@@ -49,72 +203,130 @@ class NotificationTest extends Base
$this->assertEquals('user3@here', $users[1]['email']);
}
- public function testGetUserList()
+ public function testGetUsersWithNotificationsWhenEverybodyAllowed()
{
- $u = new User($this->registry);
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
- $n = new Notification($this->registry);
+ $u = new User($this->container);
+ $p = new Project($this->container);
+ $n = new Notification($this->container);
+ $pp = new ProjectPermission($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
- $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'is_everybody_allowed' => 1)));
+ $this->assertTrue($pp->isEverybodyAllowed(1));
// Email + Notifications enabled
- $this->assertTrue($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
+ $this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
// No email + Notifications enabled
- $this->assertTrue($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
+ $this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
// Email + Notifications enabled
- $this->assertTrue($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
+ $this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
// No email + notifications disabled
- $this->assertTrue($u->create(array('username' => 'user4')));
-
- // We allow all users to be member of our projects
- $this->assertTrue($pp->allowUser(1, 1));
- $this->assertTrue($pp->allowUser(1, 2));
- $this->assertTrue($pp->allowUser(1, 3));
- $this->assertTrue($pp->allowUser(1, 4));
+ $this->assertNotFalse($u->create(array('username' => 'user4')));
- $this->assertTrue($pp->allowUser(2, 1));
- $this->assertTrue($pp->allowUser(2, 2));
- $this->assertTrue($pp->allowUser(2, 3));
- $this->assertTrue($pp->allowUser(2, 4));
+ $users = $n->getUsersWithNotificationEnabled(1);
- $users = $n->getUsersList(1);
$this->assertNotEmpty($users);
$this->assertEquals(2, count($users));
$this->assertEquals('user1@here', $users[0]['email']);
$this->assertEquals('user3@here', $users[1]['email']);
+ }
- $users = $n->getUsersList(2);
- $this->assertNotEmpty($users);
- $this->assertEquals(2, count($users));
- $this->assertEquals('user1@here', $users[0]['email']);
- $this->assertEquals('user3@here', $users[1]['email']);
+ public function testGetMailContent()
+ {
+ $n = new Notification($this->container);
+ $p = new Project($this->container);
+ $tf = new TaskFinder($this->container);
+ $tc = new TaskCreation($this->container);
+ $s = new Subtask($this->container);
+ $c = new Comment($this->container);
+ $f = new File($this->container);
- // User 3 choose to receive notification only for project 2
- $n->saveSettings(4, array('notifications_enabled' => 1, 'projects' => array(2 => true)));
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1)));
+ $this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
+ $this->assertEquals(1, $f->create(1, 'test', 'blah', false, 123));
- $users = $n->getUsersList(1);
- $this->assertNotEmpty($users);
- $this->assertEquals(1, count($users));
- $this->assertEquals('user1@here', $users[0]['email']);
+ $task = $tf->getDetails(1);
+ $subtask = $s->getById(1, true);
+ $comment = $c->getById(1);
+ $file = $c->getById(1);
- $users = $n->getUsersList(2);
- $this->assertNotEmpty($users);
- $this->assertEquals(2, count($users));
- $this->assertEquals('user1@here', $users[0]['email']);
- $this->assertEquals('user3@here', $users[1]['email']);
+ $this->assertNotEmpty($task);
+ $this->assertNotEmpty($subtask);
+ $this->assertNotEmpty($comment);
+ $this->assertNotEmpty($file);
- // User 1 excluded
- $users = $n->getUsersList(1, array(2));
- $this->assertEmpty($users);
+ foreach (Subscriber\NotificationSubscriber::getSubscribedEvents() as $event => $values) {
+ $this->assertNotEmpty($n->getMailContent($event, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file)));
+ }
+ }
- $users = $n->getUsersList(2, array(2));
- $this->assertNotEmpty($users);
- $this->assertEquals(1, count($users));
- $this->assertEquals('user3@here', $users[0]['email']);
+ public function testGetEmailSubject()
+ {
+ $n = new Notification($this->container);
+
+ $this->assertEquals(
+ '[test][Task opened] blah (#2)',
+ $n->getMailSubject('task.open', array('task' => array('id' => 2, 'title' => 'blah', 'project_name' => 'test')))
+ );
+ }
+
+ public function testSendNotificationsToCreator()
+ {
+ $u = new User($this->container);
+ $p = new Project($this->container);
+ $n = new Notification($this->container);
+ $pp = new ProjectPermission($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
+ $this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
+ $this->assertTrue($pp->addMember(1, 2));
+
+ $n->sendNotifications('task.open', array('task' => array(
+ 'id' => 2, 'title' => 'blah', 'project_name' => 'test', 'project_id' => 1, 'owner_id' => 0, 'creator_id' => 2
+ )));
+
+ $this->assertEquals('user1@here', $this->container['emailClient']->email);
+ $this->assertEquals('user1', $this->container['emailClient']->name);
+ $this->assertEquals('[test][Task opened] blah (#2)', $this->container['emailClient']->subject);
+ $this->assertNotEmpty($this->container['emailClient']->html);
+ }
+
+ public function testSendNotificationsToAnotherAssignee()
+ {
+ $u = new User($this->container);
+ $p = new Project($this->container);
+ $n = new Notification($this->container);
+ $pp = new ProjectPermission($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
+ $this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
+ $this->assertTrue($pp->addMember(1, 2));
+
+ $n->sendNotifications('task.open', array('task' => array(
+ 'id' => 2, 'title' => 'blah', 'project_name' => 'test', 'project_id' => 1, 'owner_id' => 1, 'creator_id' => 1
+ )));
+
+ $this->assertEmpty($this->container['emailClient']->email);
+ }
+
+ public function testSendNotificationsToNotMember()
+ {
+ $u = new User($this->container);
+ $p = new Project($this->container);
+ $n = new Notification($this->container);
+ $pp = new ProjectPermission($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
+ $this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
+
+ $n->sendNotifications('task.open', array('task' => array(
+ 'id' => 2, 'title' => 'blah', 'project_name' => 'test', 'project_id' => 1, 'owner_id' => 0, 'creator_id' => 2
+ )));
+
+ $this->assertEmpty($this->container['emailClient']->email);
}
}
diff --git a/tests/units/PostmarkTest.php b/tests/units/PostmarkTest.php
new file mode 100644
index 00000000..b708217d
--- /dev/null
+++ b/tests/units/PostmarkTest.php
@@ -0,0 +1,106 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Integration\Postmark;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\Project;
+use Model\ProjectPermission;
+use Model\User;
+
+class PostmarkTest extends Base
+{
+ public function testSendEmail()
+ {
+ $pm = new Postmark($this->container);
+ $pm->sendEmail('test@localhost', 'Me', 'Test', 'Content', 'Bob');
+
+ $this->assertEquals('https://api.postmarkapp.com/email', $this->container['httpClient']->getUrl());
+
+ $data = $this->container['httpClient']->getData();
+
+ $this->assertArrayHasKey('From', $data);
+ $this->assertArrayHasKey('To', $data);
+ $this->assertArrayHasKey('Subject', $data);
+ $this->assertArrayHasKey('HtmlBody', $data);
+
+ $this->assertEquals('Me <test@localhost>', $data['To']);
+ $this->assertEquals('Bob <notifications@kanboard.local>', $data['From']);
+ $this->assertEquals('Test', $data['Subject']);
+ $this->assertEquals('Content', $data['HtmlBody']);
+
+ $this->assertContains('Accept: application/json', $this->container['httpClient']->getHeaders());
+ $this->assertContains('X-Postmark-Server-Token: ', $this->container['httpClient']->getHeaders());
+ }
+
+ public function testHandlePayload()
+ {
+ $w = new Postmark($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $u = new User($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost')));
+
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
+
+ // Empty payload
+ $this->assertFalse($w->receiveEmail(array()));
+
+ // Unknown user
+ $this->assertFalse($w->receiveEmail(array('From' => 'a@b.c', 'Subject' => 'Email task', 'MailboxHash' => 'foobar', 'TextBody' => 'boo')));
+
+ // Project not found
+ $this->assertFalse($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test', 'TextBody' => 'boo')));
+
+ // User is not member
+ $this->assertFalse($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo')));
+ $this->assertTrue($pp->addMember(2, 2));
+
+ // The task must be created
+ $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo')));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('Email task', $task['title']);
+ $this->assertEquals('boo', $task['description']);
+ $this->assertEquals(2, $task['creator_id']);
+ }
+
+ public function testHtml2Markdown()
+ {
+ $w = new Postmark($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $u = new User($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost')));
+ $this->assertEquals(1, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
+ $this->assertTrue($pp->addMember(1, 2));
+
+ $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo', 'HtmlBody' => '<p><strong>boo</strong></p>')));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals('Email task', $task['title']);
+ $this->assertEquals('**boo**', $task['description']);
+ $this->assertEquals(2, $task['creator_id']);
+
+ $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => '**boo**', 'HtmlBody' => '')));
+
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals('Email task', $task['title']);
+ $this->assertEquals('**boo**', $task['description']);
+ $this->assertEquals(2, $task['creator_id']);
+ }
+}
diff --git a/tests/units/ProjectActivityTest.php b/tests/units/ProjectActivityTest.php
index 7e7841dd..f0b27649 100644
--- a/tests/units/ProjectActivityTest.php
+++ b/tests/units/ProjectActivityTest.php
@@ -4,21 +4,33 @@ require_once __DIR__.'/Base.php';
use Model\Task;
use Model\TaskFinder;
+use Model\TaskCreation;
use Model\ProjectActivity;
use 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->registry);
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $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, $t->create(array('title' => 'Task #1', 'project_id' => 1)));
- $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 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->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))));
@@ -29,20 +41,20 @@ class ProjectActivityTest extends Base
$this->assertNotEmpty($events);
$this->assertTrue(is_array($events));
$this->assertEquals(2, count($events));
- $this->assertEquals(time(), $events[0]['date_creation']);
+ $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->registry);
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $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, $t->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
$nb_events = 80;
@@ -62,13 +74,13 @@ class ProjectActivityTest extends Base
public function testCleanup()
{
- $e = new ProjectActivity($this->registry);
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $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, $t->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
$max = 15;
$nb_events = 100;
@@ -77,7 +89,7 @@ class ProjectActivityTest extends Base
$this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
}
- $this->assertEquals($nb_events, $this->registry->shared('db')->table('project_activities')->count());
+ $this->assertEquals($nb_events, $this->container['db']->table('project_activities')->count());
$e->cleanup($max);
$events = $e->getProject(1);
@@ -97,6 +109,6 @@ class ProjectActivityTest extends Base
$this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1))));
}
- $this->assertEquals(ProjectActivity::MAX_EVENTS, $this->registry->shared('db')->table('project_activities')->count());
+ $this->assertEquals(ProjectActivity::MAX_EVENTS, $this->container['db']->table('project_activities')->count());
}
}
diff --git a/tests/units/ProjectDailySummary.php b/tests/units/ProjectDailySummary.php
new file mode 100644
index 00000000..9ae875fa
--- /dev/null
+++ b/tests/units/ProjectDailySummary.php
@@ -0,0 +1,84 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Project;
+use Model\ProjectDailySummary;
+use Model\Task;
+use Model\TaskCreation;
+
+class ProjectDailySummaryTest extends Base
+{
+ public function testUpdateTotals()
+ {
+ $p = new Project($this->container);
+ $pds = new ProjectDailySummary($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(0, $pds->countDays(1, date('Y-m-d', strtotime('-2days')), date('Y-m-d')));
+
+ for ($i = 0; $i < 10; $i++) {
+ $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 1)));
+ }
+
+ for ($i = 0; $i < 5; $i++) {
+ $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 4)));
+ }
+
+ $pds->updateTotals(1, date('Y-m-d', strtotime('-2days')));
+
+ for ($i = 0; $i < 15; $i++) {
+ $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 3)));
+ }
+
+ for ($i = 0; $i < 25; $i++) {
+ $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 2)));
+ }
+
+ $pds->updateTotals(1, date('Y-m-d', strtotime('-1 day')));
+
+ $this->assertNotFalse($t->close(1));
+ $this->assertNotFalse($t->close(2));
+
+ for ($i = 0; $i < 3; $i++) {
+ $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 3)));
+ }
+
+ for ($i = 0; $i < 5; $i++) {
+ $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 2)));
+ }
+
+ for ($i = 0; $i < 4; $i++) {
+ $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 4)));
+ }
+
+ $pds->updateTotals(1, date('Y-m-d'));
+
+ $this->assertEquals(3, $pds->countDays(3, date('Y-m-d', strtotime('-2days')), date('Y-m-d')));
+ $metrics = $pds->getAggregatedMetrics(1, date('Y-m-d', strtotime('-2days')), date('Y-m-d'));
+
+ $this->assertNotEmpty($metrics);
+ $this->assertEquals(4, count($metrics));
+ $this->assertEquals(5, count($metrics[0]));
+ $this->assertEquals('Backlog', $metrics[0][1]);
+
+ $this->assertEquals(date('Y-m-d', strtotime('-2days')), $metrics[1][0]);
+ $this->assertEquals(10, $metrics[1][1]);
+ $this->assertEquals(0, $metrics[1][2]);
+ $this->assertEquals(0, $metrics[1][3]);
+ $this->assertEquals(5, $metrics[1][4]);
+
+ $this->assertEquals(date('Y-m-d', strtotime('-1day')), $metrics[2][0]);
+ $this->assertEquals(10, $metrics[2][1]);
+ $this->assertEquals(25, $metrics[2][2]);
+ $this->assertEquals(15, $metrics[2][3]);
+ $this->assertEquals(5, $metrics[2][4]);
+
+ $this->assertEquals(date('Y-m-d'), $metrics[3][0]);
+ $this->assertEquals(8, $metrics[3][1]);
+ $this->assertEquals(30, $metrics[3][2]);
+ $this->assertEquals(18, $metrics[3][3]);
+ $this->assertEquals(9, $metrics[3][4]);
+ }
+}
diff --git a/tests/units/ProjectDuplicationTest.php b/tests/units/ProjectDuplicationTest.php
new file mode 100644
index 00000000..311ecc4a
--- /dev/null
+++ b/tests/units/ProjectDuplicationTest.php
@@ -0,0 +1,359 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Action;
+use Model\Project;
+use Model\Category;
+use Model\ProjectPermission;
+use Model\ProjectDuplication;
+use Model\User;
+use Model\Swimlane;
+use Model\Task;
+use Model\TaskCreation;
+use Model\TaskFinder;
+
+class ProjectDuplicationTest extends Base
+{
+ public function testProjectName()
+ {
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals('test (Clone)', $pd->getClonedProjectName('test'));
+
+ $this->assertEquals(50, strlen($pd->getClonedProjectName(str_repeat('a', 50))));
+ $this->assertEquals(str_repeat('a', 42).' (Clone)', $pd->getClonedProjectName(str_repeat('a', 50)));
+
+ $this->assertEquals(50, strlen($pd->getClonedProjectName(str_repeat('a', 60))));
+ $this->assertEquals(str_repeat('a', 42).' (Clone)', $pd->getClonedProjectName(str_repeat('a', 60)));
+ }
+
+ public function testCopyProjectWithLongName()
+ {
+ $p = new Project($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => str_repeat('a', 50))));
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $project = $p->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals(str_repeat('a', 42).' (Clone)', $project['name']);
+ }
+
+ public function testClonePublicProject()
+ {
+ $p = new Project($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'Public')));
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $project = $p->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Public (Clone)', $project['name']);
+ $this->assertEquals(0, $project['is_private']);
+ $this->assertEquals(0, $project['is_public']);
+ $this->assertEmpty($project['token']);
+ }
+
+ public function testClonePrivateProject()
+ {
+ $p = new Project($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'Private', 'is_private' => 1), 1, true));
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $project = $p->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Private (Clone)', $project['name']);
+ $this->assertEquals(1, $project['is_private']);
+ $this->assertEquals(0, $project['is_public']);
+ $this->assertEmpty($project['token']);
+
+ $pp = new ProjectPermission($this->container);
+
+ $this->assertEquals(array(1 => 'admin'), $pp->getMembers(1));
+ $this->assertEquals(array(1 => 'admin'), $pp->getMembers(2));
+ }
+
+ public function testCloneProjectWithCategories()
+ {
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
+ $this->assertEquals(3, $c->create(array('name' => 'C3', 'project_id' => 1)));
+
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $project = $p->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('P1 (Clone)', $project['name']);
+
+ $categories = $c->getAll(2);
+ $this->assertNotempty($categories);
+ $this->assertEquals(3, count($categories));
+
+ $this->assertEquals(4, $categories[0]['id']);
+ $this->assertEquals('C1', $categories[0]['name']);
+
+ $this->assertEquals(5, $categories[1]['id']);
+ $this->assertEquals('C2', $categories[1]['name']);
+
+ $this->assertEquals(6, $categories[2]['id']);
+ $this->assertEquals('C3', $categories[2]['name']);
+ }
+
+ public function testCloneProjectWithUsers()
+ {
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+ $pp = new ProjectPermission($this->container);
+ $u = new User($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(2, $u->create(array('username' => 'unittest1', 'password' => 'unittest')));
+ $this->assertEquals(3, $u->create(array('username' => 'unittest2', 'password' => 'unittest')));
+ $this->assertEquals(4, $u->create(array('username' => 'unittest3', 'password' => 'unittest')));
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+ $this->assertTrue($pp->addMember(1, 2));
+ $this->assertTrue($pp->addMember(1, 4));
+ $this->assertTrue($pp->addManager(1, 3));
+ $this->assertTrue($pp->isMember(1, 2));
+ $this->assertTrue($pp->isMember(1, 3));
+ $this->assertTrue($pp->isMember(1, 4));
+ $this->assertFalse($pp->isManager(1, 2));
+ $this->assertTrue($pp->isManager(1, 3));
+ $this->assertFalse($pp->isManager(1, 4));
+
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $project = $p->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('P1 (Clone)', $project['name']);
+
+ $this->assertEquals(3, count($pp->getMembers(2)));
+ $this->assertTrue($pp->isMember(2, 2));
+ $this->assertTrue($pp->isMember(2, 3));
+ $this->assertTrue($pp->isMember(2, 4));
+ $this->assertFalse($pp->isManager(2, 2));
+ $this->assertTrue($pp->isManager(2, 3));
+ $this->assertFalse($pp->isManager(2, 4));
+ }
+
+ public function testCloneProjectWithActionTaskAssignCurrentUser()
+ {
+ $p = new Project($this->container);
+ $a = new Action($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $a->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => 'TaskAssignCurrentUser',
+ 'params' => array('column_id' => 2),
+ )));
+
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $actions = $a->getAllByProject(2);
+
+ $this->assertNotEmpty($actions);
+ $this->assertEquals('TaskAssignCurrentUser', $actions[0]['action_name']);
+ $this->assertNotEmpty($actions[0]['params']);
+ $this->assertEquals(6, $actions[0]['params'][0]['value']);
+ }
+
+ public function testCloneProjectWithActionTaskAssignColorCategory()
+ {
+ $p = new Project($this->container);
+ $a = new Action($this->container);
+ $c = new Category($this->container);
+ $pd = new ProjectDuplication($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
+ $this->assertEquals(3, $c->create(array('name' => 'C3', 'project_id' => 1)));
+
+ $this->assertEquals(1, $a->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE_UPDATE,
+ 'action_name' => 'TaskAssignColorCategory',
+ 'params' => array('color_id' => 'blue', 'category_id' => 2),
+ )));
+
+ $this->assertEquals(2, $pd->duplicate(1));
+
+ $actions = $a->getAllByProject(2);
+
+ $this->assertNotEmpty($actions);
+ $this->assertEquals('TaskAssignColorCategory', $actions[0]['action_name']);
+ $this->assertNotEmpty($actions[0]['params']);
+ $this->assertEquals('blue', $actions[0]['params'][0]['value']);
+ $this->assertEquals(5, $actions[0]['params'][1]['value']);
+ }
+
+ public function testCloneProjectWithSwimlanesAndTasks()
+ {
+ $p = new Project($this->container);
+ $pd = new ProjectDuplication($this->container);
+ $s = new Swimlane($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+
+ // create initial swimlanes
+ $this->assertEquals(1, $s->create(1, 'S1'));
+ $this->assertEquals(2, $s->create(1, 'S2'));
+ $this->assertEquals(3, $s->create(1, 'S3'));
+
+ $default_swimlane1 = $s->getDefault(1);
+ $default_swimlane1['default_swimlane'] = 'New Default';
+
+ $this->assertTrue($s->updateDefault($default_swimlane1));
+
+ //create initial tasks
+ $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+ $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+
+ $this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'swimlane', 'task')));
+ $project = $p->getByName('P1 (Clone)');
+ $this->assertNotFalse($project);
+ $project_id = $project['id'];
+
+ // Check if Swimlanes have been duplicated
+ $swimlanes = $s->getAll($project_id);
+
+ $this->assertCount(3, $swimlanes);
+ $this->assertEquals(4, $swimlanes[0]['id']);
+ $this->assertEquals('S1', $swimlanes[0]['name']);
+ $this->assertEquals(5, $swimlanes[1]['id']);
+ $this->assertEquals('S2', $swimlanes[1]['name']);
+ $this->assertEquals(6, $swimlanes[2]['id']);
+ $this->assertEquals('S3', $swimlanes[2]['name']);
+ $new_default = $s->getDefault($project_id);
+ $this->assertEquals('New Default', $new_default['default_swimlane']);
+
+ // Check if Tasks have been duplicated
+
+ $tasks = $tf->getAll($project_id);
+
+ $this->assertCount(3, $tasks);
+ // $this->assertEquals(4, $tasks[0]['id']);
+ $this->assertEquals('T1', $tasks[0]['title']);
+ // $this->assertEquals(5, $tasks[1]['id']);
+ $this->assertEquals('T2', $tasks[1]['title']);
+ // $this->assertEquals(6, $tasks[2]['id']);
+ $this->assertEquals('T3', $tasks[2]['title']);
+
+ $p->remove($project_id);
+
+ $this->assertFalse($p->exists($project_id));
+ $this->assertCount(0, $s->getAll($project_id));
+ $this->assertCount(0, $tf->getAll($project_id));
+ }
+
+ public function testCloneProjectWithSwimlanes()
+ {
+ $p = new Project($this->container);
+ $pd = new ProjectDuplication($this->container);
+ $s = new Swimlane($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+
+ // create initial swimlanes
+ $this->assertEquals(1, $s->create(1, 'S1'));
+ $this->assertEquals(2, $s->create(1, 'S2'));
+ $this->assertEquals(3, $s->create(1, 'S3'));
+
+ $default_swimlane1 = $s->getDefault(1);
+ $default_swimlane1['default_swimlane'] = 'New Default';
+
+ $this->assertTrue($s->updateDefault($default_swimlane1));
+
+ //create initial tasks
+ $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+ $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+
+ $this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'swimlane')));
+ $project = $p->getByName('P1 (Clone)');
+ $this->assertNotFalse($project);
+ $project_id = $project['id'];
+
+ $swimlanes = $s->getAll($project_id);
+
+ $this->assertCount(3, $swimlanes);
+ $this->assertEquals(4, $swimlanes[0]['id']);
+ $this->assertEquals('S1', $swimlanes[0]['name']);
+ $this->assertEquals(5, $swimlanes[1]['id']);
+ $this->assertEquals('S2', $swimlanes[1]['name']);
+ $this->assertEquals(6, $swimlanes[2]['id']);
+ $this->assertEquals('S3', $swimlanes[2]['name']);
+ $new_default = $s->getDefault($project_id);
+ $this->assertEquals('New Default', $new_default['default_swimlane']);
+
+ // Check if Tasks have NOT been duplicated
+ $this->assertCount(0, $tf->getAll($project_id));
+ }
+
+ public function testCloneProjectWithTasks()
+ {
+ $p = new Project($this->container);
+ $pd = new ProjectDuplication($this->container);
+ $s = new Swimlane($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+
+ // create initial swimlanes
+ $this->assertEquals(1, $s->create(1, 'S1'));
+ $this->assertEquals(2, $s->create(1, 'S2'));
+ $this->assertEquals(3, $s->create(1, 'S3'));
+
+ $default_swimlane1 = $s->getDefault(1);
+ $default_swimlane1['default_swimlane'] = 'New Default';
+
+ $this->assertTrue($s->updateDefault($default_swimlane1));
+
+ //create initial tasks
+ $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+ $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+
+ $this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'task')));
+ $project = $p->getByName('P1 (Clone)');
+ $this->assertNotFalse($project);
+ $project_id = $project['id'];
+
+ // Check if Swimlanes have NOT been duplicated
+ $this->assertCount(0, $s->getAll($project_id));
+
+ // Check if Tasks have been duplicated
+ $tasks = $tf->getAll($project_id);
+
+ $this->assertCount(3, $tasks);
+ //$this->assertEquals(4, $tasks[0]['id']);
+ $this->assertEquals('T1', $tasks[0]['title']);
+ //$this->assertEquals(5, $tasks[1]['id']);
+ $this->assertEquals('T2', $tasks[1]['title']);
+ //$this->assertEquals(6, $tasks[2]['id']);
+ $this->assertEquals('T3', $tasks[2]['title']);
+ }
+}
diff --git a/tests/units/ProjectPermissionTest.php b/tests/units/ProjectPermissionTest.php
index ee608d03..66406392 100644
--- a/tests/units/ProjectPermissionTest.php
+++ b/tests/units/ProjectPermissionTest.php
@@ -10,78 +10,144 @@ class ProjectPermissionTest extends Base
{
public function testAllowEverybody()
{
- $user = new User($this->registry);
- $this->assertTrue($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
- $this->assertTrue($user->create(array('username' => 'unittest#2', 'password' => 'unittest')));
+ $user = new User($this->container);
+ $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertNotFalse($user->create(array('username' => 'unittest#2', 'password' => 'unittest')));
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertFalse($pp->isEverybodyAllowed(1));
$this->assertTrue($pp->isUserAllowed(1, 1));
$this->assertFalse($pp->isUserAllowed(1, 2));
$this->assertFalse($pp->isUserAllowed(1, 3));
- $this->assertEquals(array(), $pp->getAllowedUsers(1));
- $this->assertEquals(array('Unassigned'), $pp->getUsersList(1));
+ $this->assertEquals(array(), $pp->getMembers(1));
+ $this->assertEquals(array('Unassigned'), $pp->getMemberList(1));
+
+ $this->assertEmpty($pp->getMemberProjects(1));
+ $this->assertEmpty($pp->getMemberProjects(2));
+ $this->assertEmpty($pp->getMemberProjects(3));
+
+ $this->assertEmpty($pp->getMemberProjectIds(1));
+ $this->assertEmpty($pp->getMemberProjectIds(2));
+ $this->assertEmpty($pp->getMemberProjectIds(3));
+
+ $this->assertEmpty($pp->getActiveMemberProjectIds(1));
+ $this->assertEmpty($pp->getActiveMemberProjectIds(2));
+ $this->assertEmpty($pp->getActiveMemberProjectIds(3));
+
+ $this->assertEmpty($pp->getActiveMemberProjects(1));
+ $this->assertEmpty($pp->getActiveMemberProjects(2));
+ $this->assertEmpty($pp->getActiveMemberProjects(3));
$this->assertTrue($p->update(array('id' => 1, 'is_everybody_allowed' => 1)));
$this->assertTrue($pp->isEverybodyAllowed(1));
$this->assertTrue($pp->isUserAllowed(1, 1));
$this->assertTrue($pp->isUserAllowed(1, 2));
$this->assertTrue($pp->isUserAllowed(1, 3));
- $this->assertEquals(array('1' => 'admin', '2' => 'unittest#1', '3' => 'unittest#2'), $pp->getAllowedUsers(1));
- $this->assertEquals(array('Unassigned', '1' => 'admin', '2' => 'unittest#1', '3' => 'unittest#2'), $pp->getUsersList(1));
+ $this->assertEquals(array('1' => 'admin', '2' => 'unittest#1', '3' => 'unittest#2'), $pp->getMembers(1));
+ $this->assertEquals(array('Unassigned', '1' => 'admin', '2' => 'unittest#1', '3' => 'unittest#2'), $pp->getMemberList(1));
+
+ $this->assertNotEmpty($pp->getMemberProjects(1));
+ $this->assertNotEmpty($pp->getMemberProjects(2));
+ $this->assertNotEmpty($pp->getMemberProjects(3));
+
+ $this->assertNotEmpty($pp->getMemberProjectIds(1));
+ $this->assertNotEmpty($pp->getMemberProjectIds(2));
+ $this->assertNotEmpty($pp->getMemberProjectIds(3));
+
+ $this->assertNotEmpty($pp->getActiveMemberProjectIds(1));
+ $this->assertNotEmpty($pp->getActiveMemberProjectIds(2));
+ $this->assertNotEmpty($pp->getActiveMemberProjectIds(3));
+
+ $this->assertNotEmpty($pp->getActiveMemberProjects(1));
+ $this->assertNotEmpty($pp->getActiveMemberProjects(2));
+ $this->assertNotEmpty($pp->getActiveMemberProjects(3));
+
+ $this->assertTrue($p->disable(1));
+
+ $this->assertEmpty($pp->getActiveMemberProjectIds(1));
+ $this->assertEmpty($pp->getActiveMemberProjectIds(2));
+ $this->assertEmpty($pp->getActiveMemberProjectIds(3));
+
+ $this->assertEmpty($pp->getActiveMemberProjects(1));
+ $this->assertEmpty($pp->getActiveMemberProjects(2));
+ $this->assertEmpty($pp->getActiveMemberProjects(3));
}
public function testDisallowEverybody()
{
// We create a regular user
- $user = new User($this->registry);
+ $user = new User($this->container);
$user->create(array('username' => 'unittest', 'password' => 'unittest'));
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertEmpty($pp->getAllowedUsers(1)); // Nobody is specified for the given project
+ $this->assertEmpty($pp->getMembers(1)); // Nobody is specified for the given project
$this->assertTrue($pp->isUserAllowed(1, 1)); // Admin should be allowed
$this->assertFalse($pp->isUserAllowed(1, 2)); // Regular user should be denied
}
public function testAllowUser()
{
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
- $user = new User($this->registry);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $user = new User($this->container);
- $user->create(array('username' => 'unittest', 'password' => 'unittest'));
+ $this->assertNotFalse($user->create(array('username' => 'unittest', 'password' => 'unittest')));
// We create a project
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEmpty($pp->getMemberProjects(1));
+ $this->assertEmpty($pp->getMemberProjects(2));
+
+ $this->assertEmpty($pp->getMemberProjectIds(1));
+ $this->assertEmpty($pp->getMemberProjectIds(2));
+
+ $this->assertEmpty($pp->getActiveMemberProjectIds(1));
+ $this->assertEmpty($pp->getActiveMemberProjectIds(2));
+
+ $this->assertEmpty($pp->getActiveMemberProjects(1));
+ $this->assertEmpty($pp->getActiveMemberProjects(2));
+
// We allow the admin user
- $this->assertTrue($pp->allowUser(1, 1));
- $this->assertTrue($pp->allowUser(1, 2));
+ $this->assertTrue($pp->addMember(1, 1));
+ $this->assertTrue($pp->addMember(1, 2));
// Non-existant project
- $this->assertFalse($pp->allowUser(50, 1));
+ $this->assertFalse($pp->addMember(50, 1));
// Non-existant user
- $this->assertFalse($pp->allowUser(1, 50));
+ $this->assertFalse($pp->addMember(1, 50));
// Both users should be allowed
- $this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $pp->getAllowedUsers(1));
+ $this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $pp->getMembers(1));
$this->assertTrue($pp->isUserAllowed(1, 1));
$this->assertTrue($pp->isUserAllowed(1, 2));
+
+ $this->assertNotEmpty($pp->getMemberProjects(1));
+ $this->assertNotEmpty($pp->getMemberProjects(2));
+
+ $this->assertNotEmpty($pp->getMemberProjectIds(1));
+ $this->assertNotEmpty($pp->getMemberProjectIds(2));
+
+ $this->assertNotEmpty($pp->getActiveMemberProjectIds(1));
+ $this->assertNotEmpty($pp->getActiveMemberProjectIds(2));
+
+ $this->assertNotEmpty($pp->getActiveMemberProjects(1));
+ $this->assertNotEmpty($pp->getActiveMemberProjects(2));
}
public function testRevokeUser()
{
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
- $user = new User($this->registry);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $user = new User($this->container);
$user->create(array('username' => 'unittest', 'password' => 'unittest'));
@@ -89,56 +155,92 @@ class ProjectPermissionTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
// We revoke our admin user (not existing row)
- $this->assertFalse($pp->revokeUser(1, 1));
+ $this->assertFalse($pp->revokeMember(1, 1));
// We should have nobody in the users list
- $this->assertEmpty($pp->getAllowedUsers(1));
+ $this->assertEmpty($pp->getMembers(1));
// Only admin is allowed
$this->assertTrue($pp->isUserAllowed(1, 1));
$this->assertFalse($pp->isUserAllowed(1, 2));
// We allow only the regular user
- $this->assertTrue($pp->allowUser(1, 2));
+ $this->assertTrue($pp->addMember(1, 2));
// All users should be allowed (admin and regular)
$this->assertTrue($pp->isUserAllowed(1, 1));
$this->assertTrue($pp->isUserAllowed(1, 2));
// However, we should have only our regular user in the list
- $this->assertEquals(array('2' => 'unittest'), $pp->getAllowedUsers(1));
+ $this->assertEquals(array('2' => 'unittest'), $pp->getMembers(1));
// We allow our admin, we should have both in the list
- $this->assertTrue($pp->allowUser(1, 1));
- $this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $pp->getAllowedUsers(1));
+ $this->assertTrue($pp->addMember(1, 1));
+ $this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $pp->getMembers(1));
$this->assertTrue($pp->isUserAllowed(1, 1));
$this->assertTrue($pp->isUserAllowed(1, 2));
// We revoke the regular user
- $this->assertTrue($pp->revokeUser(1, 2));
+ $this->assertTrue($pp->revokeMember(1, 2));
// Only admin should be allowed
$this->assertTrue($pp->isUserAllowed(1, 1));
$this->assertFalse($pp->isUserAllowed(1, 2));
// We should have only admin in the list
- $this->assertEquals(array('1' => 'admin'), $pp->getAllowedUsers(1));
+ $this->assertEquals(array('1' => 'admin'), $pp->getMembers(1));
// We revoke the admin user
- $this->assertTrue($pp->revokeUser(1, 1));
- $this->assertEmpty($pp->getAllowedUsers(1));
+ $this->assertTrue($pp->revokeMember(1, 1));
+ $this->assertEmpty($pp->getMembers(1));
// Only admin should be allowed again
$this->assertTrue($pp->isUserAllowed(1, 1));
$this->assertFalse($pp->isUserAllowed(1, 2));
}
+ public function testManager()
+ {
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $u = new User($this->container);
+
+ $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest')));
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
+ $this->assertFalse($pp->isMember(1, 2));
+ $this->assertFalse($pp->isManager(1, 2));
+
+ $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'), 1, true));
+ $this->assertFalse($pp->isMember(2, 2));
+ $this->assertFalse($pp->isManager(2, 2));
+
+ $this->assertEquals(3, $p->create(array('name' => 'UnitTest3'), 2, true));
+ $this->assertTrue($pp->isMember(3, 2));
+ $this->assertTrue($pp->isManager(3, 2));
+
+ $this->assertEquals(4, $p->create(array('name' => 'UnitTest4')));
+
+ $this->assertTrue($pp->addManager(4, 2));
+ $this->assertTrue($pp->isMember(4, 2));
+ $this->assertTrue($pp->isManager(4, 2));
+
+ $this->assertEquals(5, $p->create(array('name' => 'UnitTest5')));
+ $this->assertTrue($pp->addMember(5, 2));
+ $this->assertTrue($pp->changeRole(5, 2, 1));
+ $this->assertTrue($pp->isMember(5, 2));
+ $this->assertTrue($pp->isManager(5, 2));
+ $this->assertTrue($pp->changeRole(5, 2, 0));
+ $this->assertTrue($pp->isMember(5, 2));
+ $this->assertFalse($pp->isManager(5, 2));
+ }
+
public function testUsersList()
{
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
- $user = new User($this->registry);
+ $user = new User($this->container);
$user->create(array('username' => 'unittest', 'password' => 'unittest'));
// We create project
@@ -147,39 +249,39 @@ class ProjectPermissionTest extends Base
// No restriction, we should have no body
$this->assertEquals(
array('Unassigned'),
- $pp->getUsersList(1)
+ $pp->getMemberList(1)
);
// We allow only the regular user
- $this->assertTrue($pp->allowUser(1, 2));
+ $this->assertTrue($pp->addMember(1, 2));
$this->assertEquals(
array(0 => 'Unassigned', 2 => 'unittest'),
- $pp->getUsersList(1)
+ $pp->getMemberList(1)
);
// We allow the admin user
- $this->assertTrue($pp->allowUser(1, 1));
+ $this->assertTrue($pp->addMember(1, 1));
$this->assertEquals(
array(0 => 'Unassigned', 1 => 'admin', 2 => 'unittest'),
- $pp->getUsersList(1)
+ $pp->getMemberList(1)
);
// We revoke only the regular user
- $this->assertTrue($pp->revokeUser(1, 2));
+ $this->assertTrue($pp->revokeMember(1, 2));
$this->assertEquals(
array(0 => 'Unassigned', 1 => 'admin'),
- $pp->getUsersList(1)
+ $pp->getMemberList(1)
);
// We revoke only the admin user, we should have everybody
- $this->assertTrue($pp->revokeUser(1, 1));
+ $this->assertTrue($pp->revokeMember(1, 1));
$this->assertEquals(
array(0 => 'Unassigned'),
- $pp->getUsersList(1)
+ $pp->getMemberList(1)
);
}
}
diff --git a/tests/units/ProjectTest.php b/tests/units/ProjectTest.php
index cec8d93d..fec53c2b 100644
--- a/tests/units/ProjectTest.php
+++ b/tests/units/ProjectTest.php
@@ -2,18 +2,36 @@
require_once __DIR__.'/Base.php';
+use Core\Translator;
+use Subscriber\ProjectModificationDateSubscriber;
use Model\Project;
use Model\ProjectPermission;
use Model\User;
use Model\Task;
+use Model\TaskCreation;
use Model\Acl;
use Model\Board;
+use Model\Config;
+use Model\Category;
class ProjectTest extends Base
{
+ public function testCreationForAllLanguages()
+ {
+ $c = new Config($this->container);
+ $p = new Project($this->container);
+
+ foreach ($c->getLanguages() as $locale => $language) {
+ Translator::load($locale);
+ $this->assertNotFalse($p->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language);
+ }
+
+ Translator::load('en_US');
+ }
+
public function testCreation()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
@@ -26,32 +44,89 @@ class ProjectTest extends Base
$this->assertEmpty($project['token']);
}
+ public function testCreationWithDefaultCategories()
+ {
+ $p = new Project($this->container);
+ $c = new Config($this->container);
+ $cat = new Category($this->container);
+
+ // Multiple categories correctly formatted
+
+ $this->assertTrue($c->save(array('project_categories' => 'Test1, Test2')));
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
+
+ $project = $p->getById(1);
+ $this->assertNotEmpty($project);
+
+ $categories = $cat->getAll(1);
+ $this->assertNotEmpty($categories);
+ $this->assertEquals(2, count($categories));
+ $this->assertEquals('Test1', $categories[0]['name']);
+ $this->assertEquals('Test2', $categories[1]['name']);
+
+ // Single category
+
+ $this->assertTrue($c->save(array('project_categories' => 'Test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+
+ $project = $p->getById(2);
+ $this->assertNotEmpty($project);
+
+ $categories = $cat->getAll(2);
+ $this->assertNotEmpty($categories);
+ $this->assertEquals(1, count($categories));
+ $this->assertEquals('Test1', $categories[0]['name']);
+
+ // Multiple categories badly formatted
+
+ $this->assertTrue($c->save(array('project_categories' => 'ABC, , DEF 3, ')));
+ $this->assertEquals(3, $p->create(array('name' => 'UnitTest3')));
+
+ $project = $p->getById(3);
+ $this->assertNotEmpty($project);
+
+ $categories = $cat->getAll(3);
+ $this->assertNotEmpty($categories);
+ $this->assertEquals(2, count($categories));
+ $this->assertEquals('ABC', $categories[0]['name']);
+ $this->assertEquals('DEF 3', $categories[1]['name']);
+
+ // No default categories
+ $this->assertTrue($c->save(array('project_categories' => ' ')));
+ $this->assertEquals(4, $p->create(array('name' => 'UnitTest4')));
+
+ $project = $p->getById(4);
+ $this->assertNotEmpty($project);
+
+ $categories = $cat->getAll(4);
+ $this->assertEmpty($categories);
+ }
+
public function testUpdateLastModifiedDate()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$now = time();
$project = $p->getById(1);
$this->assertNotEmpty($project);
- $this->assertEquals($now, $project['last_modified']);
+ $this->assertEquals($now, $project['last_modified'], 'Wrong Timestamp', 1);
sleep(1);
$this->assertTrue($p->updateModificationDate(1));
$project = $p->getById(1);
$this->assertNotEmpty($project);
- $this->assertEquals($now + 1, $project['last_modified']);
+ $this->assertGreaterThan($now, $project['last_modified']);
}
public function testIsLastModified()
{
- $p = new Project($this->registry);
- $t = new Task($this->registry);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
$now = time();
- $p->attachEvents();
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
@@ -61,9 +136,13 @@ class ProjectTest extends Base
sleep(1);
- $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1)));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
- $this->assertEquals('Event\ProjectModificationDateListener', $this->registry->shared('event')->getLastListenerExecuted());
+ $listener = new ProjectModificationDateSubscriber($this->container);
+ $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($listener, 'execute'));
+
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.Subscriber\ProjectModificationDateSubscriber::execute', $called);
$project = $p->getById(1);
$this->assertNotEmpty($project);
@@ -72,7 +151,7 @@ class ProjectTest extends Base
public function testRemove()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertTrue($p->remove(1));
@@ -81,7 +160,7 @@ class ProjectTest extends Base
public function testEnable()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertTrue($p->disable(1));
@@ -95,7 +174,7 @@ class ProjectTest extends Base
public function testDisable()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertTrue($p->disable(1));
@@ -110,7 +189,7 @@ class ProjectTest extends Base
public function testEnablePublicAccess()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertTrue($p->enablePublicAccess(1));
@@ -125,7 +204,7 @@ class ProjectTest extends Base
public function testDisablePublicAccess()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
$this->assertTrue($p->enablePublicAccess(1));
@@ -139,35 +218,59 @@ class ProjectTest extends Base
$this->assertFalse($p->disablePublicAccess(123));
}
- public function testDuplicate()
+ public function testIdentifier()
{
- $p = new Project($this->registry);
+ $p = new Project($this->container);
- // Clone public project
- $this->assertEquals(1, $p->create(array('name' => 'Public')));
- $this->assertEquals(2, $p->duplicate(1));
+ // Creation
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+
+ $project = $p->getById(1);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('TEST1', $project['identifier']);
$project = $p->getById(2);
$this->assertNotEmpty($project);
- $this->assertEquals('Public (Clone)', $project['name']);
- $this->assertEquals(0, $project['is_private']);
- $this->assertEquals(0, $project['is_public']);
- $this->assertEmpty($project['token']);
+ $this->assertEquals('', $project['identifier']);
- // Clone private project
- $this->assertEquals(3, $p->create(array('name' => 'Private', 'is_private' => 1), 1));
- $this->assertEquals(4, $p->duplicate(3));
+ // Update
+ $this->assertTrue($p->update(array('id' => '2', 'identifier' => 'test2')));
- $project = $p->getById(4);
+ $project = $p->getById(2);
$this->assertNotEmpty($project);
- $this->assertEquals('Private (Clone)', $project['name']);
- $this->assertEquals(1, $project['is_private']);
- $this->assertEquals(0, $project['is_public']);
- $this->assertEmpty($project['token']);
+ $this->assertEquals('TEST2', $project['identifier']);
+
+ $project = $p->getByIdentifier('test1');
+ $this->assertNotEmpty($project);
+ $this->assertEquals('TEST1', $project['identifier']);
+
+ $project = $p->getByIdentifier('');
+ $this->assertFalse($project);
+
+ // Validation rules
+ $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'TEST1'));
+ $this->assertFalse($r[0]);
+
+ $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test1'));
+ $this->assertFalse($r[0]);
+
+ $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1'));
+ $this->assertTrue($r[0]);
+
+ $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3'));
+ $this->assertTrue($r[0]);
+
+ $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => ''));
+ $this->assertTrue($r[0]);
+
+ $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2'));
+ $this->assertFalse($r[0]);
- $pp = new ProjectPermission($this->registry);
+ $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c'));
+ $this->assertFalse($r[0]);
- $this->assertEquals(array(1 => 'admin'), $pp->getAllowedUsers(3));
- $this->assertEquals(array(1 => 'admin'), $pp->getAllowedUsers(4));
+ $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test 123'));
+ $this->assertFalse($r[0]);
}
}
diff --git a/tests/units/SendgridWebhookTest.php b/tests/units/SendgridWebhookTest.php
new file mode 100644
index 00000000..3b30d212
--- /dev/null
+++ b/tests/units/SendgridWebhookTest.php
@@ -0,0 +1,107 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Integration\SendgridWebhook;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\Project;
+use Model\ProjectPermission;
+use Model\User;
+
+class SendgridWebhookTest extends Base
+{
+ public function testHandlePayload()
+ {
+ $w = new SendgridWebhook($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $u = new User($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(2, $u->create(array('name' => 'me', 'email' => 'me@localhost')));
+
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1')));
+
+ // Empty payload
+ $this->assertFalse($w->parsePayload(array()));
+
+ // Unknown user
+ $this->assertFalse($w->parsePayload(array(
+ 'envelope' => '{"to":["a@b.c"],"from":"a.b.c"}',
+ 'subject' => 'Email task'
+ )));
+
+ // Project not found
+ $this->assertFalse($w->parsePayload(array(
+ 'envelope' => '{"to":["a@b.c"],"from":"me@localhost"}',
+ 'subject' => 'Email task'
+ )));
+
+ // User is not member
+ $this->assertFalse($w->parsePayload(array(
+ 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}',
+ 'subject' => 'Email task'
+ )));
+
+ $this->assertTrue($pp->addMember(2, 2));
+
+ // The task must be created
+ $this->assertTrue($w->parsePayload(array(
+ 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}',
+ 'subject' => 'Email task'
+ )));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('Email task', $task['title']);
+ $this->assertEquals('', $task['description']);
+ $this->assertEquals(2, $task['creator_id']);
+
+ // Html content
+ $this->assertTrue($w->parsePayload(array(
+ 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}',
+ 'subject' => 'Email task',
+ 'html' => '<strong>bold</strong> text',
+ )));
+
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('Email task', $task['title']);
+ $this->assertEquals('**bold** text', $task['description']);
+ $this->assertEquals(2, $task['creator_id']);
+
+ // Text content
+ $this->assertTrue($w->parsePayload(array(
+ 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}',
+ 'subject' => 'Email task',
+ 'text' => '**bold** text',
+ )));
+
+ $task = $tf->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('Email task', $task['title']);
+ $this->assertEquals('**bold** text', $task['description']);
+ $this->assertEquals(2, $task['creator_id']);
+
+ // Text + html content
+ $this->assertTrue($w->parsePayload(array(
+ 'envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}',
+ 'subject' => 'Email task',
+ 'html' => '<strong>bold</strong> html',
+ 'text' => '**bold** text',
+ )));
+
+ $task = $tf->getById(4);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('Email task', $task['title']);
+ $this->assertEquals('**bold** html', $task['description']);
+ $this->assertEquals(2, $task['creator_id']);
+ }
+}
diff --git a/tests/units/SubtaskTest.php b/tests/units/SubtaskTest.php
index f272db1f..791f8089 100644
--- a/tests/units/SubtaskTest.php
+++ b/tests/units/SubtaskTest.php
@@ -3,25 +3,137 @@
require_once __DIR__.'/Base.php';
use Model\Task;
-use Model\SubTask;
+use Model\TaskCreation;
+use Model\Subtask;
use Model\Project;
use Model\Category;
use Model\User;
class SubTaskTest extends Base
{
+ public function testMoveUp()
+ {
+ $tc = new TaskCreation($this->container);
+ $s = new Subtask($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $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)));
+
+ // Check positions
+ $subtask = $s->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['position']);
+
+ $subtask = $s->getById(2);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(2, $subtask['position']);
+
+ $subtask = $s->getById(3);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(3, $subtask['position']);
+
+ // Move up
+ $this->assertTrue($s->moveUp(1, 2));
+
+ // Check positions
+ $subtask = $s->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(2, $subtask['position']);
+
+ $subtask = $s->getById(2);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['position']);
+
+ $subtask = $s->getById(3);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(3, $subtask['position']);
+
+ // We can't move up #2
+ $this->assertFalse($s->moveUp(1, 2));
+
+ // Test remove
+ $this->assertTrue($s->remove(1));
+ $this->assertTrue($s->moveUp(1, 3));
+
+ // Check positions
+ $subtask = $s->getById(1);
+ $this->assertEmpty($subtask);
+
+ $subtask = $s->getById(2);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(2, $subtask['position']);
+
+ $subtask = $s->getById(3);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['position']);
+ }
+
+ public function testMoveDown()
+ {
+ $tc = new TaskCreation($this->container);
+ $s = new Subtask($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $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)));
+
+ // Move down #1
+ $this->assertTrue($s->moveDown(1, 1));
+
+ // Check positions
+ $subtask = $s->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(2, $subtask['position']);
+
+ $subtask = $s->getById(2);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['position']);
+
+ $subtask = $s->getById(3);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(3, $subtask['position']);
+
+ // We can't move down #3
+ $this->assertFalse($s->moveDown(1, 3));
+
+ // Test remove
+ $this->assertTrue($s->remove(1));
+ $this->assertTrue($s->moveDown(1, 2));
+
+ // Check positions
+ $subtask = $s->getById(1);
+ $this->assertEmpty($subtask);
+
+ $subtask = $s->getById(2);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(2, $subtask['position']);
+
+ $subtask = $s->getById(3);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['position']);
+ }
+
public function testDuplicate()
{
- $t = new Task($this->registry);
- $s = new SubTask($this->registry);
- $p = new Project($this->registry);
+ $tc = new TaskCreation($this->container);
+ $s = new Subtask($this->container);
+ $p = new Project($this->container);
// We create a project
$this->assertEquals(1, $p->create(array('name' => 'test1')));
// We create 2 tasks
- $this->assertEquals(1, $t->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
- $this->assertEquals(2, $t->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0)));
+ $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0)));
// We create many subtasks for the first task
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1, 'another_subtask' => 'on')));
@@ -52,5 +164,8 @@ class SubTaskTest extends Base
$this->assertEquals(0, $subtasks[0]['user_id']);
$this->assertEquals(0, $subtasks[1]['user_id']);
+
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(2, $subtasks[1]['position']);
}
}
diff --git a/tests/units/SubtaskTimeTrackingTest.php b/tests/units/SubtaskTimeTrackingTest.php
new file mode 100644
index 00000000..e15e60da
--- /dev/null
+++ b/tests/units/SubtaskTimeTrackingTest.php
@@ -0,0 +1,231 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\TaskFinder;
+use Model\TaskCreation;
+use Model\Subtask;
+use Model\SubtaskTimeTracking;
+use Model\Project;
+use Model\Category;
+use Model\User;
+
+class SubtaskTimeTrackingTest extends Base
+{
+ public function testLogStartTime()
+ {
+ $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(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ $this->assertTrue($st->logStartTime(1, 1));
+
+ $timesheet = $st->getUserTimesheet(1);
+ $this->assertNotEmpty($timesheet);
+ $this->assertCount(1, $timesheet);
+ $this->assertNotEmpty($timesheet[0]['start']);
+ $this->assertEmpty($timesheet[0]['end']);
+ $this->assertEquals(1, $timesheet[0]['user_id']);
+ $this->assertEquals(1, $timesheet[0]['subtask_id']);
+ }
+
+ public function testLogStartEnd()
+ {
+ $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(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ // No start time
+ $this->assertTrue($st->logEndTime(1, 1));
+ $timesheet = $st->getUserTimesheet(1);
+ $this->assertEmpty($timesheet);
+
+ // Log start and end time
+ $this->assertTrue($st->logStartTime(1, 1));
+ sleep(1);
+ $this->assertTrue($st->logEndTime(1, 1));
+
+ $timesheet = $st->getUserTimesheet(1);
+ $this->assertNotEmpty($timesheet);
+ $this->assertCount(1, $timesheet);
+ $this->assertNotEmpty($timesheet[0]['start']);
+ $this->assertNotEmpty($timesheet[0]['end']);
+ $this->assertEquals(1, $timesheet[0]['user_id']);
+ $this->assertEquals(1, $timesheet[0]['subtask_id']);
+ $this->assertNotEquals($timesheet[0]['start'], $timesheet[0]['end']);
+ }
+
+ public function testCalculateSubtaskTime()
+ {
+ $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(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2, 'time_estimated' => 3.3)));
+ $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 1.1, 'time_estimated' => 4.4)));
+
+ $time = $st->calculateSubtaskTime(1);
+ $this->assertNotempty($time);
+ $this->assertCount(2, $time);
+ $this->assertEquals(3.3, $time['total_spent'], 'Total spent', 0.01);
+ $this->assertEquals(7.7, $time['total_estimated'], 'Total estimated', 0.01);
+ }
+
+ public function testUpdateSubtaskTimeSpent()
+ {
+ $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(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2)));
+ $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
+
+ $this->assertTrue($st->logStartTime(1, 1));
+ $this->assertTrue($st->logStartTime(2, 1));
+
+ // Fake start time
+ $this->container['db']->table(SubtaskTimeTracking::TABLE)->update(array('start' => time() - 3600));
+
+ $this->assertTrue($st->logEndTime(1, 1));
+ $this->assertTrue($st->logEndTime(2, 1));
+
+ $timesheet = $st->getUserTimesheet(1);
+ $this->assertNotEmpty($timesheet);
+ $this->assertCount(2, $timesheet);
+ $this->assertEquals(3600, $timesheet[0]['end'] - $timesheet[0]['start'], 'Wrong timestamps', 1);
+ $this->assertEquals(3600, $timesheet[1]['end'] - $timesheet[1]['start'], 'Wrong timestamps', 1);
+
+ $time = $st->calculateSubtaskTime(1);
+ $this->assertNotempty($time);
+ $this->assertEquals(4.2, $time['total_spent'], 'Total spent', 0.01);
+ $this->assertEquals(0, $time['total_estimated'], 'Total estimated', 0.01);
+
+ $time = $st->calculateSubtaskTime(2);
+ $this->assertNotempty($time);
+ $this->assertEquals(0, $time['total_spent'], 'Total spent', 0.01);
+ $this->assertEquals(0, $time['total_estimated'], 'Total estimated', 0.01);
+ }
+
+ public function testUpdateTaskTimeTracking()
+ {
+ $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(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 1.5, 'time_spent' => 0.5)));
+
+ $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_spent' => 2.2)));
+ $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 1)));
+
+ $st->updateTaskTimeTracking(1);
+ $st->updateTaskTimeTracking(2);
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2.2, $task['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(1, $task['time_estimated'], 'Total estimated', 0.01);
+
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0.5, $task['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(1.5, $task['time_estimated'], 'Total estimated', 0.01);
+ }
+
+ 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/SwimlaneTest.php b/tests/units/SwimlaneTest.php
new file mode 100644
index 00000000..37226613
--- /dev/null
+++ b/tests/units/SwimlaneTest.php
@@ -0,0 +1,409 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Project;
+use Model\Task;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\Swimlane;
+
+class SwimlaneTest extends Base
+{
+ public function testCreation()
+ {
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $s->create(1, 'Swimlane #1'));
+
+ $swimlanes = $s->getSwimlanes(1);
+ $this->assertNotEmpty($swimlanes);
+ $this->assertEquals(2, count($swimlanes));
+ $this->assertEquals('Default swimlane', $swimlanes[0]['name']);
+ $this->assertEquals('Swimlane #1', $swimlanes[1]['name']);
+
+ $this->assertEquals(1, $s->getIdByName(1, 'Swimlane #1'));
+ $this->assertEquals(0, $s->getIdByName(2, 'Swimlane #2'));
+
+ $this->assertEquals('Swimlane #1', $s->getNameById(1));
+ $this->assertEquals('', $s->getNameById(23));
+ }
+
+ public function testGetList()
+ {
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $s->create(1, 'Swimlane #1'));
+ $this->assertEquals(2, $s->create(1, 'Swimlane #2'));
+
+ $swimlanes = $s->getList(1);
+ $expected = array('Default swimlane', 'Swimlane #1', 'Swimlane #2');
+
+ $this->assertEquals($expected, $swimlanes);
+ }
+
+ public function testRename()
+ {
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $s->create(1, 'Swimlane #1'));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals('Swimlane #1', $swimlane['name']);
+
+ $this->assertTrue($s->rename(1, 'foobar'));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals('foobar', $swimlane['name']);
+ }
+
+ public function testRenameDefaultSwimlane()
+ {
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertTrue($s->updateDefault(array('id' => 1, 'default_swimlane' => 'foo', 'show_default_swimlane' => 1)));
+
+ $default = $s->getDefault(1);
+ $this->assertNotEmpty($default);
+ $this->assertEquals('foo', $default['default_swimlane']);
+ $this->assertEquals(1, $default['show_default_swimlane']);
+
+ $this->assertTrue($s->updateDefault(array('id' => 1, 'default_swimlane' => 'foo', 'show_default_swimlane' => 0)));
+
+ $default = $s->getDefault(1);
+ $this->assertNotEmpty($default);
+ $this->assertEquals('foo', $default['default_swimlane']);
+ $this->assertEquals(0, $default['show_default_swimlane']);
+ }
+
+ public function testDisable()
+ {
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $s->create(1, 'Swimlane #1'));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(1, $swimlane['position']);
+
+ $this->assertEquals(2, $s->getLastPosition(1));
+ $this->assertTrue($s->disable(1, 1));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(0, $swimlane['is_active']);
+ $this->assertEquals(0, $swimlane['position']);
+
+ $this->assertEquals(1, $s->getLastPosition(1));
+
+ // Create a new swimlane
+ $this->assertEquals(2, $s->create(1, 'Swimlane #2'));
+
+ $swimlane = $s->getById(2);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(1, $swimlane['position']);
+
+ // Enable our disabled swimlane
+ $this->assertTrue($s->enable(1, 1));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(2, $swimlane['position']);
+ }
+
+ public function testRemove()
+ {
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $s->create(1, 'Swimlane #1'));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'swimlane_id' => 1)));
+
+ $task = $tf->getbyId(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['swimlane_id']);
+
+ $this->assertTrue($s->remove(1, 1));
+
+ $task = $tf->getbyId(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['swimlane_id']);
+
+ $this->assertEmpty($s->getById(1));
+ }
+
+ public function testUpdatePositions()
+ {
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $s->create(1, 'Swimlane #1'));
+ $this->assertEquals(2, $s->create(1, 'Swimlane #2'));
+ $this->assertEquals(3, $s->create(1, 'Swimlane #3'));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(1, $swimlane['position']);
+
+ $swimlane = $s->getById(2);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(2, $swimlane['position']);
+
+ $swimlane = $s->getById(3);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(3, $swimlane['position']);
+
+ // Disable the 2nd swimlane
+ $this->assertTrue($s->disable(1, 2));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(1, $swimlane['position']);
+
+ $swimlane = $s->getById(2);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(0, $swimlane['is_active']);
+ $this->assertEquals(0, $swimlane['position']);
+
+ $swimlane = $s->getById(3);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(2, $swimlane['position']);
+
+ // Remove the first swimlane
+ $this->assertTrue($s->remove(1, 1));
+
+ $swimlane = $s->getById(1);
+ $this->assertEmpty($swimlane);
+
+ $swimlane = $s->getById(2);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(0, $swimlane['is_active']);
+ $this->assertEquals(0, $swimlane['position']);
+
+ $swimlane = $s->getById(3);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(1, $swimlane['position']);
+ }
+
+ public function testMoveUp()
+ {
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $s->create(1, 'Swimlane #1'));
+ $this->assertEquals(2, $s->create(1, 'Swimlane #2'));
+ $this->assertEquals(3, $s->create(1, 'Swimlane #3'));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(1, $swimlane['position']);
+
+ $swimlane = $s->getById(2);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(2, $swimlane['position']);
+
+ $swimlane = $s->getById(3);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(3, $swimlane['position']);
+
+ // Move the swimlane 3 up
+ $this->assertTrue($s->moveUp(1, 3));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(1, $swimlane['position']);
+
+ $swimlane = $s->getById(2);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(3, $swimlane['position']);
+
+ $swimlane = $s->getById(3);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(2, $swimlane['position']);
+
+ // First swimlane can be moved up
+ $this->assertFalse($s->moveUp(1, 1));
+
+ // Move with a disabled swimlane
+ $this->assertTrue($s->disable(1, 1));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(0, $swimlane['is_active']);
+ $this->assertEquals(0, $swimlane['position']);
+
+ $swimlane = $s->getById(2);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(2, $swimlane['position']);
+
+ $swimlane = $s->getById(3);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(1, $swimlane['position']);
+
+ // Move the 2nd swimlane up
+ $this->assertTrue($s->moveUp(1, 2));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(0, $swimlane['is_active']);
+ $this->assertEquals(0, $swimlane['position']);
+
+ $swimlane = $s->getById(2);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(1, $swimlane['position']);
+
+ $swimlane = $s->getById(3);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(2, $swimlane['position']);
+ }
+
+ public function testMoveDown()
+ {
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $s->create(1, 'Swimlane #1'));
+ $this->assertEquals(2, $s->create(1, 'Swimlane #2'));
+ $this->assertEquals(3, $s->create(1, 'Swimlane #3'));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(1, $swimlane['position']);
+
+ $swimlane = $s->getById(2);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(2, $swimlane['position']);
+
+ $swimlane = $s->getById(3);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(3, $swimlane['position']);
+
+ // Move the swimlane 1 down
+ $this->assertTrue($s->moveDown(1, 1));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(2, $swimlane['position']);
+
+ $swimlane = $s->getById(2);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(1, $swimlane['position']);
+
+ $swimlane = $s->getById(3);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(3, $swimlane['position']);
+
+ // Last swimlane can be moved down
+ $this->assertFalse($s->moveDown(1, 3));
+
+ // Move with a disabled swimlane
+ $this->assertTrue($s->disable(1, 3));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(2, $swimlane['position']);
+
+ $swimlane = $s->getById(2);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(1, $swimlane['position']);
+
+ $swimlane = $s->getById(3);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(0, $swimlane['is_active']);
+ $this->assertEquals(0, $swimlane['position']);
+
+ // Move the 2st swimlane down
+ $this->assertTrue($s->moveDown(1, 2));
+
+ $swimlane = $s->getById(1);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(1, $swimlane['position']);
+
+ $swimlane = $s->getById(2);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(1, $swimlane['is_active']);
+ $this->assertEquals(2, $swimlane['position']);
+
+ $swimlane = $s->getById(3);
+ $this->assertNotEmpty($swimlane);
+ $this->assertEquals(0, $swimlane['is_active']);
+ $this->assertEquals(0, $swimlane['position']);
+ }
+
+ public function testDuplicateSwimlane()
+ {
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+ $this->assertEquals(2, $p->create(array('name' => 'P2')));
+ $this->assertEquals(1, $s->create(1, 'S1'));
+ $this->assertEquals(2, $s->create(1, 'S2'));
+ $this->assertEquals(3, $s->create(1, 'S3'));
+
+ $default_swimlane1 = $s->getDefault(1);
+ $default_swimlane1['default_swimlane'] = 'New Default';
+
+ $this->assertTrue($s->updateDefault($default_swimlane1));
+
+ $this->assertTrue($s->duplicate(1, 2));
+
+ $swimlanes = $s->getAll(2);
+
+ $this->assertCount(3, $swimlanes);
+ $this->assertEquals(4, $swimlanes[0]['id']);
+ $this->assertEquals('S1', $swimlanes[0]['name']);
+ $this->assertEquals(5, $swimlanes[1]['id']);
+ $this->assertEquals('S2', $swimlanes[1]['name']);
+ $this->assertEquals(6, $swimlanes[2]['id']);
+ $this->assertEquals('S3', $swimlanes[2]['name']);
+ $new_default = $s->getDefault(2);
+ $this->assertEquals('New Default', $new_default['default_swimlane']);
+ }
+}
diff --git a/tests/units/TaskCreationTest.php b/tests/units/TaskCreationTest.php
new file mode 100644
index 00000000..986f1eb1
--- /dev/null
+++ b/tests/units/TaskCreationTest.php
@@ -0,0 +1,358 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Task;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\TaskStatus;
+use Model\Project;
+use Model\ProjectPermission;
+
+class TaskCreationTest extends Base
+{
+ public function onCreate($event)
+ {
+ $this->assertInstanceOf('Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals('test', $event_data['title']);
+ }
+
+ public function testNoProjectId()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {});
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(0, $tc->create(array('title' => 'test', 'project_id' => 0)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayNotHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
+ $this->assertArrayNotHasKey(Task::EVENT_CREATE.'.closure', $called);
+ }
+
+ public function testNoTitle()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {});
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called);
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('Untitled', $task['title']);
+ $this->assertEquals(1, $task['project_id']);
+ }
+
+ public function testMinimum()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(Task::EVENT_CREATE, array($this, 'onCreate'));
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(Task::EVENT_CREATE.'.TaskCreationTest::onCreate', $called);
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('yellow', $task['color_id']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(0, $task['creator_id']);
+
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals('', $task['description']);
+ $this->assertEquals('', $task['reference']);
+
+ $this->assertEquals(time(), $task['date_creation'], 'Wrong timestamp', 1);
+ $this->assertEquals(time(), $task['date_modification'], 'Wrog timestamp', 1);
+ $this->assertEquals(0, $task['date_due']);
+ $this->assertEquals(0, $task['date_completed']);
+ $this->assertEquals(0, $task['date_started']);
+
+ $this->assertEquals(0, $task['time_estimated']);
+ $this->assertEquals(0, $task['time_spent']);
+
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['is_active']);
+ $this->assertEquals(0, $task['score']);
+ }
+
+ public function testColorId()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'color_id' => 'blue')));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('blue', $task['color_id']);
+ }
+
+ public function testOwnerId()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['owner_id']);
+ }
+
+ public function testCategoryId()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'category_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['category_id']);
+ }
+
+ public function testCreatorId()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'creator_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['creator_id']);
+ }
+
+ public function testColumnId()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ }
+
+ public function testPosition()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+ }
+
+ public function testDescription()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'description' => 'test')));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('test', $task['description']);
+ }
+
+ public function testReference()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'reference' => 'test')));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('test', $task['reference']);
+ }
+
+ public function testDateDue()
+ {
+ $date = '2014-11-23';
+ $timestamp = strtotime('+2days');
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => $date)));
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => $timestamp)));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals($date, date('Y-m-d', $task['date_due']));
+
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals($timestamp, $task['date_due']);
+ }
+
+ public function testDateStarted()
+ {
+ $date = '2014-11-23';
+ $timestamp = strtotime('+2days');
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => $date)));
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => $timestamp)));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals($date, date('Y-m-d', $task['date_started']));
+
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals($timestamp, $task['date_started']);
+ }
+
+ public function testTime()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.5, 'time_spent' => 2.3)));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1.5, $task['time_estimated']);
+ $this->assertEquals(2.3, $task['time_spent']);
+ }
+
+ public function testStripColumn()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'another_task' => '1')));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+ }
+
+ public function testScore()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'score' => '3')));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+ $this->assertEquals(3, $task['score']);
+ }
+}
diff --git a/tests/units/TaskDuplicationTest.php b/tests/units/TaskDuplicationTest.php
new file mode 100644
index 00000000..cd791312
--- /dev/null
+++ b/tests/units/TaskDuplicationTest.php
@@ -0,0 +1,563 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Task;
+use Model\TaskCreation;
+use Model\TaskDuplication;
+use Model\TaskFinder;
+use Model\TaskStatus;
+use Model\Project;
+use Model\ProjectPermission;
+use Model\Category;
+use Model\User;
+use Model\Swimlane;
+
+class TaskDuplicationTest extends Base
+{
+ public function testDuplicateSameProject()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+
+ // We create a task and a project
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+
+ // Some categories
+ $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 1)));
+ $this->assertTrue($c->exists(1, 1));
+ $this->assertTrue($c->exists(2, 1));
+
+ $this->assertEquals(
+ 1,
+ $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2, 'time_spent' => 4.4)
+ ));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(3, $task['column_id']);
+ $this->assertEquals(2, $task['category_id']);
+ $this->assertEquals(4.4, $task['time_spent']);
+
+ $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {});
+
+ // We duplicate our task
+ $this->assertEquals(2, $td->duplicate(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called);
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(1, $task['owner_id']);
+ $this->assertEquals(2, $task['category_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(3, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(0, $task['time_spent']);
+ }
+
+ public function testDuplicateAnotherProject()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertTrue($c->exists(1, 1));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1)));
+
+ $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(Task::EVENT_CREATE, function() {});
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $td->duplicateToProject(1, 2));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(Task::EVENT_CREATE.'.closure', $called);
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithCategory()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
+ $this->assertTrue($c->exists(1, 1));
+ $this->assertTrue($c->exists(2, 2));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $td->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(2, $task['category_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithSwimlane()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($s->create(1, 'Swimlane #1'));
+ $this->assertNotFalse($s->create(2, 'Swimlane #1'));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $td->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(2, $task['swimlane_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithoutSwimlane()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($s->create(1, 'Swimlane #1'));
+ $this->assertNotFalse($s->create(2, 'Swimlane #2'));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $td->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithUser()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $td->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+
+ // We create a new user for our project
+ $user = new User($this->container);
+ $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertTrue($pp->addMember(1, 2));
+ $this->assertTrue($pp->addMember(2, 2));
+ $this->assertTrue($pp->isUserAllowed(1, 2));
+ $this->assertTrue($pp->isUserAllowed(2, 2));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(3, $td->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['position']);
+ $this->assertEquals(2, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+
+ // We duplicate a task with a not allowed user
+ $this->assertEquals(4, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3)));
+ $this->assertEquals(5, $td->duplicateToProject(4, 2));
+
+ $task = $tf->getById(5);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3, $task['position']);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(5, $task['column_id']);
+ }
+
+ public function onMoveProject($event)
+ {
+ $this->assertInstanceOf('Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals('test', $event_data['title']);
+ }
+
+ public function testMoveAnotherProject()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $user = new User($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333)));
+
+ $this->container['dispatcher']->addListener(Task::EVENT_MOVE_PROJECT, array($this, 'onMoveProject'));
+
+ // We duplicate our task to the 2nd project
+ $this->assertTrue($td->moveToProject(1, 2));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(Task::EVENT_MOVE_PROJECT.'.TaskDuplicationTest::onMoveProject', $called);
+
+ // Check the values of the moved task
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testMoveAnotherProjectWithCategory()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 2)));
+ $this->assertTrue($c->exists(1, 1));
+ $this->assertTrue($c->exists(2, 2));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($td->moveToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(2, $task['category_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testMoveAnotherProjectWithUser()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $user = new User($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ // We create a new user for our project
+ $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertTrue($pp->addMember(1, 2));
+ $this->assertTrue($pp->addMember(2, 2));
+ $this->assertTrue($pp->isUserAllowed(1, 2));
+ $this->assertTrue($pp->isUserAllowed(2, 2));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($td->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(5, $task['column_id']);
+ }
+
+ public function testMoveAnotherProjectWithForbiddenUser()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $pp = new ProjectPermission($this->container);
+ $user = new User($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ // We create a new user for our project
+ $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertTrue($pp->addMember(1, 2));
+ $this->assertTrue($pp->addMember(2, 2));
+ $this->assertTrue($pp->isUserAllowed(1, 2));
+ $this->assertTrue($pp->isUserAllowed(2, 2));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 3)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($td->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(5, $task['column_id']);
+ }
+
+ public function testMoveAnotherProjectWithSwimlane()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($s->create(1, 'Swimlane #1'));
+ $this->assertNotFalse($s->create(2, 'Swimlane #1'));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($td->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(2, $task['swimlane_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testMoveAnotherProjectWithoutSwimlane()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($s->create(1, 'Swimlane #1'));
+ $this->assertNotFalse($s->create(2, 'Swimlane #2'));
+
+ // We create a task
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($td->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testCalculateRecurringTaskDueDate()
+ {
+ $td = new TaskDuplication($this->container);
+
+ $values = array('date_due' => 0);
+ $td->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(0, $values['date_due']);
+
+ $values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS);
+ $td->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(0, $values['date_due']);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS);
+ $td->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(time() + 86400, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS);
+ $td->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(time() - 2 * 86400, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS);
+ $td->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(1431291376 + 86400, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS);
+ $td->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(1431291376 - 86400, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_MONTHS);
+ $td->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(1436561776, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => Task::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_YEARS);
+ $td->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(1494449776, $values['date_due'], '', 1);
+ }
+
+ public function testDuplicateRecurringTask()
+ {
+ $td = new TaskDuplication($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+
+ $this->assertEquals(1, $tc->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'date_due' => 1436561776,
+ 'recurrence_status' => Task::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => Task::RECURRING_TRIGGER_CLOSE,
+ 'recurrence_factor' => 2,
+ 'recurrence_timeframe' => Task::RECURRING_TIMEFRAME_DAYS,
+ 'recurrence_basedate' => Task::RECURRING_BASEDATE_TRIGGERDATE,
+ )));
+
+ $this->assertEquals(2, $td->duplicateRecurringTask(1));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(Task::RECURRING_STATUS_PROCESSED, $task['recurrence_status']);
+ $this->assertEquals(2, $task['recurrence_child']);
+ $this->assertEquals(1436561776, $task['date_due'], '', 2);
+
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(Task::RECURRING_STATUS_PENDING, $task['recurrence_status']);
+ $this->assertEquals(Task::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']);
+ $this->assertEquals(Task::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']);
+ $this->assertEquals(Task::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']);
+ $this->assertEquals(1, $task['recurrence_parent']);
+ $this->assertEquals(2, $task['recurrence_factor']);
+ $this->assertEquals(strtotime('+2 days'), $task['date_due'], '', 2);
+ }
+}
diff --git a/tests/units/TaskExportTest.php b/tests/units/TaskExportTest.php
index ad0bbdc4..3892f2bd 100644
--- a/tests/units/TaskExportTest.php
+++ b/tests/units/TaskExportTest.php
@@ -3,21 +3,28 @@
require_once __DIR__.'/Base.php';
use Model\Task;
+use Model\TaskCreation;
use Model\TaskExport;
use Model\Project;
use Model\Category;
use Model\User;
+use Model\Swimlane;
class TaskExportTest extends Base
{
public function testExport()
{
- $t = new Task($this->registry);
- $p = new Project($this->registry);
- $c = new Category($this->registry);
- $e = new TaskExport($this->registry);
+ $tc = new TaskCreation($this->container);
+ $p = new Project($this->container);
+ $c = new Category($this->container);
+ $e = new TaskExport($this->container);
+ $s = new Swimlane($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Export Project')));
+
+ $this->assertEquals(1, $s->create(1, 'S1'));
+ $this->assertEquals(2, $s->create(1, 'S2'));
+
$this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
$this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 1)));
$this->assertNotFalse($c->create(array('name' => 'Category #3', 'project_id' => 1)));
@@ -33,16 +40,19 @@ class TaskExportTest extends Base
'color_id' => rand(0, 1) === 0 ? 'green' : 'purple',
'category_id' => rand(0, 3),
'date_due' => array_rand(array(0, date('Y-m-d'), date('Y-m-d', strtotime('+'.$i.'day')))),
- 'score' => rand(0, 21)
+ 'score' => rand(0, 21),
+ 'swimlane_id' => rand(0, 2),
);
- $this->assertEquals($i, $t->create($task));
+ $this->assertEquals($i, $tc->create($task));
}
$rows = $e->export(1, strtotime('-1 day'), strtotime('+1 day'));
+
$this->assertEquals($i, count($rows));
$this->assertEquals('Task Id', $rows[0][0]);
$this->assertEquals(1, $rows[1][0]);
- $this->assertEquals('Task #'.($i - 1), $rows[$i - 1][11]);
+ $this->assertEquals('Task #'.($i - 1), $rows[$i - 1][12]);
+ $this->assertTrue(in_array($rows[$i - 1][4], array('Default swimlane', 'S1', 'S2')));
}
}
diff --git a/tests/units/TaskFinderTest.php b/tests/units/TaskFinderTest.php
index 5a90f3af..96a3809b 100644
--- a/tests/units/TaskFinderTest.php
+++ b/tests/units/TaskFinderTest.php
@@ -3,6 +3,7 @@
require_once __DIR__.'/Base.php';
use Model\Task;
+use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
use Model\ProjectPermission;
@@ -13,15 +14,15 @@ class TaskFinderTest extends Base
{
public function testGetOverdueTasks()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $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, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
- $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => 0)));
- $this->assertEquals(4, $t->create(array('title' => 'Task #3', 'project_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
+ $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => 0)));
+ $this->assertEquals(4, $tc->create(array('title' => 'Task #3', 'project_id' => 1)));
$tasks = $tf->getOverdueTasks();
$this->assertNotEmpty($tasks);
diff --git a/tests/units/TaskLinkTest.php b/tests/units/TaskLinkTest.php
new file mode 100644
index 00000000..e213e25a
--- /dev/null
+++ b/tests/units/TaskLinkTest.php
@@ -0,0 +1,185 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Link;
+use Model\TaskLink;
+use Model\TaskCreation;
+use Model\Project;
+
+class TaskLinkTest extends Base
+{
+ public function testCreateTaskLinkWithNoOpposite()
+ {
+ $tl = new TaskLink($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $tl->create(1, 2, 1));
+
+ $links = $tl->getAll(1);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('relates to', $links[0]['label']);
+ $this->assertEquals('B', $links[0]['title']);
+ $this->assertEquals(2, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $links = $tl->getAll(2);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('relates to', $links[0]['label']);
+ $this->assertEquals('A', $links[0]['title']);
+ $this->assertEquals(1, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $task_link = $tl->getById(1);
+ $this->assertNotEmpty($task_link);
+ $this->assertEquals(1, $task_link['id']);
+ $this->assertEquals(1, $task_link['task_id']);
+ $this->assertEquals(2, $task_link['opposite_task_id']);
+ $this->assertEquals(1, $task_link['link_id']);
+
+ $opposite_task_link = $tl->getOppositeTaskLink($task_link);
+ $this->assertNotEmpty($opposite_task_link);
+ $this->assertEquals(2, $opposite_task_link['id']);
+ $this->assertEquals(2, $opposite_task_link['task_id']);
+ $this->assertEquals(1, $opposite_task_link['opposite_task_id']);
+ $this->assertEquals(1, $opposite_task_link['link_id']);
+ }
+
+ public function testCreateTaskLinkWithOpposite()
+ {
+ $tl = new TaskLink($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $tl->create(1, 2, 2));
+
+ $links = $tl->getAll(1);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('blocks', $links[0]['label']);
+ $this->assertEquals('B', $links[0]['title']);
+ $this->assertEquals(2, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $links = $tl->getAll(2);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('is blocked by', $links[0]['label']);
+ $this->assertEquals('A', $links[0]['title']);
+ $this->assertEquals(1, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $task_link = $tl->getById(1);
+ $this->assertNotEmpty($task_link);
+ $this->assertEquals(1, $task_link['id']);
+ $this->assertEquals(1, $task_link['task_id']);
+ $this->assertEquals(2, $task_link['opposite_task_id']);
+ $this->assertEquals(2, $task_link['link_id']);
+
+ $opposite_task_link = $tl->getOppositeTaskLink($task_link);
+ $this->assertNotEmpty($opposite_task_link);
+ $this->assertEquals(2, $opposite_task_link['id']);
+ $this->assertEquals(2, $opposite_task_link['task_id']);
+ $this->assertEquals(1, $opposite_task_link['opposite_task_id']);
+ $this->assertEquals(3, $opposite_task_link['link_id']);
+ }
+
+ public function testUpdate()
+ {
+ $tl = new TaskLink($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(2, $p->create(array('name' => 'test2')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $tc->create(array('project_id' => 2, 'title' => 'B')));
+ $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C')));
+
+ $this->assertEquals(1, $tl->create(1, 2, 5));
+ $this->assertTrue($tl->update(1, 1, 3, 11));
+
+ $links = $tl->getAll(1);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('is fixed by', $links[0]['label']);
+ $this->assertEquals('C', $links[0]['title']);
+ $this->assertEquals(3, $links[0]['task_id']);
+
+ $links = $tl->getAll(2);
+ $this->assertEmpty($links);
+
+ $links = $tl->getAll(3);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('fixes', $links[0]['label']);
+ $this->assertEquals('A', $links[0]['title']);
+ $this->assertEquals(1, $links[0]['task_id']);
+ }
+
+ public function testRemove()
+ {
+ $tl = new TaskLink($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $tl->create(1, 2, 2));
+
+ $links = $tl->getAll(1);
+ $this->assertNotEmpty($links);
+ $links = $tl->getAll(2);
+ $this->assertNotEmpty($links);
+
+ $this->assertTrue($tl->remove($links[0]['id']));
+
+ $links = $tl->getAll(1);
+ $this->assertEmpty($links);
+ $links = $tl->getAll(2);
+ $this->assertEmpty($links);
+ }
+
+ public function testValidation()
+ {
+ $tl = new TaskLink($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
+
+ $links = $tl->getAll(1);
+ $this->assertEmpty($links);
+
+ $links = $tl->getAll(2);
+ $this->assertEmpty($links);
+
+ // Check validation
+ $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2));
+ $this->assertTrue($r[0]);
+
+ $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1));
+ $this->assertFalse($r[0]);
+
+ $r = $tl->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
+ $this->assertFalse($r[0]);
+
+ $r = $tl->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2));
+ $this->assertFalse($r[0]);
+
+ $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1));
+ $this->assertFalse($r[0]);
+ }
+}
diff --git a/tests/units/TaskModificationTest.php b/tests/units/TaskModificationTest.php
new file mode 100644
index 00000000..e6d8f8dc
--- /dev/null
+++ b/tests/units/TaskModificationTest.php
@@ -0,0 +1,253 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Task;
+use Model\TaskCreation;
+use Model\TaskModification;
+use Model\TaskFinder;
+use Model\TaskStatus;
+use Model\Project;
+use Model\ProjectPermission;
+
+class TaskModificationTest extends Base
+{
+ public function onCreateUpdate($event)
+ {
+ $this->assertInstanceOf('Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals('Task #1', $event_data['title']);
+ }
+
+ public function onUpdate($event)
+ {
+ $this->assertInstanceOf('Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals('Task #1', $event_data['title']);
+ }
+
+ public function onAssigneeChange($event)
+ {
+ $this->assertInstanceOf('Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals(1, $event_data['owner_id']);
+ }
+
+ public function testChangeTitle()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate'));
+ $this->container['dispatcher']->addListener(Task::EVENT_UPDATE, array($this, 'onUpdate'));
+
+ $this->assertTrue($tm->update(array('id' => 1, 'title' => 'Task #1')));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE.'.TaskModificationTest::onCreateUpdate', $called);
+ $this->assertArrayHasKey(Task::EVENT_UPDATE.'.TaskModificationTest::onUpdate', $called);
+
+ $task = $tf->getById(1);
+ $this->assertEquals('Task #1', $task['title']);
+ }
+
+ public function testChangeAssignee()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['owner_id']);
+
+ $this->container['dispatcher']->addListener(Task::EVENT_ASSIGNEE_CHANGE, array($this, 'onAssigneeChange'));
+
+ $this->assertTrue($tm->update(array('id' => 1, 'owner_id' => 1)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(Task::EVENT_ASSIGNEE_CHANGE.'.TaskModificationTest::onAssigneeChange', $called);
+
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['owner_id']);
+ }
+
+ public function testChangeDescription()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals('', $task['description']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'description' => 'test')));
+
+ $task = $tf->getById(1);
+ $this->assertEquals('test', $task['description']);
+ }
+
+ public function testChangeCategory()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['category_id']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'category_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['category_id']);
+ }
+
+ public function testChangeColor()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals('yellow', $task['color_id']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'color_id' => 'blue')));
+
+ $task = $tf->getById(1);
+ $this->assertEquals('blue', $task['color_id']);
+ }
+
+ public function testChangeScore()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['score']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'score' => 13)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(13, $task['score']);
+ }
+
+ public function testChangeDueDate()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['date_due']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'date_due' => '2014-11-24')));
+
+ $task = $tf->getById(1);
+ $this->assertEquals('2014-11-24', date('Y-m-d', $task['date_due']));
+
+ $this->assertTrue($tm->update(array('id' => 1, 'date_due' => time())));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(date('Y-m-d'), date('Y-m-d', $task['date_due']));
+ }
+
+ public function testChangeStartedDate()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['date_started']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'date_started' => '2014-11-24')));
+
+ $task = $tf->getById(1);
+ $this->assertEquals('2014-11-24', date('Y-m-d', $task['date_started']));
+
+ $this->assertTrue($tm->update(array('id' => 1, 'date_started' => time())));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(date('Y-m-d'), date('Y-m-d', $task['date_started']));
+ }
+
+ public function testChangeTimeEstimated()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['time_estimated']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'time_estimated' => 13.3)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(13.3, $task['time_estimated']);
+ }
+
+ public function testChangeTimeSpent()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $tf = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(0, $task['time_spent']);
+
+ $this->assertTrue($tm->update(array('id' => 1, 'time_spent' => 13.3)));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(13.3, $task['time_spent']);
+ }
+}
diff --git a/tests/units/TaskPermissionTest.php b/tests/units/TaskPermissionTest.php
index 5a94a274..0bf68ce3 100644
--- a/tests/units/TaskPermissionTest.php
+++ b/tests/units/TaskPermissionTest.php
@@ -3,34 +3,37 @@
require_once __DIR__.'/Base.php';
use Model\Task;
+use Model\TaskCreation;
use Model\TaskFinder;
use Model\TaskPermission;
use Model\Project;
use Model\Category;
use Model\User;
+use Model\UserSession;
class TaskPermissionTest extends Base
{
public function testPrepareCreation()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $tp = new TaskPermission($this->registry);
- $p = new Project($this->registry);
- $u = new User($this->registry);
-
- $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456')));
- $this->assertTrue($u->create(array('username' => 'toto2', 'password' => '123456')));
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $tp = new TaskPermission($this->container);
+ $p = new Project($this->container);
+ $u = new User($this->container);
+ $us = new UserSession($this->container);
+
+ $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456')));
+ $this->assertNotFalse($u->create(array('username' => 'toto2', 'password' => '123456')));
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'creator_id' => 1)));
- $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'creator_id' => 2)));
- $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'creator_id' => 3)));
- $this->assertEquals(4, $t->create(array('title' => 'Task #4', 'project_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'creator_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'creator_id' => 2)));
+ $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'creator_id' => 3)));
+ $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1)));
// User #1 can remove everything
$user = $u->getbyId(1);
$this->assertNotEmpty($user);
- $u->updateSession($user);
+ $us->refresh($user);
$task = $tf->getbyId(1);
$this->assertNotEmpty($task);
@@ -39,7 +42,7 @@ class TaskPermissionTest extends Base
// User #2 can't remove the task #1
$user = $u->getbyId(2);
$this->assertNotEmpty($user);
- $u->updateSession($user);
+ $us->refresh($user);
$task = $tf->getbyId(1);
$this->assertNotEmpty($task);
@@ -48,7 +51,7 @@ class TaskPermissionTest extends Base
// User #1 can remove everything
$user = $u->getbyId(1);
$this->assertNotEmpty($user);
- $u->updateSession($user);
+ $us->refresh($user);
$task = $tf->getbyId(2);
$this->assertNotEmpty($task);
@@ -57,7 +60,7 @@ class TaskPermissionTest extends Base
// User #2 can remove his own task
$user = $u->getbyId(2);
$this->assertNotEmpty($user);
- $u->updateSession($user);
+ $us->refresh($user);
$task = $tf->getbyId(2);
$this->assertNotEmpty($task);
@@ -66,7 +69,7 @@ class TaskPermissionTest extends Base
// User #1 can remove everything
$user = $u->getbyId(1);
$this->assertNotEmpty($user);
- $u->updateSession($user);
+ $us->refresh($user);
$task = $tf->getbyId(3);
$this->assertNotEmpty($task);
@@ -75,7 +78,7 @@ class TaskPermissionTest extends Base
// User #2 can't remove the task #3
$user = $u->getbyId(2);
$this->assertNotEmpty($user);
- $u->updateSession($user);
+ $us->refresh($user);
$task = $tf->getbyId(3);
$this->assertNotEmpty($task);
@@ -84,7 +87,7 @@ class TaskPermissionTest extends Base
// User #1 can remove everything
$user = $u->getbyId(1);
$this->assertNotEmpty($user);
- $u->updateSession($user);
+ $us->refresh($user);
$task = $tf->getbyId(4);
$this->assertNotEmpty($task);
@@ -93,7 +96,7 @@ class TaskPermissionTest extends Base
// User #2 can't remove the task #4
$user = $u->getbyId(2);
$this->assertNotEmpty($user);
- $u->updateSession($user);
+ $us->refresh($user);
$task = $tf->getbyId(4);
$this->assertNotEmpty($task);
diff --git a/tests/units/TaskPositionTest.php b/tests/units/TaskPositionTest.php
new file mode 100644
index 00000000..ca7b3bf2
--- /dev/null
+++ b/tests/units/TaskPositionTest.php
@@ -0,0 +1,600 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Task;
+use Model\TaskPosition;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\Project;
+use Model\Swimlane;
+
+class TaskPositionTest extends Base
+{
+ public function testCalculatePositionBadPosition()
+ {
+ $tp = new TaskPosition($this->container);
+ $tc = new TaskCreation($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)));
+
+ $this->assertFalse($tp->calculatePositions(1, 1, 2, 0));
+ }
+
+ public function testCalculatePositionBadColumn()
+ {
+ $tp = new TaskPosition($this->container);
+ $tc = new TaskCreation($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)));
+
+ $this->assertFalse($tp->calculatePositions(1, 1, 10, 1));
+ }
+
+ public function testCalculatePositions()
+ {
+ $tp = new TaskPosition($this->container);
+ $tc = new TaskCreation($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)));
+
+ $positions = $tp->calculatePositions(1, 1, 2, 1);
+ $this->assertNotFalse($positions);
+ $this->assertNotEmpty($positions);
+ $this->assertEmpty($positions[1]);
+ $this->assertEmpty($positions[3]);
+ $this->assertEmpty($positions[4]);
+ $this->assertEquals(array(1), $positions[2]);
+ }
+
+ public function testMoveTaskWithColumnThatNotChange()
+ {
+ $tp = new TaskPosition($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, 'column_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(6, $tc->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(7, $tc->create(array('title' => 'Task #7', 'project_id' => 1, 'column_id' => 3)));
+ $this->assertEquals(8, $tc->create(array('title' => 'Task #8', 'project_id' => 1, 'column_id' => 1)));
+
+ // We move the task 3 to the column 3
+ $this->assertTrue($tp->movePosition(1, 3, 3, 2));
+
+ // Check tasks position
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+
+ $task = $tf->getById(2);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+
+ $task = $tf->getById(3);
+ $this->assertEquals(3, $task['id']);
+ $this->assertEquals(3, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+
+ $task = $tf->getById(4);
+ $this->assertEquals(4, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+
+ $task = $tf->getById(5);
+ $this->assertEquals(5, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+
+ $task = $tf->getById(6);
+ $this->assertEquals(6, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(3, $task['position']);
+
+ $task = $tf->getById(7);
+ $this->assertEquals(7, $task['id']);
+ $this->assertEquals(3, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+
+ $task = $tf->getById(8);
+ $this->assertEquals(8, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(3, $task['position']);
+ }
+
+ public function testMoveTaskWithBadPreviousPosition()
+ {
+ $tp = new TaskPosition($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, $this->container['db']->table('tasks')->insert(array('title' => 'A', 'column_id' => 1, 'project_id' => 1, 'position' => 1)));
+
+ // Both tasks have the same position
+ $this->assertEquals(2, $this->container['db']->table('tasks')->insert(array('title' => 'B', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
+ $this->assertEquals(3, $this->container['db']->table('tasks')->insert(array('title' => 'C', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
+
+ // Move the first column to the last position of the 2nd column
+ $this->assertTrue($tp->movePosition(1, 1, 2, 3));
+
+ // Check tasks position
+ $task = $tf->getById(2);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+
+ $task = $tf->getById(3);
+ $this->assertEquals(3, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(3, $task['position']);
+ }
+
+ public function testMoveTaskTop()
+ {
+ $tp = new TaskPosition($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, 'column_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
+
+ // Move the last task to the top
+ $this->assertTrue($tp->movePosition(1, 4, 1, 1));
+
+ // Check tasks position
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+
+ $task = $tf->getById(2);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(3, $task['position']);
+
+ $task = $tf->getById(3);
+ $this->assertEquals(3, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(4, $task['position']);
+
+ $task = $tf->getById(4);
+ $this->assertEquals(4, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ }
+
+ public function testMoveTaskBottom()
+ {
+ $tp = new TaskPosition($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, 'column_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
+
+ // Move the last task to the bottom
+ $this->assertTrue($tp->movePosition(1, 1, 1, 4));
+
+ // Check tasks position
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(4, $task['position']);
+
+ $task = $tf->getById(2);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+
+ $task = $tf->getById(3);
+ $this->assertEquals(3, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+
+ $task = $tf->getById(4);
+ $this->assertEquals(4, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(3, $task['position']);
+ }
+
+ public function testMovePosition()
+ {
+ $tp = new TaskPosition($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')));
+ $counter = 1;
+ $task_per_column = 5;
+
+ foreach (array(1, 2, 3, 4) as $column_id) {
+
+ for ($i = 1; $i <= $task_per_column; $i++, $counter++) {
+
+ $task = array(
+ 'title' => 'Task #'.$i.'-'.$column_id,
+ 'project_id' => 1,
+ 'column_id' => $column_id,
+ 'owner_id' => 0,
+ );
+
+ $this->assertEquals($counter, $tc->create($task));
+
+ $task = $tf->getById($counter);
+ $this->assertNotFalse($task);
+ $this->assertNotEmpty($task);
+ $this->assertEquals($i, $task['position']);
+ }
+ }
+
+ // We move task id #4, column 1, position 4 to the column 2, position 3
+ $this->assertTrue($tp->movePosition(1, 4, 2, 3));
+
+ // We check the new position of the task
+ $task = $tf->getById(4);
+ $this->assertEquals(4, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(3, $task['position']);
+
+ // The tasks before have the correct position
+ $task = $tf->getById(3);
+ $this->assertEquals(3, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(3, $task['position']);
+
+ $task = $tf->getById(7);
+ $this->assertEquals(7, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+
+ // The tasks after have the correct position
+ $task = $tf->getById(5);
+ $this->assertEquals(5, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(4, $task['position']);
+
+ $task = $tf->getById(8);
+ $this->assertEquals(8, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(4, $task['position']);
+
+ // The number of tasks per column
+ $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column, $tf->countByColumnId(1, 4));
+
+ // We move task id #1, column 1, position 1 to the column 4, position 6 (last position)
+ $this->assertTrue($tp->movePosition(1, 1, 4, $task_per_column + 1));
+
+ // We check the new position of the task
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(4, $task['column_id']);
+ $this->assertEquals($task_per_column + 1, $task['position']);
+
+ // The tasks before have the correct position
+ $task = $tf->getById(20);
+ $this->assertEquals(20, $task['id']);
+ $this->assertEquals(4, $task['column_id']);
+ $this->assertEquals($task_per_column, $task['position']);
+
+ // The tasks after have the correct position
+ $task = $tf->getById(2);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+
+ // The number of tasks per column
+ $this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
+
+ // Our previous moved task should stay at the same place
+ $task = $tf->getById(4);
+ $this->assertEquals(4, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(3, $task['position']);
+
+ // Test wrong position number
+ $this->assertFalse($tp->movePosition(1, 2, 3, 0));
+ $this->assertFalse($tp->movePosition(1, 2, 3, -2));
+
+ // Wrong column
+ $this->assertFalse($tp->movePosition(1, 2, 22, 2));
+
+ // Test position greater than the last position
+ $this->assertTrue($tp->movePosition(1, 11, 1, 22));
+
+ $task = $tf->getById(11);
+ $this->assertEquals(11, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals($tf->countByColumnId(1, 1), $task['position']);
+
+ $task = $tf->getById(5);
+ $this->assertEquals(5, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals($tf->countByColumnId(1, 1) - 1, $task['position']);
+
+ $task = $tf->getById(4);
+ $this->assertEquals(4, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(3, $task['position']);
+
+ $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
+
+ // Our previous moved task should stay at the same place
+ $task = $tf->getById(4);
+ $this->assertEquals(4, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(3, $task['position']);
+
+ // Test moving task to position 1
+ $this->assertTrue($tp->movePosition(1, 14, 1, 1));
+
+ $task = $tf->getById(14);
+ $this->assertEquals(14, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+
+ $task = $tf->getById(2);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+
+ $this->assertEquals($task_per_column, $tf->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
+ }
+
+ public function testMoveTaskSwimlane()
+ {
+ $tp = new TaskPosition($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $s->create(1, 'test 1'));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 1)));
+
+ // Move the task to the swimlane
+ $this->assertTrue($tp->movePosition(1, 1, 2, 1, 1));
+
+ // Check tasks position
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['swimlane_id']);
+
+ $task = $tf->getById(2);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(0, $task['swimlane_id']);
+
+ $task = $tf->getById(3);
+ $this->assertEquals(3, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+ $this->assertEquals(0, $task['swimlane_id']);
+
+ $task = $tf->getById(4);
+ $this->assertEquals(4, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(3, $task['position']);
+ $this->assertEquals(0, $task['swimlane_id']);
+
+ // Move the task to the swimlane
+ $this->assertTrue($tp->movePosition(1, 2, 2, 1, 1));
+
+ // Check tasks position
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+ $this->assertEquals(1, $task['swimlane_id']);
+
+ $task = $tf->getById(2);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['swimlane_id']);
+
+ $task = $tf->getById(3);
+ $this->assertEquals(3, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(0, $task['swimlane_id']);
+
+ $task = $tf->getById(4);
+ $this->assertEquals(4, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+ $this->assertEquals(0, $task['swimlane_id']);
+
+ // Move the task 5 to the last column
+ $this->assertTrue($tp->movePosition(1, 5, 4, 1, 0));
+
+ // Check tasks position
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+ $this->assertEquals(1, $task['swimlane_id']);
+
+ $task = $tf->getById(2);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['swimlane_id']);
+
+ $task = $tf->getById(3);
+ $this->assertEquals(3, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(0, $task['swimlane_id']);
+
+ $task = $tf->getById(4);
+ $this->assertEquals(4, $task['id']);
+ $this->assertEquals(1, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+ $this->assertEquals(0, $task['swimlane_id']);
+
+ $task = $tf->getById(5);
+ $this->assertEquals(5, $task['id']);
+ $this->assertEquals(4, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(0, $task['swimlane_id']);
+ }
+
+ public function testEvents()
+ {
+ $tp = new TaskPosition($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
+ $s = new Swimlane($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $s->create(1, 'test 1'));
+
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2)));
+
+ $this->container['dispatcher']->addListener(Task::EVENT_MOVE_COLUMN, array($this, 'onMoveColumn'));
+ $this->container['dispatcher']->addListener(Task::EVENT_MOVE_POSITION, array($this, 'onMovePosition'));
+ $this->container['dispatcher']->addListener(Task::EVENT_MOVE_SWIMLANE, array($this, 'onMoveSwimlane'));
+
+ // We move the task 1 to the column 2
+ $this->assertTrue($tp->movePosition(1, 1, 2, 1));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+
+ $task = $tf->getById(2);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN.'.TaskPositionTest::onMoveColumn', $called);
+ $this->assertEquals(1, count($called));
+
+ // We move the task 1 to the position 2
+ $this->assertTrue($tp->movePosition(1, 1, 2, 2));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+
+ $task = $tf->getById(2);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(Task::EVENT_MOVE_POSITION.'.TaskPositionTest::onMovePosition', $called);
+ $this->assertEquals(2, count($called));
+
+ // Move to another swimlane
+ $this->assertTrue($tp->movePosition(1, 1, 3, 1, 1));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(3, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['swimlane_id']);
+
+ $task = $tf->getById(2);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(0, $task['swimlane_id']);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(Task::EVENT_MOVE_SWIMLANE.'.TaskPositionTest::onMoveSwimlane', $called);
+ $this->assertEquals(3, count($called));
+ }
+
+ public function onMoveColumn($event)
+ {
+ $this->assertInstanceOf('Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals(1, $event_data['position']);
+ $this->assertEquals(2, $event_data['column_id']);
+ $this->assertEquals(1, $event_data['project_id']);
+ }
+
+ public function onMovePosition($event)
+ {
+ $this->assertInstanceOf('Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals(2, $event_data['position']);
+ $this->assertEquals(2, $event_data['column_id']);
+ $this->assertEquals(1, $event_data['project_id']);
+ }
+
+ public function onMoveSwimlane($event)
+ {
+ $this->assertInstanceOf('Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals(1, $event_data['position']);
+ $this->assertEquals(3, $event_data['column_id']);
+ $this->assertEquals(1, $event_data['project_id']);
+ $this->assertEquals(1, $event_data['swimlane_id']);
+ }
+}
diff --git a/tests/units/TaskStatusTest.php b/tests/units/TaskStatusTest.php
new file mode 100644
index 00000000..b62ae560
--- /dev/null
+++ b/tests/units/TaskStatusTest.php
@@ -0,0 +1,77 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Task;
+use Model\TaskCreation;
+use Model\TaskFinder;
+use Model\TaskStatus;
+use Model\Project;
+use Model\ProjectPermission;
+
+class TaskStatusTest extends Base
+{
+ public function testStatus()
+ {
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $ts = new TaskStatus($this->container);
+ $p = new Project($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
+
+ // The task must be open
+
+ $this->assertTrue($ts->isOpen(1));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
+ $this->assertEquals(0, $task['date_completed']);
+ $this->assertEquals(time(), $task['date_modification']);
+
+ // We close the task
+
+ $this->container['dispatcher']->addListener(Task::EVENT_CLOSE, array($this, 'onTaskClose'));
+ $this->container['dispatcher']->addListener(Task::EVENT_OPEN, array($this, 'onTaskOpen'));
+
+ $this->assertTrue($ts->close(1));
+ $this->assertTrue($ts->isClosed(1));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(Task::STATUS_CLOSED, $task['is_active']);
+ $this->assertEquals(time(), $task['date_completed'], 'Bad completion timestamp', 1);
+ $this->assertEquals(time(), $task['date_modification'], 'Bad modification timestamp', 1);
+
+ // We open the task again
+
+ $this->assertTrue($ts->open(1));
+ $this->assertTrue($ts->isOpen(1));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
+ $this->assertEquals(0, $task['date_completed']);
+ $this->assertEquals(time(), $task['date_modification'], 1);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey('task.close.TaskStatusTest::onTaskClose', $called);
+ $this->assertArrayHasKey('task.open.TaskStatusTest::onTaskOpen', $called);
+ }
+
+ public function onTaskOpen($event)
+ {
+ $this->assertInstanceOf('Event\TaskEvent', $event);
+ $this->assertArrayHasKey('task_id', $event);
+ $this->assertNotEmpty($event['task_id']);
+ }
+
+ public function onTaskClose($event)
+ {
+ $this->assertInstanceOf('Event\TaskEvent', $event);
+ $this->assertArrayHasKey('task_id', $event);
+ $this->assertNotEmpty($event['task_id']);
+ }
+}
diff --git a/tests/units/TaskTest.php b/tests/units/TaskTest.php
index e82faf19..d9c0fa4f 100644
--- a/tests/units/TaskTest.php
+++ b/tests/units/TaskTest.php
@@ -3,7 +3,9 @@
require_once __DIR__.'/Base.php';
use Model\Task;
+use Model\TaskCreation;
use Model\TaskFinder;
+use Model\TaskStatus;
use Model\Project;
use Model\ProjectPermission;
use Model\Category;
@@ -11,637 +13,17 @@ use Model\User;
class TaskTest extends Base
{
- public function testPrepareCreation()
- {
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
-
- $input = array(
- 'title' => 'youpi',
- 'description' => '',
- 'project_id' => '1',
- 'owner_id' => '0',
- 'category_id' => '0',
- 'column_id' => '2',
- 'color_id' => 'yellow',
- 'score' => '',
- 'date_due' => '',
- 'creator_id' => '1',
- 'another_task' => '1',
- );
-
- $t->prepareCreation($input);
-
- $this->assertInternalType('integer', $input['date_due']);
- $this->assertEquals(0, $input['date_due']);
-
- $this->assertInternalType('integer', $input['score']);
- $this->assertEquals(0, $input['score']);
-
- $this->assertArrayNotHasKey('another_task', $input);
-
- $this->assertArrayHasKey('date_creation', $input);
- $this->assertEquals(time(), $input['date_creation']);
-
- $this->assertArrayHasKey('date_modification', $input);
- $this->assertEquals(time(), $input['date_modification']);
-
- $this->assertArrayHasKey('position', $input);
- $this->assertGreaterThan(0, $input['position']);
-
- $input = array(
- 'title' => 'youpi',
- 'project_id' => '1',
- );
-
- $t->prepareCreation($input);
-
- $this->assertArrayNotHasKey('date_due', $input);
- $this->assertArrayNotHasKey('score', $input);
-
- $this->assertArrayHasKey('date_creation', $input);
- $this->assertEquals(time(), $input['date_creation']);
-
- $this->assertArrayHasKey('date_modification', $input);
- $this->assertEquals(time(), $input['date_modification']);
-
- $this->assertArrayHasKey('position', $input);
- $this->assertGreaterThan(0, $input['position']);
-
- $this->assertArrayHasKey('color_id', $input);
- $this->assertEquals('yellow', $input['color_id']);
-
- $this->assertArrayHasKey('column_id', $input);
- $this->assertEquals(1, $input['column_id']);
-
- $input = array(
- 'title' => 'youpi',
- 'project_id' => '1',
- 'date_due' => '2014-09-15',
- );
-
- $t->prepareCreation($input);
-
- $this->assertArrayHasKey('date_due', $input);
- $this->assertInternalType('integer', $input['date_due']);
- $this->assertEquals('2014-09-15', date('Y-m-d', $input['date_due']));
- }
-
- public function testPrepareModification()
- {
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
-
- $input = array(
- 'id' => '1',
- 'description' => 'Boo',
- );
-
- $t->prepareModification($input);
-
- $this->assertArrayNotHasKey('id', $input);
- $this->assertArrayHasKey('date_modification', $input);
- $this->assertEquals(time(), $input['date_modification']);
- }
-
- public function testCreation()
- {
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
-
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals('yellow', $task['color_id']);
- $this->assertEquals(time(), $task['date_creation']);
- $this->assertEquals(time(), $task['date_modification']);
- $this->assertEquals(0, $task['date_due']);
-
- $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1)));
-
- $task = $tf->getById(2);
- $this->assertEquals(2, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(2, $task['position']);
- $this->assertEquals(time(), $task['date_creation']);
- $this->assertEquals(time(), $task['date_modification']);
- $this->assertEquals(0, $task['date_due']);
-
- $tasks = $tf->getAll(1, 1);
- $this->assertNotEmpty($tasks);
- $this->assertTrue(is_array($tasks));
- $this->assertEquals(1, $tasks[0]['id']);
- $this->assertEquals(2, $tasks[1]['id']);
-
- $tasks = $tf->getAll(1, 0);
- $this->assertEmpty($tasks);
- }
-
public function testRemove()
{
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $t = new Task($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
$this->assertTrue($t->remove(1));
$this->assertFalse($t->remove(1234));
}
-
- public function testMoveTaskWithColumnThatNotChange()
- {
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
-
- $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(4, $t->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 2)));
- $this->assertEquals(5, $t->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 2)));
- $this->assertEquals(6, $t->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 2)));
- $this->assertEquals(7, $t->create(array('title' => 'Task #7', 'project_id' => 1, 'column_id' => 3)));
- $this->assertEquals(8, $t->create(array('title' => 'Task #8', 'project_id' => 1, 'column_id' => 1)));
-
- // We move the task 3 to the column 3
- $this->assertTrue($t->movePosition(1, 3, 3, 2));
-
- // Check tasks position
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(1, $task['position']);
-
- $task = $tf->getById(2);
- $this->assertEquals(2, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(2, $task['position']);
-
- $task = $tf->getById(3);
- $this->assertEquals(3, $task['id']);
- $this->assertEquals(3, $task['column_id']);
- $this->assertEquals(2, $task['position']);
-
- $task = $tf->getById(4);
- $this->assertEquals(4, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(1, $task['position']);
-
- $task = $tf->getById(5);
- $this->assertEquals(5, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(2, $task['position']);
-
- $task = $tf->getById(6);
- $this->assertEquals(6, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(3, $task['position']);
-
- $task = $tf->getById(7);
- $this->assertEquals(7, $task['id']);
- $this->assertEquals(3, $task['column_id']);
- $this->assertEquals(1, $task['position']);
-
- $task = $tf->getById(8);
- $this->assertEquals(8, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(3, $task['position']);
- }
-
- public function testMoveTaskWithBadPreviousPosition()
- {
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $this->registry->shared('db')->table('tasks')->insert(array('title' => 'A', 'column_id' => 1, 'project_id' => 1, 'position' => 1)));
-
- // Both tasks have the same position
- $this->assertEquals(2, $this->registry->shared('db')->table('tasks')->insert(array('title' => 'B', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
- $this->assertEquals(3, $this->registry->shared('db')->table('tasks')->insert(array('title' => 'C', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
-
- // Move the first column to the last position of the 2nd column
- $this->assertTrue($t->movePosition(1, 1, 2, 3));
-
- // Check tasks position
- $task = $tf->getById(2);
- $this->assertEquals(2, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(1, $task['position']);
-
- $task = $tf->getById(3);
- $this->assertEquals(3, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(2, $task['position']);
-
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(3, $task['position']);
- }
-
- public function testMoveTaskTop()
- {
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(4, $t->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
-
- // Move the last task to the top
- $this->assertTrue($t->movePosition(1, 4, 1, 1));
-
- // Check tasks position
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(2, $task['position']);
-
- $task = $tf->getById(2);
- $this->assertEquals(2, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(3, $task['position']);
-
- $task = $tf->getById(3);
- $this->assertEquals(3, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(4, $task['position']);
-
- $task = $tf->getById(4);
- $this->assertEquals(4, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- }
-
- public function testMoveTaskBottom()
- {
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(2, $t->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(3, $t->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(4, $t->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
-
- // Move the last task to hte top
- $this->assertTrue($t->movePosition(1, 1, 1, 4));
-
- // Check tasks position
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(4, $task['position']);
-
- $task = $tf->getById(2);
- $this->assertEquals(2, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(1, $task['position']);
-
- $task = $tf->getById(3);
- $this->assertEquals(3, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(2, $task['position']);
-
- $task = $tf->getById(4);
- $this->assertEquals(4, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(3, $task['position']);
- }
-
- public function testMovePosition()
- {
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $counter = 1;
- $task_per_column = 5;
-
- foreach (array(1, 2, 3, 4) as $column_id) {
-
- for ($i = 1; $i <= $task_per_column; $i++, $counter++) {
-
- $task = array(
- 'title' => 'Task #'.$i.'-'.$column_id,
- 'project_id' => 1,
- 'column_id' => $column_id,
- 'owner_id' => 0,
- );
-
- $this->assertEquals($counter, $t->create($task));
-
- $task = $tf->getById($counter);
- $this->assertNotFalse($task);
- $this->assertNotEmpty($task);
- $this->assertEquals($i, $task['position']);
- }
- }
-
- // We move task id #4, column 1, position 4 to the column 2, position 3
- $this->assertTrue($t->movePosition(1, 4, 2, 3));
-
- // We check the new position of the task
- $task = $tf->getById(4);
- $this->assertEquals(4, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(3, $task['position']);
-
- // The tasks before have the correct position
- $task = $tf->getById(3);
- $this->assertEquals(3, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(3, $task['position']);
-
- $task = $tf->getById(7);
- $this->assertEquals(7, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(2, $task['position']);
-
- // The tasks after have the correct position
- $task = $tf->getById(5);
- $this->assertEquals(5, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(4, $task['position']);
-
- $task = $tf->getById(8);
- $this->assertEquals(8, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(4, $task['position']);
-
- // The number of tasks per column
- $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
- $this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
- $this->assertEquals($task_per_column, $tf->countByColumnId(1, 4));
-
- // We move task id #1, column 1, position 1 to the column 4, position 6 (last position)
- $this->assertTrue($t->movePosition(1, 1, 4, $task_per_column + 1));
-
- // We check the new position of the task
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(4, $task['column_id']);
- $this->assertEquals($task_per_column + 1, $task['position']);
-
- // The tasks before have the correct position
- $task = $tf->getById(20);
- $this->assertEquals(20, $task['id']);
- $this->assertEquals(4, $task['column_id']);
- $this->assertEquals($task_per_column, $task['position']);
-
- // The tasks after have the correct position
- $task = $tf->getById(2);
- $this->assertEquals(2, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(1, $task['position']);
-
- // The number of tasks per column
- $this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
- $this->assertEquals($task_per_column, $tf->countByColumnId(1, 3));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
-
- // Our previous moved task should stay at the same place
- $task = $tf->getById(4);
- $this->assertEquals(4, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(3, $task['position']);
-
- // Test wrong position number
- $this->assertFalse($t->movePosition(1, 2, 3, 0));
- $this->assertFalse($t->movePosition(1, 2, 3, -2));
-
- // Wrong column
- $this->assertFalse($t->movePosition(1, 2, 22, 2));
-
- // Test position greater than the last position
- $this->assertTrue($t->movePosition(1, 11, 1, 22));
-
- $task = $tf->getById(11);
- $this->assertEquals(11, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals($tf->countByColumnId(1, 1), $task['position']);
-
- $task = $tf->getById(5);
- $this->assertEquals(5, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals($tf->countByColumnId(1, 1) - 1, $task['position']);
-
- $task = $tf->getById(4);
- $this->assertEquals(4, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(3, $task['position']);
-
- $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
- $this->assertEquals($task_per_column - 1, $tf->countByColumnId(1, 3));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
-
- // Our previous moved task should stay at the same place
- $task = $tf->getById(4);
- $this->assertEquals(4, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(3, $task['position']);
-
- // Test moving task to position 1
- $this->assertTrue($t->movePosition(1, 14, 1, 1));
-
- $task = $tf->getById(14);
- $this->assertEquals(14, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(1, $task['position']);
-
- $task = $tf->getById(2);
- $this->assertEquals(2, $task['id']);
- $this->assertEquals(1, $task['column_id']);
- $this->assertEquals(2, $task['position']);
-
- $this->assertEquals($task_per_column, $tf->countByColumnId(1, 1));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 2));
- $this->assertEquals($task_per_column - 2, $tf->countByColumnId(1, 3));
- $this->assertEquals($task_per_column + 1, $tf->countByColumnId(1, 4));
- }
-
- public function testDuplicateToTheSameProject()
- {
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $c = new Category($this->registry);
-
- // We create a task and a project
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
-
- // Some categories
- $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
- $this->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 1)));
- $this->assertTrue($c->exists(1, 1));
- $this->assertTrue($c->exists(2, 1));
-
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2)));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['position']);
-
- // We duplicate our task
- $this->assertEquals(2, $t->duplicateToSameProject($task));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(Task::STATUS_OPEN, $task['is_active']);
- $this->assertEquals(1, $task['project_id']);
- $this->assertEquals(1, $task['owner_id']);
- $this->assertEquals(2, $task['category_id']);
- $this->assertEquals(3, $task['column_id']);
- $this->assertEquals(2, $task['position']);
- }
-
- public function testDuplicateToAnotherProject()
- {
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $c = new Category($this->registry);
-
- // We create 2 projects
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- $this->assertNotFalse($c->create(array('name' => 'Category #1', 'project_id' => 1)));
- $this->assertTrue($c->exists(1, 1));
-
- // We create a task
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1, 'category_id' => 1)));
- $task = $tf->getById(1);
-
- // We duplicate our task to the 2nd project
- $this->assertEquals(2, $t->duplicateToAnotherProject(2, $task));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['owner_id']);
- $this->assertEquals(0, $task['category_id']);
- $this->assertEquals(5, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testMoveToAnotherProject()
- {
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $pp = new ProjectPermission($this->registry);
- $user = new User($this->registry);
-
- // We create a regular user
- $user->create(array('username' => 'unittest1', 'password' => 'unittest'));
- $user->create(array('username' => 'unittest2', 'password' => 'unittest'));
-
- // We create 2 projects
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
-
- // We create a task
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333)));
- $this->assertEquals(2, $t->create(array('title' => 'test2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3, 'category_id' => 10, 'position' => 333)));
-
- // We duplicate our task to the 2nd project
- $task = $tf->getById(1);
- $this->assertEquals(1, $t->moveToAnotherProject(2, $task));
- //$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
-
- // Check the values of the duplicated task
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['owner_id']);
- $this->assertEquals(0, $task['category_id']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals(5, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals('test', $task['title']);
-
- // We allow only one user on the second project
- $this->assertTrue($pp->allowUser(2, 2));
-
- // The owner should be reseted
- $task = $tf->getById(2);
- $this->assertEquals(2, $t->moveToAnotherProject(2, $task));
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['owner_id']);
- }
-
- public function testEvents()
- {
- $t = new Task($this->registry);
- $p = new Project($this->registry);
-
- // We create a project
- $this->assertEquals(1, $p->create(array('name' => 'test')));
-
- // We create task
- $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE));
-
- // We update a task
- $this->assertTrue($t->update(array('title' => 'test2', 'id' => 1)));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_UPDATE));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CREATE_UPDATE));
-
- // We close our task
- $this->assertTrue($t->close(1));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_CLOSE));
-
- // We open our task
- $this->assertTrue($t->open(1));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_OPEN));
-
- // We change the column of our task
- $this->assertTrue($t->movePosition(1, 1, 2, 1));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
-
- // We change the position of our task
- $this->assertEquals(2, $t->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 2)));
- $this->assertTrue($t->movePosition(1, 1, 2, 2));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_POSITION));
-
- // We change the column and the position of our task
- $this->assertTrue($t->movePosition(1, 1, 1, 1));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_COLUMN));
-
- // We change the assignee
- $this->assertTrue($t->update(array('owner_id' => 1, 'id' => 1)));
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_ASSIGNEE_CHANGE));
- }
}
diff --git a/tests/units/TextHelperTest.php b/tests/units/TextHelperTest.php
new file mode 100644
index 00000000..20b89fa8
--- /dev/null
+++ b/tests/units/TextHelperTest.php
@@ -0,0 +1,64 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Helper\Text;
+
+class TextHelperTest extends Base
+{
+ public function testMarkdown()
+ {
+ $h = new Text($this->container);
+
+ $this->assertEquals('<p>Test</p>', $h->markdown('Test'));
+
+ $this->assertEquals(
+ '<p>Task #123</p>',
+ $h->markdown('Task #123')
+ );
+
+ $this->assertEquals(
+ '<p>Task <a href="?controller=a&amp;action=b&amp;c=d&amp;task_id=123">#123</a></p>',
+ $h->markdown('Task #123', array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd')))
+ );
+
+ $this->assertEquals(
+ '<p>Check that: <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454">http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454</a></p>',
+ $h->markdown(
+ 'Check that: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454',
+ array('controller' => 'a', 'action' => 'b', 'params' => array('c' => 'd'))
+ )
+ );
+ }
+
+ public function testFormatBytes()
+ {
+ $h = new Text($this->container);
+
+ $this->assertEquals('1k', $h->bytes(1024));
+ $this->assertEquals('33.71k', $h->bytes(34520));
+ }
+
+ public function testTruncate()
+ {
+ $h = new Text($this->container);
+
+ $this->assertEquals('abc', $h->truncate('abc'));
+ $this->assertEquals(str_repeat('a', 85).' [...]', $h->truncate(str_repeat('a', 200)));
+ }
+
+ public function testContains()
+ {
+ $h = new Text($this->container);
+
+ $this->assertTrue($h->contains('abc', 'b'));
+ $this->assertFalse($h->contains('abc', 'd'));
+ }
+
+ public function testInList()
+ {
+ $h = new Text($this->container);
+ $this->assertEquals('?', $h->in('a', array('b' => 'c')));
+ $this->assertEquals('c', $h->in('b', array('b' => 'c')));
+ }
+}
diff --git a/tests/units/TimeTrackingTest.php b/tests/units/TimeTrackingTest.php
deleted file mode 100644
index aa772a36..00000000
--- a/tests/units/TimeTrackingTest.php
+++ /dev/null
@@ -1,46 +0,0 @@
-<?php
-
-require_once __DIR__.'/Base.php';
-
-use Model\SubTask;
-use Model\Task;
-use Model\TaskFinder;
-use Model\Project;
-use Model\TimeTracking;
-
-class TimeTrackingTest extends Base
-{
- public function testCalculateTime()
- {
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
- $s = new SubTask($this->registry);
- $ts = new TimeTracking($this->registry);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'time_estimated' => 4.5)));
- $this->assertTrue($t->update(array('id' => 1, 'time_spent' => 3.5)));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(4.5, $task['time_estimated']);
- $this->assertEquals(3.5, $task['time_spent']);
-
- $timesheet = $ts->getTaskTimesheet($task, array());
- $this->assertNotEmpty($timesheet);
- $this->assertEquals(4.5, $timesheet['time_estimated']);
- $this->assertEquals(3.5, $timesheet['time_spent']);
- $this->assertEquals(1, $timesheet['time_remaining']);
-
- // Subtasks calculation
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5.5, 'time_spent' => 3)));
- $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => 4)));
-
- $timesheet = $ts->getTaskTimesheet($task, $s->getAll(1));
- $this->assertNotEmpty($timesheet);
- $this->assertEquals(5.5, $timesheet['time_estimated']);
- $this->assertEquals(7, $timesheet['time_spent']);
- $this->assertEquals(-1.5, $timesheet['time_remaining']);
- }
-}
diff --git a/tests/units/TimetableTest.php b/tests/units/TimetableTest.php
new file mode 100644
index 00000000..9c40dce1
--- /dev/null
+++ b/tests/units/TimetableTest.php
@@ -0,0 +1,256 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\User;
+use Model\Timetable;
+use Model\TimetableDay;
+use Model\TimetableWeek;
+use Model\TimetableOff;
+use Model\TimetableExtra;
+
+class TimetableTest extends Base
+{
+ public function testCalculateWorkDays()
+ {
+ $w = new TimetableWeek($this->container);
+ $t = new Timetable($this->container);
+
+ $this->assertNotFalse($w->create(1, 1, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 1, '13:00', '17:00'));
+ $this->assertNotFalse($w->create(1, 2, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 2, '13:00', '17:00'));
+
+ $monday = new DateTime('next Monday');
+
+ $timetable = $t->calculate(1, $monday, new DateTime('next Monday + 6 days'));
+ $this->assertNotEmpty($timetable);
+ $this->assertCount(4, $timetable);
+
+ $this->assertEquals($monday->format('Y-m-d').' 09:30', $timetable[0][0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 12:00', $timetable[0][1]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 13:00', $timetable[1][0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 17:00', $timetable[1][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($monday->add(new DateInterval('P1D'))->format('Y-m-d').' 09:30', $timetable[2][0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 12:00', $timetable[2][1]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 13:00', $timetable[3][0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 17:00', $timetable[3][1]->format('Y-m-d H:i'));
+ }
+
+ public function testCalculateOverTime()
+ {
+ $d = new TimetableDay($this->container);
+ $w = new TimetableWeek($this->container);
+ $e = new TimetableExtra($this->container);
+ $t = new Timetable($this->container);
+
+ $monday = new DateTime('next Monday');
+ $tuesday = new DateTime('next Monday + 1 day');
+ $friday = new DateTime('next Monday + 4 days');
+
+ $this->assertNotFalse($d->create(1, '08:00', '12:00'));
+ $this->assertNotFalse($d->create(1, '14:00', '18:00'));
+
+ $this->assertNotFalse($w->create(1, 1, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 1, '13:00', '17:00'));
+ $this->assertNotFalse($w->create(1, 2, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 2, '13:00', '17:00'));
+
+ $this->assertNotFalse($e->create(1, $tuesday->format('Y-m-d'), 0, '17:00', '22:00'));
+ $this->assertNotFalse($e->create(1, $friday->format('Y-m-d'), 1));
+
+ $timetable = $t->calculate(1, $monday, new DateTime('next Monday + 6 days'));
+ $this->assertNotEmpty($timetable);
+ $this->assertCount(7, $timetable);
+
+ $this->assertEquals($monday->format('Y-m-d').' 09:30', $timetable[0][0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 12:00', $timetable[0][1]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 13:00', $timetable[1][0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 17:00', $timetable[1][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($tuesday->format('Y-m-d').' 09:30', $timetable[2][0]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 12:00', $timetable[2][1]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 13:00', $timetable[3][0]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 17:00', $timetable[3][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($tuesday->format('Y-m-d').' 17:00', $timetable[4][0]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 22:00', $timetable[4][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($friday->format('Y-m-d').' 08:00', $timetable[5][0]->format('Y-m-d H:i'));
+ $this->assertEquals($friday->format('Y-m-d').' 12:00', $timetable[5][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($friday->format('Y-m-d').' 14:00', $timetable[6][0]->format('Y-m-d H:i'));
+ $this->assertEquals($friday->format('Y-m-d').' 18:00', $timetable[6][1]->format('Y-m-d H:i'));
+ }
+
+ public function testCalculateTimeOff()
+ {
+ $d = new TimetableDay($this->container);
+ $w = new TimetableWeek($this->container);
+ $o = new TimetableOff($this->container);
+ $t = new Timetable($this->container);
+
+ $monday = new DateTime('next Monday');
+ $tuesday = new DateTime('next Monday + 1 day');
+ $friday = new DateTime('next Monday + 4 days');
+
+ $this->assertNotFalse($d->create(1, '08:00', '12:00'));
+ $this->assertNotFalse($d->create(1, '14:00', '18:00'));
+
+ $this->assertNotFalse($w->create(1, 1, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 1, '13:00', '17:00'));
+ $this->assertNotFalse($w->create(1, 2, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 2, '13:00', '17:00'));
+ $this->assertNotFalse($w->create(1, 5, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 5, '13:00', '17:00'));
+
+ $this->assertNotFalse($o->create(1, $tuesday->format('Y-m-d'), 0, '14:00', '15:00'));
+ $this->assertNotFalse($o->create(1, $monday->format('Y-m-d'), 1));
+
+ $timetable = $t->calculate(1, $monday, new DateTime('next Monday + 6 days'));
+ $this->assertNotEmpty($timetable);
+ $this->assertCount(5, $timetable);
+
+ $this->assertEquals($tuesday->format('Y-m-d').' 09:30', $timetable[0][0]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 12:00', $timetable[0][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($tuesday->format('Y-m-d').' 13:00', $timetable[1][0]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 14:00', $timetable[1][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($tuesday->format('Y-m-d').' 15:00', $timetable[2][0]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 17:00', $timetable[2][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($friday->format('Y-m-d').' 09:30', $timetable[3][0]->format('Y-m-d H:i'));
+ $this->assertEquals($friday->format('Y-m-d').' 12:00', $timetable[3][1]->format('Y-m-d H:i'));
+
+ $this->assertEquals($friday->format('Y-m-d').' 13:00', $timetable[4][0]->format('Y-m-d H:i'));
+ $this->assertEquals($friday->format('Y-m-d').' 17:00', $timetable[4][1]->format('Y-m-d H:i'));
+ }
+
+ public function testClosestTimeSlot()
+ {
+ $w = new TimetableWeek($this->container);
+ $t = new Timetable($this->container);
+
+ $this->assertNotFalse($w->create(1, 1, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 1, '13:00', '17:00'));
+ $this->assertNotFalse($w->create(1, 2, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 2, '13:00', '17:00'));
+
+ $monday = new DateTime('next Monday');
+ $tuesday = new DateTime('next Monday + 1 day');
+
+ $timetable = $t->calculate(1, new DateTime('next Monday'), new DateTime('next Monday + 6 days'));
+ $this->assertNotEmpty($timetable);
+ $this->assertCount(4, $timetable);
+
+ // Start to work before timetable
+ $date = clone($monday);
+ $date->setTime(5, 02);
+
+ $slot = $t->findClosestTimeSlot($date, $timetable);
+ $this->assertNotEmpty($slot);
+ $this->assertEquals($monday->format('Y-m-d').' 09:30', $slot[0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 12:00', $slot[1]->format('Y-m-d H:i'));
+
+ // Start to work at the end of the timeslot
+ $date = clone($monday);
+ $date->setTime(12, 02);
+
+ $slot = $t->findClosestTimeSlot($date, $timetable);
+ $this->assertNotEmpty($slot);
+ $this->assertEquals($monday->format('Y-m-d').' 09:30', $slot[0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 12:00', $slot[1]->format('Y-m-d H:i'));
+
+ // Start to work at lunch time
+ $date = clone($monday);
+ $date->setTime(12, 32);
+
+ $slot = $t->findClosestTimeSlot($date, $timetable);
+ $this->assertNotEmpty($slot);
+ $this->assertEquals($monday->format('Y-m-d').' 13:00', $slot[0]->format('Y-m-d H:i'));
+ $this->assertEquals($monday->format('Y-m-d').' 17:00', $slot[1]->format('Y-m-d H:i'));
+
+ // Start to work early in the morning
+ $date = clone($tuesday);
+ $date->setTime(8, 02);
+
+ $slot = $t->findClosestTimeSlot($date, $timetable);
+ $this->assertNotEmpty($slot);
+ $this->assertEquals($tuesday->format('Y-m-d').' 09:30', $slot[0]->format('Y-m-d H:i'));
+ $this->assertEquals($tuesday->format('Y-m-d').' 12:00', $slot[1]->format('Y-m-d H:i'));
+ }
+
+ public function testCalculateDuration()
+ {
+ $w = new TimetableWeek($this->container);
+ $t = new Timetable($this->container);
+
+ $this->assertNotFalse($w->create(1, 1, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 1, '13:00', '17:00'));
+ $this->assertNotFalse($w->create(1, 2, '09:30', '12:00'));
+ $this->assertNotFalse($w->create(1, 2, '13:00', '17:00'));
+
+ $monday = new DateTime('next Monday');
+ $tuesday = new DateTime('next Monday + 1 day');
+
+ // Different day
+ $start = clone($monday);
+ $start->setTime(16, 02);
+
+ $end = clone($tuesday);
+ $end->setTime(10, 03);
+
+ $this->assertEquals(1.5, $t->calculateEffectiveDuration(1, $start, $end));
+
+ // Same time slot
+ $start = clone($monday);
+ $start->setTime(16, 02);
+
+ $end = clone($monday);
+ $end->setTime(17, 03);
+
+ $this->assertEquals(1, $t->calculateEffectiveDuration(1, $start, $end));
+
+ // Intermediate time slot
+ $start = clone($monday);
+ $start->setTime(10, 02);
+
+ $end = clone($tuesday);
+ $end->setTime(16, 03);
+
+ $this->assertEquals(11.5, $t->calculateEffectiveDuration(1, $start, $end));
+
+ // Different day
+ $start = clone($monday);
+ $start->setTime(9, 02);
+
+ $end = clone($tuesday);
+ $end->setTime(10, 03);
+
+ $this->assertEquals(7, $t->calculateEffectiveDuration(1, $start, $end));
+
+ // Start before first time slot
+ $start = clone($monday);
+ $start->setTime(5, 32);
+
+ $end = clone($tuesday);
+ $end->setTime(11, 17);
+
+ $this->assertEquals(8.25, $t->calculateEffectiveDuration(1, $start, $end));
+ }
+
+ public function testCalculateDurationWithEmptyTimetable()
+ {
+ $t = new Timetable($this->container);
+
+ $start = new DateTime('next Monday');
+ $start->setTime(16, 02);
+
+ $end = new DateTime('next Monday');
+ $end->setTime(17, 03);
+
+ $this->assertEquals(1, $t->calculateEffectiveDuration(1, $start, $end));
+ }
+}
diff --git a/tests/units/ToolTest.php b/tests/units/ToolTest.php
new file mode 100644
index 00000000..4a62fe3b
--- /dev/null
+++ b/tests/units/ToolTest.php
@@ -0,0 +1,15 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Core\Tool;
+
+class ToolTest extends Base
+{
+ public function testMailboxHash()
+ {
+ $this->assertEquals('test1', Tool::getMailboxHash('a+test1@localhost'));
+ $this->assertEquals('', Tool::getMailboxHash('test1@localhost'));
+ $this->assertEquals('', Tool::getMailboxHash('test1'));
+ }
+}
diff --git a/tests/units/UrlHelperTest.php b/tests/units/UrlHelperTest.php
new file mode 100644
index 00000000..d70842aa
--- /dev/null
+++ b/tests/units/UrlHelperTest.php
@@ -0,0 +1,64 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Helper\Url;
+use Model\Config;
+
+class UrlHelperTest extends Base
+{
+ public function testLink()
+ {
+ $h = new Url($this->container);
+ $this->assertEquals(
+ '<a href="?controller=a&amp;action=b&amp;d=e" class="f" title="g" target="_blank">label</a>',
+ $h->link('label', 'a', 'b', array('d' => 'e'), false, 'f', 'g', true)
+ );
+ }
+
+ public function testHref()
+ {
+ $h = new Url($this->container);
+ $this->assertEquals(
+ '?controller=a&amp;action=b&amp;d=e',
+ $h->href('a', 'b', array('d' => 'e'))
+ );
+ }
+
+ public function testTo()
+ {
+ $h = new Url($this->container);
+ $this->assertEquals(
+ '?controller=a&action=b&d=e',
+ $h->to('a', 'b', array('d' => 'e'))
+ );
+ }
+
+ public function testServer()
+ {
+ $h = new Url($this->container);
+
+ $_SERVER['PHP_SELF'] = '/';
+ $_SERVER['SERVER_NAME'] = 'localhost';
+ $_SERVER['SERVER_PORT'] = 1234;
+
+ $this->assertEquals('http://localhost:1234/', $h->server());
+ }
+
+ public function testBase()
+ {
+ $h = new Url($this->container);
+
+ $_SERVER['PHP_SELF'] = '/';
+ $_SERVER['SERVER_NAME'] = 'localhost';
+ $_SERVER['SERVER_PORT'] = 1234;
+
+ $this->assertEquals('http://localhost:1234/', $h->base());
+
+ $c = new Config($this->container);
+ $c->save(array('application_url' => 'https://mykanboard/'));
+
+ $this->assertEquals('https://mykanboard/', $c->get('application_url'));
+ $this->assertEquals('https://mykanboard/', $h->base());
+ }
+}
diff --git a/tests/units/UserSessionTest.php b/tests/units/UserSessionTest.php
new file mode 100644
index 00000000..45f1bfde
--- /dev/null
+++ b/tests/units/UserSessionTest.php
@@ -0,0 +1,45 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Core\Session;
+use Model\UserSession;
+
+class UserSessionTest extends Base
+{
+ public function testIsAdmin()
+ {
+ $s = new Session;
+ $us = new UserSession($this->container);
+
+ $this->assertFalse($us->isAdmin());
+
+ $s['user'] = array();
+ $this->assertFalse($us->isAdmin());
+
+ $s['user'] = array('is_admin' => '1');
+ $this->assertFalse($us->isAdmin());
+
+ $s['user'] = array('is_admin' => false);
+ $this->assertFalse($us->isAdmin());
+
+ $s['user'] = array('is_admin' => '2');
+ $this->assertFalse($us->isAdmin());
+
+ $s['user'] = array('is_admin' => true);
+ $this->assertTrue($us->isAdmin());
+ }
+
+ public function testLastSeenProject()
+ {
+ $us = new UserSession($this->container);
+
+ $this->assertEquals(0, $us->getLastSeenProjectId());
+
+ $us->storeLastSeenProjectId(33);
+ $this->assertEquals(33, $us->getLastSeenProjectId());
+
+ $us->storeLastSeenProjectId(66);
+ $this->assertEquals(66, $us->getLastSeenProjectId());
+ }
+}
diff --git a/tests/units/UserTest.php b/tests/units/UserTest.php
index b66a6c27..a596918e 100644
--- a/tests/units/UserTest.php
+++ b/tests/units/UserTest.php
@@ -4,14 +4,34 @@ require_once __DIR__.'/Base.php';
use Model\User;
use Model\Task;
+use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
class UserTest extends Base
{
+ public function testGetByEmail()
+ {
+ $u = new User($this->container);
+ $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'email' => 'user1@localhost')));
+ $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'email' => '')));
+
+ $this->assertNotEmpty($u->getByEmail('user1@localhost'));
+ $this->assertEmpty($u->getByEmail(''));
+ }
+
+ public function testPassword()
+ {
+ $password = 'test123';
+ $hash = password_hash($password, PASSWORD_BCRYPT);
+
+ $this->assertNotEmpty($hash);
+ $this->assertTrue(password_verify($password, $hash));
+ }
+
public function testPrepare()
{
- $u = new User($this->registry);
+ $u = new User($this->container);
$input = array(
'username' => 'user1',
@@ -62,9 +82,9 @@ class UserTest extends Base
public function testCreate()
{
- $u = new User($this->registry);
- $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
- $this->assertTrue($u->create(array('username' => 'titi', 'is_ldap_user' => 1)));
+ $u = new User($this->container);
+ $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
+ $this->assertNotFalse($u->create(array('username' => 'titi', 'is_ldap_user' => 1)));
$this->assertFalse($u->create(array('username' => 'toto')));
$user = $u->getById(1);
@@ -94,8 +114,8 @@ class UserTest extends Base
public function testUpdate()
{
- $u = new User($this->registry);
- $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
+ $u = new User($this->container);
+ $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
$this->assertTrue($u->update(array('id' => 2, 'username' => 'biloute')));
$user = $u->getById(2);
@@ -109,14 +129,14 @@ class UserTest extends Base
public function testRemove()
{
- $u = new User($this->registry);
- $t = new Task($this->registry);
- $tf = new TaskFinder($this->registry);
- $p = new Project($this->registry);
+ $u = new User($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
+ $p = new Project($this->container);
- $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
+ $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2)));
+ $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2)));
$task = $tf->getById(1);
$this->assertEquals(1, $task['id']);
@@ -131,5 +151,45 @@ class UserTest extends Base
$task = $tf->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(0, $task['owner_id']);
+
+ // Make sure that private projects are also removed
+ $user_id1 = $u->create(array('username' => 'toto1', 'password' => '123456', 'name' => 'Toto'));
+ $user_id2 = $u->create(array('username' => 'toto2', 'password' => '123456', 'name' => 'Toto'));
+ $this->assertNotFalse($user_id1);
+ $this->assertNotFalse($user_id2);
+ $this->assertEquals(2, $p->create(array('name' => 'Private project #1', 'is_private' => 1), $user_id1, true));
+ $this->assertEquals(3, $p->create(array('name' => 'Private project #2', 'is_private' => 1), $user_id2, true));
+
+ $this->assertTrue($u->remove($user_id1));
+
+ $this->assertNotEmpty($p->getById(1));
+ $this->assertNotEmpty($p->getById(3));
+
+ $this->assertEmpty($p->getById(2));
+ }
+
+ public function testEnableDisablePublicAccess()
+ {
+ $u = new User($this->container);
+ $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456')));
+
+ $user = $u->getById(2);
+ $this->assertNotEmpty($user);
+ $this->assertEquals('toto', $user['username']);
+ $this->assertEmpty($user['token']);
+
+ $this->assertTrue($u->enablePublicAccess(2));
+
+ $user = $u->getById(2);
+ $this->assertNotEmpty($user);
+ $this->assertEquals('toto', $user['username']);
+ $this->assertNotEmpty($user['token']);
+
+ $this->assertTrue($u->disablePublicAccess(2));
+
+ $user = $u->getById(2);
+ $this->assertNotEmpty($user);
+ $this->assertEquals('toto', $user['username']);
+ $this->assertEmpty($user['token']);
}
}
diff --git a/tests/units/WebhookTest.php b/tests/units/WebhookTest.php
new file mode 100644
index 00000000..946d744c
--- /dev/null
+++ b/tests/units/WebhookTest.php
@@ -0,0 +1,112 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+use Model\Config;
+use Model\Task;
+use Model\TaskCreation;
+use Model\TaskModification;
+use Model\Project;
+use Model\Comment;
+use Subscriber\WebhookSubscriber;
+
+class WebhookTest extends Base
+{
+ public function testTaskCreation()
+ {
+ $c = new Config($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $this->container['dispatcher']->addSubscriber(new WebhookSubscriber($this->container));
+
+ $c->save(array('webhook_url' => 'http://localhost/?task-creation'));
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->assertStringStartsWith('http://localhost/?task-creation&token=', $this->container['httpClient']->getUrl());
+
+ $event = $this->container['httpClient']->getData();
+ $this->assertNotEmpty($event);
+ $this->assertArrayHasKey('event_name', $event);
+ $this->assertArrayHasKey('event_data', $event);
+ $this->assertEquals('task.create', $event['event_name']);
+ $this->assertNotEmpty($event['event_data']);
+
+ $this->assertArrayHasKey('project_id', $event['event_data']);
+ $this->assertArrayHasKey('task_id', $event['event_data']);
+ $this->assertArrayHasKey('title', $event['event_data']);
+ $this->assertArrayHasKey('column_id', $event['event_data']);
+ $this->assertArrayHasKey('color_id', $event['event_data']);
+ $this->assertArrayHasKey('swimlane_id', $event['event_data']);
+ $this->assertArrayHasKey('date_creation', $event['event_data']);
+ $this->assertArrayHasKey('date_modification', $event['event_data']);
+ $this->assertArrayHasKey('date_moved', $event['event_data']);
+ $this->assertArrayHasKey('position', $event['event_data']);
+ }
+
+ public function testTaskModification()
+ {
+ $c = new Config($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tm = new TaskModification($this->container);
+ $this->container['dispatcher']->addSubscriber(new WebhookSubscriber($this->container));
+
+ $c->save(array('webhook_url' => 'http://localhost/modif/'));
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertTrue($tm->update(array('id' => 1, 'title' => 'test update')));
+
+ $this->assertStringStartsWith('http://localhost/modif/?token=', $this->container['httpClient']->getUrl());
+
+ $event = $this->container['httpClient']->getData();
+ $this->assertNotEmpty($event);
+ $this->assertArrayHasKey('event_name', $event);
+ $this->assertArrayHasKey('event_data', $event);
+ $this->assertEquals('task.update', $event['event_name']);
+ $this->assertNotEmpty($event['event_data']);
+
+ $this->assertArrayHasKey('project_id', $event['event_data']);
+ $this->assertArrayHasKey('task_id', $event['event_data']);
+ $this->assertArrayHasKey('title', $event['event_data']);
+ $this->assertArrayHasKey('column_id', $event['event_data']);
+ $this->assertArrayHasKey('color_id', $event['event_data']);
+ $this->assertArrayHasKey('swimlane_id', $event['event_data']);
+ $this->assertArrayHasKey('date_creation', $event['event_data']);
+ $this->assertArrayHasKey('date_modification', $event['event_data']);
+ $this->assertArrayHasKey('date_moved', $event['event_data']);
+ $this->assertArrayHasKey('position', $event['event_data']);
+ }
+
+ public function testCommentCreation()
+ {
+ $c = new Config($this->container);
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $cm = new Comment($this->container);
+ $this->container['dispatcher']->addSubscriber(new WebhookSubscriber($this->container));
+
+ $c->save(array('webhook_url' => 'http://localhost/comment'));
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(1, $cm->create(array('task_id' => 1, 'comment' => 'test comment', 'user_id' => 1)));
+
+ $this->assertStringStartsWith('http://localhost/comment?token=', $this->container['httpClient']->getUrl());
+
+ $event = $this->container['httpClient']->getData();
+ $this->assertNotEmpty($event);
+ $this->assertArrayHasKey('event_name', $event);
+ $this->assertArrayHasKey('event_data', $event);
+ $this->assertEquals('comment.create', $event['event_name']);
+ $this->assertNotEmpty($event['event_data']);
+
+ $this->assertArrayHasKey('task_id', $event['event_data']);
+ $this->assertArrayHasKey('user_id', $event['event_data']);
+ $this->assertArrayHasKey('comment', $event['event_data']);
+ $this->assertArrayHasKey('id', $event['event_data']);
+ $this->assertEquals('test comment', $event['event_data']['comment']);
+ }
+}