summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/Action/BaseActionTest.php10
-rw-r--r--tests/units/Action/CommentCreationMoveTaskColumnTest.php6
-rw-r--r--tests/units/Action/TaskAssignCategoryColorTest.php18
-rw-r--r--tests/units/Action/TaskAssignCategoryLinkTest.php92
-rw-r--r--tests/units/Action/TaskAssignColorCategoryTest.php18
-rw-r--r--tests/units/Action/TaskAssignColorColumnTest.php18
-rw-r--r--tests/units/Action/TaskAssignColorLinkTest.php45
-rw-r--r--tests/units/Action/TaskAssignColorPriorityTest.php18
-rw-r--r--tests/units/Action/TaskAssignColorUserTest.php18
-rw-r--r--tests/units/Action/TaskAssignCurrentUserColumnTest.php26
-rw-r--r--tests/units/Action/TaskAssignDueDateOnCreationTest.php37
-rw-r--r--tests/units/Action/TaskAssignSpecificUserTest.php17
-rw-r--r--tests/units/Action/TaskCloseColumnTest.php18
-rw-r--r--tests/units/Action/TaskCloseNoActivityColumnTest.php49
-rw-r--r--tests/units/Action/TaskCloseTest.php15
-rw-r--r--tests/units/Action/TaskDuplicateAnotherProjectTest.php18
-rw-r--r--tests/units/Action/TaskEmailTest.php19
-rw-r--r--tests/units/Action/TaskMoveAnotherProjectTest.php17
-rw-r--r--tests/units/Action/TaskMoveColumnAssignedTest.php18
-rw-r--r--tests/units/Action/TaskMoveColumnCategoryChangeTest.php31
-rw-r--r--tests/units/Action/TaskMoveColumnClosedTest.php91
-rw-r--r--tests/units/Action/TaskMoveColumnNotMovedPeriodTest.php50
-rw-r--r--tests/units/Action/TaskMoveColumnUnAssignedTest.php31
-rw-r--r--tests/units/Action/TaskOpenTest.php15
-rw-r--r--tests/units/Action/TaskUpdateStartDateTest.php20
-rw-r--r--tests/units/Auth/ReverseProxyAuthTest.php111
-rw-r--r--tests/units/Auth/TotpAuthTest.php5
-rw-r--r--tests/units/Base.php12
-rw-r--r--tests/units/Core/Action/ActionManagerTest.php40
-rw-r--r--tests/units/Core/Filter/LexerBuilderTest.php46
-rw-r--r--tests/units/Core/Filter/LexerTest.php56
-rw-r--r--tests/units/Core/Filter/OrCriteriaTest.php5
-rw-r--r--tests/units/Core/Http/RequestTest.php3
-rw-r--r--tests/units/Core/Ldap/LdapUserTest.php60
-rw-r--r--tests/units/EventBuilder/CommentEventBuilderTest.php37
-rw-r--r--tests/units/EventBuilder/ProjectFileEventBuilderTest.php33
-rw-r--r--tests/units/EventBuilder/SubtaskEventBuilderTest.php62
-rw-r--r--tests/units/EventBuilder/TaskEventBuilderTest.php100
-rw-r--r--tests/units/EventBuilder/TaskFileEventBuilderTest.php36
-rw-r--r--tests/units/EventBuilder/TaskLinkEventBuilderTest.php70
-rw-r--r--tests/units/Filter/TaskMovedDateFilterTest.php43
-rw-r--r--tests/units/Filter/TaskPriorityFilterTest.php47
-rw-r--r--tests/units/Filter/TaskTagFilterTest.php122
-rw-r--r--tests/units/Formatter/BoardFormatterTest.php392
-rw-r--r--tests/units/Formatter/TaskAutoCompleteFormatterTest.php34
-rw-r--r--tests/units/FunctionTest.php123
-rw-r--r--tests/units/Helper/UserHelperTest.php30
-rw-r--r--tests/units/Job/CommentEventJobTest.php52
-rw-r--r--tests/units/Job/ProjectFileEventJobTest.php43
-rw-r--r--tests/units/Job/ProjectMetricJobTest.php47
-rw-r--r--tests/units/Job/SubtaskEventJobTest.php52
-rw-r--r--tests/units/Job/TaskEventJobTest.php189
-rw-r--r--tests/units/Job/TaskFileEventJobTest.php46
-rw-r--r--tests/units/Job/TaskLinkEventJobTest.php65
-rw-r--r--tests/units/Model/ActionModelTest.php (renamed from tests/units/Model/ActionTest.php)20
-rw-r--r--tests/units/Model/BoardTest.php121
-rw-r--r--tests/units/Model/CategoryModelTest.php (renamed from tests/units/Model/CategoryTest.php)14
-rw-r--r--tests/units/Model/CommentModelTest.php106
-rw-r--r--tests/units/Model/CommentTest.php92
-rw-r--r--tests/units/Model/GroupModelTest.php (renamed from tests/units/Model/GroupTest.php)11
-rw-r--r--tests/units/Model/NotificationModelTest.php104
-rw-r--r--tests/units/Model/NotificationTest.php68
-rw-r--r--tests/units/Model/ProjectDuplicationModelTest.php548
-rw-r--r--tests/units/Model/ProjectDuplicationTest.php482
-rw-r--r--tests/units/Model/ProjectModelTest.php (renamed from tests/units/Model/ProjectTest.php)196
-rw-r--r--tests/units/Model/ProjectPermissionTest.php23
-rw-r--r--tests/units/Model/ProjectTaskPriorityModelTest.php84
-rw-r--r--tests/units/Model/SubtaskModelTest.php175
-rw-r--r--tests/units/Model/SubtaskPositionModelTest.php77
-rw-r--r--tests/units/Model/SubtaskStatusModelTest.php123
-rw-r--r--tests/units/Model/SubtaskTaskConversionModelTest.php37
-rw-r--r--tests/units/Model/SubtaskTest.php388
-rw-r--r--tests/units/Model/SubtaskTimeTrackingModelTest.php277
-rw-r--r--tests/units/Model/SubtaskTimeTrackingTest.php240
-rw-r--r--tests/units/Model/SwimlaneTest.php10
-rw-r--r--tests/units/Model/TagDuplicationModelTest.php31
-rw-r--r--tests/units/Model/TagModelTest.php120
-rw-r--r--tests/units/Model/TaskCreationModelTest.php403
-rw-r--r--tests/units/Model/TaskCreationTest.php414
-rw-r--r--tests/units/Model/TaskDuplicationModelTest.php142
-rw-r--r--tests/units/Model/TaskDuplicationTest.php700
-rw-r--r--tests/units/Model/TaskFileModelTest.php (renamed from tests/units/Model/TaskFileTest.php)15
-rw-r--r--tests/units/Model/TaskFinderModelTest.php142
-rw-r--r--tests/units/Model/TaskFinderTest.php115
-rw-r--r--tests/units/Model/TaskLinkModelTest.php239
-rw-r--r--tests/units/Model/TaskLinkTest.php196
-rw-r--r--tests/units/Model/TaskModelTest.php30
-rw-r--r--tests/units/Model/TaskModificationModelTest.php323
-rw-r--r--tests/units/Model/TaskModificationTest.php283
-rw-r--r--tests/units/Model/TaskPositionModelTest.php (renamed from tests/units/Model/TaskPositionTest.php)394
-rw-r--r--tests/units/Model/TaskProjectDuplicationModelTest.php377
-rw-r--r--tests/units/Model/TaskProjectMoveModelTest.php277
-rw-r--r--tests/units/Model/TaskRecurrenceModelTest.php126
-rw-r--r--tests/units/Model/TaskTagModelTest.php148
-rw-r--r--tests/units/Model/TaskTest.php58
-rw-r--r--tests/units/Model/UserModelTest.php384
-rw-r--r--tests/units/Model/UserTest.php400
-rw-r--r--tests/units/Notification/MailNotificationTest.php117
-rw-r--r--tests/units/Notification/MailTest.php117
-rw-r--r--tests/units/Notification/WebhookNotificationTest.php (renamed from tests/units/Notification/WebhookTest.php)14
-rw-r--r--tests/units/Pagination/ProjectPaginationTest.php35
-rw-r--r--tests/units/Pagination/SubtaskPaginationTest.php36
-rw-r--r--tests/units/Pagination/TaskPaginationTest.php30
-rw-r--r--tests/units/Pagination/UserPaginationTest.php27
-rw-r--r--tests/units/Subscriber/RecurringTaskSubscriberTest.php164
-rw-r--r--tests/units/User/Avatar/LetterAvatarProviderTest.php2
-rw-r--r--tests/units/Validator/ProjectValidatorTest.php12
107 files changed, 7611 insertions, 4132 deletions
diff --git a/tests/units/Action/BaseActionTest.php b/tests/units/Action/BaseActionTest.php
index 1d50c70e..feeba3f9 100644
--- a/tests/units/Action/BaseActionTest.php
+++ b/tests/units/Action/BaseActionTest.php
@@ -23,7 +23,7 @@ class DummyAction extends Kanboard\Action\Base
public function getEventRequiredParameters()
{
- return array('p1', 'p2');
+ return array('p1', 'p2', 'p3' => array('p4'));
}
public function doAction(array $data)
@@ -60,7 +60,7 @@ class BaseActionTest extends Base
public function testGetEventRequiredParameters()
{
$dummyAction = new DummyAction($this->container);
- $this->assertEquals(array('p1', 'p2'), $dummyAction->getEventRequiredParameters());
+ $this->assertEquals(array('p1', 'p2', 'p3' => array('p4')), $dummyAction->getEventRequiredParameters());
}
public function testGetCompatibleEvents()
@@ -113,7 +113,7 @@ class BaseActionTest extends Base
$dummyAction = new DummyAction($this->container);
$dummyAction->setProjectId(1234);
- $this->assertTrue($dummyAction->hasRequiredParameters(array('p1' => 12, 'p2' => 34)));
+ $this->assertTrue($dummyAction->hasRequiredParameters(array('p1' => 12, 'p2' => 34, 'p3' => array('p4' => 'foobar'))));
$this->assertFalse($dummyAction->hasRequiredParameters(array('p1' => 12)));
$this->assertFalse($dummyAction->hasRequiredParameters(array()));
}
@@ -125,7 +125,7 @@ class BaseActionTest extends Base
$dummyAction->addEvent('my.event', 'My Event Overrided');
$events = $dummyAction->getEvents();
- $this->assertcount(2, $events);
+ $this->assertCount(2, $events);
$this->assertEquals(array('my.event', 'foobar'), $events);
}
@@ -136,7 +136,7 @@ class BaseActionTest extends Base
$dummyAction->setParam('p1', 'something');
$dummyAction->addEvent('foobar', 'FooBar');
- $event = new GenericEvent(array('project_id' => 1234, 'p1' => 'something', 'p2' => 'abc'));
+ $event = new GenericEvent(array('project_id' => 1234, 'p1' => 'something', 'p2' => 'abc', 'p3' => array('p4' => 'a')));
$this->assertTrue($dummyAction->execute($event, 'foobar'));
$this->assertFalse($dummyAction->execute($event, 'foobar'));
diff --git a/tests/units/Action/CommentCreationMoveTaskColumnTest.php b/tests/units/Action/CommentCreationMoveTaskColumnTest.php
index 5eaf515e..b3d21287 100644
--- a/tests/units/Action/CommentCreationMoveTaskColumnTest.php
+++ b/tests/units/Action/CommentCreationMoveTaskColumnTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\CommentModel;
@@ -22,7 +22,7 @@ class CommentCreationMoveTaskColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array('task' => array('project_id' => 1, 'column_id' => 2), 'task_id' => 1));
$action = new CommentCreationMoveTaskColumn($this->container);
$action->setProjectId(1);
@@ -45,7 +45,7 @@ class CommentCreationMoveTaskColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array('task' => array('project_id' => 1, 'column_id' => 3), 'task_id' => 1));
$action = new CommentCreationMoveTaskColumn($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignCategoryColorTest.php b/tests/units/Action/TaskAssignCategoryColorTest.php
index 09c08264..5a0f7d03 100644
--- a/tests/units/Action/TaskAssignCategoryColorTest.php
+++ b/tests/units/Action/TaskAssignCategoryColorTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
@@ -23,7 +23,13 @@ class TaskAssignCategoryColorTest extends Base
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'color_id' => 'red'));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'color_id' => 'red',
+ )
+ ));
$action = new TaskAssignCategoryColor($this->container);
$action->setProjectId(1);
@@ -47,7 +53,13 @@ class TaskAssignCategoryColorTest extends Base
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'color_id' => 'blue'));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'color_id' => 'blue',
+ )
+ ));
$action = new TaskAssignCategoryColor($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignCategoryLinkTest.php b/tests/units/Action/TaskAssignCategoryLinkTest.php
index 712c3c02..1576f81b 100644
--- a/tests/units/Action/TaskAssignCategoryLinkTest.php
+++ b/tests/units/Action/TaskAssignCategoryLinkTest.php
@@ -2,94 +2,100 @@
require_once __DIR__.'/../Base.php';
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskLinkModel;
use Kanboard\Model\CategoryModel;
-use Kanboard\Event\TaskLinkEvent;
use Kanboard\Action\TaskAssignCategoryLink;
class TaskAssignCategoryLinkTest extends Base
{
public function testAssignCategory()
{
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignCategoryLink($this->container);
$action->setProjectId(1);
$action->setParam('category_id', 1);
$action->setParam('link_id', 2);
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
- $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
- $event = new TaskLinkEvent(array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'opposite_task_id' => 2,
- 'link_id' => 2,
- ));
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertTrue($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['category_id']);
}
public function testWhenLinkDontMatch()
{
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignCategoryLink($this->container);
$action->setProjectId(1);
$action->setParam('category_id', 1);
- $action->setParam('link_id', 1);
+ $action->setParam('link_id', 2);
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
- $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
- $event = new TaskLinkEvent(array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'opposite_task_id' => 2,
- 'link_id' => 2,
- ));
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['category_id']);
}
public function testThatExistingCategoryWillNotChange()
{
- $tc = new TaskCreationModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignCategoryLink($this->container);
$action->setProjectId(1);
- $action->setParam('category_id', 2);
+ $action->setParam('category_id', 1);
$action->setParam('link_id', 2);
- $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(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'category_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'category_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
- $event = new TaskLinkEvent(array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'opposite_task_id' => 2,
- 'link_id' => 2,
- ));
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['category_id']);
}
}
diff --git a/tests/units/Action/TaskAssignColorCategoryTest.php b/tests/units/Action/TaskAssignColorCategoryTest.php
index 6502035f..16ad1290 100644
--- a/tests/units/Action/TaskAssignColorCategoryTest.php
+++ b/tests/units/Action/TaskAssignColorCategoryTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
@@ -23,7 +23,13 @@ class TaskAssignColorCategoryTest extends Base
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'category_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'category_id' => 1,
+ )
+ ));
$action = new TaskAssignColorCategory($this->container);
$action->setProjectId(1);
@@ -45,7 +51,13 @@ class TaskAssignColorCategoryTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'category_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'category_id' => 2,
+ )
+ ));
$action = new TaskAssignColorCategory($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignColorColumnTest.php b/tests/units/Action/TaskAssignColorColumnTest.php
index d4ba8e01..ccfb9e88 100644
--- a/tests/units/Action/TaskAssignColorColumnTest.php
+++ b/tests/units/Action/TaskAssignColorColumnTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -20,7 +20,13 @@ class TaskAssignColorColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskAssignColorColumn($this->container);
$action->setProjectId(1);
@@ -42,7 +48,13 @@ class TaskAssignColorColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskAssignColorColumn($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignColorLinkTest.php b/tests/units/Action/TaskAssignColorLinkTest.php
index 07d0969b..77a6c90e 100644
--- a/tests/units/Action/TaskAssignColorLinkTest.php
+++ b/tests/units/Action/TaskAssignColorLinkTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -13,42 +13,55 @@ class TaskAssignColorLinkTest extends Base
{
public function testChangeColor()
{
- $projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
$taskFinderModel = new TaskFinderModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
-
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'link_id' => 1));
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignColorLink($this->container);
$action->setProjectId(1);
+ $action->setParam('link_id', 2);
$action->setParam('color_id', 'red');
- $action->setParam('link_id', 1);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
+
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertTrue($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
$task = $taskFinderModel->getById(1);
- $this->assertNotEmpty($task);
$this->assertEquals('red', $task['color_id']);
}
public function testWithWrongLink()
{
- $projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
-
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'link_id' => 2));
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
$action = new TaskAssignColorLink($this->container);
$action->setProjectId(1);
+ $action->setParam('link_id', 2);
$action->setParam('color_id', 'red');
- $action->setParam('link_id', 1);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $event = TaskLinkEventBuilder::getInstance($this->container)
+ ->withTaskLinkId(1)
+ ->buildEvent();
$this->assertFalse($action->execute($event, TaskLinkModel::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('yellow', $task['color_id']);
}
}
diff --git a/tests/units/Action/TaskAssignColorPriorityTest.php b/tests/units/Action/TaskAssignColorPriorityTest.php
index 2fce8e66..0ea874cd 100644
--- a/tests/units/Action/TaskAssignColorPriorityTest.php
+++ b/tests/units/Action/TaskAssignColorPriorityTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
@@ -23,7 +23,13 @@ class TaskAssignColorPriorityTest extends Base
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'priority' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'priority' => 1,
+ )
+ ));
$action = new TaskAssignColorPriority($this->container);
$action->setProjectId(1);
@@ -45,7 +51,13 @@ class TaskAssignColorPriorityTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'priority' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'priority' => 2,
+ )
+ ));
$action = new TaskAssignColorPriority($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignColorUserTest.php b/tests/units/Action/TaskAssignColorUserTest.php
index 370f9070..45faa3ff 100644
--- a/tests/units/Action/TaskAssignColorUserTest.php
+++ b/tests/units/Action/TaskAssignColorUserTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -20,7 +20,13 @@ class TaskAssignColorUserTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'owner_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'owner_id' => 1,
+ )
+ ));
$action = new TaskAssignColorUser($this->container);
$action->setProjectId(1);
@@ -42,7 +48,13 @@ class TaskAssignColorUserTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'owner_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'owner_id' => 2,
+ )
+ ));
$action = new TaskAssignColorUser($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignCurrentUserColumnTest.php b/tests/units/Action/TaskAssignCurrentUserColumnTest.php
index 6fdbda63..3b64d718 100644
--- a/tests/units/Action/TaskAssignCurrentUserColumnTest.php
+++ b/tests/units/Action/TaskAssignCurrentUserColumnTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -22,7 +22,13 @@ class TaskAssignCurrentUserColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskAssignCurrentUserColumn($this->container);
$action->setProjectId(1);
@@ -45,7 +51,13 @@ class TaskAssignCurrentUserColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskAssignCurrentUserColumn($this->container);
$action->setProjectId(1);
@@ -62,7 +74,13 @@ class TaskAssignCurrentUserColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskAssignCurrentUserColumn($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskAssignDueDateOnCreationTest.php b/tests/units/Action/TaskAssignDueDateOnCreationTest.php
new file mode 100644
index 00000000..26c0584e
--- /dev/null
+++ b/tests/units/Action/TaskAssignDueDateOnCreationTest.php
@@ -0,0 +1,37 @@
+<?php
+
+use Kanboard\Action\TaskAssignDueDateOnCreation;
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskAssignDueDateOnCreationTest extends Base
+{
+ public function testAction()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $action = new TaskAssignDueDateOnCreation($this->container);
+ $action->setProjectId(1);
+ $action->setParam('duration', 4);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_CREATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(date('Y-m-d', strtotime('+4days')), date('Y-m-d', $task['date_due']));
+ }
+}
diff --git a/tests/units/Action/TaskAssignSpecificUserTest.php b/tests/units/Action/TaskAssignSpecificUserTest.php
index 78ec314f..0e63fc13 100644
--- a/tests/units/Action/TaskAssignSpecificUserTest.php
+++ b/tests/units/Action/TaskAssignSpecificUserTest.php
@@ -3,6 +3,7 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -20,7 +21,13 @@ class TaskAssignSpecificUserTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 0)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskAssignSpecificUser($this->container);
$action->setProjectId(1);
@@ -42,7 +49,13 @@ class TaskAssignSpecificUserTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskAssignSpecificUser($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskCloseColumnTest.php b/tests/units/Action/TaskCloseColumnTest.php
index f9a938f0..7afb0478 100644
--- a/tests/units/Action/TaskCloseColumnTest.php
+++ b/tests/units/Action/TaskCloseColumnTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -20,7 +20,13 @@ class TaskCloseColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskCloseColumn($this->container);
$action->setProjectId(1);
@@ -41,7 +47,13 @@ class TaskCloseColumnTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskCloseColumn($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskCloseNoActivityColumnTest.php b/tests/units/Action/TaskCloseNoActivityColumnTest.php
new file mode 100644
index 00000000..243d3359
--- /dev/null
+++ b/tests/units/Action/TaskCloseNoActivityColumnTest.php
@@ -0,0 +1,49 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Action\TaskCloseNoActivityColumn;
+use Kanboard\Event\TaskListEvent;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskModel;
+
+class TaskCloseNoActivityColumnTest extends Base
+{
+ public function testClose()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $this->container['db']->table(TaskModel::TABLE)->in('id', array(1, 3))->update(array('date_modification' => strtotime('-10days')));
+
+ $tasks = $taskFinderModel->getAll(1);
+ $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1));
+
+ $action = new TaskCloseNoActivityColumn($this->container);
+ $action->setProjectId(1);
+ $action->setParam('duration', 2);
+ $action->setParam('column_id', 2);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['is_active']);
+ }
+}
diff --git a/tests/units/Action/TaskCloseTest.php b/tests/units/Action/TaskCloseTest.php
index 3df10cb8..589ef133 100644
--- a/tests/units/Action/TaskCloseTest.php
+++ b/tests/units/Action/TaskCloseTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -19,7 +19,12 @@ class TaskCloseTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ )
+ ));
$action = new TaskClose($this->container);
$action->setProjectId(1);
@@ -40,7 +45,11 @@ class TaskCloseTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1));
+ $event = new TaskEvent(array(
+ 'task' => array(
+ 'project_id' => 1,
+ )
+ ));
$action = new TaskClose($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskDuplicateAnotherProjectTest.php b/tests/units/Action/TaskDuplicateAnotherProjectTest.php
index 98ff187f..5cd0c977 100644
--- a/tests/units/Action/TaskDuplicateAnotherProjectTest.php
+++ b/tests/units/Action/TaskDuplicateAnotherProjectTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskCreationModel;
@@ -21,7 +21,13 @@ class TaskDuplicateAnotherProjectTest extends Base
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskDuplicateAnotherProject($this->container);
$action->setProjectId(1);
@@ -43,7 +49,13 @@ class TaskDuplicateAnotherProjectTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskDuplicateAnotherProject($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskEmailTest.php b/tests/units/Action/TaskEmailTest.php
index df71aaf8..421c89ca 100644
--- a/tests/units/Action/TaskEmailTest.php
+++ b/tests/units/Action/TaskEmailTest.php
@@ -2,7 +2,8 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
+use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
@@ -16,16 +17,20 @@ class TaskEmailTest extends Base
$userModel = new UserModel($this->container);
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
$this->assertTrue($userModel->update(array('id' => 1, 'email' => 'admin@localhost')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => $taskFinderModel->getDetails(1)
+ ));
$action = new TaskEmail($this->container);
$action->setProjectId(1);
- $action->setParam('column_id', 2);
+ $action->setParam('column_id', 1);
$action->setParam('user_id', 1);
$action->setParam('subject', 'My email subject');
@@ -47,7 +52,13 @@ class TaskEmailTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskEmail($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskMoveAnotherProjectTest.php b/tests/units/Action/TaskMoveAnotherProjectTest.php
index d36df47b..a41fd03f 100644
--- a/tests/units/Action/TaskMoveAnotherProjectTest.php
+++ b/tests/units/Action/TaskMoveAnotherProjectTest.php
@@ -3,6 +3,7 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskCreationModel;
@@ -21,7 +22,13 @@ class TaskMoveAnotherProjectTest extends Base
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskMoveAnotherProject($this->container);
$action->setProjectId(1);
@@ -44,7 +51,13 @@ class TaskMoveAnotherProjectTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskMoveAnotherProject($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskMoveColumnAssignedTest.php b/tests/units/Action/TaskMoveColumnAssignedTest.php
index f8982969..aa9d3592 100644
--- a/tests/units/Action/TaskMoveColumnAssignedTest.php
+++ b/tests/units/Action/TaskMoveColumnAssignedTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskCreationModel;
@@ -19,9 +19,12 @@ class TaskMoveColumnAssignedTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 1)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => $taskFinderModel->getDetails(1),
+ ));
$action = new TaskMoveColumnAssigned($this->container);
$action->setProjectId(1);
@@ -43,7 +46,14 @@ class TaskMoveColumnAssignedTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3, 'owner_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ 'owner_id' => 1,
+ )
+ ));
$action = new TaskMoveColumnAssigned($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php
index c42383f8..7e0856df 100644
--- a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php
+++ b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\CategoryModel;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
@@ -24,7 +24,16 @@ class TaskMoveColumnCategoryChangeTest extends Base
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'category_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 1,
+ 'category_id' => 1,
+ 'position' => 1,
+ 'swimlane_id' => 0,
+ )
+ ));
$action = new TaskMoveColumnCategoryChange($this->container);
$action->setProjectId(1);
@@ -50,7 +59,14 @@ class TaskMoveColumnCategoryChangeTest extends Base
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2, 'category_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ 'category_id' => 1,
+ )
+ ));
$action = new TaskMoveColumnCategoryChange($this->container);
$action->setProjectId(1);
@@ -72,7 +88,14 @@ class TaskMoveColumnCategoryChangeTest extends Base
$this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 1)));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'category_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 1,
+ 'category_id' => 2,
+ )
+ ));
$action = new TaskMoveColumnCategoryChange($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskMoveColumnClosedTest.php b/tests/units/Action/TaskMoveColumnClosedTest.php
new file mode 100644
index 00000000..318b995d
--- /dev/null
+++ b/tests/units/Action/TaskMoveColumnClosedTest.php
@@ -0,0 +1,91 @@
+<?php
+
+use Kanboard\Action\TaskMoveColumnClosed;
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskMoveColumnClosedTest extends Base
+{
+ public function testSuccess()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0)));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $action = new TaskMoveColumnClosed($this->container);
+ $action->setProjectId(1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_CLOSE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(2, $task['column_id']);
+ }
+
+ public function testWhenTaskIsOpen()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $action = new TaskMoveColumnClosed($this->container);
+ $action->setProjectId(1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(1, $task['column_id']);
+ }
+
+ public function testWhenTaskIsAlreadyInDestinationColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0, 'column_id' => 2)));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $action = new TaskMoveColumnClosed($this->container);
+ $action->setProjectId(1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertFalse($action->execute($event, TaskModel::EVENT_CLOSE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(2, $task['column_id']);
+ }
+}
diff --git a/tests/units/Action/TaskMoveColumnNotMovedPeriodTest.php b/tests/units/Action/TaskMoveColumnNotMovedPeriodTest.php
new file mode 100644
index 00000000..7fa16cf2
--- /dev/null
+++ b/tests/units/Action/TaskMoveColumnNotMovedPeriodTest.php
@@ -0,0 +1,50 @@
+<?php
+
+use Kanboard\Action\TaskMoveColumnNotMovedPeriod;
+use Kanboard\Event\TaskListEvent;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskMoveColumnNotMovedPeriodTest extends Base
+{
+ public function testAction()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 3)));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $this->container['db']->table(TaskModel::TABLE)->in('id', array(2, 3))->update(array('date_moved' => strtotime('-10days')));
+
+ $tasks = $taskFinderModel->getAll(1);
+ $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1));
+
+ $action = new TaskMoveColumnNotMovedPeriod($this->container);
+ $action->setProjectId(1);
+ $action->setParam('duration', 2);
+ $action->setParam('src_column_id', 2);
+ $action->setParam('dest_column_id', 3);
+
+ $this->assertTrue($action->execute($event, TaskModel::EVENT_DAILY_CRONJOB));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['column_id']);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3, $task['column_id']);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3, $task['column_id']);
+ }
+}
diff --git a/tests/units/Action/TaskMoveColumnUnAssignedTest.php b/tests/units/Action/TaskMoveColumnUnAssignedTest.php
index befae36b..b45dec08 100644
--- a/tests/units/Action/TaskMoveColumnUnAssignedTest.php
+++ b/tests/units/Action/TaskMoveColumnUnAssignedTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\TaskCreationModel;
@@ -21,7 +21,16 @@ class TaskMoveColumnUnAssignedTest extends Base
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 0));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 1,
+ 'owner_id' => 0,
+ 'position' => 1,
+ 'swimlane_id' => 0,
+ )
+ ));
$action = new TaskMoveColumnUnAssigned($this->container);
$action->setProjectId(1);
@@ -43,7 +52,14 @@ class TaskMoveColumnUnAssignedTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2, 'owner_id' => 0));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ 'owner_id' => 0,
+ )
+ ));
$action = new TaskMoveColumnUnAssigned($this->container);
$action->setProjectId(1);
@@ -60,7 +76,14 @@ class TaskMoveColumnUnAssignedTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 1,
+ 'owner_id' => 1,
+ )
+ ));
$action = new TaskMoveColumnUnAssigned($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskOpenTest.php b/tests/units/Action/TaskOpenTest.php
index 1018e2ea..825c6ac9 100644
--- a/tests/units/Action/TaskOpenTest.php
+++ b/tests/units/Action/TaskOpenTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -19,7 +19,12 @@ class TaskOpenTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0)));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ )
+ ));
$action = new TaskOpen($this->container);
$action->setProjectId(1);
@@ -40,7 +45,11 @@ class TaskOpenTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1));
+ $event = new TaskEvent(array(
+ 'task' => array(
+ 'project_id' => 1,
+ )
+ ));
$action = new TaskOpen($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Action/TaskUpdateStartDateTest.php b/tests/units/Action/TaskUpdateStartDateTest.php
index ddd9eafd..05fac100 100644
--- a/tests/units/Action/TaskUpdateStartDateTest.php
+++ b/tests/units/Action/TaskUpdateStartDateTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\GenericEvent;
+use Kanboard\Event\TaskEvent;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
@@ -11,7 +11,7 @@ use Kanboard\Action\TaskUpdateStartDate;
class TaskUpdateStartDateTest extends Base
{
- public function testClose()
+ public function testAction()
{
$projectModel = new ProjectModel($this->container);
$taskCreationModel = new TaskCreationModel($this->container);
@@ -20,7 +20,13 @@ class TaskUpdateStartDateTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 2,
+ )
+ ));
$action = new TaskUpdateStartDate($this->container);
$action->setProjectId(1);
@@ -41,7 +47,13 @@ class TaskUpdateStartDateTest extends Base
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+ $event = new TaskEvent(array(
+ 'task_id' => 1,
+ 'task' => array(
+ 'project_id' => 1,
+ 'column_id' => 3,
+ )
+ ));
$action = new TaskUpdateStartDate($this->container);
$action->setProjectId(1);
diff --git a/tests/units/Auth/ReverseProxyAuthTest.php b/tests/units/Auth/ReverseProxyAuthTest.php
new file mode 100644
index 00000000..cdbc247d
--- /dev/null
+++ b/tests/units/Auth/ReverseProxyAuthTest.php
@@ -0,0 +1,111 @@
+<?php
+
+use Kanboard\Auth\ReverseProxyAuth;
+use Kanboard\Core\Security\Role;
+use Kanboard\Model\UserModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ReverseProxyAuthTest extends Base
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->container['request'] = $this
+ ->getMockBuilder('\Kanboard\Core\Http\Request')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('getRemoteUser'))
+ ->getMock();
+ }
+
+ public function testGetName()
+ {
+ $provider = new ReverseProxyAuth($this->container);
+ $this->assertEquals('ReverseProxy', $provider->getName());
+ }
+
+ public function testAuthenticateSuccess()
+ {
+ $this->container['request']
+ ->expects($this->once())
+ ->method('getRemoteUser')
+ ->will($this->returnValue('admin'));
+
+ $provider = new ReverseProxyAuth($this->container);
+ $this->assertTrue($provider->authenticate());
+ }
+
+ public function testAuthenticateFailure()
+ {
+ $this->container['request']
+ ->expects($this->once())
+ ->method('getRemoteUser')
+ ->will($this->returnValue(''));
+
+ $provider = new ReverseProxyAuth($this->container);
+ $this->assertFalse($provider->authenticate());
+ }
+
+ public function testValidSession()
+ {
+ $this->container['request']
+ ->expects($this->once())
+ ->method('getRemoteUser')
+ ->will($this->returnValue('admin'));
+
+ $this->container['sessionStorage']->user = array(
+ 'username' => 'admin'
+ );
+
+ $provider = new ReverseProxyAuth($this->container);
+ $this->assertTrue($provider->isValidSession());
+ }
+
+ public function testInvalidSession()
+ {
+ $this->container['request']
+ ->expects($this->once())
+ ->method('getRemoteUser')
+ ->will($this->returnValue('foobar'));
+
+ $this->container['sessionStorage']->user = array(
+ 'username' => 'admin'
+ );
+
+ $provider = new ReverseProxyAuth($this->container);
+ $this->assertFalse($provider->isValidSession());
+ }
+
+ public function testRoleForNewUser()
+ {
+ $this->container['request']
+ ->expects($this->once())
+ ->method('getRemoteUser')
+ ->will($this->returnValue('someone'));
+
+ $provider = new ReverseProxyAuth($this->container);
+ $this->assertTrue($provider->authenticate());
+
+ $user = $provider->getUser();
+ $this->assertEquals(Role::APP_USER, $user->getRole());
+ }
+
+ public function testRoleIsPreservedForExistingUser()
+ {
+ $this->container['request']
+ ->expects($this->once())
+ ->method('getRemoteUser')
+ ->will($this->returnValue('someone'));
+
+ $provider = new ReverseProxyAuth($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'someone', 'role' => Role::APP_MANAGER)));
+
+ $this->assertTrue($provider->authenticate());
+
+ $user = $provider->getUser();
+ $this->assertEquals(Role::APP_MANAGER, $user->getRole());
+ }
+}
diff --git a/tests/units/Auth/TotpAuthTest.php b/tests/units/Auth/TotpAuthTest.php
index c8dcfb28..3a82c01c 100644
--- a/tests/units/Auth/TotpAuthTest.php
+++ b/tests/units/Auth/TotpAuthTest.php
@@ -35,16 +35,17 @@ class TotpAuthTest extends Base
public function testGetUrl()
{
$provider = new TotpAuth($this->container);
+
$this->assertEmpty($provider->getQrCodeUrl('me'));
$this->assertEmpty($provider->getKeyUrl('me'));
$provider->setSecret('mySecret');
$this->assertEquals(
- 'https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=M|0&chl=otpauth%3A%2F%2Ftotp%2Fme%3Fsecret%3DmySecret',
+ 'https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=M|0&chl=otpauth%3A%2F%2Ftotp%2Fme%3Fsecret%3DmySecret%26issuer%3DKanboard',
$provider->getQrCodeUrl('me')
);
- $this->assertEquals('otpauth://totp/me?secret=mySecret', $provider->getKeyUrl('me'));
+ $this->assertEquals('otpauth://totp/me?secret=mySecret&issuer=Kanboard', $provider->getKeyUrl('me'));
}
public function testAuthentication()
diff --git a/tests/units/Base.php b/tests/units/Base.php
index f7bee241..e44223ce 100644
--- a/tests/units/Base.php
+++ b/tests/units/Base.php
@@ -16,6 +16,11 @@ abstract class Base extends PHPUnit_Framework_TestCase
{
protected $container;
+ /**
+ * @var EventDispatcher
+ */
+ protected $dispatcher;
+
public function setUp()
{
date_default_timezone_set('UTC');
@@ -41,6 +46,7 @@ abstract class Base extends PHPUnit_Framework_TestCase
$this->container->register(new Kanboard\ServiceProvider\RouteProvider());
$this->container->register(new Kanboard\ServiceProvider\AvatarProvider());
$this->container->register(new Kanboard\ServiceProvider\FilterProvider());
+ $this->container->register(new Kanboard\ServiceProvider\JobProvider());
$this->container->register(new Kanboard\ServiceProvider\QueueProvider());
$this->container['dispatcher'] = new TraceableEventDispatcher(
@@ -48,8 +54,10 @@ abstract class Base extends PHPUnit_Framework_TestCase
new Stopwatch
);
- $this->container['db']->logQueries = true;
- $this->container['logger'] = new Logger;
+ $this->dispatcher = $this->container['dispatcher'];
+
+ $this->container['db']->getStatementHandler()->withLogging();
+ $this->container['logger'] = new Logger();
$this->container['httpClient'] = $this
->getMockBuilder('\Kanboard\Core\Http\Client')
diff --git a/tests/units/Core/Action/ActionManagerTest.php b/tests/units/Core/Action/ActionManagerTest.php
index e7c2071f..4878c0c9 100644
--- a/tests/units/Core/Action/ActionManagerTest.php
+++ b/tests/units/Core/Action/ActionManagerTest.php
@@ -96,7 +96,7 @@ class ActionManagerTest extends Base
$actions = $actionManager->getAvailableActions();
$actionManager->attachEvents();
- $this->assertEmpty($this->container['dispatcher']->getListeners());
+ $this->assertEmpty($this->dispatcher->getListeners());
$this->assertEquals(1, $projectModel->create(array('name' =>'test')));
$this->assertEquals(1, $actionModel->create(array(
@@ -107,7 +107,7 @@ class ActionManagerTest extends Base
)));
$actionManager->attachEvents();
- $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_CREATE);
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE);
$this->assertCount(1, $listeners);
$this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]);
@@ -148,7 +148,7 @@ class ActionManagerTest extends Base
$actionManager->attachEvents();
- $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN);
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_MOVE_COLUMN);
$this->assertCount(1, $listeners);
$this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]);
@@ -158,7 +158,6 @@ class ActionManagerTest extends Base
public function testThatEachListenerAreDifferentInstance()
{
$projectModel = new ProjectModel($this->container);
- $projectUserRoleModel = new ProjectUserRoleModel($this->container);
$actionModel = new ActionModel($this->container);
$actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container);
$actionManager = new ActionManager($this->container);
@@ -183,7 +182,7 @@ class ActionManagerTest extends Base
$actionManager->attachEvents();
- $listeners = $this->container['dispatcher']->getListeners(TaskModel::EVENT_MOVE_COLUMN);
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_MOVE_COLUMN);
$this->assertCount(2, $listeners);
$this->assertFalse($listeners[0][0] === $listeners[1][0]);
@@ -193,4 +192,35 @@ class ActionManagerTest extends Base
$this->assertEquals(1, $listeners[1][0]->getParam('column_id'));
$this->assertEquals('red', $listeners[1][0]->getParam('color_id'));
}
+
+ public function testRemoveEvents()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $actionModel = new ActionModel($this->container);
+ $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container);
+ $actionManager = new ActionManager($this->container);
+ $actionManager->register($actionTaskAssignColorColumn);
+
+ $actions = $actionManager->getAvailableActions();
+
+ $this->assertEquals(1, $projectModel->create(array('name' =>'test')));
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => TaskModel::EVENT_CREATE,
+ 'action_name' => key($actions),
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $actionManager->attachEvents();
+ $this->dispatcher->addListener(TaskModel::EVENT_CREATE, function () {});
+
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE);
+ $this->assertCount(2, $listeners);
+
+ $actionManager->removeEvents();
+
+ $listeners = $this->dispatcher->getListeners(TaskModel::EVENT_CREATE);
+ $this->assertCount(1, $listeners);
+ $this->assertNotInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0]);
+ }
}
diff --git a/tests/units/Core/Filter/LexerBuilderTest.php b/tests/units/Core/Filter/LexerBuilderTest.php
index 23726f32..31e237dc 100644
--- a/tests/units/Core/Filter/LexerBuilderTest.php
+++ b/tests/units/Core/Filter/LexerBuilderTest.php
@@ -8,6 +8,7 @@ use Kanboard\Filter\TaskTitleFilter;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\UserModel;
class LexerBuilderTest extends Base
{
@@ -103,4 +104,49 @@ class LexerBuilderTest extends Base
$this->assertFalse($builder === $clone);
$this->assertFalse($builder->build('test')->getQuery() === $clone->build('test')->getQuery());
}
+
+ public function testBuilderWithMixedCaseSearchAttribute()
+ {
+ $project = new ProjectModel($this->container);
+ $taskCreation = new TaskCreationModel($this->container);
+ $taskFinder = new TaskFinderModel($this->container);
+ $query = $taskFinder->getExtendedQuery();
+
+ $this->assertEquals(1, $project->create(array('name' => 'Project')));
+ $this->assertNotFalse($taskCreation->create(array('project_id' => 1, 'title' => 'Test')));
+
+ $builder = new LexerBuilder();
+ $builder->withFilter(new TaskAssigneeFilter());
+ $builder->withFilter(new TaskTitleFilter(), true);
+ $builder->withQuery($query);
+ $tasks = $builder->build('AsSignEe:nobody')->toArray();
+
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Test', $tasks[0]['title']);
+ }
+
+ public function testWithOrCriteria()
+ {
+ $taskFinder = new TaskFinderModel($this->container);
+ $taskCreation = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $userModel = new UserModel($this->container);
+ $query = $taskFinder->getExtendedQuery();
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test 1', 'project_id' => 1, 'owner_id' => 2)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test 2', 'project_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(3, $taskCreation->create(array('title' => 'Test 3', 'project_id' => 1, 'owner_id' => 0)));
+
+ $builder = new LexerBuilder();
+ $builder->withFilter(new TaskAssigneeFilter());
+ $builder->withFilter(new TaskTitleFilter(), true);
+ $builder->withQuery($query);
+ $tasks = $builder->build('assignee:admin assignee:foobar')->toArray();
+
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('Test 1', $tasks[0]['title']);
+ $this->assertEquals('Test 2', $tasks[1]['title']);
+ }
}
diff --git a/tests/units/Core/Filter/LexerTest.php b/tests/units/Core/Filter/LexerTest.php
index c72231c4..d57a7953 100644
--- a/tests/units/Core/Filter/LexerTest.php
+++ b/tests/units/Core/Filter/LexerTest.php
@@ -202,4 +202,60 @@ class LexerTest extends Base
$this->assertSame($expected, $lexer->tokenize('६Δↈ五一'));
}
+
+ public function testTokenizeWithMultipleValues()
+ {
+ $lexer = new Lexer();
+ $lexer->addToken("/^(tag:)/", 'T_TAG');
+
+ $expected = array(
+ 'T_TAG' => array('tag 1', 'tag2'),
+ );
+
+ $this->assertSame($expected, $lexer->tokenize('tag:"tag 1" tag:tag2'));
+ }
+
+ public function testTokenizeWithDash()
+ {
+ $lexer = new Lexer();
+ $lexer->addToken("/^(test:)/", 'T_TEST');
+
+ $expected = array(
+ 'T_TEST' => array('PO-123'),
+ );
+
+ $this->assertSame($expected, $lexer->tokenize('test:PO-123'));
+
+ $lexer = new Lexer();
+ $lexer->setDefaultToken('myDefaultToken');
+
+ $expected = array(
+ 'myDefaultToken' => array('PO-123'),
+ );
+
+ $this->assertSame($expected, $lexer->tokenize('PO-123'));
+ }
+
+ public function testTokenizeWithUnderscore()
+ {
+ $lexer = new Lexer();
+ $lexer->addToken("/^(test:)/", 'T_TEST');
+
+ $expected = array(
+ 'T_TEST' => array('PO_123'),
+ );
+
+ $this->assertSame($expected, $lexer->tokenize('test:PO_123'));
+
+ $lexer = new Lexer();
+ $lexer->addToken("/^(test:)/", 'T_TEST');
+ $lexer->setDefaultToken('myDefaultToken');
+
+ $expected = array(
+ 'T_TEST' => array('ABC-123'),
+ 'myDefaultToken' => array('PO_123'),
+ );
+
+ $this->assertSame($expected, $lexer->tokenize('test:ABC-123 PO_123'));
+ }
}
diff --git a/tests/units/Core/Filter/OrCriteriaTest.php b/tests/units/Core/Filter/OrCriteriaTest.php
index a46726c3..cf520f36 100644
--- a/tests/units/Core/Filter/OrCriteriaTest.php
+++ b/tests/units/Core/Filter/OrCriteriaTest.php
@@ -22,8 +22,9 @@ class OrCriteriaTest extends Base
$this->assertEquals(2, $userModel->create(array('username' => 'foobar', 'name' => 'Foo Bar')));
$this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
- $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 2)));
- $this->assertEquals(2, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test 1', 'project_id' => 1, 'owner_id' => 2)));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test 2', 'project_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(3, $taskCreation->create(array('title' => 'Test 3', 'project_id' => 1, 'owner_id' => 0)));
$criteria = new OrCriteria();
$criteria->withQuery($query);
diff --git a/tests/units/Core/Http/RequestTest.php b/tests/units/Core/Http/RequestTest.php
index 6fa796f7..1db0100c 100644
--- a/tests/units/Core/Http/RequestTest.php
+++ b/tests/units/Core/Http/RequestTest.php
@@ -169,6 +169,9 @@ class RequestTest extends Base
$request = new Request($this->container, array(), array(), array(), array(), array());
$this->assertEquals('Unknown', $request->getIpAddress());
+ $request = new Request($this->container, array('HTTP_X_REAL_IP' => '192.168.1.1,127.0.0.1'), array(), array(), array(), array());
+ $this->assertEquals('192.168.1.1', $request->getIpAddress());
+
$request = new Request($this->container, array('HTTP_X_FORWARDED_FOR' => '192.168.0.1,127.0.0.1'), array(), array(), array(), array());
$this->assertEquals('192.168.0.1', $request->getIpAddress());
diff --git a/tests/units/Core/Ldap/LdapUserTest.php b/tests/units/Core/Ldap/LdapUserTest.php
index 505b8a03..143a8c0d 100644
--- a/tests/units/Core/Ldap/LdapUserTest.php
+++ b/tests/units/Core/Ldap/LdapUserTest.php
@@ -845,4 +845,64 @@ class LdapUserTest extends Base
$this->assertTrue($this->user->hasGroupUserFilter());
}
+
+ public function testHasGroupsConfigured()
+ {
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupAdminDn')
+ ->will($this->returnValue('something'));
+
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupManagerDn')
+ ->will($this->returnValue('something'));
+
+ $this->assertTrue($this->user->hasGroupsConfigured());
+ }
+
+ public function testHasGroupAdminDnConfigured()
+ {
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupAdminDn')
+ ->will($this->returnValue('something'));
+
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupManagerDn')
+ ->will($this->returnValue(''));
+
+ $this->assertTrue($this->user->hasGroupsConfigured());
+ }
+
+ public function testHasGroupManagerDnConfigured()
+ {
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupAdminDn')
+ ->will($this->returnValue(''));
+
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupManagerDn')
+ ->will($this->returnValue('something'));
+
+ $this->assertTrue($this->user->hasGroupsConfigured());
+ }
+
+ public function testHasGroupsNotConfigured()
+ {
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupAdminDn')
+ ->will($this->returnValue(''));
+
+ $this->user
+ ->expects($this->any())
+ ->method('getGroupManagerDn')
+ ->will($this->returnValue(''));
+
+ $this->assertFalse($this->user->hasGroupsConfigured());
+ }
}
diff --git a/tests/units/EventBuilder/CommentEventBuilderTest.php b/tests/units/EventBuilder/CommentEventBuilderTest.php
new file mode 100644
index 00000000..2f6a90b5
--- /dev/null
+++ b/tests/units/EventBuilder/CommentEventBuilderTest.php
@@ -0,0 +1,37 @@
+<?php
+
+use Kanboard\EventBuilder\CommentEventBuilder;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class CommentEventBuilderTest extends Base
+{
+ public function testWithMissingComment()
+ {
+ $commentEventBuilder = new CommentEventBuilder($this->container);
+ $commentEventBuilder->withCommentId(42);
+ $this->assertNull($commentEventBuilder->buildEvent());
+ }
+
+ public function testBuild()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $commentEventBuilder = new CommentEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
+
+ $commentEventBuilder->withCommentId(1);
+ $event = $commentEventBuilder->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\CommentEvent', $event);
+ $this->assertNotEmpty($event['comment']);
+ $this->assertNotEmpty($event['task']);
+ }
+}
diff --git a/tests/units/EventBuilder/ProjectFileEventBuilderTest.php b/tests/units/EventBuilder/ProjectFileEventBuilderTest.php
new file mode 100644
index 00000000..8f5eb87e
--- /dev/null
+++ b/tests/units/EventBuilder/ProjectFileEventBuilderTest.php
@@ -0,0 +1,33 @@
+<?php
+
+use Kanboard\EventBuilder\ProjectFileEventBuilder;
+use Kanboard\Model\ProjectFileModel;
+use Kanboard\Model\ProjectModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectFileEventBuilderTest extends Base
+{
+ public function testWithMissingFile()
+ {
+ $projectFileEventBuilder = new ProjectFileEventBuilder($this->container);
+ $projectFileEventBuilder->withFileId(42);
+ $this->assertNull($projectFileEventBuilder->buildEvent());
+ }
+
+ public function testBuild()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectFileModel = new ProjectFileModel($this->container);
+ $projectFileEventBuilder = new ProjectFileEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $projectFileModel->create(1, 'Test', '/tmp/test', 123));
+
+ $event = $projectFileEventBuilder->withFileId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\ProjectFileEvent', $event);
+ $this->assertNotEmpty($event['file']);
+ $this->assertNotEmpty($event['project']);
+ }
+}
diff --git a/tests/units/EventBuilder/SubtaskEventBuilderTest.php b/tests/units/EventBuilder/SubtaskEventBuilderTest.php
new file mode 100644
index 00000000..fe425cb8
--- /dev/null
+++ b/tests/units/EventBuilder/SubtaskEventBuilderTest.php
@@ -0,0 +1,62 @@
+<?php
+
+use Kanboard\EventBuilder\SubtaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskEventBuilderTest extends Base
+{
+ public function testWithMissingSubtask()
+ {
+ $subtaskEventBuilder = new SubtaskEventBuilder($this->container);
+ $subtaskEventBuilder->withSubtaskId(42);
+ $this->assertNull($subtaskEventBuilder->buildEvent());
+ }
+
+ public function testBuildWithoutChanges()
+ {
+ $subtaskModel = new SubtaskModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskEventBuilder = new SubtaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'test')));
+
+ $event = $subtaskEventBuilder->withSubtaskId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
+ $this->assertNotEmpty($event['subtask']);
+ $this->assertNotEmpty($event['task']);
+ $this->assertArrayNotHasKey('changes', $event);
+ }
+
+ public function testBuildWithChanges()
+ {
+ $subtaskModel = new SubtaskModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskEventBuilder = new SubtaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'test')));
+
+ $event = $subtaskEventBuilder
+ ->withSubtaskId(1)
+ ->withValues(array('title' => 'new title', 'user_id' => 1))
+ ->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
+ $this->assertNotEmpty($event['subtask']);
+ $this->assertNotEmpty($event['task']);
+ $this->assertNotEmpty($event['changes']);
+ $this->assertCount(2, $event['changes']);
+ $this->assertEquals('new title', $event['changes']['title']);
+ $this->assertEquals(1, $event['changes']['user_id']);
+ }
+}
diff --git a/tests/units/EventBuilder/TaskEventBuilderTest.php b/tests/units/EventBuilder/TaskEventBuilderTest.php
new file mode 100644
index 00000000..c89dcd85
--- /dev/null
+++ b/tests/units/EventBuilder/TaskEventBuilderTest.php
@@ -0,0 +1,100 @@
+<?php
+
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskEventBuilderTest extends Base
+{
+ public function testWithMissingTask()
+ {
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+ $taskEventBuilder->withTaskId(42);
+ $this->assertNull($taskEventBuilder->buildEvent());
+ }
+
+ public function testBuildWithTask()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'before', 'project_id' => 1)));
+
+ $event = $taskEventBuilder
+ ->withTaskId(1)
+ ->withTask(array('title' => 'before'))
+ ->withChanges(array('title' => 'after'))
+ ->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+ $this->assertNotEmpty($event['task']);
+ $this->assertEquals(1, $event['task_id']);
+ $this->assertEquals(array('title' => 'after'), $event['changes']);
+ }
+
+ public function testBuildWithoutChanges()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = $taskEventBuilder->withTaskId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+ $this->assertNotEmpty($event['task']);
+ $this->assertEquals(1, $event['task_id']);
+ $this->assertArrayNotHasKey('changes', $event);
+ }
+
+ public function testBuildWithChanges()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = $taskEventBuilder
+ ->withTaskId(1)
+ ->withChanges(array('title' => 'new title'))
+ ->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+ $this->assertNotEmpty($event['task']);
+ $this->assertNotEmpty($event['changes']);
+ $this->assertEquals('new title', $event['changes']['title']);
+ }
+
+ public function testBuildWithChangesAndValues()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskEventBuilder = new TaskEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = $taskEventBuilder
+ ->withTaskId(1)
+ ->withChanges(array('title' => 'new title', 'project_id' => 1))
+ ->withValues(array('key' => 'value'))
+ ->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+ $this->assertNotEmpty($event['task']);
+ $this->assertNotEmpty($event['changes']);
+ $this->assertNotEmpty($event['key']);
+ $this->assertEquals('value', $event['key']);
+
+ $this->assertCount(1, $event['changes']);
+ $this->assertEquals('new title', $event['changes']['title']);
+ }
+}
diff --git a/tests/units/EventBuilder/TaskFileEventBuilderTest.php b/tests/units/EventBuilder/TaskFileEventBuilderTest.php
new file mode 100644
index 00000000..c90e18d3
--- /dev/null
+++ b/tests/units/EventBuilder/TaskFileEventBuilderTest.php
@@ -0,0 +1,36 @@
+<?php
+
+use Kanboard\EventBuilder\TaskFileEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFileModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskFileEventBuilderTest extends Base
+{
+ public function testWithMissingFile()
+ {
+ $taskFileEventBuilder = new TaskFileEventBuilder($this->container);
+ $taskFileEventBuilder->withFileId(42);
+ $this->assertNull($taskFileEventBuilder->buildEvent());
+ }
+
+ public function testBuild()
+ {
+ $taskFileModel = new TaskFileModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFileEventBuilder = new TaskFileEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $taskFileModel->create(1, 'Test', '/tmp/test', 123));
+
+ $event = $taskFileEventBuilder->withFileId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskFileEvent', $event);
+ $this->assertNotEmpty($event['file']);
+ $this->assertNotEmpty($event['task']);
+ }
+}
diff --git a/tests/units/EventBuilder/TaskLinkEventBuilderTest.php b/tests/units/EventBuilder/TaskLinkEventBuilderTest.php
new file mode 100644
index 00000000..18508146
--- /dev/null
+++ b/tests/units/EventBuilder/TaskLinkEventBuilderTest.php
@@ -0,0 +1,70 @@
+<?php
+
+use Kanboard\EventBuilder\TaskLinkEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskLinkModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskLinkEventBuilderTest extends Base
+{
+ public function testWithMissingLink()
+ {
+ $taskLinkEventBuilder = new TaskLinkEventBuilder($this->container);
+ $taskLinkEventBuilder->withTaskLinkId(42);
+ $this->assertNull($taskLinkEventBuilder->buildEvent());
+ }
+
+ public function testBuild()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkEventBuilder = new TaskLinkEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $event = $taskLinkEventBuilder->withTaskLinkId(1)->buildEvent();
+
+ $this->assertInstanceOf('Kanboard\Event\TaskLinkEvent', $event);
+ $this->assertNotEmpty($event['task_link']);
+ $this->assertNotEmpty($event['task']);
+ }
+
+ public function testBuildTitle()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkEventBuilder = new TaskLinkEventBuilder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $eventData = $taskLinkEventBuilder->withTaskLinkId(1)->buildEvent();
+
+ $title = $taskLinkEventBuilder->buildTitleWithAuthor('Foobar', TaskLinkModel::EVENT_CREATE_UPDATE, $eventData->getAll());
+ $this->assertEquals('Foobar set a new internal link for the task #1', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithAuthor('Foobar', TaskLinkModel::EVENT_DELETE, $eventData->getAll());
+ $this->assertEquals('Foobar removed an internal link for the task #1', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithAuthor('Foobar', 'not found', $eventData->getAll());
+ $this->assertSame('', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithoutAuthor(TaskLinkModel::EVENT_CREATE_UPDATE, $eventData->getAll());
+ $this->assertEquals('A new internal link for the task #1 have been defined', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithoutAuthor(TaskLinkModel::EVENT_DELETE, $eventData->getAll());
+ $this->assertEquals('Internal link removed for the task #1', $title);
+
+ $title = $taskLinkEventBuilder->buildTitleWithoutAuthor('not found', $eventData->getAll());
+ $this->assertSame('', $title);
+ }
+}
diff --git a/tests/units/Filter/TaskMovedDateFilterTest.php b/tests/units/Filter/TaskMovedDateFilterTest.php
new file mode 100644
index 00000000..9b721913
--- /dev/null
+++ b/tests/units/Filter/TaskMovedDateFilterTest.php
@@ -0,0 +1,43 @@
+<?php
+
+use Kanboard\Filter\TaskMovedDateFilter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModificationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\UserModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskMovedDateFilterTest extends Base
+{
+ public function test()
+ {
+ $taskFinder = new TaskFinderModel($this->container);
+ $taskCreation = new TaskCreationModel($this->container);
+ $taskModification = new TaskModificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test1', 'project_id' => 1)));
+ $this->assertTrue($taskModification->update(array('id' => 1, 'date_moved' => time())));
+ $this->assertEquals(2, $taskCreation->create(array('title' => 'Test2', 'project_id' => 1)));
+ $this->assertTrue($taskModification->update(array('id' => 2, 'date_moved' => strtotime('-1days'))));
+ $this->assertEquals(3, $taskCreation->create(array('title' => 'Test3', 'project_id' => 1)));
+ $this->assertTrue($taskModification->update(array('id' => 3, 'date_moved' => strtotime('-3days'))));
+
+ $query = $taskFinder->getExtendedQuery();
+ $filter = new TaskMovedDateFilter('>='.date('Y-m-d', strtotime('-1days')));
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $this->assertCount(2, $query->findAll());
+
+ $query = $taskFinder->getExtendedQuery();
+ $filter = new TaskMovedDateFilter('<yesterday');
+ $filter->setDateParser($this->container['dateParser']);
+ $filter->withQuery($query)->apply();
+
+ $this->assertCount(1, $query->findAll());
+ }
+}
diff --git a/tests/units/Filter/TaskPriorityFilterTest.php b/tests/units/Filter/TaskPriorityFilterTest.php
new file mode 100644
index 00000000..4c95ddce
--- /dev/null
+++ b/tests/units/Filter/TaskPriorityFilterTest.php
@@ -0,0 +1,47 @@
+<?php
+
+use Kanboard\Filter\TaskPriorityFilter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskPriorityFilterTest extends Base
+{
+ public function testWithDefinedPriority()
+ {
+ $taskFinder = new TaskFinderModel($this->container);
+ $taskCreation = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $query = $taskFinder->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1, 'priority' => 2)));
+
+ $filter = new TaskPriorityFilter();
+ $filter->withQuery($query);
+ $filter->withValue(2);
+ $filter->apply();
+
+ $this->assertCount(1, $query->findAll());
+ }
+
+ public function testWithNoPriority()
+ {
+ $taskFinder = new TaskFinderModel($this->container);
+ $taskCreation = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $query = $taskFinder->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreation->create(array('title' => 'Test', 'project_id' => 1)));
+
+ $filter = new TaskPriorityFilter();
+ $filter->withQuery($query);
+ $filter->withValue(2);
+ $filter->apply();
+
+ $this->assertCount(0, $query->findAll());
+ }
+}
diff --git a/tests/units/Filter/TaskTagFilterTest.php b/tests/units/Filter/TaskTagFilterTest.php
new file mode 100644
index 00000000..72ed9904
--- /dev/null
+++ b/tests/units/Filter/TaskTagFilterTest.php
@@ -0,0 +1,122 @@
+<?php
+
+use Kanboard\Filter\TaskTagFilter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskTagModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskTagFilterTest extends Base
+{
+ public function testWithMultipleMatches()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
+ $this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
+
+ $filter = new TaskTagFilter();
+ $filter->setDatabase($this->container['db']);
+ $filter->withQuery($query);
+ $filter->withValue('my tag 3');
+ $filter->apply();
+
+ $tasks = $query->asc(TaskModel::TABLE.'.title')->findAll();
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('test1', $tasks[0]['title']);
+ $this->assertEquals('test2', $tasks[1]['title']);
+ }
+
+ public function testWithSingleMatch()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
+ $this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
+
+ $filter = new TaskTagFilter();
+ $filter->setDatabase($this->container['db']);
+ $filter->withQuery($query);
+ $filter->withValue('my tag 2');
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('test1', $tasks[0]['title']);
+ }
+
+ public function testWithNoMatch()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
+ $this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
+
+ $filter = new TaskTagFilter();
+ $filter->setDatabase($this->container['db']);
+ $filter->withQuery($query);
+ $filter->withValue('my tag 42');
+ $filter->apply();
+
+ $tasks = $query->findAll();
+ $this->assertCount(0, $tasks);
+ }
+
+ public function testWithSameTagInMultipleProjects()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+ $query = $taskFinderModel->getExtendedQuery();
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 2, 'title' => 'test2')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag')));
+ $this->assertTrue($taskTagModel->save(2, 2, array('My tag')));
+
+ $filter = new TaskTagFilter();
+ $filter->setDatabase($this->container['db']);
+ $filter->withQuery($query);
+ $filter->withValue('my tag');
+ $filter->apply();
+
+ $tasks = $query->asc(TaskModel::TABLE.'.title')->findAll();
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('test1', $tasks[0]['title']);
+ $this->assertEquals('test2', $tasks[1]['title']);
+ }
+}
diff --git a/tests/units/Formatter/BoardFormatterTest.php b/tests/units/Formatter/BoardFormatterTest.php
new file mode 100644
index 00000000..c107eaf5
--- /dev/null
+++ b/tests/units/Formatter/BoardFormatterTest.php
@@ -0,0 +1,392 @@
+<?php
+
+use Kanboard\Formatter\BoardFormatter;
+use Kanboard\Model\ColumnModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SwimlaneModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskTagModel;
+
+require_once __DIR__.'/../Base.php';
+
+class BoardFormatterTest extends Base
+{
+ public function testFormatWithSwimlanes()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $swimlaneModel->create(array('name' => 'Swimlane 1', 'project_id' => 1)));
+ $this->assertEquals(2, $swimlaneModel->create(array('name' => 'Swimlane 2', 'project_id' => 1)));
+
+ // 2 task within the same column but no score
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task 1', 'project_id' => 1, 'swimlane_id' => 0, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task 2', 'project_id' => 1, 'swimlane_id' => 0, 'column_id' => 1)));
+
+ // 2 tasks in the same column with score
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task 3', 'project_id' => 1, 'swimlane_id' => 0, 'column_id' => 1, 'score' => 4)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task 4', 'project_id' => 1, 'swimlane_id' => 0, 'column_id' => 1, 'score' => 5)));
+
+ // 1 task in 2nd column
+ $this->assertEquals(5, $taskCreationModel->create(array('title' => 'Task 5', 'project_id' => 1, 'swimlane_id' => 0, 'column_id' => 2)));
+
+ // tasks in same column but different swimlanes
+ $this->assertEquals(6, $taskCreationModel->create(array('title' => 'Task 6', 'project_id' => 1, 'swimlane_id' => 0, 'column_id' => 3, 'score' => 1)));
+ $this->assertEquals(7, $taskCreationModel->create(array('title' => 'Task 7', 'project_id' => 1, 'swimlane_id' => 1, 'column_id' => 3, 'score' => 2)));
+ $this->assertEquals(8, $taskCreationModel->create(array('title' => 'Task 8', 'project_id' => 1, 'swimlane_id' => 2, 'column_id' => 3, 'score' => 3)));
+
+ $board = BoardFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->withProjectId(1)
+ ->format();
+
+ $this->assertCount(3, $board);
+
+ $this->assertEquals('Default swimlane', $board[0]['name']);
+ $this->assertCount(4, $board[0]['columns']);
+ $this->assertEquals(3, $board[0]['nb_swimlanes']);
+ $this->assertEquals(4, $board[0]['nb_columns']);
+ $this->assertEquals(6, $board[0]['nb_tasks']);
+ $this->assertEquals(10, $board[0]['score']);
+
+ $this->assertEquals(4, $board[0]['columns'][0]['column_nb_tasks']);
+ $this->assertEquals(1, $board[0]['columns'][1]['column_nb_tasks']);
+ $this->assertEquals(3, $board[0]['columns'][2]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_nb_tasks']);
+
+ $this->assertEquals(9, $board[0]['columns'][0]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][1]['column_score']);
+ $this->assertEquals(6, $board[0]['columns'][2]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_score']);
+
+ $this->assertSame(9, $board[0]['columns'][0]['score']);
+ $this->assertSame(0, $board[0]['columns'][1]['score']);
+ $this->assertSame(1, $board[0]['columns'][2]['score']);
+ $this->assertSame(0, $board[0]['columns'][3]['score']);
+
+ $this->assertSame(4, $board[0]['columns'][0]['nb_tasks']);
+ $this->assertSame(1, $board[0]['columns'][1]['nb_tasks']);
+ $this->assertSame(1, $board[0]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Task 1', $board[0]['columns'][0]['tasks'][0]['title']);
+ $this->assertEquals('Task 2', $board[0]['columns'][0]['tasks'][1]['title']);
+ $this->assertEquals('Task 3', $board[0]['columns'][0]['tasks'][2]['title']);
+ $this->assertEquals('Task 4', $board[0]['columns'][0]['tasks'][3]['title']);
+ $this->assertEquals('Task 5', $board[0]['columns'][1]['tasks'][0]['title']);
+ $this->assertEquals('Task 6', $board[0]['columns'][2]['tasks'][0]['title']);
+
+ $this->assertEquals('Swimlane 1', $board[1]['name']);
+ $this->assertCount(4, $board[1]['columns']);
+ $this->assertEquals(3, $board[1]['nb_swimlanes']);
+ $this->assertEquals(4, $board[1]['nb_columns']);
+ $this->assertEquals(1, $board[1]['nb_tasks']);
+ $this->assertEquals(2, $board[1]['score']);
+
+ $this->assertSame(0, $board[1]['columns'][0]['score']);
+ $this->assertSame(0, $board[1]['columns'][1]['score']);
+ $this->assertSame(2, $board[1]['columns'][2]['score']);
+ $this->assertSame(0, $board[1]['columns'][3]['score']);
+
+ $this->assertSame(0, $board[1]['columns'][0]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][1]['nb_tasks']);
+ $this->assertSame(1, $board[1]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Task 7', $board[1]['columns'][2]['tasks'][0]['title']);
+
+ $this->assertEquals('Swimlane 2', $board[2]['name']);
+ $this->assertCount(4, $board[2]['columns']);
+ $this->assertEquals(3, $board[2]['nb_swimlanes']);
+ $this->assertEquals(4, $board[2]['nb_columns']);
+ $this->assertEquals(1, $board[2]['nb_tasks']);
+ $this->assertEquals(3, $board[2]['score']);
+
+ $this->assertSame(0, $board[2]['columns'][0]['score']);
+ $this->assertSame(0, $board[2]['columns'][1]['score']);
+ $this->assertSame(3, $board[2]['columns'][2]['score']);
+ $this->assertSame(0, $board[2]['columns'][3]['score']);
+
+ $this->assertSame(0, $board[2]['columns'][0]['nb_tasks']);
+ $this->assertSame(0, $board[2]['columns'][1]['nb_tasks']);
+ $this->assertSame(1, $board[2]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[2]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Task 8', $board[2]['columns'][2]['tasks'][0]['title']);
+ }
+
+ public function testFormatWithoutDefaultSwimlane()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertTrue($swimlaneModel->disableDefault(1));
+ $this->assertEquals(1, $swimlaneModel->create(array('name' => 'Swimlane 1', 'project_id' => 1)));
+ $this->assertEquals(2, $swimlaneModel->create(array('name' => 'Swimlane 2', 'project_id' => 1)));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task 1', 'project_id' => 1, 'swimlane_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task 2', 'project_id' => 1, 'swimlane_id' => 2, 'column_id' => 2)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task 3', 'project_id' => 1, 'swimlane_id' => 1, 'column_id' => 2, 'score' => 1)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task 4', 'project_id' => 1, 'swimlane_id' => 2, 'column_id' => 1)));
+
+ $board = BoardFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->withProjectId(1)
+ ->format();
+
+ $this->assertCount(2, $board);
+
+ $this->assertEquals('Swimlane 1', $board[0]['name']);
+ $this->assertCount(4, $board[0]['columns']);
+ $this->assertEquals(2, $board[0]['nb_swimlanes']);
+ $this->assertEquals(4, $board[0]['nb_columns']);
+ $this->assertEquals(2, $board[0]['nb_tasks']);
+ $this->assertEquals(1, $board[0]['score']);
+
+ $this->assertEquals(2, $board[0]['columns'][0]['column_nb_tasks']);
+ $this->assertEquals(2, $board[0]['columns'][1]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][2]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_nb_tasks']);
+
+ $this->assertEquals(0, $board[0]['columns'][0]['column_score']);
+ $this->assertEquals(1, $board[0]['columns'][1]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][2]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_score']);
+
+ $this->assertSame(0, $board[0]['columns'][0]['score']);
+ $this->assertSame(1, $board[0]['columns'][1]['score']);
+ $this->assertSame(0, $board[0]['columns'][2]['score']);
+ $this->assertSame(0, $board[0]['columns'][3]['score']);
+
+ $this->assertSame(1, $board[0]['columns'][0]['nb_tasks']);
+ $this->assertSame(1, $board[0]['columns'][1]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Task 1', $board[0]['columns'][0]['tasks'][0]['title']);
+ $this->assertEquals('Task 3', $board[0]['columns'][1]['tasks'][0]['title']);
+
+ $this->assertEquals('Swimlane 2', $board[1]['name']);
+ $this->assertCount(4, $board[1]['columns']);
+ $this->assertEquals(2, $board[1]['nb_swimlanes']);
+ $this->assertEquals(4, $board[1]['nb_columns']);
+ $this->assertEquals(2, $board[1]['nb_tasks']);
+ $this->assertEquals(0, $board[1]['score']);
+
+ $this->assertSame(0, $board[1]['columns'][0]['score']);
+ $this->assertSame(0, $board[1]['columns'][1]['score']);
+ $this->assertSame(0, $board[1]['columns'][2]['score']);
+ $this->assertSame(0, $board[1]['columns'][3]['score']);
+
+ $this->assertSame(1, $board[1]['columns'][0]['nb_tasks']);
+ $this->assertSame(1, $board[1]['columns'][1]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Task 4', $board[1]['columns'][0]['tasks'][0]['title']);
+ $this->assertEquals('Task 2', $board[1]['columns'][1]['tasks'][0]['title']);
+ }
+
+ public function testFormatWithoutSwimlane()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertTrue($swimlaneModel->disableDefault(1));
+
+ $board = BoardFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->withProjectId(1)
+ ->format();
+
+ $this->assertCount(0, $board);
+ }
+
+ public function testFormatWithoutColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $columnModel = new ColumnModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertTrue($columnModel->remove(1));
+ $this->assertTrue($columnModel->remove(2));
+ $this->assertTrue($columnModel->remove(3));
+ $this->assertTrue($columnModel->remove(4));
+
+ $board = BoardFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->withProjectId(1)
+ ->format();
+
+ $this->assertCount(0, $board);
+ }
+
+ public function testFormatWithoutTask()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $swimlaneModel->create(array('name' => 'Swimlane 1', 'project_id' => 1)));
+ $this->assertEquals(2, $swimlaneModel->create(array('name' => 'Swimlane 2', 'project_id' => 1)));
+
+ $board = BoardFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->withProjectId(1)
+ ->format();
+
+ $this->assertCount(3, $board);
+
+ $this->assertEquals('Default swimlane', $board[0]['name']);
+ $this->assertCount(4, $board[0]['columns']);
+ $this->assertEquals(3, $board[0]['nb_swimlanes']);
+ $this->assertEquals(4, $board[0]['nb_columns']);
+ $this->assertEquals(0, $board[0]['nb_tasks']);
+ $this->assertEquals(0, $board[0]['score']);
+
+ $this->assertEquals(0, $board[0]['columns'][0]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][1]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][2]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_nb_tasks']);
+
+ $this->assertEquals(0, $board[0]['columns'][0]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][1]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][2]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_score']);
+
+ $this->assertSame(0, $board[0]['columns'][0]['score']);
+ $this->assertSame(0, $board[0]['columns'][1]['score']);
+ $this->assertSame(0, $board[0]['columns'][2]['score']);
+ $this->assertSame(0, $board[0]['columns'][3]['score']);
+
+ $this->assertSame(0, $board[0]['columns'][0]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][1]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Swimlane 1', $board[1]['name']);
+ $this->assertCount(4, $board[1]['columns']);
+ $this->assertEquals(3, $board[1]['nb_swimlanes']);
+ $this->assertEquals(4, $board[1]['nb_columns']);
+ $this->assertEquals(0, $board[1]['nb_tasks']);
+ $this->assertEquals(0, $board[1]['score']);
+
+ $this->assertSame(0, $board[1]['columns'][0]['score']);
+ $this->assertSame(0, $board[1]['columns'][1]['score']);
+ $this->assertSame(0, $board[1]['columns'][2]['score']);
+ $this->assertSame(0, $board[1]['columns'][3]['score']);
+
+ $this->assertSame(0, $board[1]['columns'][0]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][1]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[1]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('Swimlane 2', $board[2]['name']);
+ $this->assertCount(4, $board[2]['columns']);
+ $this->assertEquals(3, $board[2]['nb_swimlanes']);
+ $this->assertEquals(4, $board[2]['nb_columns']);
+ $this->assertEquals(0, $board[2]['nb_tasks']);
+ $this->assertEquals(0, $board[2]['score']);
+
+ $this->assertSame(0, $board[2]['columns'][0]['score']);
+ $this->assertSame(0, $board[2]['columns'][1]['score']);
+ $this->assertSame(0, $board[2]['columns'][2]['score']);
+ $this->assertSame(0, $board[2]['columns'][3]['score']);
+
+ $this->assertSame(0, $board[2]['columns'][0]['nb_tasks']);
+ $this->assertSame(0, $board[2]['columns'][1]['nb_tasks']);
+ $this->assertSame(0, $board[2]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[2]['columns'][3]['nb_tasks']);
+ }
+
+ public function testFormatWithTags()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2', 'column_id' => 3)));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2')));
+ $this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
+
+ $board = BoardFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->withProjectId(1)
+ ->format();
+
+ $this->assertCount(1, $board);
+
+ $this->assertEquals('Default swimlane', $board[0]['name']);
+ $this->assertCount(4, $board[0]['columns']);
+ $this->assertEquals(1, $board[0]['nb_swimlanes']);
+ $this->assertEquals(4, $board[0]['nb_columns']);
+ $this->assertEquals(3, $board[0]['nb_tasks']);
+ $this->assertEquals(0, $board[0]['score']);
+
+ $this->assertEquals(2, $board[0]['columns'][0]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][1]['column_nb_tasks']);
+ $this->assertEquals(1, $board[0]['columns'][2]['column_nb_tasks']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_nb_tasks']);
+
+ $this->assertEquals(0, $board[0]['columns'][0]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][1]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][2]['column_score']);
+ $this->assertEquals(0, $board[0]['columns'][3]['column_score']);
+
+ $this->assertSame(0, $board[0]['columns'][0]['score']);
+ $this->assertSame(0, $board[0]['columns'][1]['score']);
+ $this->assertSame(0, $board[0]['columns'][2]['score']);
+ $this->assertSame(0, $board[0]['columns'][3]['score']);
+
+ $this->assertSame(2, $board[0]['columns'][0]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][1]['nb_tasks']);
+ $this->assertSame(1, $board[0]['columns'][2]['nb_tasks']);
+ $this->assertSame(0, $board[0]['columns'][3]['nb_tasks']);
+
+ $this->assertEquals('test1', $board[0]['columns'][0]['tasks'][0]['title']);
+ $this->assertEquals('test3', $board[0]['columns'][0]['tasks'][1]['title']);
+ $this->assertEquals('test2', $board[0]['columns'][2]['tasks'][0]['title']);
+
+ $expected = array(
+ array(
+ 'id' => 1,
+ 'name' => 'My tag 1',
+ 'task_id' => 1,
+ ),
+ array(
+ 'id' => 2,
+ 'name' => 'My tag 2',
+ 'task_id' => 1,
+ ),
+ );
+
+ $this->assertEquals($expected, $board[0]['columns'][0]['tasks'][0]['tags']);
+ $this->assertEquals(array(), $board[0]['columns'][0]['tasks'][1]['tags']);
+
+ $expected = array(
+ array(
+ 'id' => 3,
+ 'name' => 'My tag 3',
+ 'task_id' => 2,
+ ),
+ );
+
+ $this->assertEquals($expected, $board[0]['columns'][2]['tasks'][0]['tags']);
+ }
+}
diff --git a/tests/units/Formatter/TaskAutoCompleteFormatterTest.php b/tests/units/Formatter/TaskAutoCompleteFormatterTest.php
new file mode 100644
index 00000000..20baf549
--- /dev/null
+++ b/tests/units/Formatter/TaskAutoCompleteFormatterTest.php
@@ -0,0 +1,34 @@
+<?php
+
+use Kanboard\Formatter\TaskAutoCompleteFormatter;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskAutoCompleteFormatterTest extends Base
+{
+ public function testFormat()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'My Project')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task 2', 'project_id' => 1)));
+
+ $tasks = TaskAutoCompleteFormatter::getInstance($this->container)
+ ->withQuery($taskFinderModel->getExtendedQuery())
+ ->format();
+
+ $this->assertCount(2, $tasks);
+ $this->assertEquals('My Project > #1 Task 1', $tasks[0]['label']);
+ $this->assertEquals('Task 1', $tasks[0]['value']);
+ $this->assertEquals(1, $tasks[0]['id']);
+ $this->assertEquals('My Project > #2 Task 2', $tasks[1]['label']);
+ $this->assertEquals('Task 2', $tasks[1]['value']);
+ $this->assertEquals(2, $tasks[1]['id']);
+ }
+}
diff --git a/tests/units/FunctionTest.php b/tests/units/FunctionTest.php
new file mode 100644
index 00000000..1c5f971d
--- /dev/null
+++ b/tests/units/FunctionTest.php
@@ -0,0 +1,123 @@
+<?php
+
+require_once __DIR__.'/Base.php';
+
+class FunctionTest extends Base
+{
+ public function testArrayColumnSum()
+ {
+ $input = array(
+ array(
+ 'my_column' => 123
+ ),
+ array(
+ 'my_column' => 456.7
+ ),
+ array()
+ );
+
+ $this->assertSame(579.7, array_column_sum($input, 'my_column'));
+ }
+
+ public function testArrayColumnIndex()
+ {
+ $input = array(
+ array(
+ 'k1' => 11,
+ 'k2' => 22,
+ ),
+ array(
+ 'k1' => 11,
+ 'k2' => 55,
+ ),
+ array(
+ 'k1' => 33,
+ 'k2' => 44,
+ ),
+ array()
+ );
+
+ $expected = array(
+ 11 => array(
+ array(
+ 'k1' => 11,
+ 'k2' => 22,
+ ),
+ array(
+ 'k1' => 11,
+ 'k2' => 55,
+ )
+ ),
+ 33 => array(
+ array(
+ 'k1' => 33,
+ 'k2' => 44,
+ )
+ )
+ );
+
+ $this->assertSame($expected, array_column_index($input, 'k1'));
+ }
+
+ public function testArrayMergeRelation()
+ {
+ $relations = array(
+ 88 => array(
+ 'id' => 123,
+ 'value' => 'test1',
+ ),
+ 99 => array(
+ 'id' => 456,
+ 'value' => 'test2',
+ ),
+ 55 => array()
+ );
+
+ $input = array(
+ array(),
+ array(
+ 'task_id' => 88,
+ 'title' => 'task1'
+ ),
+ array(
+ 'task_id' => 99,
+ 'title' => 'task2'
+ ),
+ array(
+ 'task_id' => 11,
+ 'title' => 'task3'
+ )
+ );
+
+ $expected = array(
+ array(
+ 'my_relation' => array(),
+ ),
+ array(
+ 'task_id' => 88,
+ 'title' => 'task1',
+ 'my_relation' => array(
+ 'id' => 123,
+ 'value' => 'test1',
+ ),
+ ),
+ array(
+ 'task_id' => 99,
+ 'title' => 'task2',
+ 'my_relation' => array(
+ 'id' => 456,
+ 'value' => 'test2',
+ ),
+ ),
+ array(
+ 'task_id' => 11,
+ 'title' => 'task3',
+ 'my_relation' => array(),
+ )
+ );
+
+ array_merge_relation($input, $relations, 'my_relation', 'task_id');
+
+ $this->assertSame($expected, $input);
+ }
+}
diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php
index 10bbc58e..4d1947d8 100644
--- a/tests/units/Helper/UserHelperTest.php
+++ b/tests/units/Helper/UserHelperTest.php
@@ -13,6 +13,21 @@ use Kanboard\Model\UserModel;
class UserHelperTest extends Base
{
+ public function testGetFullname()
+ {
+ $userModel = new UserModel($this->container);
+ $userHelper = new UserHelper($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User #2')));
+
+ $user1 = $userModel->getById(2);
+ $user2 = $userModel->getById(3);
+
+ $this->assertEquals('user1', $userHelper->getFullname($user1));
+ $this->assertEquals('User #2', $userHelper->getFullname($user2));
+ }
+
public function testInitials()
{
$helper = new UserHelper($this->container);
@@ -31,6 +46,12 @@ class UserHelperTest extends Base
$this->assertEquals('Project Viewer', $helper->getRoleName(Role::PROJECT_VIEWER));
}
+ public function testHasAccessWithoutSession()
+ {
+ $helper = new UserHelper($this->container);
+ $this->assertFalse($helper->hasAccess('UserCreationController', 'create'));
+ }
+
public function testHasAccessForAdmins()
{
$helper = new UserHelper($this->container);
@@ -73,6 +94,15 @@ class UserHelperTest extends Base
$this->assertTrue($helper->hasAccess('ProjectCreationController', 'createPrivate'));
}
+ public function testHasProjectAccessWithoutSession()
+ {
+ $helper = new UserHelper($this->container);
+ $project = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $project->create(array('name' => 'My project')));
+ $this->assertFalse($helper->hasProjectAccess('ProjectEditController', 'edit', 1));
+ }
+
public function testHasProjectAccessForAdmins()
{
$helper = new UserHelper($this->container);
diff --git a/tests/units/Job/CommentEventJobTest.php b/tests/units/Job/CommentEventJobTest.php
new file mode 100644
index 00000000..8571af8e
--- /dev/null
+++ b/tests/units/Job/CommentEventJobTest.php
@@ -0,0 +1,52 @@
+<?php
+
+use Kanboard\Job\CommentEventJob;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class CommentEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $commentEventJob = new CommentEventJob($this->container);
+ $commentEventJob->withParams(123, 'foobar');
+
+ $this->assertSame(array(123, 'foobar'), $commentEventJob->getJobParams());
+ }
+
+ public function testWithMissingComment()
+ {
+ $this->container['dispatcher']->addListener(CommentModel::EVENT_CREATE, function() {});
+
+ $commentEventJob = new CommentEventJob($this->container);
+ $commentEventJob->execute(42, CommentModel::EVENT_CREATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerEvents()
+ {
+ $this->container['dispatcher']->addListener(CommentModel::EVENT_CREATE, function() {});
+ $this->container['dispatcher']->addListener(CommentModel::EVENT_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(CommentModel::EVENT_DELETE, function() {});
+
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'foobar', 'user_id' => 1)));
+ $this->assertTrue($commentModel->update(array('id' => 1, 'comment' => 'test')));
+ $this->assertTrue($commentModel->remove(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(CommentModel::EVENT_CREATE.'.closure', $called);
+ $this->assertArrayHasKey(CommentModel::EVENT_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(CommentModel::EVENT_DELETE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Job/ProjectFileEventJobTest.php b/tests/units/Job/ProjectFileEventJobTest.php
new file mode 100644
index 00000000..f266d293
--- /dev/null
+++ b/tests/units/Job/ProjectFileEventJobTest.php
@@ -0,0 +1,43 @@
+<?php
+
+use Kanboard\Job\ProjectFileEventJob;
+use Kanboard\Model\ProjectFileModel;
+use Kanboard\Model\ProjectModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectFileEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $projectFileEventJob = new ProjectFileEventJob($this->container);
+ $projectFileEventJob->withParams(123, 'foobar');
+
+ $this->assertSame(array(123, 'foobar'), $projectFileEventJob->getJobParams());
+ }
+
+ public function testWithMissingFile()
+ {
+ $this->container['dispatcher']->addListener(ProjectFileModel::EVENT_CREATE, function() {});
+
+ $projectFileEventJob = new ProjectFileEventJob($this->container);
+ $projectFileEventJob->execute(42, ProjectFileModel::EVENT_CREATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerEvents()
+ {
+ $this->container['dispatcher']->addListener(ProjectFileModel::EVENT_CREATE, function() {});
+
+ $projectModel = new ProjectModel($this->container);
+ $projectFileModel = new ProjectFileModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $projectFileModel->create(1, 'Test', '/tmp/test', 123));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(ProjectFileModel::EVENT_CREATE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Job/ProjectMetricJobTest.php b/tests/units/Job/ProjectMetricJobTest.php
new file mode 100644
index 00000000..e5b0474d
--- /dev/null
+++ b/tests/units/Job/ProjectMetricJobTest.php
@@ -0,0 +1,47 @@
+<?php
+
+use Kanboard\Job\ProjectMetricJob;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectMetricJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $projectMetricJob = new ProjectMetricJob($this->container);
+ $projectMetricJob->withParams(123);
+
+ $this->assertSame(
+ array(123),
+ $projectMetricJob->getJobParams()
+ );
+ }
+
+ public function testJob()
+ {
+ $this->container['projectDailyColumnStatsModel'] = $this
+ ->getMockBuilder('\Kanboard\Model\ProjectDailyColumnStatsModel')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('updateTotals'))
+ ->getMock();
+
+ $this->container['projectDailyStatsModel'] = $this
+ ->getMockBuilder('\Kanboard\Model\ProjectDailyStatsModel')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('updateTotals'))
+ ->getMock();
+
+ $this->container['projectDailyColumnStatsModel']
+ ->expects($this->once())
+ ->method('updateTotals')
+ ->with(42, date('Y-m-d'));
+
+ $this->container['projectDailyStatsModel']
+ ->expects($this->once())
+ ->method('updateTotals')
+ ->with(42, date('Y-m-d'));
+
+ $job = new ProjectMetricJob($this->container);
+ $job->execute(42);
+ }
+}
diff --git a/tests/units/Job/SubtaskEventJobTest.php b/tests/units/Job/SubtaskEventJobTest.php
new file mode 100644
index 00000000..bdc30b51
--- /dev/null
+++ b/tests/units/Job/SubtaskEventJobTest.php
@@ -0,0 +1,52 @@
+<?php
+
+use Kanboard\Job\SubtaskEventJob;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $subtaskEventJob = new SubtaskEventJob($this->container);
+ $subtaskEventJob->withParams(123, 'foobar', array('k' => 'v'));
+
+ $this->assertSame(array(123, 'foobar', array('k' => 'v')), $subtaskEventJob->getJobParams());
+ }
+
+ public function testWithMissingSubtask()
+ {
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, function() {});
+
+ $subtaskEventJob = new SubtaskEventJob($this->container);
+ $subtaskEventJob->execute(42, SubtaskModel::EVENT_CREATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerEvents()
+ {
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, function() {});
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, function() {});
+
+ $subtaskModel = new SubtaskModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'before')));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'task_id' => 1, 'title' => 'after')));
+ $this->assertTrue($subtaskModel->remove(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(SubtaskModel::EVENT_CREATE.'.closure', $called);
+ $this->assertArrayHasKey(SubtaskModel::EVENT_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(SubtaskModel::EVENT_DELETE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Job/TaskEventJobTest.php b/tests/units/Job/TaskEventJobTest.php
new file mode 100644
index 00000000..c399faad
--- /dev/null
+++ b/tests/units/Job/TaskEventJobTest.php
@@ -0,0 +1,189 @@
+<?php
+
+use Kanboard\Job\TaskEventJob;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SwimlaneModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskModificationModel;
+use Kanboard\Model\TaskPositionModel;
+use Kanboard\Model\TaskProjectMoveModel;
+use Kanboard\Model\TaskStatusModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $taskEventJob = new TaskEventJob($this->container);
+ $taskEventJob->withParams(123, array('foobar'), array('k' => 'v'), array('k1' => 'v1'), array('k2' => 'v2'));
+
+ $this->assertSame(
+ array(123, array('foobar'), array('k' => 'v'), array('k1' => 'v1'), array('k2' => 'v2')),
+ $taskEventJob->getJobParams()
+ );
+ }
+
+ public function testWithMissingTask()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function() {});
+
+ $taskEventJob = new TaskEventJob($this->container);
+ $taskEventJob->execute(42, array(TaskModel::EVENT_CREATE));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerCreateEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function() {});
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ }
+
+ public function testTriggerUpdateEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, function() {});
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'title' => 'new title')));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ }
+
+ public function testTriggerAssigneeChangeEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_ASSIGNEE_CHANGE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'owner_id' => 1)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_ASSIGNEE_CHANGE.'.closure', $called);
+ }
+
+ public function testTriggerCloseEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CLOSE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskStatusModel = new TaskStatusModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($taskStatusModel->close(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CLOSE.'.closure', $called);
+ }
+
+ public function testTriggerOpenEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_OPEN, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskStatusModel = new TaskStatusModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($taskStatusModel->close(1));
+ $this->assertTrue($taskStatusModel->open(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_OPEN.'.closure', $called);
+ }
+
+ public function testTriggerMovePositionEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_POSITION, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test 2', 'project_id' => 1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 2));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_POSITION.'.closure', $called);
+ }
+
+ public function testTriggerMoveColumnEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_COLUMN, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 2));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_COLUMN.'.closure', $called);
+ }
+
+ public function testTriggerMoveSwimlaneEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_SWIMLANE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $swimlaneModel->create(array('name' => 'S1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 1, 1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_SWIMLANE.'.closure', $called);
+ }
+
+ public function testTriggerMoveProjectEvent()
+ {
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_PROJECT, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.closure', $called);
+ }
+}
diff --git a/tests/units/Job/TaskFileEventJobTest.php b/tests/units/Job/TaskFileEventJobTest.php
new file mode 100644
index 00000000..921fe801
--- /dev/null
+++ b/tests/units/Job/TaskFileEventJobTest.php
@@ -0,0 +1,46 @@
+<?php
+
+use Kanboard\Job\TaskFileEventJob;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFileModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskFileEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $taskFileEventJob = new TaskFileEventJob($this->container);
+ $taskFileEventJob->withParams(123, 'foobar');
+
+ $this->assertSame(array(123, 'foobar'), $taskFileEventJob->getJobParams());
+ }
+
+ public function testWithMissingFile()
+ {
+ $this->container['dispatcher']->addListener(TaskFileModel::EVENT_CREATE, function() {});
+
+ $taskFileEventJob = new TaskFileEventJob($this->container);
+ $taskFileEventJob->execute(42, TaskFileModel::EVENT_CREATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerEvents()
+ {
+ $this->container['dispatcher']->addListener(TaskFileModel::EVENT_CREATE, function() {});
+
+ $taskFileModel = new TaskFileModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $taskFileModel->create(1, 'Test', '/tmp/test', 123));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskFileModel::EVENT_CREATE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Job/TaskLinkEventJobTest.php b/tests/units/Job/TaskLinkEventJobTest.php
new file mode 100644
index 00000000..1949316a
--- /dev/null
+++ b/tests/units/Job/TaskLinkEventJobTest.php
@@ -0,0 +1,65 @@
+<?php
+
+use Kanboard\Job\TaskLinkEventJob;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskLinkModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskLinkEventJobTest extends Base
+{
+ public function testJobParams()
+ {
+ $taskLinkEventJob = new TaskLinkEventJob($this->container);
+ $taskLinkEventJob->withParams(123, 'foobar');
+
+ $this->assertSame(array(123, 'foobar'), $taskLinkEventJob->getJobParams());
+ }
+
+ public function testWithMissingLink()
+ {
+ $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskLinkEventJob = new TaskLinkEventJob($this->container);
+ $taskLinkEventJob->execute(42, TaskLinkModel::EVENT_CREATE_UPDATE);
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertEmpty($called);
+ }
+
+ public function testTriggerCreationEvents()
+ {
+ $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_CREATE_UPDATE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskLinkModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ }
+
+ public function testTriggerDeleteEvents()
+ {
+ $this->container['dispatcher']->addListener(TaskLinkModel::EVENT_DELETE, function() {});
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'task 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'task 2', 'project_id' => 1)));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+ $this->assertTrue($taskLinkModel->remove(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskLinkModel::EVENT_DELETE.'.closure', $called);
+ }
+}
diff --git a/tests/units/Model/ActionTest.php b/tests/units/Model/ActionModelTest.php
index 5db18983..4e21a999 100644
--- a/tests/units/Model/ActionTest.php
+++ b/tests/units/Model/ActionModelTest.php
@@ -11,7 +11,7 @@ use Kanboard\Model\CategoryModel;
use Kanboard\Model\ProjectUserRoleModel;
use Kanboard\Core\Security\Role;
-class ActionTest extends Base
+class ActionModelTest extends Base
{
public function testCreate()
{
@@ -69,6 +69,24 @@ class ActionTest extends Base
$this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $action['params']);
}
+ public function testGetProjectId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $actionModel = new ActionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => TaskModel::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $this->assertEquals(1, $actionModel->getProjectId(1));
+ $this->assertSame(0, $actionModel->getProjectId(42));
+ }
+
public function testGetAll()
{
$projectModel = new ProjectModel($this->container);
diff --git a/tests/units/Model/BoardTest.php b/tests/units/Model/BoardTest.php
index 80587d89..9f540c63 100644
--- a/tests/units/Model/BoardTest.php
+++ b/tests/units/Model/BoardTest.php
@@ -3,12 +3,8 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Model\ProjectModel;
-use Kanboard\Model\BoardModel;
use Kanboard\Model\ColumnModel;
use Kanboard\Model\ConfigModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\SwimlaneModel;
class BoardTest extends Base
{
@@ -45,121 +41,4 @@ class BoardTest extends Base
$this->assertEquals('column #1', $columns[5]);
$this->assertEquals('column #2', $columns[6]);
}
-
- public function testGetBoard()
- {
- $p = new ProjectModel($this->container);
- $b = new BoardModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
-
- $board = $b->getBoard(1);
- $this->assertNotEmpty($board);
- $this->assertEquals(1, count($board));
- $this->assertEquals(6, count($board[0]));
- $this->assertArrayHasKey('name', $board[0]);
- $this->assertArrayHasKey('nb_tasks', $board[0]);
- $this->assertArrayHasKey('columns', $board[0]);
- $this->assertArrayHasKey('tasks', $board[0]['columns'][2]);
- $this->assertArrayHasKey('nb_tasks', $board[0]['columns'][2]);
- $this->assertArrayHasKey('title', $board[0]['columns'][2]);
- $this->assertArrayHasKey('nb_column_tasks', $board[0]['columns'][0]);
- $this->assertArrayHasKey('total_score', $board[0]['columns'][0]);
- }
-
- public function testGetBoardWithSwimlane()
- {
- $b = new BoardModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $s = new SwimlaneModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => '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, 'score' => 2)));
- $this->assertEquals(6, $tc->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 4, 'score' => 3, 'swimlane_id' => 1)));
-
- $board = $b->getBoard(1);
- $this->assertNotEmpty($board);
- $this->assertEquals(2, count($board));
- $this->assertEquals(6, count($board[0]));
- $this->assertArrayHasKey('name', $board[0]);
- $this->assertArrayHasKey('nb_tasks', $board[0]);
- $this->assertArrayHasKey('columns', $board[0]);
- $this->assertArrayHasKey('tasks', $board[0]['columns'][2]);
- $this->assertArrayHasKey('nb_tasks', $board[0]['columns'][2]);
- $this->assertArrayHasKey('title', $board[0]['columns'][2]);
- $this->assertArrayHasKey('nb_column_tasks', $board[0]['columns'][0]);
- $this->assertArrayNotHasKey('nb_column_tasks', $board[1]['columns'][0]);
- $this->assertArrayNotHasKey('total_score', $board[1]['columns'][0]);
- $this->assertArrayHasKey('score', $board[0]['columns'][3]);
- $this->assertArrayHasKey('total_score', $board[0]['columns'][3]);
- $this->assertEquals(2, $board[0]['columns'][3]['score']);
- $this->assertEquals(5, $board[0]['columns'][3]['total_score']);
-
- $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']);
- }
}
diff --git a/tests/units/Model/CategoryTest.php b/tests/units/Model/CategoryModelTest.php
index 1fdc51f6..80a20af6 100644
--- a/tests/units/Model/CategoryTest.php
+++ b/tests/units/Model/CategoryModelTest.php
@@ -8,7 +8,7 @@ use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\CategoryModel;
-class CategoryTest extends Base
+class CategoryModelTest extends Base
{
public function testCreation()
{
@@ -81,6 +81,18 @@ class CategoryTest extends Base
$this->assertSame(0, $categoryModel->getIdByName(1, 'Category #2'));
}
+ public function testGetProjectId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test')));
+
+ $this->assertEquals(1, $categoryModel->getProjectId(1));
+ $this->assertSame(0, $categoryModel->getProjectId(2));
+ }
+
public function testGetList()
{
$projectModel = new ProjectModel($this->container);
diff --git a/tests/units/Model/CommentModelTest.php b/tests/units/Model/CommentModelTest.php
new file mode 100644
index 00000000..4178a839
--- /dev/null
+++ b/tests/units/Model/CommentModelTest.php
@@ -0,0 +1,106 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\CommentModel;
+
+class CommentModelTest extends Base
+{
+ public function testCreate()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
+ $this->assertEquals(2, $commentModel->create(array('task_id' => 1, 'comment' => 'bla bla')));
+
+ $comment = $commentModel->getById(1);
+ $this->assertNotEmpty($comment);
+ $this->assertEquals('bla bla', $comment['comment']);
+ $this->assertEquals(1, $comment['task_id']);
+ $this->assertEquals(1, $comment['user_id']);
+ $this->assertEquals('admin', $comment['username']);
+ $this->assertEquals(time(), $comment['date_creation'], '', 3);
+
+ $comment = $commentModel->getById(2);
+ $this->assertNotEmpty($comment);
+ $this->assertEquals('bla bla', $comment['comment']);
+ $this->assertEquals(1, $comment['task_id']);
+ $this->assertEquals(0, $comment['user_id']);
+ $this->assertEquals('', $comment['username']);
+ $this->assertEquals(time(), $comment['date_creation'], '', 3);
+ }
+
+ public function testGetAll()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+ $this->assertEquals(2, $commentModel->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1)));
+ $this->assertEquals(3, $commentModel->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1)));
+
+ $comments = $commentModel->getAll(1);
+
+ $this->assertNotEmpty($comments);
+ $this->assertEquals(3, count($comments));
+ $this->assertEquals(1, $comments[0]['id']);
+ $this->assertEquals(2, $comments[1]['id']);
+ $this->assertEquals(3, $comments[2]['id']);
+
+ $this->assertEquals(3, $commentModel->count(1));
+ }
+
+ public function testUpdate()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+ $this->assertTrue($commentModel->update(array('id' => 1, 'comment' => 'bla')));
+
+ $comment = $commentModel->getById(1);
+ $this->assertNotEmpty($comment);
+ $this->assertEquals('bla', $comment['comment']);
+ }
+
+ public function testRemove()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+
+ $this->assertTrue($commentModel->remove(1));
+ $this->assertFalse($commentModel->remove(1));
+ $this->assertFalse($commentModel->remove(1111));
+ }
+
+ public function testGetProjectId()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+
+ $this->assertEquals(1, $commentModel->getProjectId(1));
+ $this->assertSame(0, $commentModel->getProjectId(2));
+ }
+}
diff --git a/tests/units/Model/CommentTest.php b/tests/units/Model/CommentTest.php
deleted file mode 100644
index 7250ae0b..00000000
--- a/tests/units/Model/CommentTest.php
+++ /dev/null
@@ -1,92 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\ProjectModel;
-use Kanboard\Model\CommentModel;
-
-class CommentTest extends Base
-{
- public function testCreate()
- {
- $c = new CommentModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
- $this->assertEquals(1, $c->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
- $this->assertEquals(2, $c->create(array('task_id' => 1, 'comment' => 'bla bla')));
-
- $comment = $c->getById(1);
- $this->assertNotEmpty($comment);
- $this->assertEquals('bla bla', $comment['comment']);
- $this->assertEquals(1, $comment['task_id']);
- $this->assertEquals(1, $comment['user_id']);
- $this->assertEquals('admin', $comment['username']);
- $this->assertEquals(time(), $comment['date_creation'], '', 3);
-
- $comment = $c->getById(2);
- $this->assertNotEmpty($comment);
- $this->assertEquals('bla bla', $comment['comment']);
- $this->assertEquals(1, $comment['task_id']);
- $this->assertEquals(0, $comment['user_id']);
- $this->assertEquals('', $comment['username']);
- $this->assertEquals(time(), $comment['date_creation'], '', 3);
- }
-
- public function testGetAll()
- {
- $c = new CommentModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $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);
-
- $this->assertNotEmpty($comments);
- $this->assertEquals(3, count($comments));
- $this->assertEquals(1, $comments[0]['id']);
- $this->assertEquals(2, $comments[1]['id']);
- $this->assertEquals(3, $comments[2]['id']);
-
- $this->assertEquals(3, $c->count(1));
- }
-
- public function testUpdate()
- {
- $c = new CommentModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $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);
- $this->assertNotEmpty($comment);
- $this->assertEquals('bla', $comment['comment']);
- }
-
- public function validateRemove()
- {
- $c = new CommentModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $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));
- $this->assertFalse($c->remove(1));
- $this->assertFalse($c->remove(1111));
- }
-}
diff --git a/tests/units/Model/GroupTest.php b/tests/units/Model/GroupModelTest.php
index 85c2c5d9..4ad0a167 100644
--- a/tests/units/Model/GroupTest.php
+++ b/tests/units/Model/GroupModelTest.php
@@ -4,7 +4,7 @@ require_once __DIR__.'/../Base.php';
use Kanboard\Model\GroupModel;
-class GroupTest extends Base
+class GroupModelTest extends Base
{
public function testCreation()
{
@@ -57,4 +57,13 @@ class GroupTest extends Base
$this->assertTrue($groupModel->remove(1));
$this->assertEmpty($groupModel->getById(1));
}
+
+ public function testGetOrCreateExternalGroupId()
+ {
+ $groupModel = new GroupModel($this->container);
+ $this->assertEquals(1, $groupModel->create('Group 1', 'ExternalId1'));
+ $this->assertEquals(1, $groupModel->getOrCreateExternalGroupId('Group 1', 'ExternalId1'));
+ $this->assertEquals(1, $groupModel->getOrCreateExternalGroupId('Group 2', 'ExternalId1'));
+ $this->assertEquals(2, $groupModel->getOrCreateExternalGroupId('Group 2', 'ExternalId2'));
+ }
}
diff --git a/tests/units/Model/NotificationModelTest.php b/tests/units/Model/NotificationModelTest.php
new file mode 100644
index 00000000..0bd9db6e
--- /dev/null
+++ b/tests/units/Model/NotificationModelTest.php
@@ -0,0 +1,104 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\TaskFileModel;
+use Kanboard\Model\TaskLinkModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\NotificationModel;
+use Kanboard\Subscriber\NotificationSubscriber;
+
+class NotificationModelTest extends Base
+{
+ public function testGetTitle()
+ {
+ $notificationModel = new NotificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $commentModel = new CommentModel($this->container);
+ $taskFileModel = new TaskFileModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'test', 'task_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
+ $this->assertEquals(1, $taskFileModel->create(1, 'test', 'blah', 123));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $task = $taskFinderModel->getDetails(1);
+ $subtask = $subtaskModel->getById(1, true);
+ $comment = $commentModel->getById(1);
+ $file = $commentModel->getById(1);
+ $tasklink = $taskLinkModel->getById(1);
+
+ foreach (NotificationSubscriber::getSubscribedEvents() as $eventName => $values) {
+ $eventData = array(
+ 'task' => $task,
+ 'comment' => $comment,
+ 'subtask' => $subtask,
+ 'file' => $file,
+ 'task_link' => $tasklink,
+ 'changes' => array()
+ );
+
+ $this->assertNotEmpty($notificationModel->getTitleWithoutAuthor($eventName, $eventData));
+ $this->assertNotEmpty($notificationModel->getTitleWithAuthor('Foobar', $eventName, $eventData));
+ }
+
+ $this->assertNotEmpty($notificationModel->getTitleWithoutAuthor(TaskModel::EVENT_OVERDUE, array('tasks' => array(array('id' => 1)))));
+ $this->assertNotEmpty($notificationModel->getTitleWithoutAuthor('unknown', array()));
+ }
+
+ public function testGetTaskIdFromEvent()
+ {
+ $notificationModel = new NotificationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $commentModel = new CommentModel($this->container);
+ $taskFileModel = new TaskFileModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'test', 'task_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
+ $this->assertEquals(1, $taskFileModel->create(1, 'test', 'blah', 123));
+
+ $task = $taskFinderModel->getDetails(1);
+ $subtask = $subtaskModel->getById(1, true);
+ $comment = $commentModel->getById(1);
+ $file = $commentModel->getById(1);
+ $tasklink = $taskLinkModel->getById(1);
+
+ $this->assertNotEmpty($task);
+ $this->assertNotEmpty($subtask);
+ $this->assertNotEmpty($comment);
+ $this->assertNotEmpty($file);
+
+ foreach (NotificationSubscriber::getSubscribedEvents() as $eventName => $values) {
+ $task_id = $notificationModel->getTaskIdFromEvent($eventName, array(
+ 'task' => $task,
+ 'comment' => $comment,
+ 'subtask' => $subtask,
+ 'file' => $file,
+ 'task_link' => $tasklink,
+ 'changes' => array()
+ ));
+
+ $this->assertEquals($task_id, $task['id']);
+ }
+
+ $this->assertEquals(1, $notificationModel->getTaskIdFromEvent(TaskModel::EVENT_OVERDUE, array('tasks' => array(array('id' => 1)))));
+ }
+}
diff --git a/tests/units/Model/NotificationTest.php b/tests/units/Model/NotificationTest.php
deleted file mode 100644
index 96ee5f4e..00000000
--- a/tests/units/Model/NotificationTest.php
+++ /dev/null
@@ -1,68 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\SubtaskModel;
-use Kanboard\Model\CommentModel;
-use Kanboard\Model\TaskFileModel;
-use Kanboard\Model\TaskModel;
-use Kanboard\Model\ProjectModel;
-use Kanboard\Model\NotificationModel;
-use Kanboard\Subscriber\NotificationSubscriber;
-
-class NotificationTest extends Base
-{
- public function testGetTitle()
- {
- $wn = new NotificationModel($this->container);
- $p = new ProjectModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $c = new CommentModel($this->container);
- $f = new TaskFileModel($this->container);
-
- $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', 123));
-
- $task = $tf->getDetails(1);
- $subtask = $s->getById(1, true);
- $comment = $c->getById(1);
- $file = $c->getById(1);
-
- $this->assertNotEmpty($task);
- $this->assertNotEmpty($subtask);
- $this->assertNotEmpty($comment);
- $this->assertNotEmpty($file);
-
- foreach (NotificationSubscriber::getSubscribedEvents() as $event_name => $values) {
- $title = $wn->getTitleWithoutAuthor($event_name, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array()
- ));
-
- $this->assertNotEmpty($title);
-
- $title = $wn->getTitleWithAuthor('foobar', $event_name, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array()
- ));
-
- $this->assertNotEmpty($title);
- }
-
- $this->assertNotEmpty($wn->getTitleWithoutAuthor(TaskModel::EVENT_OVERDUE, array('tasks' => array(array('id' => 1)))));
- $this->assertNotEmpty($wn->getTitleWithoutAuthor('unkown', array()));
- }
-}
diff --git a/tests/units/Model/ProjectDuplicationModelTest.php b/tests/units/Model/ProjectDuplicationModelTest.php
new file mode 100644
index 00000000..54261728
--- /dev/null
+++ b/tests/units/Model/ProjectDuplicationModelTest.php
@@ -0,0 +1,548 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\ActionModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\CategoryModel;
+use Kanboard\Model\ProjectUserRoleModel;
+use Kanboard\Model\ProjectGroupRoleModel;
+use Kanboard\Model\ProjectDuplicationModel;
+use Kanboard\Model\TagModel;
+use Kanboard\Model\TaskTagModel;
+use Kanboard\Model\UserModel;
+use Kanboard\Model\GroupModel;
+use Kanboard\Model\GroupMemberModel;
+use Kanboard\Model\SwimlaneModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Core\Security\Role;
+
+class ProjectDuplicationModelTest extends Base
+{
+ public function testGetSelections()
+ {
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $this->assertCount(7, $projectDuplicationModel->getOptionalSelection());
+ $this->assertCount(8, $projectDuplicationModel->getPossibleSelection());
+ }
+
+ public function testGetClonedProjectName()
+ {
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals('test (Clone)', $projectDuplicationModel->getClonedProjectName('test'));
+
+ $this->assertEquals(50, strlen($projectDuplicationModel->getClonedProjectName(str_repeat('a', 50))));
+ $this->assertEquals(str_repeat('a', 42).' (Clone)', $projectDuplicationModel->getClonedProjectName(str_repeat('a', 50)));
+
+ $this->assertEquals(50, strlen($projectDuplicationModel->getClonedProjectName(str_repeat('a', 60))));
+ $this->assertEquals(str_repeat('a', 42).' (Clone)', $projectDuplicationModel->getClonedProjectName(str_repeat('a', 60)));
+ }
+
+ public function testClonePublicProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Public')));
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Public (Clone)', $project['name']);
+ $this->assertEquals(1, $project['is_active']);
+ $this->assertEquals(0, $project['is_private']);
+ $this->assertEquals(0, $project['is_public']);
+ $this->assertEquals(0, $project['owner_id']);
+ $this->assertEmpty($project['token']);
+ }
+
+ public function testClonePrivateProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Private', 'is_private' => 1), 1, true));
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Private (Clone)', $project['name']);
+ $this->assertEquals(1, $project['is_active']);
+ $this->assertEquals(1, $project['is_private']);
+ $this->assertEquals(0, $project['is_public']);
+ $this->assertEquals(0, $project['owner_id']);
+ $this->assertEmpty($project['token']);
+
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1));
+ }
+
+ public function testCloneSharedProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Shared')));
+ $this->assertTrue($projectModel->update(array('id' => 1, 'is_public' => 1, 'token' => 'test')));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals('test', $project['token']);
+ $this->assertEquals(1, $project['is_public']);
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Shared (Clone)', $project['name']);
+ $this->assertEquals('', $project['token']);
+ $this->assertEquals(0, $project['is_public']);
+ }
+
+ public function testCloneInactiveProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Inactive')));
+ $this->assertTrue($projectModel->update(array('id' => 1, 'is_active' => 0)));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals(0, $project['is_active']);
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Inactive (Clone)', $project['name']);
+ $this->assertEquals(1, $project['is_active']);
+ }
+
+ public function testCloneProjectWithOwner()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Owner')));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals(0, $project['owner_id']);
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Owner (Clone)', $project['name']);
+ $this->assertEquals(1, $project['owner_id']);
+
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1));
+ }
+
+ public function testCloneProjectWithDifferentPriorities()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array(
+ 'name' => 'My project',
+ 'priority_default' => 2,
+ 'priority_start' => -2,
+ 'priority_end' => 8,
+ )));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('My project (Clone)', $project['name']);
+ $this->assertEquals(2, $project['priority_default']);
+ $this->assertEquals(-2, $project['priority_start']);
+ $this->assertEquals(8, $project['priority_end']);
+ }
+
+ public function testCloneProjectWithDifferentName()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Owner')));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals(0, $project['owner_id']);
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1, 'Foobar'));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Foobar', $project['name']);
+ $this->assertEquals(1, $project['owner_id']);
+ }
+
+ public function testCloneProjectAndForceItToBePrivate()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Owner')));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals(0, $project['owner_id']);
+ $this->assertEquals(0, $project['is_private']);
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1, 'Foobar', true));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('Foobar', $project['name']);
+ $this->assertEquals(1, $project['owner_id']);
+ $this->assertEquals(1, $project['is_private']);
+ }
+
+ public function testCloneProjectWithCategories()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(2, $categoryModel->create(array('name' => 'C2', 'project_id' => 1)));
+ $this->assertEquals(3, $categoryModel->create(array('name' => 'C3', 'project_id' => 1)));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $project = $projectModel->getById(2);
+ $this->assertNotEmpty($project);
+ $this->assertEquals('P1 (Clone)', $project['name']);
+
+ $categories = $categoryModel->getAll(2);
+ $this->assertCount(3, $categories);
+ $this->assertEquals('C1', $categories[0]['name']);
+ $this->assertEquals('C2', $categories[1]['name']);
+ $this->assertEquals('C3', $categories[2]['name']);
+ }
+
+ public function testCloneProjectWithUsers()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
+ $this->assertEquals(4, $userModel->create(array('username' => 'user3')));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 4, Role::PROJECT_VIEWER));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $this->assertCount(3, $projectUserRoleModel->getUsers(2));
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2));
+ $this->assertEquals(Role::PROJECT_MEMBER, $projectUserRoleModel->getUserRole(2, 3));
+ $this->assertEquals(Role::PROJECT_VIEWER, $projectUserRoleModel->getUserRole(2, 4));
+ }
+
+ public function testCloneProjectWithUsersAndOverrideOwner()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1'), 2));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals(2, $project['owner_id']);
+
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 1, Role::PROJECT_MEMBER));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 1));
+
+ $this->assertCount(2, $projectUserRoleModel->getUsers(2));
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2));
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1));
+
+ $project = $projectModel->getById(2);
+ $this->assertEquals(1, $project['owner_id']);
+ }
+
+ public function testCloneTeamProjectToPrivatProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1'), 2));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals(2, $project['owner_id']);
+ $this->assertEquals(0, $project['is_private']);
+
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 1, Role::PROJECT_MEMBER));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel'), 3, 'My private project', true));
+
+ $this->assertCount(1, $projectUserRoleModel->getUsers(2));
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 3));
+
+ $project = $projectModel->getById(2);
+ $this->assertEquals(3, $project['owner_id']);
+ $this->assertEquals(1, $project['is_private']);
+ }
+
+ public function testCloneProjectWithGroups()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $userModel = new UserModel($this->container);
+ $groupModel = new GroupModel($this->container);
+ $groupMemberModel = new GroupMemberModel($this->container);
+ $projectGroupRoleModel = new ProjectGroupRoleModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $groupModel->create('G1'));
+ $this->assertEquals(2, $groupModel->create('G2'));
+ $this->assertEquals(3, $groupModel->create('G3'));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
+ $this->assertEquals(4, $userModel->create(array('username' => 'user3')));
+
+ $this->assertTrue($groupMemberModel->addUser(1, 2));
+ $this->assertTrue($groupMemberModel->addUser(2, 3));
+ $this->assertTrue($groupMemberModel->addUser(3, 4));
+
+ $this->assertTrue($projectGroupRoleModel->addGroup(1, 1, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectGroupRoleModel->addGroup(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectGroupRoleModel->addGroup(1, 3, Role::PROJECT_VIEWER));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $this->assertCount(3, $projectGroupRoleModel->getGroups(2));
+ $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2));
+ $this->assertEquals(Role::PROJECT_MEMBER, $projectUserRoleModel->getUserRole(2, 3));
+ $this->assertEquals(Role::PROJECT_VIEWER, $projectUserRoleModel->getUserRole(2, 4));
+ }
+
+ public function testCloneProjectWithActionTaskAssignCurrentUser()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $actionModel = new ActionModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => TaskModel::EVENT_MOVE_COLUMN,
+ 'action_name' => 'TaskAssignCurrentUser',
+ 'params' => array('column_id' => 2),
+ )));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $actions = $actionModel->getAllByProject(2);
+
+ $this->assertNotEmpty($actions);
+ $this->assertEquals('TaskAssignCurrentUser', $actions[0]['action_name']);
+ $this->assertNotEmpty($actions[0]['params']);
+ $this->assertEquals(6, $actions[0]['params']['column_id']);
+ }
+
+ public function testCloneProjectWithActionTaskAssignColorCategory()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $actionModel = new ActionModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(2, $categoryModel->create(array('name' => 'C2', 'project_id' => 1)));
+ $this->assertEquals(3, $categoryModel->create(array('name' => 'C3', 'project_id' => 1)));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => TaskModel::EVENT_CREATE_UPDATE,
+ 'action_name' => 'TaskAssignColorCategory',
+ 'params' => array('color_id' => 'blue', 'category_id' => 2),
+ )));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1));
+
+ $actions = $actionModel->getAllByProject(2);
+
+ $this->assertNotEmpty($actions);
+ $this->assertEquals('TaskAssignColorCategory', $actions[0]['action_name']);
+ $this->assertNotEmpty($actions[0]['params']);
+ $this->assertEquals('blue', $actions[0]['params']['color_id']);
+ $this->assertEquals(5, $actions[0]['params']['category_id']);
+ }
+
+ public function testCloneProjectWithSwimlanes()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1', 'default_swimlane' => 'New Default')));
+
+ // create initial swimlanes
+ $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S1')));
+ $this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S2')));
+ $this->assertEquals(3, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S3')));
+
+ // create initial tasks
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T0', 'project_id' => 1, 'swimlane_id' => 0)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'swimlane_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'swimlane_id' => 2)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'swimlane_id' => 3)));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'swimlaneModel')));
+
+ $swimlanes = $swimlaneModel->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']);
+
+ $swimlane = $swimlaneModel->getDefault(2);
+ $this->assertEquals('New Default', $swimlane['default_swimlane']);
+
+ // Check if tasks are NOT been duplicated
+ $this->assertCount(0, $taskFinderModel->getAll(2));
+ }
+
+ public function testCloneProjectWithTasks()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+
+ // create initial tasks
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3)));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'projectTaskDuplicationModel')));
+
+ // Check if Tasks have been duplicated
+ $tasks = $taskFinderModel->getAll(2);
+ $this->assertCount(3, $tasks);
+ $this->assertEquals('T1', $tasks[0]['title']);
+ $this->assertEquals('T2', $tasks[1]['title']);
+ $this->assertEquals('T3', $tasks[2]['title']);
+ }
+
+ public function testCloneProjectWithSwimlanesAndTasks()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1', 'default_swimlane' => 'New Default')));
+
+ // create initial swimlanes
+ $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S1')));
+ $this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S2')));
+ $this->assertEquals(3, $swimlaneModel->create(array('project_id' => 1, 'name' => 'S3')));
+
+ // create initial tasks
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('projectPermissionModel', 'swimlaneModel', 'projectTaskDuplicationModel')));
+
+ // Check if Swimlanes have been duplicated
+ $swimlanes = $swimlaneModel->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']);
+
+ $swimlane = $swimlaneModel->getDefault(2);
+ $this->assertEquals('New Default', $swimlane['default_swimlane']);
+
+ // Check if Tasks have been duplicated
+ $tasks = $taskFinderModel->getAll(2);
+
+ $this->assertCount(3, $tasks);
+ $this->assertEquals('T1', $tasks[0]['title']);
+ $this->assertEquals('T2', $tasks[1]['title']);
+ $this->assertEquals('T3', $tasks[2]['title']);
+ }
+
+ public function testCloneProjectWithTags()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectDuplicationModel = new ProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $tagModel = new TagModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'tags' => array('A'))));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'tags' => array('A', 'B'))));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'tags' => array('C'))));
+
+ $this->assertEquals(2, $projectDuplicationModel->duplicate(1, array('categoryModel', 'actionModel', 'tagDuplicationModel', 'projectTaskDuplicationModel')));
+
+ $tasks = $taskFinderModel->getAll(2);
+ $this->assertCount(3, $tasks);
+ $this->assertEquals('T1', $tasks[0]['title']);
+ $this->assertEquals('T2', $tasks[1]['title']);
+ $this->assertEquals('T3', $tasks[2]['title']);
+
+ $tags = $tagModel->getAllByProject(2);
+ $this->assertCount(3, $tags);
+ $this->assertEquals(4, $tags[0]['id']);
+ $this->assertEquals('A', $tags[0]['name']);
+ $this->assertEquals(5, $tags[1]['id']);
+ $this->assertEquals('B', $tags[1]['name']);
+ $this->assertEquals(6, $tags[2]['id']);
+ $this->assertEquals('C', $tags[2]['name']);
+
+ $tags = $taskTagModel->getList(4);
+ $this->assertEquals('A', $tags[4]);
+
+ $tags = $taskTagModel->getList(5);
+ $this->assertEquals('A', $tags[4]);
+ $this->assertEquals('B', $tags[5]);
+
+ $tags = $taskTagModel->getList(6);
+ $this->assertEquals('C', $tags[6]);
+ }
+}
diff --git a/tests/units/Model/ProjectDuplicationTest.php b/tests/units/Model/ProjectDuplicationTest.php
deleted file mode 100644
index 312c7168..00000000
--- a/tests/units/Model/ProjectDuplicationTest.php
+++ /dev/null
@@ -1,482 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\ActionModel;
-use Kanboard\Model\ProjectModel;
-use Kanboard\Model\CategoryModel;
-use Kanboard\Model\ProjectUserRoleModel;
-use Kanboard\Model\ProjectGroupRoleModel;
-use Kanboard\Model\ProjectDuplicationModel;
-use Kanboard\Model\UserModel;
-use Kanboard\Model\GroupModel;
-use Kanboard\Model\GroupMemberModel;
-use Kanboard\Model\SwimlaneModel;
-use Kanboard\Model\TaskModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Core\Security\Role;
-
-class ProjectDuplicationTest extends Base
-{
- public function testGetSelections()
- {
- $projectDuplicationModel = new ProjectDuplicationModel($this->container);
- $this->assertCount(6, $projectDuplicationModel->getOptionalSelection());
- $this->assertCount(7, $projectDuplicationModel->getPossibleSelection());
- }
-
- public function testGetClonedProjectName()
- {
- $pd = new ProjectDuplicationModel($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 testClonePublicProject()
- {
- $p = new ProjectModel($this->container);
- $pd = new ProjectDuplicationModel($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(1, $project['is_active']);
- $this->assertEquals(0, $project['is_private']);
- $this->assertEquals(0, $project['is_public']);
- $this->assertEquals(0, $project['owner_id']);
- $this->assertEmpty($project['token']);
- }
-
- public function testClonePrivateProject()
- {
- $p = new ProjectModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
- $pp = new ProjectUserRoleModel($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_active']);
- $this->assertEquals(1, $project['is_private']);
- $this->assertEquals(0, $project['is_public']);
- $this->assertEquals(0, $project['owner_id']);
- $this->assertEmpty($project['token']);
-
- $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 1));
- }
-
- public function testCloneSharedProject()
- {
- $p = new ProjectModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Shared')));
- $this->assertTrue($p->update(array('id' => 1, 'is_public' => 1, 'token' => 'test')));
-
- $project = $p->getById(1);
- $this->assertEquals('test', $project['token']);
- $this->assertEquals(1, $project['is_public']);
-
- $this->assertEquals(2, $pd->duplicate(1));
-
- $project = $p->getById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('Shared (Clone)', $project['name']);
- $this->assertEquals('', $project['token']);
- $this->assertEquals(0, $project['is_public']);
- }
-
- public function testCloneInactiveProject()
- {
- $p = new ProjectModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Inactive')));
- $this->assertTrue($p->update(array('id' => 1, 'is_active' => 0)));
-
- $project = $p->getById(1);
- $this->assertEquals(0, $project['is_active']);
-
- $this->assertEquals(2, $pd->duplicate(1));
-
- $project = $p->getById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('Inactive (Clone)', $project['name']);
- $this->assertEquals(1, $project['is_active']);
- }
-
- public function testCloneProjectWithOwner()
- {
- $p = new ProjectModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
- $projectUserRoleModel = new ProjectUserRoleModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Owner')));
-
- $project = $p->getById(1);
- $this->assertEquals(0, $project['owner_id']);
-
- $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 1));
-
- $project = $p->getById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('Owner (Clone)', $project['name']);
- $this->assertEquals(1, $project['owner_id']);
-
- $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1));
- }
-
- public function testCloneProjectWithDifferentName()
- {
- $p = new ProjectModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Owner')));
-
- $project = $p->getById(1);
- $this->assertEquals(0, $project['owner_id']);
-
- $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 1, 'Foobar'));
-
- $project = $p->getById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('Foobar', $project['name']);
- $this->assertEquals(1, $project['owner_id']);
- }
-
- public function testCloneProjectAndForceItToBePrivate()
- {
- $p = new ProjectModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Owner')));
-
- $project = $p->getById(1);
- $this->assertEquals(0, $project['owner_id']);
- $this->assertEquals(0, $project['is_private']);
-
- $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 1, 'Foobar', true));
-
- $project = $p->getById(2);
- $this->assertNotEmpty($project);
- $this->assertEquals('Foobar', $project['name']);
- $this->assertEquals(1, $project['owner_id']);
- $this->assertEquals(1, $project['is_private']);
- }
-
- public function testCloneProjectWithCategories()
- {
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($this->container);
- $pd = new ProjectDuplicationModel($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->assertCount(3, $categories);
- $this->assertEquals('C1', $categories[0]['name']);
- $this->assertEquals('C2', $categories[1]['name']);
- $this->assertEquals('C3', $categories[2]['name']);
- }
-
- public function testCloneProjectWithUsers()
- {
- $p = new ProjectModel($this->container);
- $pp = new ProjectUserRoleModel($this->container);
- $u = new UserModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
-
- $this->assertEquals(2, $u->create(array('username' => 'user1')));
- $this->assertEquals(3, $u->create(array('username' => 'user2')));
- $this->assertEquals(4, $u->create(array('username' => 'user3')));
-
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
-
- $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER));
- $this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER));
- $this->assertTrue($pp->addUser(1, 4, Role::PROJECT_VIEWER));
-
- $this->assertEquals(2, $pd->duplicate(1));
-
- $this->assertCount(3, $pp->getUsers(2));
- $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 2));
- $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(2, 3));
- $this->assertEquals(Role::PROJECT_VIEWER, $pp->getUserRole(2, 4));
- }
-
- public function testCloneProjectWithUsersAndOverrideOwner()
- {
- $p = new ProjectModel($this->container);
- $pp = new ProjectUserRoleModel($this->container);
- $u = new UserModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
-
- $this->assertEquals(2, $u->create(array('username' => 'user1')));
- $this->assertEquals(1, $p->create(array('name' => 'P1'), 2));
-
- $project = $p->getById(1);
- $this->assertEquals(2, $project['owner_id']);
-
- $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER));
- $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER));
-
- $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 1));
-
- $this->assertCount(2, $pp->getUsers(2));
- $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 2));
- $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 1));
-
- $project = $p->getById(2);
- $this->assertEquals(1, $project['owner_id']);
- }
-
- public function testCloneTeamProjectToPrivatProject()
- {
- $p = new ProjectModel($this->container);
- $pp = new ProjectUserRoleModel($this->container);
- $u = new UserModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
-
- $this->assertEquals(2, $u->create(array('username' => 'user1')));
- $this->assertEquals(3, $u->create(array('username' => 'user2')));
- $this->assertEquals(1, $p->create(array('name' => 'P1'), 2));
-
- $project = $p->getById(1);
- $this->assertEquals(2, $project['owner_id']);
- $this->assertEquals(0, $project['is_private']);
-
- $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER));
- $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER));
-
- $this->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel'), 3, 'My private project', true));
-
- $this->assertCount(1, $pp->getUsers(2));
- $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 3));
-
- $project = $p->getById(2);
- $this->assertEquals(3, $project['owner_id']);
- $this->assertEquals(1, $project['is_private']);
- }
-
- public function testCloneProjectWithGroups()
- {
- $p = new ProjectModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
- $userModel = new UserModel($this->container);
- $groupModel = new GroupModel($this->container);
- $groupMemberModel = new GroupMemberModel($this->container);
- $projectGroupRoleModel = new ProjectGroupRoleModel($this->container);
- $projectUserRoleModel = new ProjectUserRoleModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
-
- $this->assertEquals(1, $groupModel->create('G1'));
- $this->assertEquals(2, $groupModel->create('G2'));
- $this->assertEquals(3, $groupModel->create('G3'));
-
- $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
- $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
- $this->assertEquals(4, $userModel->create(array('username' => 'user3')));
-
- $this->assertTrue($groupMemberModel->addUser(1, 2));
- $this->assertTrue($groupMemberModel->addUser(2, 3));
- $this->assertTrue($groupMemberModel->addUser(3, 4));
-
- $this->assertTrue($projectGroupRoleModel->addGroup(1, 1, Role::PROJECT_MANAGER));
- $this->assertTrue($projectGroupRoleModel->addGroup(1, 2, Role::PROJECT_MEMBER));
- $this->assertTrue($projectGroupRoleModel->addGroup(1, 3, Role::PROJECT_VIEWER));
-
- $this->assertEquals(2, $pd->duplicate(1));
-
- $this->assertCount(3, $projectGroupRoleModel->getGroups(2));
- $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2));
- $this->assertEquals(Role::PROJECT_MEMBER, $projectUserRoleModel->getUserRole(2, 3));
- $this->assertEquals(Role::PROJECT_VIEWER, $projectUserRoleModel->getUserRole(2, 4));
- }
-
- public function testCloneProjectWithActionTaskAssignCurrentUser()
- {
- $p = new ProjectModel($this->container);
- $a = new ActionModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
-
- $this->assertEquals(1, $a->create(array(
- 'project_id' => 1,
- 'event_name' => TaskModel::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']['column_id']);
- }
-
- public function testCloneProjectWithActionTaskAssignColorCategory()
- {
- $p = new ProjectModel($this->container);
- $a = new ActionModel($this->container);
- $c = new CategoryModel($this->container);
- $pd = new ProjectDuplicationModel($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' => TaskModel::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']['color_id']);
- $this->assertEquals(5, $actions[0]['params']['category_id']);
- }
-
- public function testCloneProjectWithSwimlanes()
- {
- $p = new ProjectModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
- $s = new SwimlaneModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'P1', 'default_swimlane' => 'New Default')));
-
- // create initial swimlanes
- $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1')));
- $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2')));
- $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3')));
-
- // create initial tasks
- $this->assertEquals(1, $tc->create(array('title' => 'T0', 'project_id' => 1, 'swimlane_id' => 0)));
- $this->assertEquals(2, $tc->create(array('title' => 'T1', 'project_id' => 1, 'swimlane_id' => 1)));
- $this->assertEquals(3, $tc->create(array('title' => 'T2', 'project_id' => 1, 'swimlane_id' => 2)));
- $this->assertEquals(4, $tc->create(array('title' => 'T3', 'project_id' => 1, 'swimlane_id' => 3)));
-
- $this->assertEquals(2, $pd->duplicate(1, array('categoryModel', 'swimlaneModel')));
-
- $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']);
-
- $swimlane = $s->getDefault(2);
- $this->assertEquals('New Default', $swimlane['default_swimlane']);
-
- // Check if tasks are NOT been duplicated
- $this->assertCount(0, $tf->getAll(2));
- }
-
- public function testCloneProjectWithTasks()
- {
- $p = new ProjectModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
-
- // create initial tasks
- $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2)));
- $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3)));
-
- $this->assertEquals(2, $pd->duplicate(1, array('categoryModel', 'actionModel', 'taskModel')));
-
- // Check if Tasks have been duplicated
- $tasks = $tf->getAll(2);
- $this->assertCount(3, $tasks);
- $this->assertEquals('T1', $tasks[0]['title']);
- $this->assertEquals('T2', $tasks[1]['title']);
- $this->assertEquals('T3', $tasks[2]['title']);
- }
-
- public function testCloneProjectWithSwimlanesAndTasks()
- {
- $p = new ProjectModel($this->container);
- $pd = new ProjectDuplicationModel($this->container);
- $s = new SwimlaneModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'P1', 'default_swimlane' => 'New Default')));
-
- // create initial swimlanes
- $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1')));
- $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2')));
- $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3')));
-
- // 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->assertEquals(2, $pd->duplicate(1, array('projectPermissionModel', 'swimlaneModel', 'taskModel')));
-
- // Check if Swimlanes have been duplicated
- $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']);
-
- $swimlane = $s->getDefault(2);
- $this->assertEquals('New Default', $swimlane['default_swimlane']);
-
- // Check if Tasks have been duplicated
- $tasks = $tf->getAll(2);
-
- $this->assertCount(3, $tasks);
- $this->assertEquals('T1', $tasks[0]['title']);
- $this->assertEquals('T2', $tasks[1]['title']);
- $this->assertEquals('T3', $tasks[2]['title']);
- }
-}
diff --git a/tests/units/Model/ProjectTest.php b/tests/units/Model/ProjectModelTest.php
index 472d7351..81e0dd57 100644
--- a/tests/units/Model/ProjectTest.php
+++ b/tests/units/Model/ProjectModelTest.php
@@ -11,16 +11,16 @@ use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ConfigModel;
use Kanboard\Model\CategoryModel;
-class ProjectTest extends Base
+class ProjectModelTest extends Base
{
public function testCreationForAllLanguages()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
foreach ($this->container['languageModel']->getLanguages() as $locale => $language) {
Translator::unload();
Translator::load($locale);
- $this->assertNotFalse($p->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language);
+ $this->assertNotFalse($projectModel->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language);
}
Translator::unload();
@@ -28,11 +28,11 @@ class ProjectTest extends Base
public function testCreation()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals(1, $project['is_active']);
$this->assertEquals(0, $project['is_public']);
@@ -43,19 +43,19 @@ class ProjectTest extends Base
public function testCreationWithDuplicateName()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertEquals(2, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest')));
}
public function testCreationWithStartAndDate()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest', 'start_date' => '2015-01-01', 'end_date' => '2015-12-31')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest', 'start_date' => '2015-01-01', 'end_date' => '2015-12-31')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals('2015-01-01', $project['start_date']);
$this->assertEquals('2015-12-31', $project['end_date']);
@@ -63,19 +63,19 @@ class ProjectTest extends Base
public function testCreationWithDefaultCategories()
{
- $p = new ProjectModel($this->container);
- $c = new ConfigModel($this->container);
- $cat = new CategoryModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $configModel = new ConfigModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
// Multiple categories correctly formatted
- $this->assertTrue($c->save(array('project_categories' => 'Test1, Test2')));
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
+ $this->assertTrue($configModel->save(array('project_categories' => 'Test1, Test2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
- $categories = $cat->getAll(1);
+ $categories = $categoryModel->getAll(1);
$this->assertNotEmpty($categories);
$this->assertEquals(2, count($categories));
$this->assertEquals('Test1', $categories[0]['name']);
@@ -83,85 +83,85 @@ class ProjectTest extends Base
// Single category
- $this->assertTrue($c->save(array('project_categories' => 'Test1')));
+ $this->assertTrue($configModel->save(array('project_categories' => 'Test1')));
$this->container['memoryCache']->flush();
- $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2')));
- $project = $p->getById(2);
+ $project = $projectModel->getById(2);
$this->assertNotEmpty($project);
- $categories = $cat->getAll(2);
+ $categories = $categoryModel->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->assertTrue($configModel->save(array('project_categories' => 'ABC, , DEF 3, ')));
$this->container['memoryCache']->flush();
- $this->assertEquals(3, $p->create(array('name' => 'UnitTest3')));
+ $this->assertEquals(3, $projectModel->create(array('name' => 'UnitTest3')));
- $project = $p->getById(3);
+ $project = $projectModel->getById(3);
$this->assertNotEmpty($project);
- $categories = $cat->getAll(3);
+ $categories = $categoryModel->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->assertTrue($configModel->save(array('project_categories' => ' ')));
$this->container['memoryCache']->flush();
- $this->assertEquals(4, $p->create(array('name' => 'UnitTest4')));
+ $this->assertEquals(4, $projectModel->create(array('name' => 'UnitTest4')));
- $project = $p->getById(4);
+ $project = $projectModel->getById(4);
$this->assertNotEmpty($project);
- $categories = $cat->getAll(4);
+ $categories = $categoryModel->getAll(4);
$this->assertEmpty($categories);
}
public function testUpdateLastModifiedDate()
{
- $p = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $projectModel = new ProjectModel($this->container);
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
$now = time();
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals($now, $project['last_modified'], 'Wrong Timestamp', 1);
sleep(1);
- $this->assertTrue($p->updateModificationDate(1));
+ $this->assertTrue($projectModel->updateModificationDate(1));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertGreaterThan($now, $project['last_modified']);
}
public function testGetAllIds()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
- $this->assertEmpty($p->getAllByIds(array()));
- $this->assertNotEmpty($p->getAllByIds(array(1, 2)));
- $this->assertCount(1, $p->getAllByIds(array(1)));
+ $this->assertEmpty($projectModel->getAllByIds(array()));
+ $this->assertNotEmpty($projectModel->getAllByIds(array(1, 2)));
+ $this->assertCount(1, $projectModel->getAllByIds(array(1)));
}
public function testIsLastModified()
{
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
$now = time();
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals($now, $project['last_modified']);
@@ -170,113 +170,113 @@ class ProjectTest extends Base
$listener = new ProjectModificationDateSubscriber($this->container);
$this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($listener, 'execute'));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
$called = $this->container['dispatcher']->getCalledListeners();
$this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.Kanboard\Subscriber\ProjectModificationDateSubscriber::execute', $called);
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
- $this->assertTrue($p->isModifiedSince(1, $now));
+ $this->assertTrue($projectModel->isModifiedSince(1, $now));
}
public function testRemove()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertTrue($p->remove(1));
- $this->assertFalse($p->remove(1234));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertTrue($projectModel->remove(1));
+ $this->assertFalse($projectModel->remove(1234));
}
public function testEnable()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertTrue($p->disable(1));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertTrue($projectModel->disable(1));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals(0, $project['is_active']);
- $this->assertFalse($p->disable(1111));
+ $this->assertFalse($projectModel->disable(1111));
}
public function testDisable()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertTrue($p->disable(1));
- $this->assertTrue($p->enable(1));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertTrue($projectModel->disable(1));
+ $this->assertTrue($projectModel->enable(1));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals(1, $project['is_active']);
- $this->assertFalse($p->enable(1234567));
+ $this->assertFalse($projectModel->enable(1234567));
}
public function testEnablePublicAccess()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertTrue($p->enablePublicAccess(1));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertTrue($projectModel->enablePublicAccess(1));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals(1, $project['is_public']);
$this->assertNotEmpty($project['token']);
- $this->assertFalse($p->enablePublicAccess(123));
+ $this->assertFalse($projectModel->enablePublicAccess(123));
}
public function testDisablePublicAccess()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertTrue($p->enablePublicAccess(1));
- $this->assertTrue($p->disablePublicAccess(1));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertTrue($projectModel->enablePublicAccess(1));
+ $this->assertTrue($projectModel->disablePublicAccess(1));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals(0, $project['is_public']);
$this->assertEmpty($project['token']);
- $this->assertFalse($p->disablePublicAccess(123));
+ $this->assertFalse($projectModel->disablePublicAccess(123));
}
public function testIdentifier()
{
- $p = new ProjectModel($this->container);
+ $projectModel = new ProjectModel($this->container);
// Creation
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
- $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'UnitTest2')));
- $project = $p->getById(1);
+ $project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals('TEST1', $project['identifier']);
- $project = $p->getById(2);
+ $project = $projectModel->getById(2);
$this->assertNotEmpty($project);
$this->assertEquals('', $project['identifier']);
// Update
- $this->assertTrue($p->update(array('id' => '2', 'identifier' => 'test2')));
+ $this->assertTrue($projectModel->update(array('id' => '2', 'identifier' => 'test2')));
- $project = $p->getById(2);
+ $project = $projectModel->getById(2);
$this->assertNotEmpty($project);
$this->assertEquals('TEST2', $project['identifier']);
- $project = $p->getByIdentifier('test1');
+ $project = $projectModel->getByIdentifier('test1');
$this->assertNotEmpty($project);
$this->assertEquals('TEST1', $project['identifier']);
- $project = $p->getByIdentifier('');
+ $project = $projectModel->getByIdentifier('');
$this->assertFalse($project);
}
@@ -303,34 +303,4 @@ class ProjectTest extends Base
$this->assertEquals('', $project['owner_username']);
$this->assertEquals(0, $project['owner_id']);
}
-
- public function testPriority()
- {
- $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $projectModel->create(array('name' => 'My project 2')));
-
- $project = $projectModel->getById(1);
- $this->assertNotEmpty($project);
- $this->assertEquals(0, $project['priority_default']);
- $this->assertEquals(0, $project['priority_start']);
- $this->assertEquals(3, $project['priority_end']);
-
- $this->assertEquals(
- array(0 => 0, 1 => 1, 2 => 2, 3 => 3),
- $projectModel->getPriorities($project)
- );
-
- $this->assertTrue($projectModel->update(array('id' => 1, 'priority_start' => 2, 'priority_end' => 5, 'priority_default' => 4)));
-
- $project = $projectModel->getById(1);
- $this->assertNotEmpty($project);
- $this->assertEquals(4, $project['priority_default']);
- $this->assertEquals(2, $project['priority_start']);
- $this->assertEquals(5, $project['priority_end']);
-
- $this->assertEquals(
- array(2 => 2, 3 => 3, 4 => 4, 5 => 5),
- $projectModel->getPriorities($project)
- );
- }
}
diff --git a/tests/units/Model/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionTest.php
index c9e0a481..a9f8ab04 100644
--- a/tests/units/Model/ProjectPermissionTest.php
+++ b/tests/units/Model/ProjectPermissionTest.php
@@ -267,6 +267,29 @@ class ProjectPermissionTest extends Base
$this->assertEquals(array(1), $projectPermission->getActiveProjectIds(3));
}
+ public function testGetProjectIds()
+ {
+ $userModel = new UserModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $userRoleModel = new ProjectUserRoleModel($this->container);
+ $projectPermission = new ProjectPermissionModel($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user 1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user 2')));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2', 'is_active' => 0)));
+
+ $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER));
+ $this->assertTrue($userRoleModel->addUser(2, 3, Role::PROJECT_MEMBER));
+
+ $this->assertEmpty($projectPermission->getProjectIds(1));
+ $this->assertEquals(array(1, 2), $projectPermission->getProjectIds(2));
+ $this->assertEquals(array(1, 2), $projectPermission->getProjectIds(3));
+ }
+
public function testDuplicate()
{
$userModel = new UserModel($this->container);
diff --git a/tests/units/Model/ProjectTaskPriorityModelTest.php b/tests/units/Model/ProjectTaskPriorityModelTest.php
new file mode 100644
index 00000000..61661e5e
--- /dev/null
+++ b/tests/units/Model/ProjectTaskPriorityModelTest.php
@@ -0,0 +1,84 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectTaskPriorityModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectTaskPriorityModelTest extends Base
+{
+ public function testPriority()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectTaskPriorityModel = new ProjectTaskPriorityModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'My project 2')));
+ $this->assertEquals(0, $projectTaskPriorityModel->getDefaultPriority(1));
+
+ $project = $projectModel->getById(1);
+ $this->assertNotEmpty($project);
+ $this->assertEquals(0, $project['priority_default']);
+ $this->assertEquals(0, $project['priority_start']);
+ $this->assertEquals(3, $project['priority_end']);
+
+ $this->assertEquals(
+ array(0 => 0, 1 => 1, 2 => 2, 3 => 3),
+ $projectTaskPriorityModel->getPriorities($project)
+ );
+
+ $this->assertTrue($projectModel->update(array('id' => 1, 'priority_start' => 2, 'priority_end' => 5, 'priority_default' => 4)));
+
+ $project = $projectModel->getById(1);
+ $this->assertNotEmpty($project);
+ $this->assertEquals(4, $project['priority_default']);
+ $this->assertEquals(2, $project['priority_start']);
+ $this->assertEquals(5, $project['priority_end']);
+
+ $this->assertEquals(
+ array(2 => 2, 3 => 3, 4 => 4, 5 => 5),
+ $projectTaskPriorityModel->getPriorities($project)
+ );
+
+ $this->assertEquals(4, $projectTaskPriorityModel->getDefaultPriority(1));
+ }
+
+ public function testGetPrioritySettings()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectTaskPriorityModel = new ProjectTaskPriorityModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'My project 2')));
+
+ $expected = array(
+ 'priority_default' => 0,
+ 'priority_start' => 0,
+ 'priority_end' => 3,
+ );
+
+ $this->assertEquals($expected, $projectTaskPriorityModel->getPrioritySettings(1));
+ $this->assertNull($projectTaskPriorityModel->getPrioritySettings(2));
+ }
+
+ public function testGetPriorityForProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectTaskPriorityModel = new ProjectTaskPriorityModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array(
+ 'name' => 'My project 1',
+ 'priority_default' => 2,
+ 'priority_start' => -2,
+ 'priority_end' => 8,
+ )));
+
+ $this->assertEquals(2, $projectTaskPriorityModel->getPriorityForProject(1, 42));
+ $this->assertEquals(0, $projectTaskPriorityModel->getPriorityForProject(1, 0));
+ $this->assertEquals(1, $projectTaskPriorityModel->getPriorityForProject(1, 1));
+ $this->assertEquals(-2, $projectTaskPriorityModel->getPriorityForProject(1, -2));
+ $this->assertEquals(-1, $projectTaskPriorityModel->getPriorityForProject(1, -1));
+ $this->assertEquals(8, $projectTaskPriorityModel->getPriorityForProject(1, 8));
+ $this->assertEquals(5, $projectTaskPriorityModel->getPriorityForProject(1, 5));
+ $this->assertEquals(2, $projectTaskPriorityModel->getPriorityForProject(1, 9));
+ $this->assertEquals(2, $projectTaskPriorityModel->getPriorityForProject(1, -3));
+ }
+}
diff --git a/tests/units/Model/SubtaskModelTest.php b/tests/units/Model/SubtaskModelTest.php
new file mode 100644
index 00000000..eed37cf3
--- /dev/null
+++ b/tests/units/Model/SubtaskModelTest.php
@@ -0,0 +1,175 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskFinderModel;
+
+class SubtaskModelTest extends Base
+{
+ public function testCreation()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['id']);
+ $this->assertEquals(1, $subtask['task_id']);
+ $this->assertEquals('subtask #1', $subtask['title']);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(0, $subtask['time_estimated']);
+ $this->assertEquals(0, $subtask['time_spent']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['position']);
+ }
+
+ public function testCreationUpdateTaskTimeTracking()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 2, 'time_spent' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 5)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(7, $task['time_estimated']);
+ $this->assertEquals(6, $task['time_spent']);
+ }
+
+ public function testModification()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'task_id' => 1, 'user_id' => 1, 'status' => SubtaskModel::STATUS_INPROGRESS)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(1, $subtask['id']);
+ $this->assertEquals(1, $subtask['task_id']);
+ $this->assertEquals('subtask #1', $subtask['title']);
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
+ $this->assertEquals(0, $subtask['time_estimated']);
+ $this->assertEquals(0, $subtask['time_spent']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['position']);
+ }
+
+ public function testModificationUpdateTaskTimeTracking()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'task_id' => 1, 'time_estimated' => 2, 'time_spent' => 1)));
+ $this->assertTrue($subtaskModel->update(array('id' => 2, 'task_id' => 1, 'time_estimated' => 2, 'time_spent' => 1)));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 5)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(7, $task['time_estimated']);
+ $this->assertEquals(6, $task['time_spent']);
+ }
+
+ public function testRemove()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+
+ $this->assertTrue($subtaskModel->remove(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertEmpty($subtask);
+ }
+
+ public function testDuplicate()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ // We create a project
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+
+ // We create 2 tasks
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->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, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1, 'another_subtask' => 'on')));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => '', 'status' => 2, 'user_id' => 1)));
+
+ // We duplicate our subtasks
+ $this->assertTrue($subtaskModel->duplicate(1, 2));
+ $subtasks = $subtaskModel->getAll(2);
+
+ $this->assertNotEmpty($subtasks);
+ $this->assertEquals(2, count($subtasks));
+
+ $this->assertEquals('subtask #1', $subtasks[0]['title']);
+ $this->assertEquals('subtask #2', $subtasks[1]['title']);
+
+ $this->assertEquals(2, $subtasks[0]['task_id']);
+ $this->assertEquals(2, $subtasks[1]['task_id']);
+
+ $this->assertEquals(5, $subtasks[0]['time_estimated']);
+ $this->assertEquals(0, $subtasks[1]['time_estimated']);
+
+ $this->assertEquals(0, $subtasks[0]['time_spent']);
+ $this->assertEquals(0, $subtasks[1]['time_spent']);
+
+ $this->assertEquals(0, $subtasks[0]['status']);
+ $this->assertEquals(0, $subtasks[1]['status']);
+
+ $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']);
+ }
+
+ public function testGetProjectId()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->getProjectId(1));
+ $this->assertEquals(0, $subtaskModel->getProjectId(2));
+ }
+}
diff --git a/tests/units/Model/SubtaskPositionModelTest.php b/tests/units/Model/SubtaskPositionModelTest.php
new file mode 100644
index 00000000..92412392
--- /dev/null
+++ b/tests/units/Model/SubtaskPositionModelTest.php
@@ -0,0 +1,77 @@
+<?php
+
+use Kanboard\Model\SubtaskPositionModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\ProjectModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskPositionModelTest extends Base
+{
+ public function testChangePosition()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskPositionModel = new SubtaskPositionModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
+ $this->assertEquals(3, $subtaskModel->create(array('title' => 'subtask #3', 'task_id' => 1)));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(1, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(2, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(3, $subtasks[2]['id']);
+
+ $this->assertTrue($subtaskPositionModel->changePosition(1, 3, 2));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(1, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(3, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(2, $subtasks[2]['id']);
+
+ $this->assertTrue($subtaskPositionModel->changePosition(1, 2, 1));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(2, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(1, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(3, $subtasks[2]['id']);
+
+ $this->assertTrue($subtaskPositionModel->changePosition(1, 2, 2));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(1, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(2, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(3, $subtasks[2]['id']);
+
+ $this->assertTrue($subtaskPositionModel->changePosition(1, 1, 3));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertEquals(1, $subtasks[0]['position']);
+ $this->assertEquals(2, $subtasks[0]['id']);
+ $this->assertEquals(2, $subtasks[1]['position']);
+ $this->assertEquals(3, $subtasks[1]['id']);
+ $this->assertEquals(3, $subtasks[2]['position']);
+ $this->assertEquals(1, $subtasks[2]['id']);
+
+ $this->assertFalse($subtaskPositionModel->changePosition(1, 2, 0));
+ $this->assertFalse($subtaskPositionModel->changePosition(1, 2, 4));
+ }
+}
diff --git a/tests/units/Model/SubtaskStatusModelTest.php b/tests/units/Model/SubtaskStatusModelTest.php
new file mode 100644
index 00000000..af4c3955
--- /dev/null
+++ b/tests/units/Model/SubtaskStatusModelTest.php
@@ -0,0 +1,123 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\SubtaskStatusModel;
+use Kanboard\Model\TaskCreationModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskStatusModelTest extends Base
+{
+ public function testToggleStatusWithoutSession()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskStatusModel = new SubtaskStatusModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+ }
+
+ public function testToggleStatusWithSession()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskStatusModel = new SubtaskStatusModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(0, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ // Set the current logged user
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskStatusModel->toggleStatus(1));
+
+ $subtask = $subtaskModel->getById(1);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
+ $this->assertEquals(1, $subtask['user_id']);
+ $this->assertEquals(1, $subtask['task_id']);
+ }
+
+ public function testCloseAll()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskStatusModel = new SubtaskStatusModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
+
+ $this->assertTrue($subtaskStatusModel->closeAll(1));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertNotEmpty($subtasks);
+
+ foreach ($subtasks as $subtask) {
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
+ }
+ }
+}
diff --git a/tests/units/Model/SubtaskTaskConversionModelTest.php b/tests/units/Model/SubtaskTaskConversionModelTest.php
new file mode 100644
index 00000000..51a623b2
--- /dev/null
+++ b/tests/units/Model/SubtaskTaskConversionModelTest.php
@@ -0,0 +1,37 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\SubtaskTaskConversionModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskTaskConversionModelTest extends Base
+{
+ public function testConvertToTask()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskConversion = new SubtaskTaskConversionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1, 'time_spent' => 2, 'time_estimated' => 3)));
+ $task_id = $subtaskConversion->convertToTask(1, 1);
+
+ $this->assertNotFalse($task_id);
+ $this->assertEmpty($subtaskModel->getById(1));
+
+ $task = $taskFinderModel->getById($task_id);
+ $this->assertEquals('subtask #1', $task['title']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(1, $task['owner_id']);
+ $this->assertEquals(2, $task['time_spent']);
+ $this->assertEquals(3, $task['time_estimated']);
+ }
+}
diff --git a/tests/units/Model/SubtaskTest.php b/tests/units/Model/SubtaskTest.php
deleted file mode 100644
index b65ee609..00000000
--- a/tests/units/Model/SubtaskTest.php
+++ /dev/null
@@ -1,388 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\SubtaskModel;
-use Kanboard\Model\ProjectModel;
-use Kanboard\Core\User\UserSession;
-use Kanboard\Model\TaskFinderModel;
-
-class SubtaskTest extends Base
-{
- public function onSubtaskCreated($event)
- {
- $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
- $data = $event->getAll();
-
- $this->assertArrayHasKey('id', $data);
- $this->assertArrayHasKey('title', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('time_estimated', $data);
- $this->assertArrayHasKey('time_spent', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('task_id', $data);
- $this->assertArrayHasKey('user_id', $data);
- $this->assertArrayHasKey('position', $data);
- $this->assertNotEmpty($data['task_id']);
- $this->assertNotEmpty($data['id']);
- }
-
- public function onSubtaskUpdated($event)
- {
- $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
- $data = $event->getAll();
-
- $this->assertArrayHasKey('id', $data);
- $this->assertArrayHasKey('title', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('time_estimated', $data);
- $this->assertArrayHasKey('time_spent', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('task_id', $data);
- $this->assertArrayHasKey('user_id', $data);
- $this->assertArrayHasKey('position', $data);
- $this->assertArrayHasKey('changes', $data);
- $this->assertArrayHasKey('user_id', $data['changes']);
- $this->assertArrayHasKey('status', $data['changes']);
-
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $data['changes']['status']);
- $this->assertEquals(1, $data['changes']['user_id']);
- }
-
- public function onSubtaskDeleted($event)
- {
- $this->assertInstanceOf('Kanboard\Event\SubtaskEvent', $event);
- $data = $event->getAll();
-
- $this->assertArrayHasKey('id', $data);
- $this->assertArrayHasKey('title', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('time_estimated', $data);
- $this->assertArrayHasKey('time_spent', $data);
- $this->assertArrayHasKey('status', $data);
- $this->assertArrayHasKey('task_id', $data);
- $this->assertArrayHasKey('user_id', $data);
- $this->assertArrayHasKey('position', $data);
- $this->assertNotEmpty($data['task_id']);
- $this->assertNotEmpty($data['id']);
- }
-
- public function testCreation()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
-
- $this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, array($this, 'onSubtaskCreated'));
-
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(1, $subtask['id']);
- $this->assertEquals(1, $subtask['task_id']);
- $this->assertEquals('subtask #1', $subtask['title']);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
- $this->assertEquals(0, $subtask['time_estimated']);
- $this->assertEquals(0, $subtask['time_spent']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['position']);
- }
-
- public function testModification()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
-
- $this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, array($this, 'onSubtaskUpdated'));
-
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
- $this->assertTrue($s->update(array('id' => 1, 'user_id' => 1, 'status' => SubtaskModel::STATUS_INPROGRESS)));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(1, $subtask['id']);
- $this->assertEquals(1, $subtask['task_id']);
- $this->assertEquals('subtask #1', $subtask['title']);
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
- $this->assertEquals(0, $subtask['time_estimated']);
- $this->assertEquals(0, $subtask['time_spent']);
- $this->assertEquals(1, $subtask['user_id']);
- $this->assertEquals(1, $subtask['position']);
- }
-
- public function testRemove()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $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->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, array($this, 'onSubtaskDeleted'));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
-
- $this->assertTrue($s->remove(1));
-
- $subtask = $s->getById(1);
- $this->assertEmpty($subtask);
- }
-
- public function testToggleStatusWithoutSession()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($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)));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $s->toggleStatus(1));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_DONE, $s->toggleStatus(1));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_TODO, $s->toggleStatus(1));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
- }
-
- public function testToggleStatusWithSession()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($this->container);
- $us = new UserSession($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)));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
- $this->assertEquals(0, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- // Set the current logged user
- $this->container['sessionStorage']->user = array('id' => 1);
-
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $s->toggleStatus(1));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
- $this->assertEquals(1, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_DONE, $s->toggleStatus(1));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
- $this->assertEquals(1, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
-
- $this->assertEquals(SubtaskModel::STATUS_TODO, $s->toggleStatus(1));
-
- $subtask = $s->getById(1);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
- $this->assertEquals(1, $subtask['user_id']);
- $this->assertEquals(1, $subtask['task_id']);
- }
-
- public function testCloseAll()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($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->assertTrue($s->closeAll(1));
-
- $subtasks = $s->getAll(1);
- $this->assertNotEmpty($subtasks);
-
- foreach ($subtasks as $subtask) {
- $this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
- }
- }
-
- public function testDuplicate()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($this->container);
-
- // We create a project
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
-
- // We create 2 tasks
- $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')));
- $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => '', 'status' => 2, 'user_id' => 1)));
-
- // We duplicate our subtasks
- $this->assertTrue($s->duplicate(1, 2));
- $subtasks = $s->getAll(2);
-
- $this->assertNotFalse($subtasks);
- $this->assertNotEmpty($subtasks);
- $this->assertEquals(2, count($subtasks));
-
- $this->assertEquals('subtask #1', $subtasks[0]['title']);
- $this->assertEquals('subtask #2', $subtasks[1]['title']);
-
- $this->assertEquals(2, $subtasks[0]['task_id']);
- $this->assertEquals(2, $subtasks[1]['task_id']);
-
- $this->assertEquals(5, $subtasks[0]['time_estimated']);
- $this->assertEquals(0, $subtasks[1]['time_estimated']);
-
- $this->assertEquals(0, $subtasks[0]['time_spent']);
- $this->assertEquals(0, $subtasks[1]['time_spent']);
-
- $this->assertEquals(0, $subtasks[0]['status']);
- $this->assertEquals(0, $subtasks[1]['status']);
-
- $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']);
- }
-
- public function testChangePosition()
- {
- $taskCreationModel = new TaskCreationModel($this->container);
- $subtaskModel = new SubtaskModel($this->container);
- $projectModel = new ProjectModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
-
- $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
- $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
- $this->assertEquals(3, $subtaskModel->create(array('title' => 'subtask #3', 'task_id' => 1)));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(1, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(2, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(3, $subtasks[2]['id']);
-
- $this->assertTrue($subtaskModel->changePosition(1, 3, 2));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(1, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(3, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(2, $subtasks[2]['id']);
-
- $this->assertTrue($subtaskModel->changePosition(1, 2, 1));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(2, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(1, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(3, $subtasks[2]['id']);
-
- $this->assertTrue($subtaskModel->changePosition(1, 2, 2));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(1, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(2, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(3, $subtasks[2]['id']);
-
- $this->assertTrue($subtaskModel->changePosition(1, 1, 3));
-
- $subtasks = $subtaskModel->getAll(1);
- $this->assertEquals(1, $subtasks[0]['position']);
- $this->assertEquals(2, $subtasks[0]['id']);
- $this->assertEquals(2, $subtasks[1]['position']);
- $this->assertEquals(3, $subtasks[1]['id']);
- $this->assertEquals(3, $subtasks[2]['position']);
- $this->assertEquals(1, $subtasks[2]['id']);
-
- $this->assertFalse($subtaskModel->changePosition(1, 2, 0));
- $this->assertFalse($subtaskModel->changePosition(1, 2, 4));
- }
-
- public function testConvertToTask()
- {
- $taskCreationModel = new TaskCreationModel($this->container);
- $taskFinderModel = new TaskFinderModel($this->container);
- $subtaskModel = new SubtaskModel($this->container);
- $projectModel = new ProjectModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
-
- $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1, 'time_spent' => 2, 'time_estimated' => 3)));
- $task_id = $subtaskModel->convertToTask(1, 1);
-
- $this->assertNotFalse($task_id);
- $this->assertEmpty($subtaskModel->getById(1));
-
- $task = $taskFinderModel->getById($task_id);
- $this->assertEquals('subtask #1', $task['title']);
- $this->assertEquals(1, $task['project_id']);
- $this->assertEquals(1, $task['owner_id']);
- $this->assertEquals(2, $task['time_spent']);
- $this->assertEquals(3, $task['time_estimated']);
- }
-}
diff --git a/tests/units/Model/SubtaskTimeTrackingModelTest.php b/tests/units/Model/SubtaskTimeTrackingModelTest.php
new file mode 100644
index 00000000..8b0fe698
--- /dev/null
+++ b/tests/units/Model/SubtaskTimeTrackingModelTest.php
@@ -0,0 +1,277 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\ConfigModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\SubtaskTimeTrackingModel;
+use Kanboard\Model\ProjectModel;
+
+class SubtaskTimeTrackingModelTest extends Base
+{
+ public function testToggleTimer()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ $this->assertFalse($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_TODO));
+ $this->assertTrue($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_INPROGRESS));
+ $this->assertTrue($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_DONE));
+ }
+
+ public function testToggleTimerWhenFeatureDisabled()
+ {
+ $configModel = new ConfigModel($this->container);
+ $configModel->save(array('subtask_time_tracking' => '0'));
+ $this->container['memoryCache']->flush();
+
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ $this->assertFalse($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_TODO));
+ $this->assertFalse($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_INPROGRESS));
+ $this->assertFalse($subtaskTimeTrackingModel->toggleTimer(1, 1, SubtaskModel::STATUS_DONE));
+ }
+
+ public function testHasTimer()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ $this->assertFalse($subtaskTimeTrackingModel->hasTimer(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->hasTimer(1, 1));
+ $this->assertFalse($subtaskTimeTrackingModel->logStartTime(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+ $this->assertFalse($subtaskTimeTrackingModel->hasTimer(1, 1));
+ }
+
+ public function testGetTimerStatus()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'user_id' => 1)));
+
+ // Nothing started
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertNotEmpty($subtasks);
+ $this->assertEquals(0, $subtasks[0]['timer_start_date']);
+ $this->assertFalse($subtasks[0]['is_timer_started']);
+
+ $subtask = $subtaskModel->getById(1, true);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(0, $subtask['timer_start_date']);
+ $this->assertFalse($subtask['is_timer_started']);
+
+ // Start the clock
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertNotEmpty($subtasks);
+ $this->assertEquals(time(), $subtasks[0]['timer_start_date'], '', 3);
+ $this->assertTrue($subtasks[0]['is_timer_started']);
+
+ $subtask = $subtaskModel->getById(1, true);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(time(), $subtask['timer_start_date'], '', 3);
+ $this->assertTrue($subtask['is_timer_started']);
+
+ // Stop the clock
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+ $subtasks = $subtaskModel->getAll(1);
+ $this->assertNotEmpty($subtasks);
+ $this->assertEquals(0, $subtasks[0]['timer_start_date']);
+ $this->assertFalse($subtasks[0]['is_timer_started']);
+
+ $subtask = $subtaskModel->getById(1, true);
+ $this->assertNotEmpty($subtask);
+ $this->assertEquals(0, $subtask['timer_start_date']);
+ $this->assertFalse($subtask['is_timer_started']);
+ }
+
+ public function testLogStartTime()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+
+ $timesheet = $subtaskTimeTrackingModel->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()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));
+
+ // No start time
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+ $timesheet = $subtaskTimeTrackingModel->getUserTimesheet(1);
+ $this->assertEmpty($timesheet);
+
+ // Log start and end time
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+ sleep(1);
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+
+ $timesheet = $subtaskTimeTrackingModel->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()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2, 'time_estimated' => 3.3)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 1.1, 'time_estimated' => 4.4)));
+
+ $time = $subtaskTimeTrackingModel->calculateSubtaskTime(1);
+ $this->assertCount(2, $time);
+ $this->assertEquals(3.3, $time['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(7.7, $time['time_estimated'], 'Total estimated', 0.01);
+ }
+
+ public function testUpdateSubtaskTimeSpent()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_spent' => 2.2)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
+
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->logStartTime(2, 1));
+
+ // Fake start time
+ $this->container['db']->table(SubtaskTimeTrackingModel::TABLE)->update(array('start' => time() - 3600));
+
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(1, 1));
+ $this->assertTrue($subtaskTimeTrackingModel->logEndTime(2, 1));
+
+ $timesheet = $subtaskTimeTrackingModel->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 = $subtaskTimeTrackingModel->calculateSubtaskTime(1);
+ $this->assertEquals(4.2, $time['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
+
+ $time = $subtaskTimeTrackingModel->calculateSubtaskTime(2);
+ $this->assertEquals(0, $time['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
+ }
+
+ public function testUpdateTaskTimeTracking()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 1.5, 'time_spent' => 0.5)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'test 3', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2)));
+
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_spent' => 2.2)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 1)));
+
+ $this->assertEquals(3, $subtaskModel->create(array('title' => 'subtask #3', 'task_id' => 2, 'time_spent' => 3.4)));
+ $this->assertEquals(4, $subtaskModel->create(array('title' => 'subtask #4', 'task_id' => 2, 'time_estimated' => 1.25)));
+
+ $this->assertEquals(5, $subtaskModel->create(array('title' => 'subtask #5', 'task_id' => 3, 'time_spent' => 8)));
+
+ $subtaskTimeTrackingModel->updateTaskTimeTracking(1);
+ $subtaskTimeTrackingModel->updateTaskTimeTracking(2);
+ $subtaskTimeTrackingModel->updateTaskTimeTracking(3);
+
+ $task = $taskFinderModel->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 = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3.4, $task['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(1.25, $task['time_estimated'], 'Total estimated', 0.01);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['time_estimated']);
+ $this->assertEquals(8, $task['time_spent']);
+
+ $this->assertTrue($subtaskModel->remove(3));
+ $this->assertTrue($subtaskModel->remove(4));
+
+ $subtaskTimeTrackingModel->updateTaskTimeTracking(2);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['time_estimated']);
+ $this->assertEquals(0, $task['time_spent']);
+ }
+}
diff --git a/tests/units/Model/SubtaskTimeTrackingTest.php b/tests/units/Model/SubtaskTimeTrackingTest.php
deleted file mode 100644
index d5ae62ae..00000000
--- a/tests/units/Model/SubtaskTimeTrackingTest.php
+++ /dev/null
@@ -1,240 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\SubtaskModel;
-use Kanboard\Model\SubtaskTimeTrackingModel;
-use Kanboard\Model\ProjectModel;
-
-class SubtaskTimeTrackingTest extends Base
-{
- public function testHasTimer()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($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->assertFalse($st->hasTimer(1, 1));
- $this->assertTrue($st->logStartTime(1, 1));
- $this->assertTrue($st->hasTimer(1, 1));
- $this->assertFalse($st->logStartTime(1, 1));
- $this->assertTrue($st->logEndTime(1, 1));
- $this->assertFalse($st->hasTimer(1, 1));
- }
-
- public function testGetTimerStatus()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->container['sessionStorage']->user = array('id' => 1);
-
- $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 #1', 'task_id' => 1, 'user_id' => 1)));
-
- // Nothing started
- $subtasks = $s->getAll(1);
- $this->assertNotEmpty($subtasks);
- $this->assertEquals(0, $subtasks[0]['timer_start_date']);
- $this->assertFalse($subtasks[0]['is_timer_started']);
-
- $subtask = $s->getById(1, true);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(0, $subtask['timer_start_date']);
- $this->assertFalse($subtask['is_timer_started']);
-
- // Start the clock
- $this->assertTrue($st->logStartTime(1, 1));
-
- $subtasks = $s->getAll(1);
- $this->assertNotEmpty($subtasks);
- $this->assertEquals(time(), $subtasks[0]['timer_start_date'], '', 3);
- $this->assertTrue($subtasks[0]['is_timer_started']);
-
- $subtask = $s->getById(1, true);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(time(), $subtask['timer_start_date'], '', 3);
- $this->assertTrue($subtask['is_timer_started']);
-
- // Stop the clock
- $this->assertTrue($st->logEndTime(1, 1));
- $subtasks = $s->getAll(1);
- $this->assertNotEmpty($subtasks);
- $this->assertEquals(0, $subtasks[0]['timer_start_date']);
- $this->assertFalse($subtasks[0]['is_timer_started']);
-
- $subtask = $s->getById(1, true);
- $this->assertNotEmpty($subtask);
- $this->assertEquals(0, $subtask['timer_start_date']);
- $this->assertFalse($subtask['is_timer_started']);
- }
-
- public function testLogStartTime()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($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 TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($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 TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($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->assertCount(2, $time);
- $this->assertEquals(3.3, $time['time_spent'], 'Total spent', 0.01);
- $this->assertEquals(7.7, $time['time_estimated'], 'Total estimated', 0.01);
- }
-
- public function testUpdateSubtaskTimeSpent()
- {
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($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(SubtaskTimeTrackingModel::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->assertEquals(4.2, $time['time_spent'], 'Total spent', 0.01);
- $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
-
- $time = $st->calculateSubtaskTime(2);
- $this->assertEquals(0, $time['time_spent'], 'Total spent', 0.01);
- $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
- }
-
- public function testUpdateTaskTimeTracking()
- {
- $tf = new TaskFinderModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $st = new SubtaskTimeTrackingModel($this->container);
- $p = new ProjectModel($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(3, $tc->create(array('title' => 'test 3', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2)));
-
- $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)));
-
- $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 2, 'time_spent' => 3.4)));
- $this->assertEquals(4, $s->create(array('title' => 'subtask #4', 'task_id' => 2, 'time_estimated' => 1.25)));
-
- $this->assertEquals(5, $s->create(array('title' => 'subtask #5', 'task_id' => 3, 'time_spent' => 8)));
-
- $st->updateTaskTimeTracking(1);
- $st->updateTaskTimeTracking(2);
- $st->updateTaskTimeTracking(3);
-
- $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(3.4, $task['time_spent'], 'Total spent', 0.01);
- $this->assertEquals(1.25, $task['time_estimated'], 'Total estimated', 0.01);
-
- $task = $tf->getById(3);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['time_estimated']);
- $this->assertEquals(8, $task['time_spent']);
-
- $this->assertTrue($s->remove(3));
- $this->assertTrue($s->remove(4));
-
- $st->updateTaskTimeTracking(2);
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['time_estimated']);
- $this->assertEquals(0, $task['time_spent']);
- }
-}
diff --git a/tests/units/Model/SwimlaneTest.php b/tests/units/Model/SwimlaneTest.php
index cf0be169..4541e07f 100644
--- a/tests/units/Model/SwimlaneTest.php
+++ b/tests/units/Model/SwimlaneTest.php
@@ -40,7 +40,17 @@ class SwimlaneTest extends Base
$this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #2')));
$swimlane = $swimlaneModel->getFirstActiveSwimlane(1);
+ $this->assertEquals(0, $swimlane['id']);
+ $this->assertEquals('Default swimlane', $swimlane['name']);
+
+ $this->assertTrue($swimlaneModel->disableDefault(1));
+
+ $swimlane = $swimlaneModel->getFirstActiveSwimlane(1);
$this->assertEquals(2, $swimlane['id']);
+ $this->assertEquals('Swimlane #2', $swimlane['name']);
+
+ $this->assertTrue($swimlaneModel->disable(1, 2));
+ $this->assertNull($swimlaneModel->getFirstActiveSwimlane(1));
}
public function testGetList()
diff --git a/tests/units/Model/TagDuplicationModelTest.php b/tests/units/Model/TagDuplicationModelTest.php
new file mode 100644
index 00000000..0c95c0fd
--- /dev/null
+++ b/tests/units/Model/TagDuplicationModelTest.php
@@ -0,0 +1,31 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TagDuplicationModel;
+use Kanboard\Model\TagModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TagDuplicationModelTest extends Base
+{
+ public function testProjectDuplication()
+ {
+ $tagModel = new TagModel($this->container);
+ $tagDuplicationModel = new TagDuplicationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'P2')));
+
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+ $this->assertEquals(2, $tagModel->create(1, 'Tag 2'));
+ $this->assertEquals(3, $tagModel->create(1, 'Tag 3'));
+
+ $this->assertTrue($tagDuplicationModel->duplicate(1, 2));
+
+ $tags = $tagModel->getAllByProject(2);
+ $this->assertCount(2, $tags);
+ $this->assertEquals('Tag 2', $tags[0]['name']);
+ $this->assertEquals('Tag 3', $tags[1]['name']);
+ }
+}
diff --git a/tests/units/Model/TagModelTest.php b/tests/units/Model/TagModelTest.php
new file mode 100644
index 00000000..f090ab4a
--- /dev/null
+++ b/tests/units/Model/TagModelTest.php
@@ -0,0 +1,120 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TagModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TagModelTest extends Base
+{
+ public function testCreation()
+ {
+ $tagModel = new TagModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+ $this->assertEquals(2, $tagModel->create(1, 'Tag 1'));
+ $this->assertEquals(3, $tagModel->create(1, 'Tag 2'));
+ $this->assertFalse($tagModel->create(0, 'Tag 1'));
+ $this->assertFalse($tagModel->create(1, 'Tag 2'));
+ }
+
+ public function testGetById()
+ {
+ $tagModel = new TagModel($this->container);
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+
+ $tag = $tagModel->getById(1);
+ $this->assertEquals(0, $tag['project_id']);
+ $this->assertEquals('Tag 1', $tag['name']);
+
+ $tag = $tagModel->getById(3);
+ $this->assertEmpty($tag);
+ }
+
+ public function testGetAll()
+ {
+ $tagModel = new TagModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+ $this->assertEquals(2, $tagModel->create(1, 'Tag 2'));
+
+ $tags = $tagModel->getAll();
+ $this->assertCount(2, $tags);
+ $this->assertEquals(0, $tags[0]['project_id']);
+ $this->assertEquals('Tag 1', $tags[0]['name']);
+
+ $this->assertEquals(1, $tags[1]['project_id']);
+ $this->assertEquals('Tag 2', $tags[1]['name']);
+ }
+
+ public function testGetAllByProjectId()
+ {
+ $tagModel = new TagModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+ $this->assertEquals(2, $tagModel->create(1, 'B'));
+ $this->assertEquals(3, $tagModel->create(1, 'A'));
+
+ $tags = $tagModel->getAllByProject(1);
+ $this->assertCount(2, $tags);
+ $this->assertEquals(1, $tags[0]['project_id']);
+ $this->assertEquals('A', $tags[0]['name']);
+
+ $this->assertEquals(1, $tags[1]['project_id']);
+ $this->assertEquals('B', $tags[1]['name']);
+ }
+
+ public function testGetIdByName()
+ {
+ $tagModel = new TagModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+ $this->assertEquals(2, $tagModel->create(1, 'Tag 1'));
+ $this->assertEquals(3, $tagModel->create(1, 'Tag 3'));
+
+ $this->assertEquals(1, $tagModel->getIdByName(1, 'tag 1'));
+ $this->assertEquals(1, $tagModel->getIdByName(0, 'tag 1'));
+ $this->assertEquals(3, $tagModel->getIdByName(1, 'TaG 3'));
+ }
+
+ public function testFindOrCreateTag()
+ {
+ $tagModel = new TagModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+
+ $this->assertEquals(2, $tagModel->findOrCreateTag(1, 'Tag 2'));
+ $this->assertEquals(2, $tagModel->findOrCreateTag(1, 'Tag 2'));
+ $this->assertEquals(1, $tagModel->findOrCreateTag(1, 'Tag 1'));
+ }
+
+ public function testRemove()
+ {
+ $tagModel = new TagModel($this->container);
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+
+ $this->assertTrue($tagModel->remove(1));
+ $this->assertFalse($tagModel->remove(1));
+ }
+
+ public function testUpdate()
+ {
+ $tagModel = new TagModel($this->container);
+ $this->assertEquals(1, $tagModel->create(0, 'Tag 1'));
+ $this->assertTrue($tagModel->update(1, 'Tag Updated'));
+
+ $tag = $tagModel->getById(1);
+ $this->assertEquals(0, $tag['project_id']);
+ $this->assertEquals('Tag Updated', $tag['name']);
+ }
+}
diff --git a/tests/units/Model/TaskCreationModelTest.php b/tests/units/Model/TaskCreationModelTest.php
new file mode 100644
index 00000000..ce9996d9
--- /dev/null
+++ b/tests/units/Model/TaskCreationModelTest.php
@@ -0,0 +1,403 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\ConfigModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+
+class TaskCreationModelTest extends Base
+{
+ public function onCreate($event)
+ {
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals('test', $event_data['task']['title']);
+ }
+
+ public function testNoTitle()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {});
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {});
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('Untitled', $task['title']);
+ $this->assertEquals(1, $task['project_id']);
+ }
+
+ public function testMinimum()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $finderModel = new TaskFinderModel($this->container);
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {});
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, array($this, 'onCreate'));
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.TaskCreationModelTest::onCreate', $called);
+
+ $task = $finderModel->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'], 'Wrong 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()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'color_id' => 'blue')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('blue', $task['color_id']);
+ }
+
+ public function testOwnerId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['owner_id']);
+ }
+
+ public function testCategoryId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'category_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['category_id']);
+ }
+
+ public function testCreatorId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'creator_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['creator_id']);
+ }
+
+ public function testThatCreatorIsDefined()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1, $task['creator_id']);
+ }
+
+ public function testColumnId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ }
+
+ public function testPosition()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => 2)));
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(2, $task['column_id']);
+ $this->assertEquals(2, $task['position']);
+ }
+
+ public function testDescription()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'description' => 'test')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('test', $task['description']);
+ }
+
+ public function testReference()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'reference' => 'test')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals('test', $task['reference']);
+ }
+
+ public function testDateDue()
+ {
+ $date = '2014-11-23';
+ $timestamp = strtotime('+2days');
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_due' => $date)));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_due' => $timestamp)));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_due' => '')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals($date, date('Y-m-d', $task['date_due']));
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(date('Y-m-d 00:00', $timestamp), date('Y-m-d 00:00', $task['date_due']));
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertEquals(3, $task['id']);
+ $this->assertEquals(0, $task['date_due']);
+ }
+
+ public function testDateStarted()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+
+ // Set only a date
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('2014-11-24 '.date('H:i'), date('Y-m-d H:i', $task['date_started']));
+
+ // Set a datetime
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24 16:25')));
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertEquals('2014-11-24 16:25', date('Y-m-d H:i', $task['date_started']));
+
+ // Set a datetime
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '11/24/2014 18:25')));
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertEquals('2014-11-24 18:25', date('Y-m-d H:i', $task['date_started']));
+
+ // Set a timestamp
+ $this->assertEquals(4, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_started' => time())));
+
+ $task = $taskFinderModel->getById(4);
+ $this->assertEquals(time(), $task['date_started'], '', 1);
+
+ // Set empty string
+ $this->assertEquals(5, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '')));
+ $task = $taskFinderModel->getById(5);
+ $this->assertEquals(0, $task['date_started']);
+ }
+
+ public function testTime()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.5, 'time_spent' => 2.3)));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => '', 'time_spent' => '')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(1.5, $task['time_estimated']);
+ $this->assertEquals(2.3, $task['time_spent']);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(0, $task['time_estimated']);
+ $this->assertEquals(0, $task['time_spent']);
+ }
+
+ public function testStripColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'another_task' => '1')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ }
+
+ public function testScore()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'score' => '3')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertNotFalse($task);
+ $this->assertEquals(3, $task['score']);
+ }
+
+ public function testDefaultColor()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $configModel = new ConfigModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('yellow', $task['color_id']);
+
+ $this->assertTrue($configModel->save(array('default_color' => 'orange')));
+ $this->container['memoryCache']->flush();
+
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('orange', $task['color_id']);
+ }
+
+ public function testDueDateYear2038TimestampBug()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_due' => strtotime('2050-01-10 12:30'))));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('2050-01-10 00:00', date('Y-m-d H:i', $task['date_due']));
+ }
+}
diff --git a/tests/units/Model/TaskCreationTest.php b/tests/units/Model/TaskCreationTest.php
deleted file mode 100644
index b249bc0b..00000000
--- a/tests/units/Model/TaskCreationTest.php
+++ /dev/null
@@ -1,414 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\ConfigModel;
-use Kanboard\Model\TaskModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\ProjectModel;
-
-class TaskCreationTest extends Base
-{
- public function onCreate($event)
- {
- $this->assertInstanceOf('Kanboard\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 ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {});
- $this->container['dispatcher']->addListener(TaskModel::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(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
- $this->assertArrayNotHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
- }
-
- public function testNoTitle()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {});
- $this->container['dispatcher']->addListener(TaskModel::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(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
- $this->assertArrayHasKey(TaskModel::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 ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {});
- $this->container['dispatcher']->addListener(TaskModel::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(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
- $this->assertArrayHasKey(TaskModel::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'], 'Wrong 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 ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($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->assertEquals(1, $task['id']);
- $this->assertEquals('blue', $task['color_id']);
- }
-
- public function testOwnerId()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($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->assertEquals(1, $task['id']);
- $this->assertEquals(1, $task['owner_id']);
- }
-
- public function testCategoryId()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($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->assertEquals(1, $task['id']);
- $this->assertEquals(1, $task['category_id']);
- }
-
- public function testCreatorId()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($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->assertEquals(1, $task['id']);
- $this->assertEquals(1, $task['creator_id']);
- }
-
- public function testThatCreatorIsDefined()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $this->container['sessionStorage']->user = array('id' => 1);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
-
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(1, $task['creator_id']);
- }
-
- public function testColumnId()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($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->assertEquals(1, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- }
-
- public function testPosition()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($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->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->assertEquals(2, $task['id']);
- $this->assertEquals(2, $task['column_id']);
- $this->assertEquals(2, $task['position']);
- }
-
- public function testDescription()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($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->assertEquals(1, $task['id']);
- $this->assertEquals('test', $task['description']);
- }
-
- public function testReference()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($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->assertEquals(1, $task['id']);
- $this->assertEquals('test', $task['reference']);
- }
-
- public function testDateDue()
- {
- $date = '2014-11-23';
- $timestamp = strtotime('+2days');
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($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)));
- $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => '')));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals($date, date('Y-m-d', $task['date_due']));
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(2, $task['id']);
- $this->assertEquals(date('Y-m-d 00:00', $timestamp), date('Y-m-d 00:00', $task['date_due']));
-
- $task = $tf->getById(3);
- $this->assertEquals(3, $task['id']);
- $this->assertEquals(0, $task['date_due']);
- }
-
- public function testDateStarted()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
-
- // Set only a date
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24')));
-
- $task = $tf->getById(1);
- $this->assertEquals('2014-11-24 '.date('H:i'), date('Y-m-d H:i', $task['date_started']));
-
- // Set a datetime
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24 16:25')));
-
- $task = $tf->getById(2);
- $this->assertEquals('2014-11-24 16:25', date('Y-m-d H:i', $task['date_started']));
-
- // Set a datetime
- $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '11/24/2014 18:25')));
-
- $task = $tf->getById(3);
- $this->assertEquals('2014-11-24 18:25', date('Y-m-d H:i', $task['date_started']));
-
- // Set a timestamp
- $this->assertEquals(4, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => time())));
-
- $task = $tf->getById(4);
- $this->assertEquals(time(), $task['date_started'], '', 1);
-
- // Set empty string
- $this->assertEquals(5, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '')));
- $task = $tf->getById(5);
- $this->assertEquals(0, $task['date_started']);
- }
-
- public function testTime()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($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->assertEquals(1, $task['id']);
- $this->assertEquals(1.5, $task['time_estimated']);
- $this->assertEquals(2.3, $task['time_spent']);
- }
-
- public function testStripColumn()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($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);
- }
-
- public function testScore()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($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']);
- }
-
- public function testDefaultColor()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $c = new ConfigModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test1')));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals('yellow', $task['color_id']);
-
- $this->assertTrue($c->save(array('default_color' => 'orange')));
- $this->container['memoryCache']->flush();
-
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test2')));
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals('orange', $task['color_id']);
- }
-
- public function testDueDateYear2038TimestampBug()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_due' => strtotime('2050-01-10 12:30'))));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals('2050-01-10 00:00', date('Y-m-d H:i', $task['date_due']));
- }
-}
diff --git a/tests/units/Model/TaskDuplicationModelTest.php b/tests/units/Model/TaskDuplicationModelTest.php
new file mode 100644
index 00000000..1c42b6a1
--- /dev/null
+++ b/tests/units/Model/TaskDuplicationModelTest.php
@@ -0,0 +1,142 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskDuplicationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\CategoryModel;
+use Kanboard\Model\TaskTagModel;
+
+class TaskDuplicationModelTest extends Base
+{
+ public function testThatDuplicateDefineCreator()
+ {
+ $taskDuplicationModel = new TaskDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['project_id']);
+ $this->assertEquals(0, $task['creator_id']);
+
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ // We duplicate our task
+ $this->assertEquals(2, $taskDuplicationModel->duplicate(1));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['creator_id']);
+ }
+
+ public function testDuplicateSameProject()
+ {
+ $taskDuplicationModel = new TaskDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+
+ // We create a task and a project
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+
+ // Some categories
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #2', 'project_id' => 1)));
+ $this->assertTrue($categoryModel->exists(1));
+ $this->assertTrue($categoryModel->exists(2));
+
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'column_id' => 3,
+ 'owner_id' => 1,
+ 'category_id' => 2,
+ 'time_spent' => 4.4
+ )));
+
+ $task = $taskFinderModel->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(TaskModel::EVENT_CREATE_UPDATE, function () {});
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {});
+
+ // We duplicate our task
+ $this->assertEquals(2, $taskDuplicationModel->duplicate(1));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(TaskModel::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 testDuplicateSameProjectWithTags()
+ {
+ $taskDuplicationModel = new TaskDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'tags' => array('T1', 'T2')
+ )));
+
+ $this->assertEquals(2, $taskDuplicationModel->duplicate(1));
+
+ $tags = $taskTagModel->getList(2);
+ $this->assertCount(2, $tags);
+ $this->assertArrayHasKey(1, $tags);
+ $this->assertArrayHasKey(2, $tags);
+ }
+
+ public function testDuplicateSameProjectWithPriority()
+ {
+ $taskDuplicationModel = new TaskDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'priority' => 2
+ )));
+
+ $this->assertEquals(2, $taskDuplicationModel->duplicate(1));
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['priority']);
+ }
+}
diff --git a/tests/units/Model/TaskDuplicationTest.php b/tests/units/Model/TaskDuplicationTest.php
deleted file mode 100644
index 79b75e54..00000000
--- a/tests/units/Model/TaskDuplicationTest.php
+++ /dev/null
@@ -1,700 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Core\DateParser;
-use Kanboard\Model\TaskModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\TaskDuplicationModel;
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\ProjectModel;
-use Kanboard\Model\ProjectUserRoleModel;
-use Kanboard\Model\CategoryModel;
-use Kanboard\Model\UserModel;
-use Kanboard\Model\SwimlaneModel;
-use Kanboard\Core\Security\Role;
-
-class TaskDuplicationTest extends Base
-{
- public function testThatDuplicateDefineCreator()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(1, $task['project_id']);
- $this->assertEquals(0, $task['creator_id']);
-
- $this->container['sessionStorage']->user = array('id' => 1);
-
- // We duplicate our task
- $this->assertEquals(2, $td->duplicate(1));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['creator_id']);
- }
-
- public function testDuplicateSameProject()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($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));
- $this->assertTrue($c->exists(2));
-
- $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(TaskModel::EVENT_CREATE_UPDATE, function () {});
- $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {});
-
- // We duplicate our task
- $this->assertEquals(2, $td->duplicate(1));
-
- $called = $this->container['dispatcher']->getCalledListeners();
- $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
- $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(TaskModel::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 TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($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));
-
- // 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(TaskModel::EVENT_CREATE_UPDATE, function () {});
- $this->container['dispatcher']->addListener(TaskModel::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(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
- $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
-
- // 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(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testDuplicateAnotherProjectWithCategory()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($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));
- $this->assertTrue($c->exists(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(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testDuplicateAnotherProjectWithPredefinedCategory()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($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->assertNotFalse($c->create(array('name' => 'Category #2', 'project_id' => 2)));
- $this->assertTrue($c->exists(1));
- $this->assertTrue($c->exists(2));
- $this->assertTrue($c->exists(3));
-
- // 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 with no category
- $this->assertEquals(2, $td->duplicateToProject(1, 2, null, null, 0));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['category_id']);
-
- // We duplicate our task to the 2nd project with a different category
- $this->assertEquals(3, $td->duplicateToProject(1, 2, null, null, 3));
-
- // Check the values of the duplicated task
- $task = $tf->getById(3);
- $this->assertNotEmpty($task);
- $this->assertEquals(3, $task['category_id']);
- }
-
- public function testDuplicateAnotherProjectWithSwimlane()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $s = new SwimlaneModel($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(array('project_id' => 1, 'name' => 'Swimlane #1')));
- $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => '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(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testDuplicateAnotherProjectWithoutSwimlane()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $s = new SwimlaneModel($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(array('project_id' => 1, 'name' => 'Swimlane #1')));
- $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => '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(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testDuplicateAnotherProjectWithPredefinedSwimlane()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $s = new SwimlaneModel($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(array('project_id' => 1, 'name' => 'Swimlane #1')));
- $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
- $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => '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, 3));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(3, $task['swimlane_id']);
- }
-
- public function testDuplicateAnotherProjectWithPredefinedColumn()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($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)));
-
- // We duplicate our task to the 2nd project with a different column
- $this->assertEquals(2, $td->duplicateToProject(1, 2, null, 7));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(7, $task['column_id']);
- }
-
- public function testDuplicateAnotherProjectWithUser()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $pp = new ProjectUserRoleModel($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(6, $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 UserModel($this->container);
- $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
- $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
- $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER));
-
- // 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(6, $task['column_id']);
- $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(1, $task['position']);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals(5, $task['column_id']);
- }
-
- public function testDuplicateAnotherProjectWithPredefinedUser()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $pr = new ProjectUserRoleModel($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)));
- $this->assertTrue($pr->addUser(2, 1, Role::PROJECT_MEMBER));
-
- // We duplicate our task to the 2nd project
- $this->assertEquals(2, $td->duplicateToProject(1, 2, null, null, null, 1));
-
- // Check the values of the duplicated task
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['owner_id']);
- }
-
- public function onMoveProject($event)
- {
- $this->assertInstanceOf('Kanboard\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 TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $user = new UserModel($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(TaskModel::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(TaskModel::EVENT_MOVE_PROJECT.'.TaskDuplicationTest::onMoveProject', $called);
-
- // 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(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 TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $c = new CategoryModel($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));
- $this->assertTrue($c->exists(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(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testMoveAnotherProjectWithUser()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $pp = new ProjectUserRoleModel($this->container);
- $user = new UserModel($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->addUser(1, 2, Role::PROJECT_MEMBER));
- $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER));
-
- // 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(6, $task['column_id']);
- }
-
- public function testMoveAnotherProjectWithForbiddenUser()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $pp = new ProjectUserRoleModel($this->container);
- $user = new UserModel($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->addUser(1, 2, Role::PROJECT_MEMBER));
- $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER));
-
- // 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(6, $task['column_id']);
- }
-
- public function testMoveAnotherProjectWithSwimlane()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $s = new SwimlaneModel($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(array('project_id' => 1, 'name' => 'Swimlane #1')));
- $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => '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(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testMoveAnotherProjectWithoutSwimlane()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $s = new SwimlaneModel($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(array('project_id' => 1, 'name' => 'Swimlane #1')));
- $this->assertNotFalse($s->create(array('project_id' => 2, 'name' => '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(6, $task['column_id']);
- $this->assertEquals(1, $task['position']);
- $this->assertEquals(2, $task['project_id']);
- $this->assertEquals('test', $task['title']);
- }
-
- public function testCalculateRecurringTaskDueDate()
- {
- $td = new TaskDuplicationModel($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' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
- $td->calculateRecurringTaskDueDate($values);
- $this->assertEquals(0, $values['date_due']);
-
- $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
- $td->calculateRecurringTaskDueDate($values);
- $this->assertEquals(time() + 86400, $values['date_due'], '', 1);
-
- $values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::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' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
- $td->calculateRecurringTaskDueDate($values);
- $this->assertEquals(1431291376 + 86400, $values['date_due'], '', 1);
-
- $values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
- $td->calculateRecurringTaskDueDate($values);
- $this->assertEquals(1431291376 - 86400, $values['date_due'], '', 1);
-
- $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_MONTHS);
- $td->calculateRecurringTaskDueDate($values);
- $this->assertEquals(1436561776, $values['date_due'], '', 1);
-
- $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_YEARS);
- $td->calculateRecurringTaskDueDate($values);
- $this->assertEquals(1494449776, $values['date_due'], '', 1);
- }
-
- public function testDuplicateRecurringTask()
- {
- $td = new TaskDuplicationModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $dp = new DateParser($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' => TaskModel::RECURRING_STATUS_PENDING,
- 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE,
- 'recurrence_factor' => 2,
- 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS,
- 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE,
- )));
-
- $this->assertEquals(2, $td->duplicateRecurringTask(1));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(TaskModel::RECURRING_STATUS_PROCESSED, $task['recurrence_status']);
- $this->assertEquals(2, $task['recurrence_child']);
- $this->assertEquals(1436486400, $task['date_due'], '', 2);
-
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(TaskModel::RECURRING_STATUS_PENDING, $task['recurrence_status']);
- $this->assertEquals(TaskModel::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']);
- $this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']);
- $this->assertEquals(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']);
- $this->assertEquals(1, $task['recurrence_parent']);
- $this->assertEquals(2, $task['recurrence_factor']);
- $this->assertEquals($dp->removeTimeFromTimestamp(strtotime('+2 days')), $task['date_due'], '', 2);
- }
-}
diff --git a/tests/units/Model/TaskFileTest.php b/tests/units/Model/TaskFileModelTest.php
index 2faee95c..de12553f 100644
--- a/tests/units/Model/TaskFileTest.php
+++ b/tests/units/Model/TaskFileModelTest.php
@@ -6,7 +6,7 @@ use Kanboard\Model\TaskFileModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
-class TaskFileTest extends Base
+class TaskFileModelTest extends Base
{
public function testCreation()
{
@@ -442,4 +442,17 @@ class TaskFileTest extends Base
$this->assertTrue($fileModel->removeAll(1));
}
+
+ public function testGetProjectId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $fileModel = new TaskFileModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foobar', 10));
+ $this->assertEquals(1, $fileModel->getProjectId(1));
+ $this->assertEquals(0, $fileModel->getProjectId(2));
+ }
}
diff --git a/tests/units/Model/TaskFinderModelTest.php b/tests/units/Model/TaskFinderModelTest.php
new file mode 100644
index 00000000..b2e2bd84
--- /dev/null
+++ b/tests/units/Model/TaskFinderModelTest.php
@@ -0,0 +1,142 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\ColumnModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+
+class TaskFinderModelTest extends Base
+{
+ public function testGetTasksForDashboardWithHiddenColumn()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $columnModel = new ColumnModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+
+ $tasks = $taskFinderModel->getUserQuery(1)->findAll();
+ $this->assertCount(2, $tasks);
+
+ $this->assertTrue($columnModel->update(2, 'Test', 0, '', 1));
+
+ $tasks = $taskFinderModel->getUserQuery(1)->findAll();
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Task #1', $tasks[0]['title']);
+
+ $this->assertTrue($columnModel->update(2, 'Test', 0, '', 0));
+
+ $tasks = $taskFinderModel->getUserQuery(1)->findAll();
+ $this->assertCount(2, $tasks);
+ }
+
+ public function testGetOverdueTasks()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => 0)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1)));
+
+ $tasks = $taskFinderModel->getOverdueTasks();
+ $this->assertNotEmpty($tasks);
+ $this->assertTrue(is_array($tasks));
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Task #1', $tasks[0]['title']);
+ }
+
+ public function testGetOverdueTasksByProject()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0)));
+ $this->assertEquals(5, $taskCreationModel->create(array('title' => 'Task #5', 'project_id' => 1)));
+
+ $tasks = $taskFinderModel->getOverdueTasksByProject(1);
+ $this->assertNotEmpty($tasks);
+ $this->assertTrue(is_array($tasks));
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('Task #1', $tasks[0]['title']);
+ }
+
+ public function testGetOverdueTasksByUser()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0)));
+ $this->assertEquals(5, $taskCreationModel->create(array('title' => 'Task #5', 'project_id' => 1)));
+
+ $tasks = $taskFinderModel->getOverdueTasksByUser(1);
+ $this->assertNotEmpty($tasks);
+ $this->assertTrue(is_array($tasks));
+ $this->assertCount(2, $tasks);
+
+ $this->assertEquals(1, $tasks[0]['id']);
+ $this->assertEquals('Task #1', $tasks[0]['title']);
+ $this->assertEquals(1, $tasks[0]['owner_id']);
+ $this->assertEquals(1, $tasks[0]['project_id']);
+ $this->assertEquals('Project #1', $tasks[0]['project_name']);
+ $this->assertEquals('admin', $tasks[0]['assignee_username']);
+ $this->assertEquals('', $tasks[0]['assignee_name']);
+
+ $this->assertEquals('Task #2', $tasks[1]['title']);
+ }
+
+ public function testCountByProject()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 2)));
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(2));
+ }
+
+ public function testGetProjectToken()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2')));
+
+ $this->assertTrue($projectModel->enablePublicAccess(1));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2)));
+
+ $project = $projectModel->getById(1);
+ $this->assertEquals($project['token'], $taskFinderModel->getProjectToken(1));
+ $this->assertEmpty($taskFinderModel->getProjectToken(2));
+ }
+}
diff --git a/tests/units/Model/TaskFinderTest.php b/tests/units/Model/TaskFinderTest.php
deleted file mode 100644
index 46792baf..00000000
--- a/tests/units/Model/TaskFinderTest.php
+++ /dev/null
@@ -1,115 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\ProjectModel;
-
-class TaskFinderTest extends Base
-{
- public function testGetOverdueTasks()
- {
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #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);
- $this->assertTrue(is_array($tasks));
- $this->assertCount(1, $tasks);
- $this->assertEquals('Task #1', $tasks[0]['title']);
- }
-
- public function testGetOverdueTasksByProject()
- {
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(2, $p->create(array('name' => 'Project #2')));
- $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' => 2, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0)));
- $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1)));
-
- $tasks = $tf->getOverdueTasksByProject(1);
- $this->assertNotEmpty($tasks);
- $this->assertTrue(is_array($tasks));
- $this->assertCount(1, $tasks);
- $this->assertEquals('Task #1', $tasks[0]['title']);
- }
-
- public function testGetOverdueTasksByUser()
- {
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(2, $p->create(array('name' => 'Project #2')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 2, 'owner_id' => 1, 'date_due' => strtotime('-1 day'))));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'date_due' => strtotime('+1 day'))));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'date_due' => 0)));
- $this->assertEquals(5, $tc->create(array('title' => 'Task #5', 'project_id' => 1)));
-
- $tasks = $tf->getOverdueTasksByUser(1);
- $this->assertNotEmpty($tasks);
- $this->assertTrue(is_array($tasks));
- $this->assertCount(2, $tasks);
-
- $this->assertEquals(1, $tasks[0]['id']);
- $this->assertEquals('Task #1', $tasks[0]['title']);
- $this->assertEquals(1, $tasks[0]['owner_id']);
- $this->assertEquals(1, $tasks[0]['project_id']);
- $this->assertEquals('Project #1', $tasks[0]['project_name']);
- $this->assertEquals('admin', $tasks[0]['assignee_username']);
- $this->assertEquals('', $tasks[0]['assignee_name']);
-
- $this->assertEquals('Task #2', $tasks[1]['title']);
- }
-
- public function testCountByProject()
- {
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(2, $p->create(array('name' => 'Project #2')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 2)));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 2)));
-
- $this->assertEquals(1, $tf->countByProjectId(1));
- $this->assertEquals(2, $tf->countByProjectId(2));
- }
-
- public function testGetProjectToken()
- {
- $taskCreationModel = new TaskCreationModel($this->container);
- $taskFinderModel = new TaskFinderModel($this->container);
- $projectModel = new ProjectModel($this->container);
-
- $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
- $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2')));
-
- $this->assertTrue($projectModel->enablePublicAccess(1));
-
- $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
- $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 2)));
-
- $project = $projectModel->getById(1);
- $this->assertEquals($project['token'], $taskFinderModel->getProjectToken(1));
- $this->assertEmpty($taskFinderModel->getProjectToken(2));
- }
-}
diff --git a/tests/units/Model/TaskLinkModelTest.php b/tests/units/Model/TaskLinkModelTest.php
new file mode 100644
index 00000000..01a7888b
--- /dev/null
+++ b/tests/units/Model/TaskLinkModelTest.php
@@ -0,0 +1,239 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskLinkModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\ProjectModel;
+
+class TaskLinkModelTest extends Base
+{
+ public function testGeyById()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 6));
+
+ $taskLink = $taskLinkModel->getById(1);
+ $this->assertEquals(1, $taskLink['id']);
+ $this->assertEquals(1, $taskLink['task_id']);
+ $this->assertEquals(2, $taskLink['opposite_task_id']);
+ $this->assertEquals(6, $taskLink['link_id']);
+ $this->assertEquals(7, $taskLink['opposite_link_id']);
+ $this->assertEquals('is a child of', $taskLink['label']);
+
+ $taskLink = $taskLinkModel->getById(2);
+ $this->assertEquals(2, $taskLink['id']);
+ $this->assertEquals(2, $taskLink['task_id']);
+ $this->assertEquals(1, $taskLink['opposite_task_id']);
+ $this->assertEquals(7, $taskLink['link_id']);
+ $this->assertEquals(6, $taskLink['opposite_link_id']);
+ $this->assertEquals('is a parent of', $taskLink['label']);
+ }
+
+ // Check postgres issue: "Cardinality violation: 7 ERROR: more than one row returned by a subquery used as an expression"
+ public function testGetTaskWithMultipleMilestoneLink()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C')));
+
+ $this->assertNotFalse($taskLinkModel->create(1, 2, 9));
+ $this->assertNotFalse($taskLinkModel->create(1, 3, 9));
+
+ $task = $taskFinderModel->getExtendedQuery()->findOne();
+ $this->assertNotEmpty($task);
+ }
+
+ public function testCreateTaskLinkWithNoOpposite()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $links = $taskLinkModel->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 = $taskLinkModel->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 = $taskLinkModel->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 = $taskLinkModel->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()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
+
+ $links = $taskLinkModel->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 = $taskLinkModel->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 = $taskLinkModel->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 = $taskLinkModel->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 testGroupByLabel()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C')));
+
+ $this->assertNotFalse($taskLinkModel->create(1, 2, 2));
+ $this->assertNotFalse($taskLinkModel->create(1, 3, 2));
+
+ $links = $taskLinkModel->getAllGroupedByLabel(1);
+ $this->assertCount(1, $links);
+ $this->assertArrayHasKey('blocks', $links);
+ $this->assertCount(2, $links['blocks']);
+ $this->assertEquals('test', $links['blocks'][0]['project_name']);
+ $this->assertEquals('Backlog', $links['blocks'][0]['column_title']);
+ $this->assertEquals('blocks', $links['blocks'][0]['label']);
+ }
+
+ public function testUpdate()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 2, 'title' => 'B')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C')));
+
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 5));
+ $this->assertTrue($taskLinkModel->update(1, 1, 3, 11));
+
+ $links = $taskLinkModel->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 = $taskLinkModel->getAll(2);
+ $this->assertEmpty($links);
+
+ $links = $taskLinkModel->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()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
+
+ $links = $taskLinkModel->getAll(1);
+ $this->assertNotEmpty($links);
+ $links = $taskLinkModel->getAll(2);
+ $this->assertNotEmpty($links);
+
+ $this->assertTrue($taskLinkModel->remove($links[0]['id']));
+
+ $links = $taskLinkModel->getAll(1);
+ $this->assertEmpty($links);
+ $links = $taskLinkModel->getAll(2);
+ $this->assertEmpty($links);
+ }
+
+ public function testGetProjectId()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
+
+ $this->assertEquals(1, $taskLinkModel->getProjectId(1));
+ $this->assertEquals(0, $taskLinkModel->getProjectId(42));
+ }
+}
diff --git a/tests/units/Model/TaskLinkTest.php b/tests/units/Model/TaskLinkTest.php
deleted file mode 100644
index bc574731..00000000
--- a/tests/units/Model/TaskLinkTest.php
+++ /dev/null
@@ -1,196 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\TaskLinkModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\ProjectModel;
-
-class TaskLinkTest extends Base
-{
- // Check postgres issue: "Cardinality violation: 7 ERROR: more than one row returned by a subquery used as an expression"
- public function testGetTaskWithMultipleMilestoneLink()
- {
- $tf = new TaskFinderModel($this->container);
- $tl = new TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($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(3, $tc->create(array('project_id' => 1, 'title' => 'C')));
-
- $this->assertNotFalse($tl->create(1, 2, 9));
- $this->assertNotFalse($tl->create(1, 3, 9));
-
- $task = $tf->getExtendedQuery()->findOne();
- $this->assertNotEmpty($task);
- }
-
- public function testCreateTaskLinkWithNoOpposite()
- {
- $tl = new TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($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 TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($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 testGroupByLabel()
- {
- $tl = new TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($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(3, $tc->create(array('project_id' => 1, 'title' => 'C')));
-
- $this->assertNotFalse($tl->create(1, 2, 2));
- $this->assertNotFalse($tl->create(1, 3, 2));
-
- $links = $tl->getAllGroupedByLabel(1);
- $this->assertCount(1, $links);
- $this->assertArrayHasKey('blocks', $links);
- $this->assertCount(2, $links['blocks']);
- $this->assertEquals('test', $links['blocks'][0]['project_name']);
- $this->assertEquals('Backlog', $links['blocks'][0]['column_title']);
- $this->assertEquals('blocks', $links['blocks'][0]['label']);
- }
-
- public function testUpdate()
- {
- $tl = new TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($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 TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($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);
- }
-}
diff --git a/tests/units/Model/TaskModelTest.php b/tests/units/Model/TaskModelTest.php
new file mode 100644
index 00000000..e42b5ae6
--- /dev/null
+++ b/tests/units/Model/TaskModelTest.php
@@ -0,0 +1,30 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\ProjectModel;
+
+class TaskModelTest extends Base
+{
+ public function testRemove()
+ {
+ $taskModel = new TaskModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
+
+ $this->assertTrue($taskModel->remove(1));
+ $this->assertFalse($taskModel->remove(1234));
+ }
+
+ public function testGetTaskIdFromText()
+ {
+ $taskModel = new TaskModel($this->container);
+ $this->assertEquals(123, $taskModel->getTaskIdFromText('My task #123'));
+ $this->assertEquals(0, $taskModel->getTaskIdFromText('My task 123'));
+ }
+}
diff --git a/tests/units/Model/TaskModificationModelTest.php b/tests/units/Model/TaskModificationModelTest.php
new file mode 100644
index 00000000..f70561b3
--- /dev/null
+++ b/tests/units/Model/TaskModificationModelTest.php
@@ -0,0 +1,323 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModificationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskTagModel;
+
+class TaskModificationModelTest extends Base
+{
+ public function onCreateUpdate($event)
+ {
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals('After', $event_data['task']['title']);
+ $this->assertEquals('After', $event_data['changes']['title']);
+ }
+
+ public function onUpdate($event)
+ {
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals('After', $event_data['task']['title']);
+ }
+
+ public function onAssigneeChange($event)
+ {
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals(1, $event_data['changes']['owner_id']);
+ }
+
+ public function testThatNoEventAreFiredWhenNoChanges()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate'));
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, array($this, 'onUpdate'));
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'title' => 'test')));
+
+ $this->assertEmpty($this->container['dispatcher']->getCalledListeners());
+ }
+
+ public function testChangeTitle()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Before', 'project_id' => 1)));
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate'));
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, array($this, 'onUpdate'));
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'title' => 'After')));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.TaskModificationModelTest::onCreateUpdate', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_UPDATE.'.TaskModificationModelTest::onUpdate', $called);
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('After', $task['title']);
+ }
+
+ public function testChangeAssignee()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['owner_id']);
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_ASSIGNEE_CHANGE, array($this, 'onAssigneeChange'));
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'owner_id' => 1)));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_ASSIGNEE_CHANGE.'.TaskModificationModelTest::onAssigneeChange', $called);
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['owner_id']);
+ }
+
+ public function testChangeDescription()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('', $task['description']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'description' => 'test')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('test', $task['description']);
+ }
+
+ public function testChangeCategory()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['category_id']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'category_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['category_id']);
+ }
+
+ public function testChangeColor()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('yellow', $task['color_id']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'color_id' => 'blue')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('blue', $task['color_id']);
+ }
+
+ public function testChangeScore()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['score']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'score' => 13)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(13, $task['score']);
+ }
+
+ public function testChangeDueDate()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['date_due']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'date_due' => '2014-11-24')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('2014-11-24', date('Y-m-d', $task['date_due']));
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'date_due' => time())));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(date('Y-m-d'), date('Y-m-d', $task['date_due']));
+ }
+
+ public function testChangeStartedDate()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['date_started']);
+
+ // Set only a date
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'date_started' => '2014-11-24')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('2014-11-24 '.date('H:i'), date('Y-m-d H:i', $task['date_started']));
+
+ // Set a datetime
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'date_started' => '2014-11-24 16:25')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('2014-11-24 16:25', date('Y-m-d H:i', $task['date_started']));
+
+ // Set a datetime
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'date_started' => '11/24/2014 18:25')));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals('2014-11-24 18:25', date('Y-m-d H:i', $task['date_started']));
+
+ // Set a timestamp
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'date_started' => time())));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(time(), $task['date_started'], '', 1);
+ }
+
+ public function testChangeTimeEstimated()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['time_estimated']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'time_estimated' => 13.3)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(13.3, $task['time_estimated']);
+ }
+
+ public function testChangeTimeSpent()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(0, $task['time_spent']);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'time_spent' => 13.3)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(13.3, $task['time_spent']);
+ }
+
+ public function testChangeTags()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'tags' => array('tag1', 'tag2'))));
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'tags' => array('tag2'))));
+
+ $tags = $taskTagModel->getList(1);
+ $this->assertEquals(array(2 => 'tag2'), $tags);
+ }
+
+ public function testRemoveAllTags()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskModificationModel = new TaskModificationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test1', 'project_id' => 1, 'tags' => array('tag1', 'tag2'))));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test2', 'project_id' => 1, 'tags' => array('tag1', 'tag2'))));
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1)));
+ $tags = $taskTagModel->getList(1);
+ $this->assertEquals(array(1 => 'tag1', 2 => 'tag2'), $tags);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 1, 'tags' => array())));
+ $tags = $taskTagModel->getList(1);
+ $this->assertEquals(array(), $tags);
+
+ $this->assertTrue($taskModificationModel->update(array('id' => 2, 'tags' => array(''))));
+ $tags = $taskTagModel->getList(2);
+ $this->assertEquals(array(), $tags);
+ }
+}
diff --git a/tests/units/Model/TaskModificationTest.php b/tests/units/Model/TaskModificationTest.php
deleted file mode 100644
index a8ace25a..00000000
--- a/tests/units/Model/TaskModificationTest.php
+++ /dev/null
@@ -1,283 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\TaskModificationModel;
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\ProjectModel;
-
-class TaskModificationTest extends Base
-{
- public function onCreateUpdate($event)
- {
- $this->assertInstanceOf('Kanboard\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('Kanboard\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('Kanboard\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 testThatNoEventAreFiredWhenNoChanges()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tm = new TaskModificationModel($this->container);
- $tf = new TaskFinderModel($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(TaskModel::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate'));
- $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, array($this, 'onUpdate'));
-
- $this->assertTrue($tm->update(array('id' => 1, 'title' => 'test')));
-
- $this->assertEmpty($this->container['dispatcher']->getCalledListeners());
- }
-
- public function testChangeTitle()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tm = new TaskModificationModel($this->container);
- $tf = new TaskFinderModel($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(TaskModel::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate'));
- $this->container['dispatcher']->addListener(TaskModel::EVENT_UPDATE, array($this, 'onUpdate'));
-
- $this->assertTrue($tm->update(array('id' => 1, 'title' => 'Task #1')));
-
- $called = $this->container['dispatcher']->getCalledListeners();
- $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.TaskModificationTest::onCreateUpdate', $called);
- $this->assertArrayHasKey(TaskModel::EVENT_UPDATE.'.TaskModificationTest::onUpdate', $called);
-
- $task = $tf->getById(1);
- $this->assertEquals('Task #1', $task['title']);
- }
-
- public function testChangeAssignee()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tm = new TaskModificationModel($this->container);
- $tf = new TaskFinderModel($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(TaskModel::EVENT_ASSIGNEE_CHANGE, array($this, 'onAssigneeChange'));
-
- $this->assertTrue($tm->update(array('id' => 1, 'owner_id' => 1)));
-
- $called = $this->container['dispatcher']->getCalledListeners();
- $this->assertArrayHasKey(TaskModel::EVENT_ASSIGNEE_CHANGE.'.TaskModificationTest::onAssigneeChange', $called);
-
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['owner_id']);
- }
-
- public function testChangeDescription()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tm = new TaskModificationModel($this->container);
- $tf = new TaskFinderModel($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 ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tm = new TaskModificationModel($this->container);
- $tf = new TaskFinderModel($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 ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tm = new TaskModificationModel($this->container);
- $tf = new TaskFinderModel($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 ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tm = new TaskModificationModel($this->container);
- $tf = new TaskFinderModel($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 ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tm = new TaskModificationModel($this->container);
- $tf = new TaskFinderModel($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 ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tm = new TaskModificationModel($this->container);
- $tf = new TaskFinderModel($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']);
-
- // Set only a date
- $this->assertTrue($tm->update(array('id' => 1, 'date_started' => '2014-11-24')));
-
- $task = $tf->getById(1);
- $this->assertEquals('2014-11-24 '.date('H:i'), date('Y-m-d H:i', $task['date_started']));
-
- // Set a datetime
- $this->assertTrue($tm->update(array('id' => 1, 'date_started' => '2014-11-24 16:25')));
-
- $task = $tf->getById(1);
- $this->assertEquals('2014-11-24 16:25', date('Y-m-d H:i', $task['date_started']));
-
- // Set a datetime
- $this->assertTrue($tm->update(array('id' => 1, 'date_started' => '11/24/2014 18:25')));
-
- $task = $tf->getById(1);
- $this->assertEquals('2014-11-24 18:25', date('Y-m-d H:i', $task['date_started']));
-
- // Set a timestamp
- $this->assertTrue($tm->update(array('id' => 1, 'date_started' => time())));
-
- $task = $tf->getById(1);
- $this->assertEquals(time(), $task['date_started'], '', 1);
- }
-
- public function testChangeTimeEstimated()
- {
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tm = new TaskModificationModel($this->container);
- $tf = new TaskFinderModel($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 ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tm = new TaskModificationModel($this->container);
- $tf = new TaskFinderModel($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/Model/TaskPositionTest.php b/tests/units/Model/TaskPositionModelTest.php
index 7ab6950e..03caf7ed 100644
--- a/tests/units/Model/TaskPositionTest.php
+++ b/tests/units/Model/TaskPositionModelTest.php
@@ -11,57 +11,57 @@ use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\SwimlaneModel;
-class TaskPositionTest extends Base
+class TaskPositionModelTest extends Base
{
public function testGetTaskProgression()
{
- $t = new TaskModel($this->container);
- $ts = new TaskStatusModel($this->container);
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskModel = new TaskModel($this->container);
+ $taskStatusModel = new TaskStatusModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
$columnModel = new ColumnModel($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(0, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(0, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
- $this->assertTrue($tp->movePosition(1, 1, 2, 1));
- $this->assertEquals(25, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 1));
+ $this->assertEquals(25, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
- $this->assertTrue($tp->movePosition(1, 1, 3, 1));
- $this->assertEquals(50, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 3, 1));
+ $this->assertEquals(50, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
- $this->assertTrue($tp->movePosition(1, 1, 4, 1));
- $this->assertEquals(75, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 4, 1));
+ $this->assertEquals(75, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
- $this->assertTrue($ts->close(1));
- $this->assertEquals(100, $t->getProgress($tf->getById(1), $columnModel->getList(1)));
+ $this->assertTrue($taskStatusModel->close(1));
+ $this->assertEquals(100, $taskModel->getProgress($taskFinderModel->getById(1), $columnModel->getList(1)));
}
public function testMoveTaskToWrongPosition()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $projectModel->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(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
// We move the task 2 to the position 0
- $this->assertFalse($tp->movePosition(1, 1, 3, 0));
+ $this->assertFalse($taskPositionModel->movePosition(1, 1, 3, 0));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
@@ -69,26 +69,26 @@ class TaskPositionTest extends Base
public function testMoveTaskToGreaterPosition()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $projectModel->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(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
// We move the task 2 to the position 42
- $this->assertTrue($tp->movePosition(1, 1, 1, 42));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 42));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -96,26 +96,26 @@ class TaskPositionTest extends Base
public function testMoveTaskToEmptyColumn()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $projectModel->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(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
// We move the task 1 to the column 3
- $this->assertTrue($tp->movePosition(1, 1, 3, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 3, 1));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -123,62 +123,62 @@ class TaskPositionTest extends Base
public function testMoveTaskToAnotherColumn()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($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)));
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(5, $taskCreationModel->create(array('title' => 'Task #5', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(6, $taskCreationModel->create(array('title' => 'Task #6', 'project_id' => 1, 'column_id' => 2)));
+ $this->assertEquals(7, $taskCreationModel->create(array('title' => 'Task #7', 'project_id' => 1, 'column_id' => 3)));
+ $this->assertEquals(8, $taskCreationModel->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));
+ $this->assertTrue($taskPositionModel->movePosition(1, 3, 3, 2));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(5);
+ $task = $taskFinderModel->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(6);
+ $task = $taskFinderModel->getById(6);
$this->assertEquals(6, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $task = $tf->getById(7);
+ $task = $taskFinderModel->getById(7);
$this->assertEquals(7, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(8);
+ $task = $taskFinderModel->getById(8);
$this->assertEquals(8, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
@@ -186,37 +186,37 @@ class TaskPositionTest extends Base
public function testMoveTaskTop()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($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)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $taskCreationModel->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));
+ $this->assertTrue($taskPositionModel->movePosition(1, 4, 1, 1));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(4, $task['position']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -224,37 +224,37 @@ class TaskPositionTest extends Base
public function testMoveTaskBottom()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($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)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
// Move the first task to the bottom
- $this->assertTrue($tp->movePosition(1, 1, 1, 4));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 1, 4));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(4, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(3);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->getById(4);
$this->assertEquals(4, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
@@ -262,12 +262,12 @@ class TaskPositionTest extends Base
public function testMovePosition()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
$counter = 1;
$task_per_column = 5;
@@ -280,240 +280,240 @@ class TaskPositionTest extends Base
'owner_id' => 0,
);
- $this->assertEquals($counter, $tc->create($task));
+ $this->assertEquals($counter, $taskCreationModel->create($task));
- $task = $tf->getById($counter);
+ $task = $taskFinderModel->getById($counter);
$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));
+ $this->assertTrue($taskPositionModel->movePosition(1, 4, 2, 3));
// We check the new position of the task
- $task = $tf->getById(4);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(3, $task['position']);
- $task = $tf->getById(7);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(4, $task['position']);
- $task = $tf->getById(8);
+ $task = $taskFinderModel->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));
+ $this->assertEquals($task_per_column - 1, $taskFinderModel->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column, $taskFinderModel->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column, $taskFinderModel->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));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 4, $task_per_column + 1));
// We check the new position of the task
- $task = $tf->getById(1);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->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));
+ $this->assertEquals($task_per_column - 2, $taskFinderModel->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column, $taskFinderModel->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 4));
// Our previous moved task should stay at the same place
- $task = $tf->getById(4);
+ $task = $taskFinderModel->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));
+ $this->assertFalse($taskPositionModel->movePosition(1, 2, 3, 0));
+ $this->assertFalse($taskPositionModel->movePosition(1, 2, 3, -2));
// Wrong column
- $this->assertFalse($tp->movePosition(1, 2, 22, 2));
+ $this->assertFalse($taskPositionModel->movePosition(1, 2, 22, 2));
// Test position greater than the last position
- $this->assertTrue($tp->movePosition(1, 11, 1, 22));
+ $this->assertTrue($taskPositionModel->movePosition(1, 11, 1, 22));
- $task = $tf->getById(11);
+ $task = $taskFinderModel->getById(11);
$this->assertEquals(11, $task['id']);
$this->assertEquals(1, $task['column_id']);
- $this->assertEquals($tf->countByColumnId(1, 1), $task['position']);
+ $this->assertEquals($taskFinderModel->countByColumnId(1, 1), $task['position']);
- $task = $tf->getById(5);
+ $task = $taskFinderModel->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(1, $task['column_id']);
- $this->assertEquals($tf->countByColumnId(1, 1) - 1, $task['position']);
+ $this->assertEquals($taskFinderModel->countByColumnId(1, 1) - 1, $task['position']);
- $task = $tf->getById(4);
+ $task = $taskFinderModel->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));
+ $this->assertEquals($task_per_column - 1, $taskFinderModel->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column - 1, $taskFinderModel->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 4));
// Our previous moved task should stay at the same place
- $task = $tf->getById(4);
+ $task = $taskFinderModel->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));
+ $this->assertTrue($taskPositionModel->movePosition(1, 14, 1, 1));
- $task = $tf->getById(14);
+ $task = $taskFinderModel->getById(14);
$this->assertEquals(14, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->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));
+ $this->assertEquals($task_per_column, $taskFinderModel->countByColumnId(1, 1));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 2));
+ $this->assertEquals($task_per_column - 2, $taskFinderModel->countByColumnId(1, 3));
+ $this->assertEquals($task_per_column + 1, $taskFinderModel->countByColumnId(1, 4));
}
public function testMoveTaskSwimlane()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $s = new SwimlaneModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => '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)));
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'test 1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(5, $taskCreationModel->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));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 1, 1));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->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));
+ $this->assertTrue($taskPositionModel->movePosition(1, 2, 2, 1, 1));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->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));
+ $this->assertTrue($taskPositionModel->movePosition(1, 5, 4, 1, 0));
// Check tasks position
- $task = $tf->getById(1);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->getById(5);
$this->assertEquals(5, $task['id']);
$this->assertEquals(4, $task['column_id']);
$this->assertEquals(1, $task['position']);
@@ -522,73 +522,73 @@ class TaskPositionTest extends Base
public function testEvents()
{
- $tp = new TaskPositionModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $s = new SwimlaneModel($this->container);
+ $taskPositionModel = new TaskPositionModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'test 1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => '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->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2)));
$this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_COLUMN, array($this, 'onMoveColumn'));
$this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_POSITION, array($this, 'onMovePosition'));
$this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_SWIMLANE, array($this, 'onMoveSwimlane'));
// We move the task 1 to the column 2
- $this->assertTrue($tp->movePosition(1, 1, 2, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 1));
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->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(TaskModel::EVENT_MOVE_COLUMN.'.TaskPositionTest::onMoveColumn', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_COLUMN.'.TaskPositionModelTest::onMoveColumn', $called);
$this->assertEquals(1, count($called));
// We move the task 1 to the position 2
- $this->assertTrue($tp->movePosition(1, 1, 2, 2));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 2, 2));
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
- $task = $tf->getById(2);
+ $task = $taskFinderModel->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(TaskModel::EVENT_MOVE_POSITION.'.TaskPositionTest::onMovePosition', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_POSITION.'.TaskPositionModelTest::onMovePosition', $called);
$this->assertEquals(2, count($called));
// Move to another swimlane
- $this->assertTrue($tp->movePosition(1, 1, 3, 1, 1));
+ $this->assertTrue($taskPositionModel->movePosition(1, 1, 3, 1, 1));
- $task = $tf->getById(1);
+ $task = $taskFinderModel->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);
+ $task = $taskFinderModel->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(TaskModel::EVENT_MOVE_SWIMLANE.'.TaskPositionTest::onMoveSwimlane', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_SWIMLANE.'.TaskPositionModelTest::onMoveSwimlane', $called);
$this->assertEquals(3, count($called));
}
diff --git a/tests/units/Model/TaskProjectDuplicationModelTest.php b/tests/units/Model/TaskProjectDuplicationModelTest.php
new file mode 100644
index 00000000..9ff33bc1
--- /dev/null
+++ b/tests/units/Model/TaskProjectDuplicationModelTest.php
@@ -0,0 +1,377 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Core\Security\Role;
+use Kanboard\Model\CategoryModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectUserRoleModel;
+use Kanboard\Model\SwimlaneModel;
+use Kanboard\Model\TagModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskProjectDuplicationModel;
+use Kanboard\Model\TaskTagModel;
+use Kanboard\Model\UserModel;
+
+class TaskProjectDuplicationModelTest extends Base
+{
+ public function testDuplicateAnotherProject()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertTrue($categoryModel->exists(1));
+
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'column_id' => 2,
+ 'owner_id' => 1,
+ 'category_id' => 1,
+ 'priority' => 3,
+ )));
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE_UPDATE, function () {});
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_CREATE, function () {});
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE_UPDATE.'.closure', $called);
+ $this->assertArrayHasKey(TaskModel::EVENT_CREATE.'.closure', $called);
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->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(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(3, $task['priority']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithCategory()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 2)));
+ $this->assertTrue($categoryModel->exists(1));
+ $this->assertTrue($categoryModel->exists(2));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->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(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithPredefinedCategory()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 2)));
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #2', 'project_id' => 2)));
+ $this->assertTrue($categoryModel->exists(1));
+ $this->assertTrue($categoryModel->exists(2));
+ $this->assertTrue($categoryModel->exists(3));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
+
+ // We duplicate our task to the 2nd project with no category
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, null, 0));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['category_id']);
+
+ // We duplicate our task to the 2nd project with a different category
+ $this->assertEquals(3, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, null, 3));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3, $task['category_id']);
+ }
+
+ public function testDuplicateAnotherProjectWithSwimlane()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->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(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithoutSwimlane()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->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(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testDuplicateAnotherProjectWithPredefinedSwimlane()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, 3));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(3, $task['swimlane_id']);
+ }
+
+ public function testDuplicateAnotherProjectWithPredefinedColumn()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2)));
+
+ // We duplicate our task to the 2nd project with a different column
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, 7));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(7, $task['column_id']);
+ }
+
+ public function testDuplicateAnotherProjectWithUser()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(6, $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 UserModel($this->container);
+ $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(3, $taskProjectDuplicationModel->duplicateToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['position']);
+ $this->assertEquals(6, $task['column_id']);
+ $this->assertEquals(2, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+
+ // We duplicate a task with a not allowed user
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3)));
+ $this->assertEquals(5, $taskProjectDuplicationModel->duplicateToProject(4, 2));
+
+ $task = $taskFinderModel->getById(5);
+ $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 testDuplicateAnotherProjectWithPredefinedUser()
+ {
+ $taskProjectDuplicationModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 1, Role::PROJECT_MEMBER));
+
+ // We duplicate our task to the 2nd project
+ $this->assertEquals(2, $taskProjectDuplicationModel->duplicateToProject(1, 2, null, null, null, 1));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['owner_id']);
+ }
+
+ public function testDuplicateAnotherProjectWithDifferentTags()
+ {
+ $taskProjectMoveModel = new TaskProjectDuplicationModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $tagModel = new TagModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create our tags for each projects
+ $this->assertEquals(1, $tagModel->create(1, 'T1'));
+ $this->assertEquals(2, $tagModel->create(1, 'T2'));
+ $this->assertEquals(3, $tagModel->create(2, 'T2'));
+ $this->assertEquals(4, $tagModel->create(2, 'T3'));
+ $this->assertEquals(5, $tagModel->create(0, 'T4'));
+ $this->assertEquals(6, $tagModel->create(0, 'T5'));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'tags' => array('T1', 'T2', 'T5'))));
+
+ // We move our task to the 2nd project
+ $this->assertEquals(2, $taskProjectMoveModel->duplicateToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['id']);
+ $this->assertEquals(2, $task['project_id']);
+
+ // Check tags
+ $tags = $taskTagModel->getList(2);
+ $this->assertCount(2, $tags);
+ $this->assertArrayHasKey(3, $tags);
+ $this->assertArrayHasKey(6, $tags);
+ }
+}
diff --git a/tests/units/Model/TaskProjectMoveModelTest.php b/tests/units/Model/TaskProjectMoveModelTest.php
new file mode 100644
index 00000000..52f61b28
--- /dev/null
+++ b/tests/units/Model/TaskProjectMoveModelTest.php
@@ -0,0 +1,277 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Core\Security\Role;
+use Kanboard\Model\CategoryModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectUserRoleModel;
+use Kanboard\Model\SwimlaneModel;
+use Kanboard\Model\TagModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskProjectMoveModel;
+use Kanboard\Model\TaskTagModel;
+use Kanboard\Model\UserModel;
+
+class TaskProjectMoveModelTest extends Base
+{
+ public function onMoveProject($event)
+ {
+ $this->assertInstanceOf('Kanboard\Event\TaskEvent', $event);
+
+ $event_data = $event->getAll();
+ $this->assertNotEmpty($event_data);
+ $this->assertEquals(1, $event_data['task_id']);
+ $this->assertEquals('test', $event_data['task']['title']);
+ }
+
+ public function testMoveAnotherProject()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'owner_id' => 1,
+ 'category_id' => 10,
+ 'position' => 333,
+ 'priority' => 1,
+ )));
+
+ $this->container['dispatcher']->addListener(TaskModel::EVENT_MOVE_PROJECT, array($this, 'onMoveProject'));
+
+ // We duplicate our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ $called = $this->container['dispatcher']->getCalledListeners();
+ $this->assertArrayHasKey(TaskModel::EVENT_MOVE_PROJECT.'.TaskProjectMoveModelTest::onMoveProject', $called);
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->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(2, $task['project_id']);
+ $this->assertEquals(5, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(1, $task['priority']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testMoveAnotherProjectWithCategory()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 1)));
+ $this->assertNotFalse($categoryModel->create(array('name' => 'Category #1', 'project_id' => 2)));
+ $this->assertTrue($categoryModel->exists(1));
+ $this->assertTrue($categoryModel->exists(2));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'category_id' => 1)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ // Check the values of the duplicated task
+ $task = $taskFinderModel->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(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testMoveAnotherProjectWithUser()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create a new user for our project
+ $this->assertNotFalse($userModel->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(6, $task['column_id']);
+ }
+
+ public function testMoveAnotherProjectWithForbiddenUser()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create a new user for our project
+ $this->assertNotFalse($userModel->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 3)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(0, $task['owner_id']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(6, $task['column_id']);
+ }
+
+ public function testMoveAnotherProjectWithSwimlane()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #1')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->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(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testMoveAnotherProjectWithoutSwimlane()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $swimlaneModel = new SwimlaneModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1')));
+ $this->assertNotFalse($swimlaneModel->create(array('project_id' => 2, 'name' => 'Swimlane #2')));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'swimlane_id' => 1)));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->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(6, $task['column_id']);
+ $this->assertEquals(1, $task['position']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals('test', $task['title']);
+ }
+
+ public function testMoveAnotherProjectWithDifferentTags()
+ {
+ $taskProjectMoveModel = new TaskProjectMoveModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $tagModel = new TagModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ // We create 2 projects
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ // We create our tags for each projects
+ $this->assertEquals(1, $tagModel->create(1, 'T1'));
+ $this->assertEquals(2, $tagModel->create(1, 'T2'));
+ $this->assertEquals(3, $tagModel->create(2, 'T3'));
+ $this->assertEquals(4, $tagModel->create(2, 'T4'));
+ $this->assertEquals(5, $tagModel->create(0, 'T5'));
+ $this->assertEquals(6, $tagModel->create(0, 'T6'));
+
+ // We create a task
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'tags' => array('T1', 'T5', 'T6'))));
+
+ // We move our task to the 2nd project
+ $this->assertTrue($taskProjectMoveModel->moveToProject(1, 2));
+
+ // Check the values of the moved task
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['project_id']);
+
+ // Check tags
+ $tags = $taskTagModel->getList(1);
+ $this->assertCount(2, $tags);
+ $this->assertArrayHasKey(5, $tags);
+ $this->assertArrayHasKey(6, $tags);
+ }
+}
diff --git a/tests/units/Model/TaskRecurrenceModelTest.php b/tests/units/Model/TaskRecurrenceModelTest.php
new file mode 100644
index 00000000..85d77bc2
--- /dev/null
+++ b/tests/units/Model/TaskRecurrenceModelTest.php
@@ -0,0 +1,126 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Core\DateParser;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Model\TaskRecurrenceModel;
+use Kanboard\Model\TaskTagModel;
+
+class TaskRecurrenceModelTest extends Base
+{
+ public function testRecurrenceSettings()
+ {
+ $taskRecurrenceModel = new TaskRecurrenceModel($this->container);
+
+ $statuses = $taskRecurrenceModel->getRecurrenceStatusList();
+ $this->assertCount(2, $statuses);
+ $this->assertArrayHasKey(TaskModel::RECURRING_STATUS_NONE, $statuses);
+ $this->assertArrayHasKey(TaskModel::RECURRING_STATUS_PENDING, $statuses);
+ $this->assertArrayNotHasKey(TaskModel::RECURRING_STATUS_PROCESSED, $statuses);
+
+ $triggers = $taskRecurrenceModel->getRecurrenceTriggerList();
+ $this->assertCount(3, $triggers);
+ $this->assertArrayHasKey(TaskModel::RECURRING_TRIGGER_FIRST_COLUMN, $triggers);
+ $this->assertArrayHasKey(TaskModel::RECURRING_TRIGGER_LAST_COLUMN, $triggers);
+ $this->assertArrayHasKey(TaskModel::RECURRING_TRIGGER_CLOSE, $triggers);
+
+ $dates = $taskRecurrenceModel->getRecurrenceBasedateList();
+ $this->assertCount(2, $dates);
+ $this->assertArrayHasKey(TaskModel::RECURRING_BASEDATE_DUEDATE, $dates);
+ $this->assertArrayHasKey(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $dates);
+
+ $timeframes = $taskRecurrenceModel->getRecurrenceTimeframeList();
+ $this->assertCount(3, $timeframes);
+ $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_DAYS, $timeframes);
+ $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_MONTHS, $timeframes);
+ $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_YEARS, $timeframes);
+ }
+
+ public function testCalculateRecurringTaskDueDate()
+ {
+ $taskRecurrenceModel = new TaskRecurrenceModel($this->container);
+
+ $values = array('date_due' => 0);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(0, $values['date_due']);
+
+ $values = array('date_due' => 0, 'recurrence_factor' => 0, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(0, $values['date_due']);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(time() + 86400, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => -2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(time() - 2 * 86400, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => 1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(1431291376 + 86400, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => -1, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(1431291376 - 86400, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_MONTHS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(1436561776, $values['date_due'], '', 1);
+
+ $values = array('date_due' => 1431291376, 'recurrence_factor' => 2, 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_DUEDATE, 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_YEARS);
+ $taskRecurrenceModel->calculateRecurringTaskDueDate($values);
+ $this->assertEquals(1494449776, $values['date_due'], '', 1);
+ }
+
+ public function testDuplicateRecurringTask()
+ {
+ $taskRecurrenceModel = new TaskRecurrenceModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $dateParser = new DateParser($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'date_due' => 1436561776,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE,
+ 'recurrence_factor' => 2,
+ 'recurrence_timeframe' => TaskModel::RECURRING_TIMEFRAME_DAYS,
+ 'recurrence_basedate' => TaskModel::RECURRING_BASEDATE_TRIGGERDATE,
+ 'tags' => array('T1', 'T2'),
+ )));
+
+ $this->assertEquals(2, $taskRecurrenceModel->duplicateRecurringTask(1));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(TaskModel::RECURRING_STATUS_PROCESSED, $task['recurrence_status']);
+ $this->assertEquals(2, $task['recurrence_child']);
+ $this->assertEquals(1436486400, $task['date_due'], '', 2);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(TaskModel::RECURRING_STATUS_PENDING, $task['recurrence_status']);
+ $this->assertEquals(TaskModel::RECURRING_TRIGGER_CLOSE, $task['recurrence_trigger']);
+ $this->assertEquals(TaskModel::RECURRING_TIMEFRAME_DAYS, $task['recurrence_timeframe']);
+ $this->assertEquals(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']);
+ $this->assertEquals(1, $task['recurrence_parent']);
+ $this->assertEquals(2, $task['recurrence_factor']);
+ $this->assertEquals($dateParser->removeTimeFromTimestamp(strtotime('+2 days')), $task['date_due'], '', 2);
+
+ $tags = $taskTagModel->getList(2);
+ $this->assertCount(2, $tags);
+ $this->assertArrayHasKey(1, $tags);
+ $this->assertArrayHasKey(2, $tags);
+ }
+}
diff --git a/tests/units/Model/TaskTagModelTest.php b/tests/units/Model/TaskTagModelTest.php
new file mode 100644
index 00000000..3485368e
--- /dev/null
+++ b/tests/units/Model/TaskTagModelTest.php
@@ -0,0 +1,148 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TagModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskTagModel;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskTagModelTest extends Base
+{
+ public function testAssociationAndDissociation()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+ $tagModel = new TagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->assertEquals(1, $tagModel->create(0, 'My tag 1'));
+ $this->assertEquals(2, $tagModel->create(0, 'My tag 2'));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', '', 'My tag 3')));
+
+ $tags = $taskTagModel->getTagsByTask(1);
+ $this->assertCount(3, $tags);
+
+ $this->assertEquals(1, $tags[0]['id']);
+ $this->assertEquals('My tag 1', $tags[0]['name']);
+
+ $this->assertEquals(2, $tags[1]['id']);
+ $this->assertEquals('My tag 2', $tags[1]['name']);
+
+ $this->assertEquals(3, $tags[2]['id']);
+ $this->assertEquals('My tag 3', $tags[2]['name']);
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 3', 'My tag 1', 'My tag 4')));
+
+ $tags = $taskTagModel->getTagsByTask(1);
+ $this->assertCount(3, $tags);
+
+ $this->assertEquals(1, $tags[0]['id']);
+ $this->assertEquals('My tag 1', $tags[0]['name']);
+
+ $this->assertEquals(3, $tags[1]['id']);
+ $this->assertEquals('My tag 3', $tags[1]['name']);
+
+ $this->assertEquals(4, $tags[2]['id']);
+ $this->assertEquals('My tag 4', $tags[2]['name']);
+
+ $tags = $tagModel->getAll();
+ $this->assertCount(4, $tags);
+ $this->assertEquals('My tag 1', $tags[0]['name']);
+ $this->assertEquals(0, $tags[0]['project_id']);
+
+ $this->assertEquals('My tag 2', $tags[1]['name']);
+ $this->assertEquals(0, $tags[1]['project_id']);
+
+ $this->assertEquals('My tag 3', $tags[2]['name']);
+ $this->assertEquals(1, $tags[2]['project_id']);
+
+ $this->assertEquals('My tag 4', $tags[3]['name']);
+ $this->assertEquals(1, $tags[3]['project_id']);
+ }
+
+ public function testGetTagsForTasks()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test3')));
+
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
+ $this->assertTrue($taskTagModel->save(1, 2, array('My tag 3')));
+
+ $tags = $taskTagModel->getTagsByTasks(array(1, 2, 3));
+
+ $expected = array(
+ 1 => array(
+ array(
+ 'id' => 1,
+ 'name' => 'My tag 1',
+ 'task_id' => 1
+ ),
+ array(
+ 'id' => 2,
+ 'name' => 'My tag 2',
+ 'task_id' => 1
+ ),
+ array(
+ 'id' => 3,
+ 'name' => 'My tag 3',
+ 'task_id' => 1
+ ),
+ ),
+ 2 => array(
+ array(
+ 'id' => 3,
+ 'name' => 'My tag 3',
+ 'task_id' => 2,
+ )
+ )
+ );
+
+ $this->assertEquals($expected, $tags);
+ }
+
+ public function testGetTagsForTasksWithEmptyList()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+ $this->assertTrue($taskTagModel->save(1, 1, array('My tag 1', 'My tag 2', 'My tag 3')));
+
+ $tags = $taskTagModel->getTagsByTasks(array());
+ $this->assertEquals(array(), $tags);
+ }
+
+ public function testGetTagIdNotAvailableInDestinationProject()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskTagModel = new TaskTagModel($this->container);
+ $tagModel = new TagModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'P1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'P2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1')));
+
+ $this->assertEquals(1, $tagModel->create(0, 'T0'));
+ $this->assertEquals(2, $tagModel->create(2, 'T1'));
+ $this->assertEquals(3, $tagModel->create(2, 'T3'));
+ $this->assertEquals(4, $tagModel->create(1, 'T2'));
+ $this->assertEquals(5, $tagModel->create(1, 'T3'));
+ $this->assertTrue($taskTagModel->save(1, 1, array('T0', 'T2', 'T3')));
+
+ $this->assertEquals(array(4, 5), $taskTagModel->getTagIdsByTaskNotAvailableInProject(1, 2));
+ }
+}
diff --git a/tests/units/Model/TaskTest.php b/tests/units/Model/TaskTest.php
deleted file mode 100644
index 89fc4dc1..00000000
--- a/tests/units/Model/TaskTest.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\ProjectModel;
-
-class TaskTest extends Base
-{
- public function testRemove()
- {
- $t = new TaskModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $p = new ProjectModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
-
- $this->assertTrue($t->remove(1));
- $this->assertFalse($t->remove(1234));
- }
-
- public function testGetTaskIdFromText()
- {
- $t = new TaskModel($this->container);
- $this->assertEquals(123, $t->getTaskIdFromText('My task #123'));
- $this->assertEquals(0, $t->getTaskIdFromText('My task 123'));
- }
-
- public function testRecurrenceSettings()
- {
- $t = new TaskModel($this->container);
-
- $statuses = $t->getRecurrenceStatusList();
- $this->assertCount(2, $statuses);
- $this->assertArrayHasKey(TaskModel::RECURRING_STATUS_NONE, $statuses);
- $this->assertArrayHasKey(TaskModel::RECURRING_STATUS_PENDING, $statuses);
- $this->assertArrayNotHasKey(TaskModel::RECURRING_STATUS_PROCESSED, $statuses);
-
- $triggers = $t->getRecurrenceTriggerList();
- $this->assertCount(3, $triggers);
- $this->assertArrayHasKey(TaskModel::RECURRING_TRIGGER_FIRST_COLUMN, $triggers);
- $this->assertArrayHasKey(TaskModel::RECURRING_TRIGGER_LAST_COLUMN, $triggers);
- $this->assertArrayHasKey(TaskModel::RECURRING_TRIGGER_CLOSE, $triggers);
-
- $dates = $t->getRecurrenceBasedateList();
- $this->assertCount(2, $dates);
- $this->assertArrayHasKey(TaskModel::RECURRING_BASEDATE_DUEDATE, $dates);
- $this->assertArrayHasKey(TaskModel::RECURRING_BASEDATE_TRIGGERDATE, $dates);
-
- $timeframes = $t->getRecurrenceTimeframeList();
- $this->assertCount(3, $timeframes);
- $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_DAYS, $timeframes);
- $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_MONTHS, $timeframes);
- $this->assertArrayHasKey(TaskModel::RECURRING_TIMEFRAME_YEARS, $timeframes);
- }
-}
diff --git a/tests/units/Model/UserModelTest.php b/tests/units/Model/UserModelTest.php
new file mode 100644
index 00000000..a0c9c575
--- /dev/null
+++ b/tests/units/Model/UserModelTest.php
@@ -0,0 +1,384 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\UserModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Core\Security\Role;
+
+class UserModelTest extends Base
+{
+ public function testGetByEmail()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1', 'password' => '123456', 'email' => 'user1@localhost')));
+ $this->assertNotFalse($userModel->create(array('username' => 'user2', 'password' => '123456', 'email' => '')));
+
+ $this->assertNotEmpty($userModel->getByEmail('user1@localhost'));
+ $this->assertEmpty($userModel->getByEmail(''));
+ }
+
+ public function testGetByExternalId()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1', 'password' => '123456', 'gitlab_id' => '1234')));
+
+ $this->assertNotEmpty($userModel->getByExternalId('gitlab_id', '1234'));
+ $this->assertEmpty($userModel->getByExternalId('gitlab_id', ''));
+
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user2', 'password' => '123456', 'github_id' => 'plop')));
+ $this->assertNotFalse($userModel->create(array('username' => 'user3', 'password' => '123456', 'github_id' => '')));
+
+ $this->assertNotEmpty($userModel->getByExternalId('github_id', 'plop'));
+ $this->assertEmpty($userModel->getByExternalId('github_id', ''));
+
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user4', 'password' => '123456', 'google_id' => '1234')));
+ $this->assertNotFalse($userModel->create(array('username' => 'user5', 'password' => '123456', 'google_id' => '')));
+
+ $this->assertNotEmpty($userModel->getByExternalId('google_id', '1234'));
+ $this->assertEmpty($userModel->getByExternalId('google_id', ''));
+ }
+
+ public function testGetByToken()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1', 'token' => 'random')));
+ $this->assertNotFalse($userModel->create(array('username' => 'user2', 'token' => '')));
+
+ $this->assertNotEmpty($userModel->getByToken('random'));
+ $this->assertEmpty($userModel->getByToken(''));
+ }
+
+ public function testGetByUsername()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1')));
+
+ $this->assertNotEmpty($userModel->getByUsername('user1'));
+ $this->assertEmpty($userModel->getByUsername('user2'));
+ $this->assertEmpty($userModel->getByUsername(''));
+ }
+
+ public function testExists()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1')));
+
+ $this->assertTrue($userModel->exists(1));
+ $this->assertTrue($userModel->exists(2));
+ $this->assertFalse($userModel->exists(3));
+ }
+
+ public function testCount()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'user1')));
+ $this->assertEquals(2, $userModel->count());
+ }
+
+ public function testGetAll()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'you')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'me', 'name' => 'Me')));
+
+ $users = $userModel->getAll();
+ $this->assertCount(3, $users);
+ $this->assertEquals('admin', $users[0]['username']);
+ $this->assertEquals('me', $users[1]['username']);
+ $this->assertEquals('you', $users[2]['username']);
+ }
+
+ public function testGetActiveUsersList()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'you')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'me', 'name' => 'Me too')));
+ $this->assertEquals(4, $userModel->create(array('username' => 'foobar', 'is_active' => 0)));
+
+ $users = $userModel->getActiveUsersList();
+
+ $expected = array(
+ 1 => 'admin',
+ 3 => 'Me too',
+ 2 => 'you',
+ );
+
+ $this->assertEquals($expected, $users);
+
+ $users = $userModel->getActiveUsersList(true);
+
+ $expected = array(
+ UserModel::EVERYBODY_ID => 'Everybody',
+ 1 => 'admin',
+ 3 => 'Me too',
+ 2 => 'you',
+ );
+
+ $this->assertEquals($expected, $users);
+ }
+
+ public function testIsAdmin()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+
+ $this->assertTrue($userModel->isAdmin(1));
+ $this->assertFalse($userModel->isAdmin(2));
+ }
+
+ public function testPassword()
+ {
+ $password = 'test123';
+ $hash = password_hash($password, PASSWORD_BCRYPT);
+
+ $this->assertNotEmpty($hash);
+ $this->assertTrue(password_verify($password, $hash));
+ }
+
+ public function testPrepare()
+ {
+ $userModel = new UserModel($this->container);
+
+ $input = array(
+ 'username' => 'user1',
+ 'password' => '1234',
+ 'confirmation' => '1234',
+ 'name' => 'me',
+ 'role' => Role::APP_ADMIN,
+ );
+
+ $userModel->prepare($input);
+ $this->assertArrayNotHasKey('confirmation', $input);
+
+ $this->assertArrayHasKey('password', $input);
+ $this->assertNotEquals('1234', $input['password']);
+ $this->assertNotEmpty($input['password']);
+
+ $input = array(
+ 'username' => 'user1',
+ 'password' => '1234',
+ 'current_password' => 'bla',
+ 'confirmation' => '1234',
+ 'name' => 'me',
+ 'is_ldap_user' => '1',
+ );
+
+ $userModel->prepare($input);
+ $this->assertArrayNotHasKey('confirmation', $input);
+ $this->assertArrayNotHasKey('current_password', $input);
+
+ $this->assertArrayHasKey('password', $input);
+ $this->assertNotEquals('1234', $input['password']);
+ $this->assertNotEmpty($input['password']);
+
+ $this->assertArrayHasKey('is_ldap_user', $input);
+ $this->assertEquals(1, $input['is_ldap_user']);
+
+ $input = array(
+ 'id' => 2,
+ 'name' => 'me',
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('id' => 2, 'name' => 'me'), $input);
+
+ $input = array(
+ 'gitlab_id' => '1234',
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('gitlab_id' => 1234), $input);
+
+ $input = array(
+ 'gitlab_id' => '',
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('gitlab_id' => null), $input);
+
+ $input = array(
+ 'gitlab_id' => 'something',
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('gitlab_id' => 0), $input);
+
+ $input = array(
+ 'username' => 'something',
+ 'password' => ''
+ );
+
+ $userModel->prepare($input);
+ $this->assertEquals(array('username' => 'something'), $input);
+ }
+
+ public function testCreate()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'user #1', 'password' => '123456', 'name' => 'User')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user #2', 'is_ldap_user' => 1)));
+ $this->assertEquals(4, $userModel->create(array('username' => 'user #3', 'role' => Role::APP_MANAGER)));
+ $this->assertEquals(5, $userModel->create(array('username' => 'user #4', 'gitlab_id' => '', 'role' => Role::APP_ADMIN)));
+ $this->assertEquals(6, $userModel->create(array('username' => 'user #5', 'gitlab_id' => '1234')));
+ $this->assertFalse($userModel->create(array('username' => 'user #1')));
+
+ $user = $userModel->getById(1);
+ $this->assertEquals('admin', $user['username']);
+ $this->assertEquals('', $user['name']);
+ $this->assertEquals(Role::APP_ADMIN, $user['role']);
+ $this->assertEquals(0, $user['is_ldap_user']);
+
+ $user = $userModel->getById(2);
+ $this->assertEquals('user #1', $user['username']);
+ $this->assertEquals('User', $user['name']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
+ $this->assertEquals(0, $user['is_ldap_user']);
+
+ $user = $userModel->getById(3);
+ $this->assertEquals('user #2', $user['username']);
+ $this->assertEquals('', $user['name']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
+ $this->assertEquals(1, $user['is_ldap_user']);
+
+ $user = $userModel->getById(4);
+ $this->assertEquals('user #3', $user['username']);
+ $this->assertEquals(Role::APP_MANAGER, $user['role']);
+
+ $user = $userModel->getById(5);
+ $this->assertEquals('user #4', $user['username']);
+ $this->assertEquals('', $user['gitlab_id']);
+ $this->assertEquals(Role::APP_ADMIN, $user['role']);
+
+ $user = $userModel->getById(6);
+ $this->assertEquals('user #5', $user['username']);
+ $this->assertEquals('1234', $user['gitlab_id']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
+ }
+
+ public function testUpdate()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'plop', 'gitlab_id' => '123')));
+
+ $this->assertTrue($userModel->update(array('id' => 2, 'username' => 'biloute')));
+ $this->assertTrue($userModel->update(array('id' => 3, 'gitlab_id' => '')));
+
+ $user = $userModel->getById(2);
+ $this->assertEquals('biloute', $user['username']);
+ $this->assertEquals('Toto', $user['name']);
+ $this->assertEquals(Role::APP_USER, $user['role']);
+ $this->assertEquals(0, $user['is_ldap_user']);
+
+ $user = $userModel->getById(3);
+ $this->assertNotEmpty($user);
+ $this->assertEquals(null, $user['gitlab_id']);
+ }
+
+ public function testRemove()
+ {
+ $userModel = new UserModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $commentModel = new CommentModel($this->container);
+
+ $this->assertNotFalse($userModel->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'Subtask #1', 'user_id' => 2, 'task_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('comment' => 'foobar', 'user_id' => 2, 'task_id' => 1)));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(2, $task['owner_id']);
+
+ $this->assertTrue($userModel->remove(1));
+ $this->assertTrue($userModel->remove(2));
+ $this->assertFalse($userModel->remove(2));
+ $this->assertFalse($userModel->remove(55));
+
+ // Make sure that assigned tasks are unassigned after removing the user
+ $task = $taskFinderModel->getById(1);
+ $this->assertEquals(1, $task['id']);
+ $this->assertEquals(0, $task['owner_id']);
+
+ // Make sure that assigned subtasks are unassigned after removing the user
+ $subtask = $subtaskModel->getById(1);
+ $this->assertEquals(1, $subtask['id']);
+ $this->assertEquals(0, $subtask['user_id']);
+
+ // Make sure that comments are not related to the user anymore
+ $comment = $commentModel->getById(1);
+ $this->assertEquals(1, $comment['id']);
+ $this->assertEquals(0, $comment['user_id']);
+
+ // Make sure that private projects are also removed
+ $user_id1 = $userModel->create(array('username' => 'toto1', 'password' => '123456', 'name' => 'Toto'));
+ $user_id2 = $userModel->create(array('username' => 'toto2', 'password' => '123456', 'name' => 'Toto'));
+ $this->assertNotFalse($user_id1);
+ $this->assertNotFalse($user_id2);
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Private project #1', 'is_private' => 1), $user_id1, true));
+ $this->assertEquals(3, $projectModel->create(array('name' => 'Private project #2', 'is_private' => 1), $user_id2, true));
+
+ $this->assertTrue($userModel->remove($user_id1));
+
+ $this->assertNotEmpty($projectModel->getById(1));
+ $this->assertNotEmpty($projectModel->getById(3));
+
+ $this->assertEmpty($projectModel->getById(2));
+ }
+
+ public function testEnableDisablePublicAccess()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertNotFalse($userModel->create(array('username' => 'toto', 'password' => '123456')));
+
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $this->assertEquals('toto', $user['username']);
+ $this->assertEmpty($user['token']);
+
+ $this->assertTrue($userModel->enablePublicAccess(2));
+
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $this->assertEquals('toto', $user['username']);
+ $this->assertNotEmpty($user['token']);
+
+ $this->assertTrue($userModel->disablePublicAccess(2));
+
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $this->assertEquals('toto', $user['username']);
+ $this->assertEmpty($user['token']);
+ }
+
+ public function testEnableDisable()
+ {
+ $userModel = new UserModel($this->container);
+ $this->assertEquals(2, $userModel->create(array('username' => 'toto')));
+
+ $this->assertTrue($userModel->isActive(2));
+ $user = $userModel->getById(2);
+ $this->assertEquals(1, $user['is_active']);
+
+ $this->assertTrue($userModel->disable(2));
+ $user = $userModel->getById(2);
+ $this->assertEquals(0, $user['is_active']);
+ $this->assertFalse($userModel->isActive(2));
+
+ $this->assertTrue($userModel->enable(2));
+ $user = $userModel->getById(2);
+ $this->assertEquals(1, $user['is_active']);
+ $this->assertTrue($userModel->isActive(2));
+ }
+}
diff --git a/tests/units/Model/UserTest.php b/tests/units/Model/UserTest.php
deleted file mode 100644
index 0be6172e..00000000
--- a/tests/units/Model/UserTest.php
+++ /dev/null
@@ -1,400 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\UserModel;
-use Kanboard\Model\SubtaskModel;
-use Kanboard\Model\CommentModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\ProjectModel;
-use Kanboard\Core\Security\Role;
-
-class UserTest extends Base
-{
- public function testGetByEmail()
- {
- $u = new UserModel($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 testGetByExternalId()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'gitlab_id' => '1234')));
-
- $this->assertNotEmpty($u->getByExternalId('gitlab_id', '1234'));
- $this->assertEmpty($u->getByExternalId('gitlab_id', ''));
-
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'github_id' => 'plop')));
- $this->assertNotFalse($u->create(array('username' => 'user3', 'password' => '123456', 'github_id' => '')));
-
- $this->assertNotEmpty($u->getByExternalId('github_id', 'plop'));
- $this->assertEmpty($u->getByExternalId('github_id', ''));
-
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user4', 'password' => '123456', 'google_id' => '1234')));
- $this->assertNotFalse($u->create(array('username' => 'user5', 'password' => '123456', 'google_id' => '')));
-
- $this->assertNotEmpty($u->getByExternalId('google_id', '1234'));
- $this->assertEmpty($u->getByExternalId('google_id', ''));
- }
-
- public function testGetByToken()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1', 'token' => 'random')));
- $this->assertNotFalse($u->create(array('username' => 'user2', 'token' => '')));
-
- $this->assertNotEmpty($u->getByToken('random'));
- $this->assertEmpty($u->getByToken(''));
- }
-
- public function testGetByUsername()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1')));
-
- $this->assertNotEmpty($u->getByUsername('user1'));
- $this->assertEmpty($u->getByUsername('user2'));
- $this->assertEmpty($u->getByUsername(''));
- }
-
- public function testExists()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1')));
-
- $this->assertTrue($u->exists(1));
- $this->assertTrue($u->exists(2));
- $this->assertFalse($u->exists(3));
- }
-
- public function testCount()
- {
- $u = new UserModel($this->container);
- $this->assertNotFalse($u->create(array('username' => 'user1')));
- $this->assertEquals(2, $u->count());
- }
-
- public function testGetAll()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'you')));
- $this->assertEquals(3, $u->create(array('username' => 'me', 'name' => 'Me')));
-
- $users = $u->getAll();
- $this->assertCount(3, $users);
- $this->assertEquals('admin', $users[0]['username']);
- $this->assertEquals('me', $users[1]['username']);
- $this->assertEquals('you', $users[2]['username']);
- }
-
- public function testGetActiveUsersList()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'you')));
- $this->assertEquals(3, $u->create(array('username' => 'me', 'name' => 'Me too')));
- $this->assertEquals(4, $u->create(array('username' => 'foobar', 'is_active' => 0)));
-
- $users = $u->getActiveUsersList();
-
- $expected = array(
- 1 => 'admin',
- 3 => 'Me too',
- 2 => 'you',
- );
-
- $this->assertEquals($expected, $users);
-
- $users = $u->getActiveUsersList(true);
-
- $expected = array(
- UserModel::EVERYBODY_ID => 'Everybody',
- 1 => 'admin',
- 3 => 'Me too',
- 2 => 'you',
- );
-
- $this->assertEquals($expected, $users);
- }
-
- public function testGetFullname()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'user1')));
- $this->assertEquals(3, $u->create(array('username' => 'user2', 'name' => 'User #2')));
-
- $user1 = $u->getById(2);
- $user2 = $u->getById(3);
-
- $this->assertNotEmpty($user1);
- $this->assertNotEmpty($user2);
-
- $this->assertEquals('user1', $u->getFullname($user1));
- $this->assertEquals('User #2', $u->getFullname($user2));
- }
-
- public function testIsAdmin()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'user1')));
-
- $this->assertTrue($u->isAdmin(1));
- $this->assertFalse($u->isAdmin(2));
- }
-
- 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 UserModel($this->container);
-
- $input = array(
- 'username' => 'user1',
- 'password' => '1234',
- 'confirmation' => '1234',
- 'name' => 'me',
- 'role' => Role::APP_ADMIN,
- );
-
- $u->prepare($input);
- $this->assertArrayNotHasKey('confirmation', $input);
-
- $this->assertArrayHasKey('password', $input);
- $this->assertNotEquals('1234', $input['password']);
- $this->assertNotEmpty($input['password']);
-
- $input = array(
- 'username' => 'user1',
- 'password' => '1234',
- 'current_password' => 'bla',
- 'confirmation' => '1234',
- 'name' => 'me',
- 'is_ldap_user' => '1',
- );
-
- $u->prepare($input);
- $this->assertArrayNotHasKey('confirmation', $input);
- $this->assertArrayNotHasKey('current_password', $input);
-
- $this->assertArrayHasKey('password', $input);
- $this->assertNotEquals('1234', $input['password']);
- $this->assertNotEmpty($input['password']);
-
- $this->assertArrayHasKey('is_ldap_user', $input);
- $this->assertEquals(1, $input['is_ldap_user']);
-
- $input = array(
- 'id' => 2,
- 'name' => 'me',
- );
-
- $u->prepare($input);
- $this->assertEquals(array('id' => 2, 'name' => 'me'), $input);
-
- $input = array(
- 'gitlab_id' => '1234',
- );
-
- $u->prepare($input);
- $this->assertEquals(array('gitlab_id' => 1234), $input);
-
- $input = array(
- 'gitlab_id' => '',
- );
-
- $u->prepare($input);
- $this->assertEquals(array('gitlab_id' => null), $input);
-
- $input = array(
- 'gitlab_id' => 'something',
- );
-
- $u->prepare($input);
- $this->assertEquals(array('gitlab_id' => 0), $input);
-
- $input = array(
- 'username' => 'something',
- 'password' => ''
- );
-
- $u->prepare($input);
- $this->assertEquals(array('username' => 'something'), $input);
- }
-
- public function testCreate()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'user #1', 'password' => '123456', 'name' => 'User')));
- $this->assertEquals(3, $u->create(array('username' => 'user #2', 'is_ldap_user' => 1)));
- $this->assertEquals(4, $u->create(array('username' => 'user #3', 'role' => Role::APP_MANAGER)));
- $this->assertEquals(5, $u->create(array('username' => 'user #4', 'gitlab_id' => '', 'role' => Role::APP_ADMIN)));
- $this->assertEquals(6, $u->create(array('username' => 'user #5', 'gitlab_id' => '1234')));
- $this->assertFalse($u->create(array('username' => 'user #1')));
-
- $user = $u->getById(1);
- $this->assertEquals('admin', $user['username']);
- $this->assertEquals('', $user['name']);
- $this->assertEquals(Role::APP_ADMIN, $user['role']);
- $this->assertEquals(0, $user['is_ldap_user']);
-
- $user = $u->getById(2);
- $this->assertEquals('user #1', $user['username']);
- $this->assertEquals('User', $user['name']);
- $this->assertEquals(Role::APP_USER, $user['role']);
- $this->assertEquals(0, $user['is_ldap_user']);
-
- $user = $u->getById(3);
- $this->assertEquals('user #2', $user['username']);
- $this->assertEquals('', $user['name']);
- $this->assertEquals(Role::APP_USER, $user['role']);
- $this->assertEquals(1, $user['is_ldap_user']);
-
- $user = $u->getById(4);
- $this->assertEquals('user #3', $user['username']);
- $this->assertEquals(Role::APP_MANAGER, $user['role']);
-
- $user = $u->getById(5);
- $this->assertEquals('user #4', $user['username']);
- $this->assertEquals('', $user['gitlab_id']);
- $this->assertEquals(Role::APP_ADMIN, $user['role']);
-
- $user = $u->getById(6);
- $this->assertEquals('user #5', $user['username']);
- $this->assertEquals('1234', $user['gitlab_id']);
- $this->assertEquals(Role::APP_USER, $user['role']);
- }
-
- public function testUpdate()
- {
- $u = new UserModel($this->container);
- $this->assertEquals(2, $u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
- $this->assertEquals(3, $u->create(array('username' => 'plop', 'gitlab_id' => '123')));
-
- $this->assertTrue($u->update(array('id' => 2, 'username' => 'biloute')));
- $this->assertTrue($u->update(array('id' => 3, 'gitlab_id' => '')));
-
- $user = $u->getById(2);
- $this->assertEquals('biloute', $user['username']);
- $this->assertEquals('Toto', $user['name']);
- $this->assertEquals(Role::APP_USER, $user['role']);
- $this->assertEquals(0, $user['is_ldap_user']);
-
- $user = $u->getById(3);
- $this->assertNotEmpty($user);
- $this->assertEquals(null, $user['gitlab_id']);
- }
-
- public function testRemove()
- {
- $u = new UserModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $p = new ProjectModel($this->container);
- $s = new SubtaskModel($this->container);
- $c = new CommentModel($this->container);
-
- $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2)));
- $this->assertEquals(1, $s->create(array('title' => 'Subtask #1', 'user_id' => 2, 'task_id' => 1)));
- $this->assertEquals(1, $c->create(array('comment' => 'foobar', 'user_id' => 2, 'task_id' => 1)));
-
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(2, $task['owner_id']);
-
- $this->assertTrue($u->remove(1));
- $this->assertTrue($u->remove(2));
- $this->assertFalse($u->remove(2));
- $this->assertFalse($u->remove(55));
-
- // Make sure that assigned tasks are unassigned after removing the user
- $task = $tf->getById(1);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(0, $task['owner_id']);
-
- // Make sure that assigned subtasks are unassigned after removing the user
- $subtask = $s->getById(1);
- $this->assertEquals(1, $subtask['id']);
- $this->assertEquals(0, $subtask['user_id']);
-
- // Make sure that comments are not related to the user anymore
- $comment = $c->getById(1);
- $this->assertEquals(1, $comment['id']);
- $this->assertEquals(0, $comment['user_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 UserModel($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']);
- }
-
- public function testEnableDisable()
- {
- $userModel = new UserModel($this->container);
- $this->assertEquals(2, $userModel->create(array('username' => 'toto')));
-
- $this->assertTrue($userModel->isActive(2));
- $user = $userModel->getById(2);
- $this->assertEquals(1, $user['is_active']);
-
- $this->assertTrue($userModel->disable(2));
- $user = $userModel->getById(2);
- $this->assertEquals(0, $user['is_active']);
- $this->assertFalse($userModel->isActive(2));
-
- $this->assertTrue($userModel->enable(2));
- $user = $userModel->getById(2);
- $this->assertEquals(1, $user['is_active']);
- $this->assertTrue($userModel->isActive(2));
- }
-}
diff --git a/tests/units/Notification/MailNotificationTest.php b/tests/units/Notification/MailNotificationTest.php
new file mode 100644
index 00000000..05f1f882
--- /dev/null
+++ b/tests/units/Notification/MailNotificationTest.php
@@ -0,0 +1,117 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\CommentModel;
+use Kanboard\Model\TaskLinkModel;
+use Kanboard\Model\UserModel;
+use Kanboard\Model\TaskFileModel;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Notification\MailNotification;
+use Kanboard\Subscriber\NotificationSubscriber;
+
+class MailNotificationTest extends Base
+{
+ public function testGetMailContent()
+ {
+ $mailNotification = new MailNotification($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $commentModel = new CommentModel($this->container);
+ $fileModel = new TaskFileModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'test', 'task_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
+ $this->assertEquals(1, $fileModel->create(1, 'test', 'blah', 123));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $task = $taskFinderModel->getDetails(1);
+ $subtask = $subtaskModel->getById(1, true);
+ $comment = $commentModel->getById(1);
+ $file = $commentModel->getById(1);
+ $tasklink = $taskLinkModel->getById(1);
+
+ $this->assertNotEmpty($task);
+ $this->assertNotEmpty($subtask);
+ $this->assertNotEmpty($comment);
+ $this->assertNotEmpty($file);
+
+ foreach (NotificationSubscriber::getSubscribedEvents() as $eventName => $values) {
+ $eventData = array(
+ 'task' => $task,
+ 'comment' => $comment,
+ 'subtask' => $subtask,
+ 'file' => $file,
+ 'task_link' => $tasklink,
+ 'changes' => array()
+ );
+ $this->assertNotEmpty($mailNotification->getMailContent($eventName, $eventData));
+ $this->assertStringStartsWith('[test] ', $mailNotification->getMailSubject($eventName, $eventData));
+ }
+ }
+
+ public function testSendWithEmailAddress()
+ {
+ $mailNotification = new MailNotification($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+ $this->assertTrue($userModel->update(array('id' => 1, 'email' => 'test@localhost')));
+
+ $this->container['emailClient'] = $this
+ ->getMockBuilder('\Kanboard\Core\Mail\Client')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('send'))
+ ->getMock();
+
+ $this->container['emailClient']
+ ->expects($this->once())
+ ->method('send')
+ ->with(
+ $this->equalTo('test@localhost'),
+ $this->equalTo('admin'),
+ $this->equalTo('[test] New task #1: test'),
+ $this->stringContains('test')
+ );
+
+ $mailNotification->notifyUser($userModel->getById(1), TaskModel::EVENT_CREATE, array('task' => $taskFinderModel->getDetails(1)));
+ }
+
+ public function testSendWithoutEmailAddress()
+ {
+ $mailNotification = new MailNotification($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $userModel = new UserModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $this->container['emailClient'] = $this
+ ->getMockBuilder('\Kanboard\Core\Mail\Client')
+ ->setConstructorArgs(array($this->container))
+ ->setMethods(array('send'))
+ ->getMock();
+
+ $this->container['emailClient']
+ ->expects($this->never())
+ ->method('send');
+
+ $mailNotification->notifyUser($userModel->getById(1), TaskModel::EVENT_CREATE, array('task' => $taskFinderModel->getDetails(1)));
+ }
+}
diff --git a/tests/units/Notification/MailTest.php b/tests/units/Notification/MailTest.php
deleted file mode 100644
index 9f077ac8..00000000
--- a/tests/units/Notification/MailTest.php
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\SubtaskModel;
-use Kanboard\Model\CommentModel;
-use Kanboard\Model\UserModel;
-use Kanboard\Model\TaskFileModel;
-use Kanboard\Model\ProjectModel;
-use Kanboard\Model\TaskModel;
-use Kanboard\Notification\MailNotification;
-use Kanboard\Subscriber\NotificationSubscriber;
-
-class MailTest extends Base
-{
- public function testGetMailContent()
- {
- $en = new MailNotification($this->container);
- $p = new ProjectModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $c = new CommentModel($this->container);
- $f = new TaskFileModel($this->container);
-
- $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', 123));
-
- $task = $tf->getDetails(1);
- $subtask = $s->getById(1, true);
- $comment = $c->getById(1);
- $file = $c->getById(1);
-
- $this->assertNotEmpty($task);
- $this->assertNotEmpty($subtask);
- $this->assertNotEmpty($comment);
- $this->assertNotEmpty($file);
-
- foreach (NotificationSubscriber::getSubscribedEvents() as $event => $values) {
- $this->assertNotEmpty($en->getMailContent($event, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array())
- ));
-
- $this->assertNotEmpty($en->getMailSubject($event, array(
- 'task' => $task,
- 'comment' => $comment,
- 'subtask' => $subtask,
- 'file' => $file,
- 'changes' => array())
- ));
- }
- }
-
- public function testSendWithEmailAddress()
- {
- $en = new MailNotification($this->container);
- $p = new ProjectModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $u = new UserModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
- $this->assertTrue($u->update(array('id' => 1, 'email' => 'test@localhost')));
-
- $this->container['emailClient'] = $this
- ->getMockBuilder('\Kanboard\Core\Mail\Client')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array('send'))
- ->getMock();
-
- $this->container['emailClient']
- ->expects($this->once())
- ->method('send')
- ->with(
- $this->equalTo('test@localhost'),
- $this->equalTo('admin'),
- $this->equalTo('[test][New task] test (#1)'),
- $this->stringContains('test')
- );
-
- $en->notifyUser($u->getById(1), TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1)));
- }
-
- public function testSendWithoutEmailAddress()
- {
- $en = new MailNotification($this->container);
- $p = new ProjectModel($this->container);
- $tf = new TaskFinderModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $u = new UserModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
-
- $this->container['emailClient'] = $this
- ->getMockBuilder('\Kanboard\Core\Mail\Client')
- ->setConstructorArgs(array($this->container))
- ->setMethods(array('send'))
- ->getMock();
-
- $this->container['emailClient']
- ->expects($this->never())
- ->method('send');
-
- $en->notifyUser($u->getById(1), TaskModel::EVENT_CREATE, array('task' => $tf->getDetails(1)));
- }
-}
diff --git a/tests/units/Notification/WebhookTest.php b/tests/units/Notification/WebhookNotificationTest.php
index 5a9eb1c7..6fbc349c 100644
--- a/tests/units/Notification/WebhookTest.php
+++ b/tests/units/Notification/WebhookNotificationTest.php
@@ -7,23 +7,23 @@ use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Subscriber\NotificationSubscriber;
-class WebhookTest extends Base
+class WebhookNotificationTest extends Base
{
public function testTaskCreation()
{
- $c = new ConfigModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
+ $configModel = new ConfigModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
$this->container['dispatcher']->addSubscriber(new NotificationSubscriber($this->container));
- $c->save(array('webhook_url' => 'http://localhost/?task-creation'));
+ $configModel->save(array('webhook_url' => 'http://localhost/?task-creation'));
$this->container['httpClient']
->expects($this->once())
->method('postJson')
->with($this->stringContains('http://localhost/?task-creation&token='), $this->anything());
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
}
}
diff --git a/tests/units/Pagination/ProjectPaginationTest.php b/tests/units/Pagination/ProjectPaginationTest.php
new file mode 100644
index 00000000..35532d0d
--- /dev/null
+++ b/tests/units/Pagination/ProjectPaginationTest.php
@@ -0,0 +1,35 @@
+<?php
+
+use Kanboard\Core\Security\Role;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\ProjectUserRoleModel;
+use Kanboard\Model\UserModel;
+use Kanboard\Pagination\ProjectPagination;
+
+require_once __DIR__.'/../Base.php';
+
+class ProjectPaginationTest extends Base
+{
+ public function testDashboardPagination()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $projectUserRoleModel = new ProjectUserRoleModel($this->container);
+ $userModel = new UserModel($this->container);
+ $projectPagination = new ProjectPagination($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'Project #2', 'is_private' => 1)));
+ $this->assertEquals(3, $projectModel->create(array('name' => 'Project #3')));
+ $this->assertEquals(4, $projectModel->create(array('name' => 'Project #4', 'is_private' => 1)));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'test')));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MANAGER));
+
+ $this->assertCount(2, $projectPagination->getDashboardPaginator(2, 'projects', 5)->getCollection());
+ $this->assertCount(0, $projectPagination->getDashboardPaginator(3, 'projects', 5)->getCollection());
+ $this->assertCount(2, $projectPagination->getDashboardPaginator(2, 'projects', 5)->setOrder(ProjectModel::TABLE.'.id')->getCollection());
+ $this->assertCount(2, $projectPagination->getDashboardPaginator(2, 'projects', 5)->setOrder(ProjectModel::TABLE.'.is_private')->getCollection());
+ $this->assertCount(2, $projectPagination->getDashboardPaginator(2, 'projects', 5)->setOrder(ProjectModel::TABLE.'.name')->getCollection());
+ }
+}
diff --git a/tests/units/Pagination/SubtaskPaginationTest.php b/tests/units/Pagination/SubtaskPaginationTest.php
new file mode 100644
index 00000000..26a51a8b
--- /dev/null
+++ b/tests/units/Pagination/SubtaskPaginationTest.php
@@ -0,0 +1,36 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\SubtaskModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Pagination\SubtaskPagination;
+
+require_once __DIR__.'/../Base.php';
+
+class SubtaskPaginationTest extends Base
+{
+ public function testDashboardPagination()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $subtaskPagination = new SubtaskPagination($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('task_id' => 1, 'title' => 'subtask #1', 'user_id' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('task_id' => 2, 'title' => 'subtask #1', 'user_id' => 1)));
+ $this->assertEquals(3, $subtaskModel->create(array('task_id' => 1, 'title' => 'subtask #1', 'user_id' => 1)));
+ $this->assertEquals(4, $subtaskModel->create(array('task_id' => 2, 'title' => 'subtask #1')));
+ $this->assertEquals(5, $subtaskModel->create(array('task_id' => 1, 'title' => 'subtask #1')));
+
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->getCollection());
+ $this->assertCount(0, $subtaskPagination->getDashboardPaginator(2, 'subtasks', 5)->getCollection());
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->setOrder(TaskModel::TABLE.'.id')->getCollection());
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->setOrder('project_name')->getCollection());
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->setOrder('task_name')->getCollection());
+ $this->assertCount(3, $subtaskPagination->getDashboardPaginator(1, 'subtasks', 5)->setOrder(SubtaskModel::TABLE.'.title')->getCollection());
+ }
+}
diff --git a/tests/units/Pagination/TaskPaginationTest.php b/tests/units/Pagination/TaskPaginationTest.php
new file mode 100644
index 00000000..027212e2
--- /dev/null
+++ b/tests/units/Pagination/TaskPaginationTest.php
@@ -0,0 +1,30 @@
+<?php
+
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Pagination\TaskPagination;
+
+require_once __DIR__.'/../Base.php';
+
+class TaskPaginationTest extends Base
+{
+ public function testDashboardPagination()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskPagination = new TaskPagination($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1)));
+
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->getCollection());
+ $this->assertCount(0, $taskPagination->getDashboardPaginator(2, 'tasks', 5)->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder(TaskModel::TABLE.'.id')->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder('project_name')->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder(TaskModel::TABLE.'.title')->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder(TaskModel::TABLE.'.priority')->getCollection());
+ $this->assertCount(1, $taskPagination->getDashboardPaginator(1, 'tasks', 5)->setOrder(TaskModel::TABLE.'.date_due')->getCollection());
+ }
+}
diff --git a/tests/units/Pagination/UserPaginationTest.php b/tests/units/Pagination/UserPaginationTest.php
new file mode 100644
index 00000000..c475aacd
--- /dev/null
+++ b/tests/units/Pagination/UserPaginationTest.php
@@ -0,0 +1,27 @@
+<?php
+
+use Kanboard\Model\UserModel;
+use Kanboard\Pagination\UserPagination;
+
+require_once __DIR__.'/../Base.php';
+
+class UserPaginationTest extends Base
+{
+ public function testListingPagination()
+ {
+ $userModel = new UserModel($this->container);
+ $userPagination = new UserPagination($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'test1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'test2')));
+
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('id')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('username')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('name')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('email')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('role')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('twofactor_activated')->setDirection('DESC')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('is_ldap_user')->getCollection());
+ $this->assertCount(3, $userPagination->getListingPaginator()->setOrder('is_active')->getCollection());
+ }
+}
diff --git a/tests/units/Subscriber/RecurringTaskSubscriberTest.php b/tests/units/Subscriber/RecurringTaskSubscriberTest.php
new file mode 100644
index 00000000..d6aba7cf
--- /dev/null
+++ b/tests/units/Subscriber/RecurringTaskSubscriberTest.php
@@ -0,0 +1,164 @@
+<?php
+
+use Kanboard\EventBuilder\TaskEventBuilder;
+use Kanboard\Model\ProjectModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskModel;
+use Kanboard\Subscriber\RecurringTaskSubscriber;
+
+require_once __DIR__.'/../Base.php';
+
+class RecurringTaskSubscriberTest extends Base
+{
+ public function testWithNoRecurrence()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1)));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceFirstColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_FIRST_COLUMN,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('src_column_id' => 1))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceFirstColumnWithWrongColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_FIRST_COLUMN,
+ 'column_id' => 2,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('src_column_id' => 2))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceLastColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_LAST_COLUMN,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('dst_column_id' => 4))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceLastColumnWithWrongColumn()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_LAST_COLUMN,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withValues(array('dst_column_id' => 2))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(1, $taskFinderModel->countByProjectId(1));
+ }
+
+ public function testWithRecurrenceOnClose()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $subscriber = new RecurringTaskSubscriber($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array(
+ 'title' => 'test',
+ 'project_id' => 1,
+ 'recurrence_status' => TaskModel::RECURRING_STATUS_PENDING,
+ 'recurrence_trigger' => TaskModel::RECURRING_TRIGGER_CLOSE,
+ )));
+
+ $event = TaskEventBuilder::getInstance($this->container)
+ ->withTaskId(1)
+ ->withChanges(array('is_active' => 0))
+ ->buildEvent();
+
+ $subscriber->onMove($event);
+ $subscriber->onClose($event);
+
+ $this->assertEquals(2, $taskFinderModel->countByProjectId(1));
+ }
+}
diff --git a/tests/units/User/Avatar/LetterAvatarProviderTest.php b/tests/units/User/Avatar/LetterAvatarProviderTest.php
index 0eb3ef8e..c145967b 100644
--- a/tests/units/User/Avatar/LetterAvatarProviderTest.php
+++ b/tests/units/User/Avatar/LetterAvatarProviderTest.php
@@ -23,7 +23,7 @@ class LetterAvatarProviderTest extends Base
{
$provider = new LetterAvatarProvider($this->container);
$user = array('id' => 123, 'name' => 'Kanboard Admin', 'username' => 'bob', 'email' => '');
- $expected = '<div class="avatar-letter" style="background-color: rgb(131, 224, 108)" title="Kanboard Admin">KA</div>';
+ $expected = '<div class="avatar-letter" style="background-color: rgb(120, 83, 58)" title="Kanboard Admin">KA</div>';
$this->assertEquals($expected, $provider->render($user, 48));
}
diff --git a/tests/units/Validator/ProjectValidatorTest.php b/tests/units/Validator/ProjectValidatorTest.php
index 07de6c25..e1e2f077 100644
--- a/tests/units/Validator/ProjectValidatorTest.php
+++ b/tests/units/Validator/ProjectValidatorTest.php
@@ -55,13 +55,19 @@ class ProjectValidatorTest extends Base
$r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1'));
$this->assertTrue($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3'));
+ $r = $validator->validateModification(array('id' => 1, 'identifier' => 'test3'));
$this->assertTrue($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => ''));
+ $r = $validator->validateModification(array('id' => 1, 'identifier' => ''));
$this->assertTrue($r[0]);
- $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2'));
+ $r = $validator->validateModification(array('id' => 1, 'identifier' => 'TEST2'));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateModification(array('id' => 1, 'name' => ''));
+ $this->assertFalse($r[0]);
+
+ $r = $validator->validateModification(array('id' => 1, 'name' => null));
$this->assertFalse($r[0]);
}
}