summaryrefslogtreecommitdiff
path: root/tests/units/Action
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/Action')
-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.php97
-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.php77
-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/TaskCloseNoActivityTest.php43
-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/TaskEmailNoActivityTest.php103
-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
27 files changed, 1465 insertions, 735 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
new file mode 100644
index 00000000..f638e017
--- /dev/null
+++ b/tests/units/Action/TaskAssignCategoryLinkTest.php
@@ -0,0 +1,97 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\Task;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Project;
+use Kanboard\Model\TaskLink;
+use Kanboard\Model\Category;
+use Kanboard\Event\TaskLinkEvent;
+use Kanboard\Action\TaskAssignCategoryLink;
+
+class TaskAssignCategoryLinkTest extends Base
+{
+ public function testAssignCategory()
+ {
+ $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);
+ $action->setProjectId(1);
+ $action->setParam('category_id', 1);
+ $action->setParam('link_id', 2);
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+ $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
+
+ $event = new TaskLinkEvent(array(
+ 'project_id' => 1,
+ 'task_id' => 1,
+ 'opposite_task_id' => 2,
+ 'link_id' => 2,
+ ));
+
+ $this->assertTrue($action->execute($event, TaskLink::EVENT_CREATE_UPDATE));
+
+ $task = $tf->getById(1);
+ $this->assertEquals(1, $task['category_id']);
+ }
+
+ 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);
+ $action->setProjectId(1);
+ $action->setParam('category_id', 1);
+ $action->setParam('link_id', 1);
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+ $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
+
+ $event = new TaskLinkEvent(array(
+ 'project_id' => 1,
+ 'task_id' => 1,
+ 'opposite_task_id' => 2,
+ 'link_id' => 2,
+ ));
+
+ $this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE));
+ }
+
+ public function testThatExistingCategoryWillNotChange()
+ {
+ $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);
+ $action->setProjectId(1);
+ $action->setParam('category_id', 2);
+ $action->setParam('link_id', 2);
+
+ $this->assertEquals(1, $p->create(array('name' => 'P1')));
+ $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
+ $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
+ $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'category_id' => 1)));
+
+ $event = new TaskLinkEvent(array(
+ 'project_id' => 1,
+ 'task_id' => 1,
+ 'opposite_task_id' => 2,
+ 'link_id' => 2,
+ ));
+
+ $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 f8946577..2fe84a5d 100644
--- a/tests/units/Action/TaskAssignCurrentUserTest.php
+++ b/tests/units/Action/TaskAssignCurrentUserTest.php
@@ -3,76 +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\Model\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));
- $event = array(
- 'project_id' => 3,
- 'task_id' => 3,
- 'column_id' => 3,
- );
+ $action = new TaskAssignCurrentUser($this->container);
+ $action->setProjectId(1);
- $this->assertFalse($action->execute(new GenericEvent($event)));
+ $this->assertTrue($action->execute($event, Task::EVENT_CREATE));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['owner_id']);
}
- public function testExecute()
+ public function testWithNoUserSession()
{
- $action = new TaskAssignCurrentUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
- $action->setParam('column_id', 2);
- $_SESSION = array(
- 'user' => array('id' => 5)
- );
+ $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);
- $us = new UserSession($this->container);
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
- $this->assertEquals(5, $us->getId());
- $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/TaskCloseNoActivityTest.php b/tests/units/Action/TaskCloseNoActivityTest.php
new file mode 100644
index 00000000..b6e04c47
--- /dev/null
+++ b/tests/units/Action/TaskCloseNoActivityTest.php
@@ -0,0 +1,43 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\TaskListEvent;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Project;
+use Kanboard\Model\Task;
+use Kanboard\Action\TaskCloseNoActivity;
+
+class TaskCloseNoActivityTest 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')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days')));
+
+ $tasks = $taskFinderModel->getAll(1);
+ $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1));
+
+ $action = new TaskCloseNoActivity($this->container);
+ $action->setProjectId(1);
+ $action->setParam('duration', 2);
+
+ $this->assertTrue($action->execute($event, Task::EVENT_DAILY_CRONJOB));
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['is_active']);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+ }
+}
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/TaskEmailNoActivityTest.php b/tests/units/Action/TaskEmailNoActivityTest.php
new file mode 100644
index 00000000..af4baed5
--- /dev/null
+++ b/tests/units/Action/TaskEmailNoActivityTest.php
@@ -0,0 +1,103 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Event\TaskListEvent;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
+use Kanboard\Model\Project;
+use Kanboard\Model\Task;
+use Kanboard\Model\User;
+use Kanboard\Action\TaskEmailNoActivity;
+
+class TaskEmailNoActivityTest extends Base
+{
+ public function testSendEmail()
+ {
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'test', 'email' => 'chuck@norris', 'name' => 'Chuck Norris')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days')));
+
+ $tasks = $taskFinderModel->getAll(1);
+ $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1));
+
+ $action = new TaskEmailNoActivity($this->container);
+ $action->setProjectId(1);
+ $action->setParam('user_id', 2);
+ $action->setParam('subject', 'Old tasks');
+ $action->setParam('duration', 2);
+
+ $this->container['emailClient']
+ ->expects($this->once())
+ ->method('send')
+ ->with('chuck@norris', 'Chuck Norris', 'Old tasks', $this->anything());
+
+ $this->assertTrue($action->execute($event, Task::EVENT_DAILY_CRONJOB));
+ }
+
+ public function testUserWithNoEmail()
+ {
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'test', 'name' => 'Chuck Norris')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days')));
+
+ $tasks = $taskFinderModel->getAll(1);
+ $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1));
+
+ $action = new TaskEmailNoActivity($this->container);
+ $action->setProjectId(1);
+ $action->setParam('user_id', 2);
+ $action->setParam('subject', 'Old tasks');
+ $action->setParam('duration', 2);
+
+ $this->container['emailClient']
+ ->expects($this->never())
+ ->method('send');
+
+ $this->assertFalse($action->execute($event, Task::EVENT_DAILY_CRONJOB));
+ }
+
+ public function testTooRecent()
+ {
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'test', 'email' => 'chuck@norris', 'name' => 'Chuck Norris')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+
+ $tasks = $taskFinderModel->getAll(1);
+ $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1));
+
+ $action = new TaskEmailNoActivity($this->container);
+ $action->setProjectId(1);
+ $action->setParam('user_id', 2);
+ $action->setParam('subject', 'Old tasks');
+ $action->setParam('duration', 2);
+
+ $this->container['emailClient']
+ ->expects($this->never())
+ ->method('send');
+
+ $this->assertFalse($action->execute($event, Task::EVENT_DAILY_CRONJOB));
+ }
+}
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));
}
}