summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/Action/BaseActionTest.php144
-rw-r--r--tests/units/Action/CommentCreationMoveTaskColumnTest.php58
-rw-r--r--tests/units/Action/CommentCreationTest.php165
-rw-r--r--tests/units/Action/TaskAssignCategoryColorTest.php60
-rw-r--r--tests/units/Action/TaskAssignCategoryLabelTest.php85
-rw-r--r--tests/units/Action/TaskAssignCategoryLinkTest.php32
-rw-r--r--tests/units/Action/TaskAssignColorCategoryTest.php90
-rw-r--r--tests/units/Action/TaskAssignColorColumnTest.php55
-rw-r--r--tests/units/Action/TaskAssignColorLinkTest.php67
-rw-r--r--tests/units/Action/TaskAssignColorUserTest.php78
-rw-r--r--tests/units/Action/TaskAssignCurrentUserColumnTest.php75
-rw-r--r--tests/units/Action/TaskAssignCurrentUserTest.php74
-rw-r--r--tests/units/Action/TaskAssignSpecificUserTest.php72
-rw-r--r--tests/units/Action/TaskAssignUserTest.php62
-rw-r--r--tests/units/Action/TaskCloseColumnTest.php53
-rw-r--r--tests/units/Action/TaskCloseTest.php106
-rw-r--r--tests/units/Action/TaskCreationTest.php49
-rw-r--r--tests/units/Action/TaskDuplicateAnotherProjectTest.php95
-rw-r--r--tests/units/Action/TaskEmailTest.php133
-rw-r--r--tests/units/Action/TaskMoveAnotherProjectTest.php90
-rw-r--r--tests/units/Action/TaskMoveColumnAssignedTest.php56
-rw-r--r--tests/units/Action/TaskMoveColumnCategoryChangeTest.php108
-rw-r--r--tests/units/Action/TaskMoveColumnUnAssignedTest.php74
-rw-r--r--tests/units/Action/TaskOpenTest.php51
-rw-r--r--tests/units/Action/TaskUpdateStartDateTest.php54
-rw-r--r--tests/units/Core/Action/ActionManagerTest.php157
-rw-r--r--tests/units/Core/Event/EventManagerTest.php18
-rw-r--r--tests/units/Integration/BitbucketWebhookTest.php2
-rw-r--r--tests/units/Integration/GithubWebhookTest.php2
-rw-r--r--tests/units/Integration/GitlabWebhookTest.php2
-rw-r--r--tests/units/Model/ActionTest.php698
-rw-r--r--tests/units/Model/ProjectDuplicationTest.php6
32 files changed, 1827 insertions, 1044 deletions
diff --git a/tests/units/Action/BaseActionTest.php b/tests/units/Action/BaseActionTest.php
new file mode 100644
index 00000000..1d50c70e
--- /dev/null
+++ b/tests/units/Action/BaseActionTest.php
@@ -0,0 +1,144 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\GenericEvent;
+
+class DummyAction extends Kanboard\Action\Base
+{
+ public function getDescription()
+ {
+ return 'Dummy Action';
+ }
+
+ public function getCompatibleEvents()
+ {
+ return array('my.event');
+ }
+
+ public function getActionRequiredParameters()
+ {
+ return array('p1' => 'Param 1');
+ }
+
+ public function getEventRequiredParameters()
+ {
+ return array('p1', 'p2');
+ }
+
+ public function doAction(array $data)
+ {
+ return true;
+ }
+
+ public function hasRequiredCondition(array $data)
+ {
+ return $data['p1'] == $this->getParam('p1');
+ }
+}
+
+class BaseActionTest extends Base
+{
+ public function testGetName()
+ {
+ $dummyAction = new DummyAction($this->container);
+ $this->assertEquals('\\DummyAction', $dummyAction->getName());
+ }
+
+ public function testGetDescription()
+ {
+ $dummyAction = new DummyAction($this->container);
+ $this->assertEquals('Dummy Action', $dummyAction->getDescription());
+ }
+
+ public function testGetActionRequiredParameters()
+ {
+ $dummyAction = new DummyAction($this->container);
+ $this->assertEquals(array('p1' => 'Param 1'), $dummyAction->getActionRequiredParameters());
+ }
+
+ public function testGetEventRequiredParameters()
+ {
+ $dummyAction = new DummyAction($this->container);
+ $this->assertEquals(array('p1', 'p2'), $dummyAction->getEventRequiredParameters());
+ }
+
+ public function testGetCompatibleEvents()
+ {
+ $dummyAction = new DummyAction($this->container);
+ $this->assertEquals(array('my.event'), $dummyAction->getCompatibleEvents());
+ }
+
+ public function testHasRequiredCondition()
+ {
+ $dummyAction = new DummyAction($this->container);
+ $dummyAction->setParam('p1', 123);
+ $this->assertTrue($dummyAction->hasRequiredCondition(array('p1' => 123)));
+ $this->assertFalse($dummyAction->hasRequiredCondition(array('p1' => 456)));
+ }
+
+ public function testProjectId()
+ {
+ $dummyAction = new DummyAction($this->container);
+ $this->assertInstanceOf('DummyAction', $dummyAction->setProjectId(123));
+ $this->assertEquals(123, $dummyAction->getProjectId());
+ }
+
+ public function testParam()
+ {
+ $dummyAction = new DummyAction($this->container);
+ $this->assertInstanceOf('DummyAction', $dummyAction->setParam('p1', 123));
+ $this->assertEquals(123, $dummyAction->getParam('p1'));
+ }
+
+ public function testHasCompatibleEvents()
+ {
+ $dummyAction = new DummyAction($this->container);
+ $this->assertTrue($dummyAction->hasCompatibleEvent('my.event'));
+ $this->assertFalse($dummyAction->hasCompatibleEvent('foobar'));
+ }
+
+ public function testHasRequiredProject()
+ {
+ $dummyAction = new DummyAction($this->container);
+ $dummyAction->setProjectId(1234);
+
+ $this->assertTrue($dummyAction->hasRequiredProject(array('project_id' => 1234)));
+ $this->assertFalse($dummyAction->hasRequiredProject(array('project_id' => 1)));
+ $this->assertFalse($dummyAction->hasRequiredProject(array()));
+ }
+
+ public function testHasRequiredParameters()
+ {
+ $dummyAction = new DummyAction($this->container);
+ $dummyAction->setProjectId(1234);
+
+ $this->assertTrue($dummyAction->hasRequiredParameters(array('p1' => 12, 'p2' => 34)));
+ $this->assertFalse($dummyAction->hasRequiredParameters(array('p1' => 12)));
+ $this->assertFalse($dummyAction->hasRequiredParameters(array()));
+ }
+
+ public function testAddEvent()
+ {
+ $dummyAction = new DummyAction($this->container);
+ $dummyAction->addEvent('foobar', 'FooBar');
+ $dummyAction->addEvent('my.event', 'My Event Overrided');
+
+ $events = $dummyAction->getEvents();
+ $this->assertcount(2, $events);
+ $this->assertEquals(array('my.event', 'foobar'), $events);
+ }
+
+ public function testExecuteOnlyOnce()
+ {
+ $dummyAction = new DummyAction($this->container);
+ $dummyAction->setProjectId(1234);
+ $dummyAction->setParam('p1', 'something');
+ $dummyAction->addEvent('foobar', 'FooBar');
+
+ $event = new GenericEvent(array('project_id' => 1234, 'p1' => 'something', 'p2' => 'abc'));
+
+ $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
new file mode 100644
index 00000000..87ee86ea
--- /dev/null
+++ b/tests/units/Action/CommentCreationMoveTaskColumnTest.php
@@ -0,0 +1,58 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\GenericEvent;
+use Kanboard\Model\Task;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\Comment;
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectUserRole;
+use Kanboard\Action\CommentCreationMoveTaskColumn;
+
+class CommentCreationMoveTaskColumnTest extends Base
+{
+ public function testSuccess()
+ {
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ $projectModel = new Project($this->container);
+ $commentModel = new Comment($this->container);
+ $taskCreationModel = new TaskCreation($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, 'column_id' => 2));
+
+ $action = new CommentCreationMoveTaskColumn($this->container);
+ $action->setProjectId(1);
+ $action->setParam('column_id', 2);
+
+ $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN));
+
+ $comment = $commentModel->getById(1);
+ $this->assertNotEmpty($comment);
+ $this->assertEquals(1, $comment['task_id']);
+ $this->assertEquals(1, $comment['user_id']);
+ $this->assertEquals('Moved to column Ready', $comment['comment']);
+ }
+
+ public function testWithUserNotLogged()
+ {
+ $projectModel = new Project($this->container);
+ $commentModel = new Comment($this->container);
+ $taskCreationModel = new TaskCreation($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, 'column_id' => 3));
+
+ $action = new CommentCreationMoveTaskColumn($this->container);
+ $action->setProjectId(1);
+ $action->setParam('column_id', 2);
+
+ $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN));
+ }
+}
diff --git a/tests/units/Action/CommentCreationTest.php b/tests/units/Action/CommentCreationTest.php
index 8a689309..8460a350 100644
--- a/tests/units/Action/CommentCreationTest.php
+++ b/tests/units/Action/CommentCreationTest.php
@@ -7,119 +7,88 @@ use Kanboard\Model\Task;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\Comment;
use Kanboard\Model\Project;
-use Kanboard\Integration\GithubWebhook;
+use Kanboard\Model\ProjectUserRole;
+use Kanboard\Model\User;
use Kanboard\Action\CommentCreation;
+use Kanboard\Core\Security\Role;
class CommentCreationTest extends Base
{
- public function testWithoutRequiredParams()
+ public function testSuccess()
{
- $action = new CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
-
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $p = new Project($this->container);
- $c = new Comment($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
-
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'user_id' => 1,
- );
-
- // Our event should be executed
- $this->assertFalse($action->execute(new GenericEvent($event)));
-
- $comment = $c->getById(1);
- $this->assertEmpty($comment);
- }
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $commentModel = new Comment($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
- public function testWithCommitMessage()
- {
- $action = new CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
-
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $p = new Project($this->container);
- $c = new Comment($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
-
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'commit_comment' => 'plop',
- );
-
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
-
- $comment = $c->getById(1);
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'comment' => 'test123', 'reference' => 'ref123', 'user_id' => 2));
+
+ $action = new CommentCreation($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
+
+ $this->assertTrue($action->execute($event, 'test.event'));
+
+ $comment = $commentModel->getById(1);
$this->assertNotEmpty($comment);
$this->assertEquals(1, $comment['task_id']);
- $this->assertEquals(0, $comment['user_id']);
- $this->assertEquals('plop', $comment['comment']);
+ $this->assertEquals('test123', $comment['comment']);
+ $this->assertEquals('ref123', $comment['reference']);
+ $this->assertEquals(2, $comment['user_id']);
}
- public function testWithUser()
+ public function testWithUserNotAssignable()
{
- $action = new CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
-
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $p = new Project($this->container);
- $c = new Comment($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
-
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'user_id' => 1,
- 'comment' => 'youpi',
- );
-
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
-
- $comment = $c->getById(1);
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $commentModel = new Comment($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'comment' => 'test123', 'user_id' => 2));
+
+ $action = new CommentCreation($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
+
+ $this->assertTrue($action->execute($event, 'test.event'));
+
+ $comment = $commentModel->getById(1);
$this->assertNotEmpty($comment);
$this->assertEquals(1, $comment['task_id']);
- $this->assertEquals(1, $comment['user_id']);
- $this->assertEquals('youpi', $comment['comment']);
+ $this->assertEquals('test123', $comment['comment']);
+ $this->assertEquals('', $comment['reference']);
+ $this->assertEquals(0, $comment['user_id']);
}
- public function testWithNoUser()
+ public function testWithNoComment()
{
- $action = new CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
-
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $p = new Project($this->container);
- $c = new Comment($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
-
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'user_id' => 0,
- 'comment' => 'youpi',
- );
-
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
-
- $comment = $c->getById(1);
- $this->assertNotEmpty($comment);
- $this->assertEquals(1, $comment['task_id']);
- $this->assertEquals(0, $comment['user_id']);
- $this->assertEquals('youpi', $comment['comment']);
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $commentModel = new Comment($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
+
+ $action = new CommentCreation($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
+
+ $this->assertFalse($action->execute($event, 'test.event'));
}
}
diff --git a/tests/units/Action/TaskAssignCategoryColorTest.php b/tests/units/Action/TaskAssignCategoryColorTest.php
new file mode 100644
index 00000000..bd8181e8
--- /dev/null
+++ b/tests/units/Action/TaskAssignCategoryColorTest.php
@@ -0,0 +1,60 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\GenericEvent;
+use Kanboard\Model\Category;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Project;
+use Kanboard\Model\Task;
+use Kanboard\Action\TaskAssignCategoryColor;
+
+class TaskAssignCategoryColorTest extends Base
+{
+ public function testChangeCategory()
+ {
+ $categoryModel = new Category($this->container);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $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'));
+
+ $action = new TaskAssignCategoryColor($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
+ $action->setParam('category_id', 1);
+
+ $this->assertTrue($action->execute($event, Task::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['category_id']);
+ }
+
+ public function testWithWrongColor()
+ {
+ $categoryModel = new Category($this->container);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $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'));
+
+ $action = new TaskAssignCategoryColor($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
+ $action->setParam('category_id', 1);
+
+ $this->assertFalse($action->execute($event, Task::EVENT_CREATE_UPDATE));
+ }
+}
diff --git a/tests/units/Action/TaskAssignCategoryLabelTest.php b/tests/units/Action/TaskAssignCategoryLabelTest.php
new file mode 100644
index 00000000..bf8bdb5b
--- /dev/null
+++ b/tests/units/Action/TaskAssignCategoryLabelTest.php
@@ -0,0 +1,85 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\GenericEvent;
+use Kanboard\Model\Category;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Project;
+use Kanboard\Action\TaskAssignCategoryLabel;
+
+class TaskAssignCategoryLabelTest extends Base
+{
+ public function testChangeCategory()
+ {
+ $categoryModel = new Category($this->container);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $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, 'label' => 'foobar'));
+
+ $action = new TaskAssignCategoryLabel($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
+ $action->setParam('label', 'foobar');
+ $action->setParam('category_id', 1);
+
+ $this->assertTrue($action->execute($event, 'test.event'));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['category_id']);
+ }
+
+ public function testWithWrongLabel()
+ {
+ $categoryModel = new Category($this->container);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $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, 'label' => 'something'));
+
+ $action = new TaskAssignCategoryLabel($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
+ $action->setParam('label', 'foobar');
+ $action->setParam('category_id', 1);
+
+ $this->assertFalse($action->execute($event, 'test.event'));
+ }
+
+ public function testWithExistingCategory()
+ {
+ $categoryModel = new Category($this->container);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
+ $this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 1)));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'category_id' => 2)));
+
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'label' => 'foobar', 'category_id' => 2));
+
+ $action = new TaskAssignCategoryLabel($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
+ $action->setParam('label', 'foobar');
+ $action->setParam('category_id', 1);
+
+ $this->assertFalse($action->execute($event, 'test.event'));
+ }
+}
diff --git a/tests/units/Action/TaskAssignCategoryLinkTest.php b/tests/units/Action/TaskAssignCategoryLinkTest.php
index 4f2d757e..f638e017 100644
--- a/tests/units/Action/TaskAssignCategoryLinkTest.php
+++ b/tests/units/Action/TaskAssignCategoryLinkTest.php
@@ -20,7 +20,8 @@ class TaskAssignCategoryLinkTest extends Base
$p = new Project($this->container);
$c = new Category($this->container);
- $action = new TaskAssignCategoryLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE);
+ $action = new TaskAssignCategoryLink($this->container);
+ $action->setProjectId(1);
$action->setParam('category_id', 1);
$action->setParam('link_id', 2);
@@ -28,30 +29,28 @@ class TaskAssignCategoryLinkTest extends Base
$this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
$this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
- $task = $tf->getById(1);
- $this->assertEquals(0, $task['category_id']);
-
- $event = array(
+ $event = new TaskLinkEvent(array(
'project_id' => 1,
'task_id' => 1,
'opposite_task_id' => 2,
'link_id' => 2,
- );
+ ));
- $this->assertTrue($action->execute(new TaskLinkEvent($event)));
+ $this->assertTrue($action->execute($event, TaskLink::EVENT_CREATE_UPDATE));
$task = $tf->getById(1);
$this->assertEquals(1, $task['category_id']);
}
- public function testThatLinkDontMatch()
+ public function testWhenLinkDontMatch()
{
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
$c = new Category($this->container);
- $action = new TaskAssignCategoryLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE);
+ $action = new TaskAssignCategoryLink($this->container);
+ $action->setProjectId(1);
$action->setParam('category_id', 1);
$action->setParam('link_id', 1);
@@ -59,14 +58,14 @@ class TaskAssignCategoryLinkTest extends Base
$this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
$this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
- $event = array(
+ $event = new TaskLinkEvent(array(
'project_id' => 1,
'task_id' => 1,
'opposite_task_id' => 2,
'link_id' => 2,
- );
+ ));
- $this->assertFalse($action->execute(new TaskLinkEvent($event)));
+ $this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE));
}
public function testThatExistingCategoryWillNotChange()
@@ -76,7 +75,8 @@ class TaskAssignCategoryLinkTest extends Base
$p = new Project($this->container);
$c = new Category($this->container);
- $action = new TaskAssignCategoryLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE);
+ $action = new TaskAssignCategoryLink($this->container);
+ $action->setProjectId(1);
$action->setParam('category_id', 2);
$action->setParam('link_id', 2);
@@ -85,13 +85,13 @@ class TaskAssignCategoryLinkTest extends Base
$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)));
- $event = array(
+ $event = new TaskLinkEvent(array(
'project_id' => 1,
'task_id' => 1,
'opposite_task_id' => 2,
'link_id' => 2,
- );
+ ));
- $this->assertFalse($action->execute(new TaskLinkEvent($event)));
+ $this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE));
}
}
diff --git a/tests/units/Action/TaskAssignColorCategoryTest.php b/tests/units/Action/TaskAssignColorCategoryTest.php
index 1bd3493b..9f188645 100644
--- a/tests/units/Action/TaskAssignColorCategoryTest.php
+++ b/tests/units/Action/TaskAssignColorCategoryTest.php
@@ -2,80 +2,58 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Model\Task;
+use Kanboard\Event\GenericEvent;
+use Kanboard\Model\Category;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
use Kanboard\Model\Project;
-use Kanboard\Model\Category;
-use Kanboard\Event\GenericEvent;
+use Kanboard\Model\Task;
use Kanboard\Action\TaskAssignColorCategory;
class TaskAssignColorCategoryTest extends Base
{
- public function testBadProject()
+ public function testChangeColor()
{
- $action = new TaskAssignColorCategory($this->container, 3, Task::EVENT_CREATE_UPDATE);
+ $categoryModel = new Category($this->container);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
- $event = array(
- 'project_id' => 2,
- 'task_id' => 3,
- 'column_id' => 5,
- );
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
- $this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute(new GenericEvent($event)));
- }
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'category_id' => 1));
- public function testExecute()
- {
- $action = new TaskAssignColorCategory($this->container, 1, Task::EVENT_CREATE_UPDATE);
+ $action = new TaskAssignColorCategory($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
$action->setParam('category_id', 1);
- $action->setParam('color_id', 'blue');
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $c = new Category($this->container);
+ $this->assertTrue($action->execute($event, Task::EVENT_CREATE_UPDATE));
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $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' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green', 'category_id' => 2)));
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('red', $task['color_id']);
+ }
- // We create an event but we don't do anything
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 1,
- 'category_id' => 2,
- 'position' => 2,
- );
+ public function testWithWrongCategory()
+ {
+ $categoryModel = new Category($this->container);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
- // Our event should NOT be executed
- $this->assertFalse($action->execute(new GenericEvent($event)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- // Our task should be assigned to the ategory_id=1 and have the green color
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(2, $task['category_id']);
- $this->assertEquals('green', $task['color_id']);
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'category_id' => 2));
- // We create an event to move the task
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 1,
- 'position' => 5,
- 'category_id' => 1,
- );
-
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
+ $action = new TaskAssignColorCategory($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
+ $action->setParam('category_id', 1);
- // Our task should have the blue color
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals('blue', $task['color_id']);
+ $this->assertFalse($action->execute($event, Task::EVENT_CREATE_UPDATE));
}
}
diff --git a/tests/units/Action/TaskAssignColorColumnTest.php b/tests/units/Action/TaskAssignColorColumnTest.php
index c09dc96e..e5858b19 100644
--- a/tests/units/Action/TaskAssignColorColumnTest.php
+++ b/tests/units/Action/TaskAssignColorColumnTest.php
@@ -3,40 +3,53 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
-use Kanboard\Model\Task;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
use Kanboard\Model\Project;
+use Kanboard\Model\Task;
use Kanboard\Action\TaskAssignColorColumn;
class TaskAssignColorColumnTest extends Base
{
- public function testColorChange()
+ public function testChangeColumn()
{
- $action = new TaskAssignColorColumn($this->container, 1, Task::EVENT_MOVE_COLUMN);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($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, 'column_id' => 2));
+
+ $action = new TaskAssignColorColumn($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
$action->setParam('column_id', 2);
- $action->setParam('color_id', 'green');
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
+ $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN));
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'yellow')));
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('red', $task['color_id']);
+ }
+
+ public function testWithWrongCategory()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 2,
- 'color_id' => 'green',
- );
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+
+ $action = new TaskAssignColorColumn($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
+ $action->setParam('column_id', 2);
- // Our task should have color green
- $task = $tf->getById(1);
- $this->assertEquals('green', $task['color_id']);
+ $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN));
}
}
diff --git a/tests/units/Action/TaskAssignColorLinkTest.php b/tests/units/Action/TaskAssignColorLinkTest.php
index 36a831dd..d89c8b06 100644
--- a/tests/units/Action/TaskAssignColorLinkTest.php
+++ b/tests/units/Action/TaskAssignColorLinkTest.php
@@ -2,47 +2,54 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Event\TaskLinkEvent;
-use Kanboard\Model\Task;
+use Kanboard\Event\GenericEvent;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
-use Kanboard\Model\TaskLink;
use Kanboard\Model\Project;
+use Kanboard\Model\TaskLink;
use Kanboard\Action\TaskAssignColorLink;
class TaskAssignColorLinkTest extends Base
{
- public function testExecute()
+ public function testChangeColor()
{
- $action = new TaskAssignColorLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE);
- $action->setParam('link_id', 2);
- $action->setParam('color_id', 'green');
-
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $tl = new TaskLink($this->container);
- $p = new Project($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
-
- // The color should be yellow
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals('yellow', $task['color_id']);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'link_id' => 2,
- );
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- // Our event should be executed
- $this->assertTrue($action->execute(new TaskLinkEvent($event)));
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'link_id' => 1));
- // The color should be green
- $task = $tf->getById(1);
+ $action = new TaskAssignColorLink($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
+ $action->setParam('link_id', 1);
+
+ $this->assertTrue($action->execute($event, TaskLink::EVENT_CREATE_UPDATE));
+
+ $task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
- $this->assertEquals('green', $task['color_id']);
+ $this->assertEquals('red', $task['color_id']);
+ }
+
+ public function testWithWrongLink()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($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));
+
+ $action = new TaskAssignColorLink($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
+ $action->setParam('link_id', 1);
+
+ $this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE));
}
}
diff --git a/tests/units/Action/TaskAssignColorUserTest.php b/tests/units/Action/TaskAssignColorUserTest.php
index ea2a8f38..e2656cc0 100644
--- a/tests/units/Action/TaskAssignColorUserTest.php
+++ b/tests/units/Action/TaskAssignColorUserTest.php
@@ -2,72 +2,54 @@
require_once __DIR__.'/../Base.php';
-use Kanboard\Model\Task;
+use Kanboard\Event\GenericEvent;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
use Kanboard\Model\Project;
-use Kanboard\Event\GenericEvent;
+use Kanboard\Model\Task;
use Kanboard\Action\TaskAssignColorUser;
class TaskAssignColorUserTest extends Base
{
- public function testBadProject()
+ public function testChangeColor()
{
- $action = new TaskAssignColorUser($this->container, 3, Task::EVENT_CREATE);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
- $event = array(
- 'project_id' => 2,
- 'task_id' => 3,
- 'column_id' => 5,
- );
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute(new GenericEvent($event)));
- }
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'owner_id' => 1));
- public function testExecute()
- {
- $action = new TaskAssignColorUser($this->container, 1, Task::EVENT_ASSIGNEE_CHANGE);
+ $action = new TaskAssignColorUser($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
$action->setParam('user_id', 1);
- $action->setParam('color_id', 'blue');
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green')));
+ $this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE));
- // We change the assignee
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'owner_id' => 5,
- );
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('red', $task['color_id']);
+ }
- // Our event should NOT be executed
- $this->assertFalse($action->execute(new GenericEvent($event)));
+ public function testWithWrongUser()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
- // Our task should be assigned to nobody and have the green color
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals('green', $task['color_id']);
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- // We change the assignee
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'owner_id' => 1,
- );
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'owner_id' => 2));
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
+ $action = new TaskAssignColorUser($this->container);
+ $action->setProjectId(1);
+ $action->setParam('color_id', 'red');
+ $action->setParam('user_id', 1);
- // Our task should be assigned to nobody and have the blue color
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['owner_id']);
- $this->assertEquals('blue', $task['color_id']);
+ $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE));
}
}
diff --git a/tests/units/Action/TaskAssignCurrentUserColumnTest.php b/tests/units/Action/TaskAssignCurrentUserColumnTest.php
new file mode 100644
index 00000000..41576ee4
--- /dev/null
+++ b/tests/units/Action/TaskAssignCurrentUserColumnTest.php
@@ -0,0 +1,75 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\GenericEvent;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Project;
+use Kanboard\Model\Task;
+use Kanboard\Action\TaskAssignCurrentUserColumn;
+
+class TaskAssignCurrentUserColumnTest extends Base
+{
+ public function testChangeUser()
+ {
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($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, 'column_id' => 2));
+
+ $action = new TaskAssignCurrentUserColumn($this->container);
+ $action->setProjectId(1);
+ $action->setParam('column_id', 2);
+
+ $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['owner_id']);
+ }
+
+ public function testWithWrongColumn()
+ {
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($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, 'column_id' => 3));
+
+ $action = new TaskAssignCurrentUserColumn($this->container);
+ $action->setProjectId(1);
+ $action->setParam('column_id', 2);
+
+ $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN));
+ }
+
+ public function testWithNoUserSession()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($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, 'column_id' => 2));
+
+ $action = new TaskAssignCurrentUserColumn($this->container);
+ $action->setProjectId(1);
+ $action->setParam('column_id', 2);
+
+ $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN));
+ }
+}
diff --git a/tests/units/Action/TaskAssignCurrentUserTest.php b/tests/units/Action/TaskAssignCurrentUserTest.php
index e2d1c11a..2fe84a5d 100644
--- a/tests/units/Action/TaskAssignCurrentUserTest.php
+++ b/tests/units/Action/TaskAssignCurrentUserTest.php
@@ -3,73 +3,51 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
-use Kanboard\Model\Task;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
use Kanboard\Model\Project;
-use Kanboard\Core\User\UserSession;
+use Kanboard\Model\Task;
use Kanboard\Action\TaskAssignCurrentUser;
class TaskAssignCurrentUserTest extends Base
{
- public function testBadProject()
+ public function testChangeUser()
{
- $action = new TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE);
- $action->setParam('column_id', 5);
+ $this->container['sessionStorage']->user = array('id' => 1);
- $event = array(
- 'project_id' => 2,
- 'task_id' => 3,
- 'column_id' => 5,
- );
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
- $this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute(new GenericEvent($event)));
- }
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- public function testBadColumn()
- {
- $action = new TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE);
- $action->setParam('column_id', 5);
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
+
+ $action = new TaskAssignCurrentUser($this->container);
+ $action->setProjectId(1);
- $event = array(
- 'project_id' => 3,
- 'task_id' => 3,
- 'column_id' => 3,
- );
+ $this->assertTrue($action->execute($event, Task::EVENT_CREATE));
- $this->assertFalse($action->execute(new GenericEvent($event)));
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['owner_id']);
}
- public function testExecute()
+ public function testWithNoUserSession()
{
- $this->container['sessionStorage']->user = array('id' => 5);
-
- $action = new TaskAssignCurrentUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 2);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 2,
- );
+ $action = new TaskAssignCurrentUser($this->container);
+ $action->setProjectId(1);
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
-
- // Our task should be assigned to the user 5 (from the session)
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['id']);
- $this->assertEquals(5, $task['owner_id']);
+ $this->assertFalse($action->execute($event, Task::EVENT_CREATE));
}
}
diff --git a/tests/units/Action/TaskAssignSpecificUserTest.php b/tests/units/Action/TaskAssignSpecificUserTest.php
index a67335e8..67b2c397 100644
--- a/tests/units/Action/TaskAssignSpecificUserTest.php
+++ b/tests/units/Action/TaskAssignSpecificUserTest.php
@@ -3,69 +3,53 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
-use Kanboard\Model\Task;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
use Kanboard\Model\Project;
+use Kanboard\Model\Task;
use Kanboard\Action\TaskAssignSpecificUser;
class TaskAssignSpecificUserTest extends Base
{
- public function testBadProject()
+ public function testChangeUser()
{
- $action = new TaskAssignSpecificUser($this->container, 3, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 5);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
- $event = array(
- 'project_id' => 2,
- 'task_id' => 3,
- 'column_id' => 5,
- );
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 0)));
- $this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute(new GenericEvent($event)));
- }
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
- public function testBadColumn()
- {
- $action = new TaskAssignSpecificUser($this->container, 3, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 5);
+ $action = new TaskAssignSpecificUser($this->container);
+ $action->setProjectId(1);
+ $action->setParam('column_id', 2);
+ $action->setParam('user_id', 1);
- $event = array(
- 'project_id' => 3,
- 'task_id' => 3,
- 'column_id' => 3,
- );
+ $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN));
- $this->assertFalse($action->execute(new GenericEvent($event)));
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['owner_id']);
}
- public function testExecute()
+ public function testWithWrongColumn()
{
- $action = new TaskAssignSpecificUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 2);
- $action->setParam('user_id', 1);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 2,
- );
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
+ $action = new TaskAssignSpecificUser($this->container);
+ $action->setProjectId(1);
+ $action->setParam('column_id', 2);
+ $action->setParam('user_id', 1);
- // Our task should be assigned to the user 1
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['owner_id']);
+ $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN));
}
}
diff --git a/tests/units/Action/TaskAssignUserTest.php b/tests/units/Action/TaskAssignUserTest.php
new file mode 100644
index 00000000..d1cb72b9
--- /dev/null
+++ b/tests/units/Action/TaskAssignUserTest.php
@@ -0,0 +1,62 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\GenericEvent;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectUserRole;
+use Kanboard\Model\User;
+use Kanboard\Model\Task;
+use Kanboard\Action\TaskAssignUser;
+use Kanboard\Core\Security\Role;
+
+class TaskAssignUserTest extends Base
+{
+ public function testChangeUser()
+ {
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 0)));
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'owner_id' => 2));
+
+ $action = new TaskAssignUser($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
+
+ $this->assertTrue($action->execute($event, 'test.event'));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(2, $task['owner_id']);
+ }
+
+ public function testWithNotAssignableUser()
+ {
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($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, 'owner_id' => 1));
+
+ $action = new TaskAssignUser($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
+
+ $this->assertFalse($action->execute($event, 'test.event'));
+ }
+}
diff --git a/tests/units/Action/TaskCloseColumnTest.php b/tests/units/Action/TaskCloseColumnTest.php
new file mode 100644
index 00000000..ce41bb41
--- /dev/null
+++ b/tests/units/Action/TaskCloseColumnTest.php
@@ -0,0 +1,53 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\GenericEvent;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Project;
+use Kanboard\Model\Task;
+use Kanboard\Action\TaskCloseColumn;
+
+class TaskCloseColumnTest extends Base
+{
+ public function testClose()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($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, 'column_id' => 2));
+
+ $action = new TaskCloseColumn($this->container);
+ $action->setProjectId(1);
+ $action->setParam('column_id', 2);
+
+ $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['is_active']);
+ }
+
+ public function testWithWrongColumn()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($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, 'column_id' => 3));
+
+ $action = new TaskCloseColumn($this->container);
+ $action->setProjectId(1);
+ $action->setParam('column_id', 2);
+
+ $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN));
+ }
+}
diff --git a/tests/units/Action/TaskCloseTest.php b/tests/units/Action/TaskCloseTest.php
index b2d83194..536d79ca 100644
--- a/tests/units/Action/TaskCloseTest.php
+++ b/tests/units/Action/TaskCloseTest.php
@@ -3,107 +3,49 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
-use Kanboard\Model\Task;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
use Kanboard\Model\Project;
-use Kanboard\Integration\GithubWebhook;
use Kanboard\Action\TaskClose;
class TaskCloseTest extends Base
{
- public function testExecutable()
+ public function testClose()
{
- $action = new TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 5);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
- $event = array(
- 'project_id' => 3,
- 'task_id' => 3,
- 'column_id' => 5,
- );
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $this->assertTrue($action->isExecutable($event));
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
- $action = new TaskClose($this->container, 3, GithubWebhook::EVENT_COMMIT);
+ $action = new TaskClose($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
- $event = array(
- 'project_id' => 3,
- 'task_id' => 3,
- );
+ $this->assertTrue($action->execute($event, 'test.event'));
- $this->assertTrue($action->isExecutable($event));
- }
-
- public function testBadEvent()
- {
- $action = new TaskClose($this->container, 3, Task::EVENT_UPDATE);
- $action->setParam('column_id', 5);
-
- $event = array(
- 'project_id' => 3,
- 'task_id' => 3,
- 'column_id' => 5,
- );
-
- $this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute(new GenericEvent($event)));
- }
-
- public function testBadProject()
- {
- $action = new TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 5);
-
- $event = array(
- 'project_id' => 2,
- 'task_id' => 3,
- 'column_id' => 5,
- );
-
- $this->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute(new GenericEvent($event)));
- }
-
- public function testBadColumn()
- {
- $action = new TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 5);
-
- $event = array(
- 'project_id' => 3,
- 'task_id' => 3,
- 'column_id' => 3,
- );
-
- $this->assertFalse($action->execute(new GenericEvent($event)));
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['is_active']);
}
- public function testExecute()
+ public function testWithNoTaskId()
{
- $action = new TaskClose($this->container, 1, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 2);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 2,
- );
+ $event = new GenericEvent(array('project_id' => 1));
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
+ $action = new TaskClose($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
- // Our task should be closed
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(0, $task['is_active']);
+ $this->assertFalse($action->execute($event, 'test.event'));
}
}
diff --git a/tests/units/Action/TaskCreationTest.php b/tests/units/Action/TaskCreationTest.php
new file mode 100644
index 00000000..57c2995d
--- /dev/null
+++ b/tests/units/Action/TaskCreationTest.php
@@ -0,0 +1,49 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\GenericEvent;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Project;
+use Kanboard\Action\TaskCreation as TaskCreationAction;
+
+class TaskCreationActionTest extends Base
+{
+ public function testSuccess()
+ {
+ $projectModel = new Project($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'title' => 'test123', 'reference' => 'ref123', 'description' => 'test'));
+
+ $action = new TaskCreationAction($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
+
+ $this->assertTrue($action->execute($event, 'test.event'));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test123', $task['title']);
+ $this->assertEquals('ref123', $task['reference']);
+ $this->assertEquals('test', $task['description']);
+ }
+
+ public function testWithNoTitle()
+ {
+ $projectModel = new Project($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'reference' => 'ref123', 'description' => 'test'));
+
+ $action = new TaskCreationAction($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
+
+ $this->assertFalse($action->execute($event, 'test.event'));
+ }
+}
diff --git a/tests/units/Action/TaskDuplicateAnotherProjectTest.php b/tests/units/Action/TaskDuplicateAnotherProjectTest.php
index 50cbad01..d9491dd9 100644
--- a/tests/units/Action/TaskDuplicateAnotherProjectTest.php
+++ b/tests/units/Action/TaskDuplicateAnotherProjectTest.php
@@ -4,92 +4,53 @@ require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
use Kanboard\Model\Task;
-use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
+use Kanboard\Model\TaskCreation;
use Kanboard\Model\Project;
use Kanboard\Action\TaskDuplicateAnotherProject;
class TaskDuplicateAnotherProjectTest extends Base
{
- public function testBadProject()
+ public function testSuccess()
{
- $action = new TaskDuplicateAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 5);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
- $event = array(
- 'project_id' => 2,
- 'task_id' => 3,
- 'column_id' => 5,
- );
+ $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->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute(new GenericEvent($event)));
- }
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
- public function testBadColumn()
- {
- $action = new TaskDuplicateAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 5);
+ $action = new TaskDuplicateAnotherProject($this->container);
+ $action->setProjectId(1);
+ $action->setParam('project_id', 2);
+ $action->setParam('column_id', 2);
- $event = array(
- 'project_id' => 3,
- 'task_id' => 3,
- 'column_id' => 3,
- );
+ $this->assertTrue($action->execute($event, Task::EVENT_CLOSE));
- $this->assertFalse($action->execute(new GenericEvent($event)));
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(2, $task['project_id']);
}
- public function testExecute()
+ public function testWithWrongColumn()
{
- $action = new TaskDuplicateAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'project 1')));
- $this->assertEquals(2, $p->create(array('name' => 'project 2')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 2,
- );
-
- // Our event should NOT be executed because we define the same project
- $action->setParam('column_id', 2);
- $action->setParam('project_id', 1);
- $this->assertFalse($action->execute(new GenericEvent($event)));
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
- // Our task should be assigned to the project 1
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['project_id']);
-
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 2,
- );
-
- // Our event should be executed because we define a different project
- $action->setParam('column_id', 2);
+ $action = new TaskDuplicateAnotherProject($this->container);
+ $action->setProjectId(1);
$action->setParam('project_id', 2);
- $this->assertTrue($action->hasRequiredCondition($event));
- $this->assertTrue($action->execute(new GenericEvent($event)));
-
- // Our task should be assigned to the project 1
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['project_id']);
+ $action->setParam('column_id', 2);
- // We should have another task assigned to the project 2
- $task = $tf->getById(2);
- $this->assertNotEmpty($task);
- $this->assertEquals(2, $task['project_id']);
+ $this->assertFalse($action->execute($event, Task::EVENT_CLOSE));
}
}
diff --git a/tests/units/Action/TaskEmailTest.php b/tests/units/Action/TaskEmailTest.php
index 404865f4..ef32a296 100644
--- a/tests/units/Action/TaskEmailTest.php
+++ b/tests/units/Action/TaskEmailTest.php
@@ -5,98 +5,30 @@ require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
use Kanboard\Model\Task;
use Kanboard\Model\TaskCreation;
-use Kanboard\Model\TaskFinder;
use Kanboard\Model\Project;
use Kanboard\Model\User;
use Kanboard\Action\TaskEmail;
class TaskEmailTest extends Base
{
- public function testNoEmail()
+ public function testSuccess()
{
- $action = new TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 2);
- $action->setParam('user_id', 1);
- $action->setParam('subject', 'My email subject');
-
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $u = new User($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 2,
- );
+ $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')));
- // Email should be not be sent
- $this->container['emailClient']->expects($this->never())->method('send');
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
- // Our event should be executed
- $this->assertFalse($action->execute(new GenericEvent($event)));
- }
-
- public function testWrongColumn()
- {
- $action = new TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 2);
- $action->setParam('user_id', 1);
- $action->setParam('subject', 'My email subject');
-
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $u = new User($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
-
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 3,
- );
-
- // Email should be not be sent
- $this->container['emailClient']->expects($this->never())->method('send');
-
- // Our event should be executed
- $this->assertFalse($action->execute(new GenericEvent($event)));
- }
-
- public function testMoveColumn()
- {
- $action = new TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN);
+ $action = new TaskEmail($this->container);
+ $action->setProjectId(1);
$action->setParam('column_id', 2);
$action->setParam('user_id', 1);
$action->setParam('subject', 'My email subject');
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $u = new User($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
- $this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost')));
-
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 2,
- );
-
- // Email should be sent
$this->container['emailClient']->expects($this->once())
->method('send')
->with(
@@ -106,45 +38,24 @@ class TaskEmailTest extends Base
$this->stringContains('test')
);
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
+ $this->assertTrue($action->execute($event, Task::EVENT_CLOSE));
}
- public function testTaskClose()
+ public function testWithWrongColumn()
{
- $action = new TaskEmail($this->container, 1, Task::EVENT_CLOSE);
- $action->setParam('column_id', 2);
- $action->setParam('user_id', 1);
- $action->setParam('subject', 'My email subject');
-
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $u = new User($this->container);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
- $this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
- // We create an event
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 2,
- );
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
- // Email should be sent
- $this->container['emailClient']->expects($this->once())
- ->method('send')
- ->with(
- $this->equalTo('admin@localhost'),
- $this->equalTo('admin'),
- $this->equalTo('My email subject'),
- $this->stringContains('test')
- );
+ $action = new TaskEmail($this->container);
+ $action->setProjectId(1);
+ $action->setParam('column_id', 2);
+ $action->setParam('user_id', 1);
+ $action->setParam('subject', 'My email subject');
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
+ $this->assertFalse($action->execute($event, Task::EVENT_CLOSE));
}
}
diff --git a/tests/units/Action/TaskMoveAnotherProjectTest.php b/tests/units/Action/TaskMoveAnotherProjectTest.php
index 93ee3b94..dfabe5f8 100644
--- a/tests/units/Action/TaskMoveAnotherProjectTest.php
+++ b/tests/units/Action/TaskMoveAnotherProjectTest.php
@@ -4,86 +4,54 @@ require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
use Kanboard\Model\Task;
-use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
+use Kanboard\Model\TaskCreation;
use Kanboard\Model\Project;
use Kanboard\Action\TaskMoveAnotherProject;
class TaskMoveAnotherProjectTest extends Base
{
- public function testBadProject()
+ public function testSuccess()
{
- $action = new TaskMoveAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 5);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
- $event = array(
- 'project_id' => 2,
- 'task_id' => 3,
- 'column_id' => 5,
- );
+ $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->assertFalse($action->isExecutable($event));
- $this->assertFalse($action->execute(new GenericEvent($event)));
- }
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
- public function testBadColumn()
- {
- $action = new TaskMoveAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 5);
+ $action = new TaskMoveAnotherProject($this->container);
+ $action->setProjectId(1);
+ $action->setParam('project_id', 2);
+ $action->setParam('column_id', 2);
- $event = array(
- 'project_id' => 3,
- 'task_id' => 3,
- 'column_id' => 3,
- );
+ $this->assertTrue($action->execute($event, Task::EVENT_CLOSE));
- $this->assertFalse($action->execute(new GenericEvent($event)));
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(2, $task['project_id']);
+ $this->assertEquals(5, $task['column_id']);
}
- public function testExecute()
+ public function testWithWrongColumn()
{
- $action = new TaskMoveAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'project 1')));
- $this->assertEquals(2, $p->create(array('name' => 'project 2')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 2,
- );
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
- // Our event should NOT be executed because we define the same project
- $action->setParam('column_id', 2);
- $action->setParam('project_id', 1);
- $this->assertFalse($action->execute(new GenericEvent($event)));
-
- // Our task should be assigned to the project 1
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['project_id']);
-
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 2,
- );
-
- // Our event should be executed because we define a different project
- $action->setParam('column_id', 2);
+ $action = new TaskMoveAnotherProject($this->container);
+ $action->setProjectId(1);
$action->setParam('project_id', 2);
- $this->assertTrue($action->execute(new GenericEvent($event)));
+ $action->setParam('column_id', 2);
- // Our task should be assigned to the project 2
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(2, $task['project_id']);
+ $this->assertFalse($action->execute($event, Task::EVENT_CLOSE));
}
}
diff --git a/tests/units/Action/TaskMoveColumnAssignedTest.php b/tests/units/Action/TaskMoveColumnAssignedTest.php
new file mode 100644
index 00000000..f0eec894
--- /dev/null
+++ b/tests/units/Action/TaskMoveColumnAssignedTest.php
@@ -0,0 +1,56 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\GenericEvent;
+use Kanboard\Model\Task;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\Project;
+use Kanboard\Action\TaskMoveColumnAssigned;
+
+class TaskMoveColumnAssignedTest extends Base
+{
+ public function testSuccess()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($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 = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 1));
+
+ $action = new TaskMoveColumnAssigned($this->container);
+ $action->setProjectId(1);
+ $action->setParam('src_column_id', 1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(2, $task['column_id']);
+ }
+
+ public function testWithWrongColumn()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+
+ $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));
+
+ $action = new TaskMoveColumnAssigned($this->container);
+ $action->setProjectId(1);
+ $action->setParam('src_column_id', 1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE));
+ }
+}
diff --git a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php
index 03423776..1f0768c1 100644
--- a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php
+++ b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php
@@ -3,60 +3,84 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
+use Kanboard\Model\Category;
use Kanboard\Model\Task;
-use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
+use Kanboard\Model\TaskCreation;
use Kanboard\Model\Project;
-use Kanboard\Model\Category;
-use Kanboard\Integration\GithubWebhook;
use Kanboard\Action\TaskMoveColumnCategoryChange;
class TaskMoveColumnCategoryChangeTest extends Base
{
- public function testExecute()
+ public function testSuccess()
{
- $action = new TaskMoveColumnCategoryChange($this->container, 1, Task::EVENT_UPDATE);
- $action->setParam('dest_column_id', 3);
- $action->setParam('category_id', 1);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+ $categoryModel = new Category($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $this->assertEquals(3, $action->getParam('dest_column_id'));
- $this->assertEquals(1, $action->getParam('category_id'));
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'category_id' => 1));
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $c = new Category($this->container);
+ $action = new TaskMoveColumnCategoryChange($this->container);
+ $action->setProjectId(1);
+ $action->setParam('category_id', 1);
+ $action->setParam('dest_column_id', 2);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $c->create(array('name' => 'bug', 'project_id' => 1)));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertTrue($action->execute($event, Task::EVENT_UPDATE));
- // No category should be assigned + column_id=1
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEmpty($task['category_id']);
- $this->assertEquals(1, $task['column_id']);
-
- // We create an event to move the task to the 2nd column
- $event = array(
- 'task_id' => 1,
- 'column_id' => 1,
- 'project_id' => 1,
- 'category_id' => 1,
- );
-
- // Our event should be executed
- $this->assertTrue($action->hasCompatibleEvent());
- $this->assertTrue($action->hasRequiredProject($event));
- $this->assertTrue($action->hasRequiredParameters($event));
- $this->assertTrue($action->hasRequiredCondition($event));
- $this->assertTrue($action->isExecutable($event));
- $this->assertTrue($action->execute(new GenericEvent($event)));
-
- // Our task should be moved to the other column
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
- $this->assertEquals(3, $task['column_id']);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(2, $task['column_id']);
+ }
+
+ public function testWithWrongColumn()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+ $categoryModel = new Category($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $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));
+
+ $action = new TaskMoveColumnCategoryChange($this->container);
+ $action->setProjectId(1);
+ $action->setParam('category_id', 1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertFalse($action->execute($event, Task::EVENT_UPDATE));
+ }
+
+ public function testWithWrongCategory()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+ $categoryModel = new Category($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
+ $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));
+
+ $action = new TaskMoveColumnCategoryChange($this->container);
+ $action->setProjectId(1);
+ $action->setParam('category_id', 1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertFalse($action->execute($event, Task::EVENT_UPDATE));
}
}
diff --git a/tests/units/Action/TaskMoveColumnUnAssignedTest.php b/tests/units/Action/TaskMoveColumnUnAssignedTest.php
new file mode 100644
index 00000000..0b54b781
--- /dev/null
+++ b/tests/units/Action/TaskMoveColumnUnAssignedTest.php
@@ -0,0 +1,74 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\GenericEvent;
+use Kanboard\Model\Task;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\Project;
+use Kanboard\Action\TaskMoveColumnUnAssigned;
+
+class TaskMoveColumnUnAssignedTest extends Base
+{
+ public function testSuccess()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($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 = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 0));
+
+ $action = new TaskMoveColumnUnAssigned($this->container);
+ $action->setProjectId(1);
+ $action->setParam('src_column_id', 1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals('test', $task['title']);
+ $this->assertEquals(2, $task['column_id']);
+ }
+
+ public function testWithWrongColumn()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+
+ $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));
+
+ $action = new TaskMoveColumnUnAssigned($this->container);
+ $action->setProjectId(1);
+ $action->setParam('src_column_id', 1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE));
+ }
+
+ public function testWithWrongUser()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+
+ $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));
+
+ $action = new TaskMoveColumnUnAssigned($this->container);
+ $action->setProjectId(1);
+ $action->setParam('src_column_id', 1);
+ $action->setParam('dest_column_id', 2);
+
+ $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE));
+ }
+}
diff --git a/tests/units/Action/TaskOpenTest.php b/tests/units/Action/TaskOpenTest.php
new file mode 100644
index 00000000..01290a64
--- /dev/null
+++ b/tests/units/Action/TaskOpenTest.php
@@ -0,0 +1,51 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\GenericEvent;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Project;
+use Kanboard\Action\TaskOpen;
+
+class TaskOpenTest extends Base
+{
+ public function testClose()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+
+ $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));
+
+ $action = new TaskOpen($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
+
+ $this->assertTrue($action->execute($event, 'test.event'));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+ }
+
+ public function testWithNoTaskId()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($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));
+
+ $action = new TaskOpen($this->container);
+ $action->setProjectId(1);
+ $action->addEvent('test.event', 'Test Event');
+
+ $this->assertFalse($action->execute($event, 'test.event'));
+ }
+}
diff --git a/tests/units/Action/TaskUpdateStartDateTest.php b/tests/units/Action/TaskUpdateStartDateTest.php
index 7d558e28..adf5bd9d 100644
--- a/tests/units/Action/TaskUpdateStartDateTest.php
+++ b/tests/units/Action/TaskUpdateStartDateTest.php
@@ -3,44 +3,50 @@
require_once __DIR__.'/../Base.php';
use Kanboard\Event\GenericEvent;
-use Kanboard\Model\Task;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskFinder;
use Kanboard\Model\Project;
+use Kanboard\Model\Task;
use Kanboard\Action\TaskUpdateStartDate;
class TaskUpdateStartDateTest extends Base
{
- public function testExecute()
+ public function testClose()
{
- $action = new TaskUpdateStartDate($this->container, 1, Task::EVENT_MOVE_COLUMN);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($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, 'column_id' => 2));
+
+ $action = new TaskUpdateStartDate($this->container);
+ $action->setProjectId(1);
$action->setParam('column_id', 2);
- // We create a task in the first column
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $p = new Project($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
+ $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN));
- // The start date must be empty
- $task = $tf->getById(1);
+ $task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
- $this->assertEmpty($task['date_started']);
+ $this->assertEquals(time(), $task['date_started'], 'Date started delta', 2);
+ }
- // We create an event to move the task to the 2nd column
- $event = array(
- 'project_id' => 1,
- 'task_id' => 1,
- 'column_id' => 2,
- );
+ public function testWithWrongColumn()
+ {
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
- // Our event should be executed
- $this->assertTrue($action->execute(new GenericEvent($event)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- // Our task should be updated
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(time(), $task['date_started'], '', 2);
+ $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
+
+ $action = new TaskUpdateStartDate($this->container);
+ $action->setProjectId(1);
+ $action->setParam('column_id', 2);
+
+ $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN));
}
}
diff --git a/tests/units/Core/Action/ActionManagerTest.php b/tests/units/Core/Action/ActionManagerTest.php
new file mode 100644
index 00000000..3714583b
--- /dev/null
+++ b/tests/units/Core/Action/ActionManagerTest.php
@@ -0,0 +1,157 @@
+<?php
+
+require_once __DIR__.'/../../Base.php';
+
+use Kanboard\Core\Action\ActionManager;
+use Kanboard\Action\TaskAssignColorColumn;
+use Kanboard\Action\TaskClose;
+use Kanboard\Action\TaskCloseColumn;
+use Kanboard\Action\TaskUpdateStartDate;
+use Kanboard\Model\Action;
+use Kanboard\Model\Task;
+use Kanboard\Model\Project;
+use Kanboard\Model\ProjectUserRole;
+use Kanboard\Core\Security\Role;
+
+class ActionManagerTest extends Base
+{
+ public function testRegister()
+ {
+ $actionManager = new ActionManager($this->container);
+ $actionTaskClose = new TaskClose($this->container);
+
+ $actionManager->register($actionTaskClose);
+ $this->assertInstanceOf(get_class($actionTaskClose), $actionManager->getAction($actionTaskClose->getName()));
+ }
+
+ public function testGetActionNotFound()
+ {
+ $this->setExpectedException('RuntimeException', 'Automatic Action Not Found: foobar');
+ $actionManager = new ActionManager($this->container);
+ $actionManager->getAction('foobar');
+ }
+
+ public function testGetAvailableActions()
+ {
+ $actionManager = new ActionManager($this->container);
+ $actionTaskClose1 = new TaskClose($this->container);
+ $actionTaskClose2 = new TaskClose($this->container);
+ $actionTaskUpdateStartDate = new TaskUpdateStartDate($this->container);
+
+ $actionManager
+ ->register($actionTaskClose1)
+ ->register($actionTaskClose2)
+ ->register($actionTaskUpdateStartDate);
+
+ $actions = $actionManager->getAvailableActions();
+ $this->assertCount(2, $actions);
+ $this->assertArrayHasKey($actionTaskClose1->getName(), $actions);
+ $this->assertArrayHasKey($actionTaskUpdateStartDate->getName(), $actions);
+ $this->assertNotEmpty($actions[$actionTaskClose1->getName()]);
+ $this->assertNotEmpty($actions[$actionTaskUpdateStartDate->getName()]);
+ }
+
+ public function testGetAvailableParameters()
+ {
+ $actionManager = new ActionManager($this->container);
+
+ $actionManager
+ ->register(new TaskCloseColumn($this->container))
+ ->register(new TaskUpdateStartDate($this->container));
+
+ $params = $actionManager->getAvailableParameters(array(
+ array('action_name' => '\Kanboard\Action\TaskCloseColumn'),
+ array('action_name' => '\Kanboard\Action\TaskUpdateStartDate'),
+ ));
+
+ $this->assertCount(2, $params);
+ $this->assertArrayHasKey('column_id', $params['\Kanboard\Action\TaskCloseColumn']);
+ $this->assertArrayHasKey('column_id', $params['\Kanboard\Action\TaskUpdateStartDate']);
+ $this->assertNotEmpty($params['\Kanboard\Action\TaskCloseColumn']['column_id']);
+ $this->assertNotEmpty($params['\Kanboard\Action\TaskUpdateStartDate']['column_id']);
+ }
+
+ public function testGetCompatibleEvents()
+ {
+ $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container);
+ $actionManager = new ActionManager($this->container);
+ $actionManager->register($actionTaskAssignColorColumn);
+
+ $events = $actionManager->getCompatibleEvents('\\'.get_class($actionTaskAssignColorColumn));
+ $this->assertCount(2, $events);
+ $this->assertArrayHasKey(Task::EVENT_CREATE, $events);
+ $this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN, $events);
+ $this->assertNotEmpty($events[Task::EVENT_CREATE]);
+ $this->assertNotEmpty($events[Task::EVENT_MOVE_COLUMN]);
+ }
+
+ public function testAttachEventsWithoutUserSession()
+ {
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+ $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container);
+ $actionManager = new ActionManager($this->container);
+ $actionManager->register($actionTaskAssignColorColumn);
+
+ $actions = $actionManager->getAvailableActions();
+
+ $actionManager->attachEvents();
+ $this->assertEmpty($this->container['dispatcher']->getListeners());
+
+ $this->assertEquals(1, $projectModel->create(array('name' =>'test')));
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => key($actions),
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $actionManager->attachEvents();
+ $listeners = $this->container['dispatcher']->getListeners(Task::EVENT_CREATE);
+ $this->assertCount(1, $listeners);
+ $this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]);
+
+ $this->assertEquals(1, $listeners[0][0]->getProjectId());
+ }
+
+ public function testAttachEventsWithLoggedUser()
+ {
+ $this->container['sessionStorage']->user = array('id' => 1);
+
+ $projectModel = new Project($this->container);
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $actionModel = new Action($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' =>'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' =>'test2')));
+
+ $this->assertTrue($projectUserRoleModel->addUser(2, 1, Role::PROJECT_MEMBER));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => key($actions),
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $this->assertEquals(2, $actionModel->create(array(
+ 'project_id' => 2,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => key($actions),
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $actionManager->attachEvents();
+
+ $listeners = $this->container['dispatcher']->getListeners(Task::EVENT_MOVE_COLUMN);
+ $this->assertCount(1, $listeners);
+ $this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]);
+
+ $this->assertEquals(2, $listeners[0][0]->getProjectId());
+ }
+}
diff --git a/tests/units/Core/Event/EventManagerTest.php b/tests/units/Core/Event/EventManagerTest.php
new file mode 100644
index 00000000..974fde62
--- /dev/null
+++ b/tests/units/Core/Event/EventManagerTest.php
@@ -0,0 +1,18 @@
+<?php
+
+require_once __DIR__.'/../../Base.php';
+
+use Kanboard\Core\Event\EventManager;
+
+class EventManagerTest extends Base
+{
+ public function testAddEvent()
+ {
+ $eventManager = new EventManager;
+ $eventManager->register('my.event', 'My Event');
+
+ $events = $eventManager->getAll();
+ $this->assertArrayHasKey('my.event', $events);
+ $this->assertEquals('My Event', $events['my.event']);
+ }
+}
diff --git a/tests/units/Integration/BitbucketWebhookTest.php b/tests/units/Integration/BitbucketWebhookTest.php
index 40dbde2e..bb6755c2 100644
--- a/tests/units/Integration/BitbucketWebhookTest.php
+++ b/tests/units/Integration/BitbucketWebhookTest.php
@@ -319,7 +319,7 @@ class BitbucketWebhookTest extends Base
$this->assertEquals(1, $data['project_id']);
$this->assertEquals(2, $data['task_id']);
$this->assertEquals('test2', $data['title']);
- $this->assertEquals("Test another commit #2\n\n\n[Commit made by @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6)", $data['commit_comment']);
+ $this->assertEquals("Test another commit #2\n\n\n[Commit made by @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6)", $data['comment']);
$this->assertEquals("Test another commit #2\n", $data['commit_message']);
$this->assertEquals('https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6', $data['commit_url']);
}
diff --git a/tests/units/Integration/GithubWebhookTest.php b/tests/units/Integration/GithubWebhookTest.php
index f00e5dde..6b5e19a5 100644
--- a/tests/units/Integration/GithubWebhookTest.php
+++ b/tests/units/Integration/GithubWebhookTest.php
@@ -453,7 +453,7 @@ class GithubWebhookTest extends Base
$this->assertEquals(1, $data['project_id']);
$this->assertEquals(1, $data['task_id']);
$this->assertEquals('boo', $data['title']);
- $this->assertEquals("Update README to fix #1\n\n[Commit made by @fguillot on Github](https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6)", $data['commit_comment']);
+ $this->assertEquals("Update README to fix #1\n\n[Commit made by @fguillot on Github](https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6)", $data['comment']);
$this->assertEquals('Update README to fix #1', $data['commit_message']);
$this->assertEquals('https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6', $data['commit_url']);
}
diff --git a/tests/units/Integration/GitlabWebhookTest.php b/tests/units/Integration/GitlabWebhookTest.php
index 3e0e6d2c..afd9f7f1 100644
--- a/tests/units/Integration/GitlabWebhookTest.php
+++ b/tests/units/Integration/GitlabWebhookTest.php
@@ -221,7 +221,7 @@ class GitlabWebhookTest extends Base
$this->assertEquals(1, $data['project_id']);
$this->assertEquals(2, $data['task_id']);
$this->assertEquals('test2', $data['title']);
- $this->assertEquals("Fix bug #2\n\n[Commit made by @Fred on Gitlab](https://gitlab.com/minicoders/test-webhook/commit/48aafa75eef9ad253aa254b0c82c987a52ebea78)", $data['commit_comment']);
+ $this->assertEquals("Fix bug #2\n\n[Commit made by @Fred on Gitlab](https://gitlab.com/minicoders/test-webhook/commit/48aafa75eef9ad253aa254b0c82c987a52ebea78)", $data['comment']);
$this->assertEquals("Fix bug #2", $data['commit_message']);
$this->assertEquals('https://gitlab.com/minicoders/test-webhook/commit/48aafa75eef9ad253aa254b0c82c987a52ebea78', $data['commit_url']);
}
diff --git a/tests/units/Model/ActionTest.php b/tests/units/Model/ActionTest.php
index 4a338707..8d574115 100644
--- a/tests/units/Model/ActionTest.php
+++ b/tests/units/Model/ActionTest.php
@@ -4,388 +4,506 @@ require_once __DIR__.'/../Base.php';
use Kanboard\Model\Action;
use Kanboard\Model\Project;
-use Kanboard\Model\Board;
use Kanboard\Model\Task;
-use Kanboard\Model\TaskPosition;
-use Kanboard\Model\TaskCreation;
-use Kanboard\Model\TaskFinder;
-use Kanboard\Model\Category;
use Kanboard\Model\User;
+use Kanboard\Model\Board;
+use Kanboard\Model\Category;
use Kanboard\Model\ProjectUserRole;
-use Kanboard\Integration\GithubWebhook;
-use Kanboard\Integration\BitbucketWebhook;
use Kanboard\Core\Security\Role;
class ActionTest extends Base
{
- public function testGetActions()
+ public function testCreate()
{
- $a = new Action($this->container);
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
- $actions = $a->getAvailableActions();
- $this->assertNotEmpty($actions);
- $this->assertEquals('Add a comment log when moving the task between columns', current($actions));
- $this->assertEquals('TaskLogMoveAnotherColumn', key($actions));
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
}
- public function testExtendActions()
+ public function testRemove()
{
- $a = new Action($this->container);
- $a->extendActions('MyClass', 'Description');
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
- $actions = $a->getAvailableActions();
- $this->assertNotEmpty($actions);
- $this->assertContains('Description', $actions);
- $this->assertArrayHasKey('MyClass', $actions);
+ $this->assertNotEmpty($actionModel->getById(1));
+ $this->assertTrue($actionModel->remove(1));
+ $this->assertEmpty($actionModel->getById(1));
}
- public function testGetEvents()
+ public function testGetById()
{
- $a = new Action($this->container);
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
- $events = $a->getAvailableEvents();
- $this->assertNotEmpty($events);
- $this->assertEquals('Bitbucket commit received', current($events));
- $this->assertEquals(BitbucketWebhook::EVENT_COMMIT, key($events));
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $action = $actionModel->getById(1);
+ $this->assertNotEmpty($action);
+ $this->assertEquals(1, $action['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $action['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $action['event_name']);
+ $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $action['params']);
}
- public function testGetCompatibleEvents()
+ public function testGetAll()
{
- $a = new Action($this->container);
- $events = $a->getCompatibleEvents('TaskAssignSpecificUser');
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $this->assertNotEmpty($events);
- $this->assertCount(2, $events);
- $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE, $events);
- $this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN, $events);
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $this->assertEquals(2, $actionModel->create(array(
+ 'project_id' => 2,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 6, 'color_id' => 'blue'),
+ )));
+
+ $actions = $actionModel->getAll();
+ $this->assertCount(2, $actions);
+
+ $this->assertEquals(1, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']);
+
+ $this->assertEquals(2, $actions[1]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[1]['action_name']);
+ $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[1]['event_name']);
+ $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[1]['params']);
}
- public function testResolveDuplicatedParameters()
+ public function testGetAllByProject()
{
- $p = new Project($this->container);
- $pp = new ProjectUserRole($this->container);
- $a = new Action($this->container);
- $c = new Category($this->container);
- $u = new User($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(2, $p->create(array('name' => 'P2')));
-
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
-
- $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 2)));
- $this->assertEquals(3, $c->create(array('name' => 'C1', 'project_id' => 2)));
-
- $this->assertEquals(2, $u->create(array('username' => 'unittest1')));
- $this->assertEquals(3, $u->create(array('username' => 'unittest2')));
-
- $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
- $this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER));
- $this->assertTrue($pp->addUser(2, 3, Role::PROJECT_MEMBER));
-
- // anything
- $this->assertEquals('blah', $a->resolveParameters(array('name' => 'foobar', 'value' => 'blah'), 2));
-
- // project_id
- $this->assertEquals(2, $a->resolveParameters(array('name' => 'project_id', 'value' => 'blah'), 2));
-
- // category_id
- $this->assertEquals(3, $a->resolveParameters(array('name' => 'category_id', 'value' => 1), 2));
- $this->assertFalse($a->resolveParameters(array('name' => 'category_id', 'value' => 0), 2));
- $this->assertFalse($a->resolveParameters(array('name' => 'category_id', 'value' => 5), 2));
-
- // column_id
- $this->assertFalse($a->resolveParameters(array('name' => 'column_id', 'value' => 10), 2));
- $this->assertFalse($a->resolveParameters(array('name' => 'column_id', 'value' => 0), 2));
- $this->assertEquals(5, $a->resolveParameters(array('name' => 'column_id', 'value' => 1), 2));
- $this->assertEquals(6, $a->resolveParameters(array('name' => 'dest_column_id', 'value' => 2), 2));
- $this->assertEquals(7, $a->resolveParameters(array('name' => 'dst_column_id', 'value' => 3), 2));
- $this->assertEquals(8, $a->resolveParameters(array('name' => 'src_column_id', 'value' => 4), 2));
-
- // user_id
- $this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 10), 2));
- $this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 0), 2));
- $this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 2), 2));
- $this->assertFalse($a->resolveParameters(array('name' => 'owner_id', 'value' => 2), 2));
- $this->assertEquals(3, $a->resolveParameters(array('name' => 'user_id', 'value' => 3), 2));
- $this->assertEquals(3, $a->resolveParameters(array('name' => 'owner_id', 'value' => 3), 2));
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $this->assertEquals(2, $actionModel->create(array(
+ 'project_id' => 2,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 6, 'color_id' => 'blue'),
+ )));
+
+ $actions = $actionModel->getAllByProject(1);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(1, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']);
+
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']);
}
- public function testDuplicateSuccess()
+ public function testGetAllByUser()
{
- $p = new Project($this->container);
- $pp = new ProjectUserRole($this->container);
- $a = new Action($this->container);
- $u = new User($this->container);
+ $projectModel = new Project($this->container);
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $userModel = new User($this->container);
+ $actionModel = new Action($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(2, $p->create(array('name' => 'P2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(3, $projectModel->create(array('name' => 'test4', 'is_active' => 0)));
- $this->assertEquals(2, $u->create(array('username' => 'unittest1')));
- $this->assertEquals(3, $u->create(array('username' => 'unittest2')));
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
- $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
- $this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER));
- $this->assertTrue($pp->addUser(2, 3, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_VIEWER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 3, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectUserRoleModel->addUser(3, 3, Role::PROJECT_MANAGER));
- $this->assertEquals(1, $a->create(array(
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
- 'event_name' => Task::EVENT_CREATE_UPDATE,
- 'action_name' => 'TaskAssignSpecificUser',
- 'params' => array(
- 'column_id' => 1,
- 'user_id' => 3,
- )
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
)));
- $action = $a->getById(1);
- $this->assertNotEmpty($action);
- $this->assertNotEmpty($action['params']);
- $this->assertEquals(1, $action['project_id']);
+ $this->assertEquals(2, $actionModel->create(array(
+ 'project_id' => 2,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 6, 'color_id' => 'blue'),
+ )));
- $this->assertTrue($a->duplicate(1, 2));
+ $this->assertEquals(3, $actionModel->create(array(
+ 'project_id' => 3,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 10, 'color_id' => 'green'),
+ )));
- $action = $a->getById(2);
- $this->assertNotEmpty($action);
- $this->assertNotEmpty($action['params']);
- $this->assertEquals(2, $action['project_id']);
- $this->assertEquals(Task::EVENT_CREATE_UPDATE, $action['event_name']);
- $this->assertEquals('TaskAssignSpecificUser', $action['action_name']);
- $this->assertEquals('column_id', $action['params'][0]['name']);
- $this->assertEquals(5, $action['params'][0]['value']);
- $this->assertEquals('user_id', $action['params'][1]['name']);
- $this->assertEquals(3, $action['params'][1]['value']);
+ $actions = $actionModel->getAllByUser(1);
+ $this->assertCount(0, $actions);
+
+ $actions = $actionModel->getAllByUser(2);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(1, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']);
+
+ $actions = $actionModel->getAllByUser(3);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']);
}
- public function testDuplicateUnableToResolveParams()
+ public function testDuplicateWithColumnAndColorParameter()
{
- $p = new Project($this->container);
- $pp = new ProjectUserRole($this->container);
- $a = new Action($this->container);
- $u = new User($this->container);
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(2, $p->create(array('name' => 'P2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $this->assertEquals(2, $u->create(array('username' => 'unittest1')));
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
- $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($actionModel->duplicate(1, 2));
- $this->assertEquals(1, $a->create(array(
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']);
+ }
+
+ public function testDuplicateWithColumnsParameter()
+ {
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
- 'event_name' => Task::EVENT_CREATE_UPDATE,
- 'action_name' => 'TaskAssignSpecificUser',
- 'params' => array(
- 'column_id' => 1,
- 'user_id' => 2,
- )
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('src_column_id' => 1, 'dst_column_id' => 2, 'dest_column_id' => 3),
)));
- $action = $a->getById(1);
- $this->assertNotEmpty($action);
- $this->assertNotEmpty($action['params']);
- $this->assertEquals(1, $action['project_id']);
- $this->assertEquals('user_id', $action['params'][1]['name']);
- $this->assertEquals(2, $action['params'][1]['value']);
+ $this->assertTrue($actionModel->duplicate(1, 2));
- $this->assertTrue($a->duplicate(1, 2));
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
- $action = $a->getById(2);
- $this->assertEmpty($action);
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']);
+ $this->assertEquals(array('src_column_id' => 5, 'dst_column_id' => 6, 'dest_column_id' => 7), $actions[0]['params']);
}
- public function testDuplicateMixedResults()
+ public function testDuplicateWithColumnParameterNotfound()
{
- $p = new Project($this->container);
- $pp = new ProjectUserRole($this->container);
- $a = new Action($this->container);
- $u = new User($this->container);
- $c = new Category($this->container);
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+ $boardModel = new Board($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(2, $p->create(array('name' => 'P2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
- $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 2)));
- $this->assertEquals(3, $c->create(array('name' => 'C1', 'project_id' => 2)));
+ $this->assertTrue($boardModel->updateColumn(2, 'My unique column'));
- $this->assertEquals(2, $u->create(array('username' => 'unittest1')));
-
- $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
- $this->assertEquals(1, $a->create(array(
+ $this->assertEquals(2, $actionModel->create(array(
'project_id' => 1,
- 'event_name' => Task::EVENT_CREATE_UPDATE,
- 'action_name' => 'TaskAssignSpecificUser',
- 'params' => array(
- 'column_id' => 1,
- 'user_id' => 2,
- )
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 2, 'color_id' => 'green'),
)));
- $action = $a->getById(1);
- $this->assertNotEmpty($action);
- $this->assertNotEmpty($action['params']);
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']);
+ }
+
+ public function testDuplicateWithProjectParameter()
+ {
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(3, $projectModel->create(array('name' => 'test2')));
- $this->assertEquals(2, $a->create(array(
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
- 'event_name' => Task::EVENT_CREATE_UPDATE,
- 'action_name' => 'TaskAssignCategoryColor',
- 'params' => array(
- 'color_id' => 'blue',
- 'category_id' => 1,
- )
+ 'event_name' => Task::EVENT_CLOSE,
+ 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject',
+ 'params' => array('column_id' => 1, 'project_id' => 3),
)));
- $action = $a->getById(2);
- $this->assertNotEmpty($action);
- $this->assertNotEmpty($action['params']);
- $this->assertEquals('category_id', $action['params'][1]['name']);
- $this->assertEquals(1, $action['params'][1]['value']);
+ $this->assertTrue($actionModel->duplicate(1, 2));
- $actions = $a->getAllByProject(1);
- $this->assertNotEmpty($actions);
- $this->assertCount(2, $actions);
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
- $this->assertTrue($a->duplicate(1, 2));
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskDuplicateAnotherProject', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CLOSE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 5, 'project_id' => 3), $actions[0]['params']);
+ }
- $actions = $a->getAllByProject(2);
- $this->assertNotEmpty($actions);
- $this->assertCount(1, $actions);
+ public function testDuplicateWithProjectParameterIdenticalToDestination()
+ {
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
- $actions = $a->getAll();
- $this->assertNotEmpty($actions);
- $this->assertCount(3, $actions);
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $action = $a->getById($actions[2]['id']);
- $this->assertNotEmpty($action);
- $this->assertNotEmpty($action['params']);
- $this->assertEquals('color_id', $action['params'][0]['name']);
- $this->assertEquals('blue', $action['params'][0]['value']);
- $this->assertEquals('category_id', $action['params'][1]['name']);
- $this->assertEquals(3, $action['params'][1]['value']);
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CLOSE,
+ 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject',
+ 'params' => array('column_id' => 1, 'project_id' => 2),
+ )));
+
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(0, $actions);
}
- public function testSingleAction()
+ public function testDuplicateWithUserParameter()
{
- $tp = new TaskPosition($this->container);
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $board = new Board($this->container);
- $project = new Project($this->container);
- $action = new Action($this->container);
-
- // We create a project
- $this->assertEquals(1, $project->create(array('name' => 'unit_test')));
-
- // We create a new action
- $this->assertEquals(1, $action->create(array(
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
+
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
'event_name' => Task::EVENT_MOVE_COLUMN,
- 'action_name' => 'TaskClose',
- 'params' => array(
- 'column_id' => 4,
- )
+ 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser',
+ 'params' => array('column_id' => 1, 'user_id' => 2),
)));
- // We create a task
- $this->assertEquals(1, $tc->create(array(
- 'title' => 'unit_test',
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignSpecificUser', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 5, 'user_id' => 2), $actions[0]['params']);
+ }
+
+ public function testDuplicateWithUserParameterButNotAssignable()
+ {
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_VIEWER));
+
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
- 'owner_id' => 1,
- 'color_id' => 'red',
- 'column_id' => 1,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser',
+ 'params' => array('column_id' => 1, 'user_id' => 2),
)));
- // We attach events
- $action->attachEvents();
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(0, $actions);
+ }
+
+ public function testDuplicateWithUserParameterButNotAvailable()
+ {
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
- // Our task should be open
- $t1 = $tf->getById(1);
- $this->assertEquals(1, $t1['is_active']);
- $this->assertEquals(1, $t1['column_id']);
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
- // We move our task
- $tp->movePosition(1, 1, 4, 1);
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser',
+ 'params' => array('column_id' => 1, 'owner_id' => 2),
+ )));
- // Our task should be closed
- $t1 = $tf->getById(1);
- $this->assertEquals(4, $t1['column_id']);
- $this->assertEquals(0, $t1['is_active']);
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(0, $actions);
}
- public function testMultipleActions()
+ public function testDuplicateWithCategoryParameter()
{
- $tp = new TaskPosition($this->container);
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $b = new Board($this->container);
- $p = new Project($this->container);
- $a = new Action($this->container);
- $g = new GithubWebhook($this->container);
-
- // We create a project
- $this->assertEquals(1, $p->create(array('name' => 'unit_test')));
-
- // We create a new action
- $this->assertEquals(1, $a->create(array(
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+ $categoryModel = new Category($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
+ $this->assertEquals(2, $categoryModel->create(array('name' => 'c1', 'project_id' => 2)));
+
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
- 'event_name' => GithubWebhook::EVENT_ISSUE_OPENED,
- 'action_name' => 'TaskCreation',
- 'params' => array()
+ 'event_name' => Task::EVENT_CREATE_UPDATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorCategory',
+ 'params' => array('column_id' => 1, 'category_id' => 1),
)));
- $this->assertEquals(2, $a->create(array(
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorCategory', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE_UPDATE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 5, 'category_id' => 2), $actions[0]['params']);
+ }
+
+ public function testDuplicateWithCategoryParameterButDifferentName()
+ {
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+ $categoryModel = new Category($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
+ $this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 2)));
+
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
- 'event_name' => GithubWebhook::EVENT_ISSUE_LABEL_CHANGE,
- 'action_name' => 'TaskAssignCategoryLabel',
- 'params' => array(
- 'label' => 'bug',
- 'category_id' => 1,
- )
+ 'event_name' => Task::EVENT_CREATE_UPDATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorCategory',
+ 'params' => array('column_id' => 1, 'category_id' => 1),
)));
- $this->assertEquals(3, $a->create(array(
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(0, $actions);
+ }
+
+ public function testDuplicateWithCategoryParameterButNotFound()
+ {
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+ $categoryModel = new Category($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
'event_name' => Task::EVENT_CREATE_UPDATE,
- 'action_name' => 'TaskAssignColorCategory',
- 'params' => array(
- 'color_id' => 'red',
- 'category_id' => 1,
- )
+ 'action_name' => '\Kanboard\Action\TaskAssignColorCategory',
+ 'params' => array('column_id' => 1, 'category_id' => 1),
)));
- // We attach events
- $a->attachEvents();
- $g->setProjectId(1);
-
- // We create a Github issue
- $issue = array(
- 'number' => 123,
- 'title' => 'Bugs everywhere',
- 'body' => 'There is a bug!',
- 'html_url' => 'http://localhost/',
- );
-
- $this->assertTrue($g->handleIssueOpened($issue));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['is_active']);
- $this->assertEquals(0, $task['category_id']);
- $this->assertEquals('yellow', $task['color_id']);
-
- // We assign a label to our issue
- $label = array(
- 'name' => 'bug',
- );
-
- $this->assertTrue($g->handleIssueLabeled($issue, $label));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['is_active']);
- $this->assertEquals(1, $task['category_id']);
- $this->assertEquals('red', $task['color_id']);
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(0, $actions);
}
}
diff --git a/tests/units/Model/ProjectDuplicationTest.php b/tests/units/Model/ProjectDuplicationTest.php
index 8b74675b..db5da525 100644
--- a/tests/units/Model/ProjectDuplicationTest.php
+++ b/tests/units/Model/ProjectDuplicationTest.php
@@ -165,7 +165,7 @@ class ProjectDuplicationTest extends Base
$this->assertNotEmpty($actions);
$this->assertEquals('TaskAssignCurrentUser', $actions[0]['action_name']);
$this->assertNotEmpty($actions[0]['params']);
- $this->assertEquals(6, $actions[0]['params'][0]['value']);
+ $this->assertEquals(6, $actions[0]['params']['column_id']);
}
public function testCloneProjectWithActionTaskAssignColorCategory()
@@ -195,8 +195,8 @@ class ProjectDuplicationTest extends Base
$this->assertNotEmpty($actions);
$this->assertEquals('TaskAssignColorCategory', $actions[0]['action_name']);
$this->assertNotEmpty($actions[0]['params']);
- $this->assertEquals('blue', $actions[0]['params'][0]['value']);
- $this->assertEquals(5, $actions[0]['params'][1]['value']);
+ $this->assertEquals('blue', $actions[0]['params']['color_id']);
+ $this->assertEquals(5, $actions[0]['params']['category_id']);
}
public function testCloneProjectWithSwimlanesAndTasks()