summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-09-28 14:26:40 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-09-28 14:26:40 -0400
commit03fa01ac7b036820ee232d893ec63241918c6012 (patch)
tree295e82e6552ffb044554a11afa95318a4e180f87 /tests/units
parent0c8de6a3f58cde2696ac276b3456f3577d312e2b (diff)
Improve automatic actions (check for compatible events/actions/parameters)
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/ActionTaskAssignColorCategoryTest.php4
-rw-r--r--tests/units/ActionTaskAssignColorUserTest.php10
-rw-r--r--tests/units/ActionTaskAssignCurrentUserTest.php6
-rw-r--r--tests/units/ActionTaskAssignSpecificUserTest.php6
-rw-r--r--tests/units/ActionTaskCloseTest.php45
-rw-r--r--tests/units/ActionTaskDuplicateAnotherProjectTest.php6
-rw-r--r--tests/units/ActionTaskMoveAnotherProjectTest.php6
-rw-r--r--tests/units/ActionTest.php86
8 files changed, 60 insertions, 109 deletions
diff --git a/tests/units/ActionTaskAssignColorCategoryTest.php b/tests/units/ActionTaskAssignColorCategoryTest.php
index 84334dc5..5a8c0458 100644
--- a/tests/units/ActionTaskAssignColorCategoryTest.php
+++ b/tests/units/ActionTaskAssignColorCategoryTest.php
@@ -10,7 +10,7 @@ class ActionTaskAssignColorCategory extends Base
{
public function testBadProject()
{
- $action = new Action\TaskAssignColorCategory(3, new Task($this->registry));
+ $action = new Action\TaskAssignColorCategory($this->registry, 3, Task::EVENT_CREATE_UPDATE);
$event = array(
'project_id' => 2,
@@ -24,7 +24,7 @@ class ActionTaskAssignColorCategory extends Base
public function testExecute()
{
- $action = new Action\TaskAssignColorCategory(1, new Task($this->registry));
+ $action = new Action\TaskAssignColorCategory($this->registry, 1, Task::EVENT_CREATE_UPDATE);
$action->setParam('category_id', 1);
$action->setParam('color_id', 'blue');
diff --git a/tests/units/ActionTaskAssignColorUserTest.php b/tests/units/ActionTaskAssignColorUserTest.php
index ee71e87c..8f6a891e 100644
--- a/tests/units/ActionTaskAssignColorUserTest.php
+++ b/tests/units/ActionTaskAssignColorUserTest.php
@@ -9,7 +9,7 @@ class ActionTaskAssignColorUser extends Base
{
public function testBadProject()
{
- $action = new Action\TaskAssignColorUser(3, new Task($this->registry));
+ $action = new Action\TaskAssignColorUser($this->registry, 3, Task::EVENT_CREATE);
$event = array(
'project_id' => 2,
@@ -23,7 +23,7 @@ class ActionTaskAssignColorUser extends Base
public function testExecute()
{
- $action = new Action\TaskAssignColorUser(1, new Task($this->registry));
+ $action = new Action\TaskAssignColorUser($this->registry, 1, Task::EVENT_ASSIGNEE_CHANGE);
$action->setParam('user_id', 1);
$action->setParam('color_id', 'blue');
@@ -33,11 +33,10 @@ class ActionTaskAssignColorUser extends Base
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green')));
- // We create an event to move the task to the 2nd column with a user id 5
+ // We change the assignee
$event = array(
'project_id' => 1,
'task_id' => 1,
- 'column_id' => 2,
'owner_id' => 5,
);
@@ -50,11 +49,10 @@ class ActionTaskAssignColorUser extends Base
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals('green', $task['color_id']);
- // We create an event to move the task to the 2nd column with a user id 1
+ // We change the assignee
$event = array(
'project_id' => 1,
'task_id' => 1,
- 'column_id' => 2,
'owner_id' => 1,
);
diff --git a/tests/units/ActionTaskAssignCurrentUserTest.php b/tests/units/ActionTaskAssignCurrentUserTest.php
index f67c1e28..cfed7be5 100644
--- a/tests/units/ActionTaskAssignCurrentUserTest.php
+++ b/tests/units/ActionTaskAssignCurrentUserTest.php
@@ -10,7 +10,7 @@ class ActionTaskAssignCurrentUser extends Base
{
public function testBadProject()
{
- $action = new Action\TaskAssignCurrentUser(3, new Task($this->registry), new Acl($this->registry));
+ $action = new Action\TaskAssignCurrentUser($this->registry, 3, Task::EVENT_CREATE);
$action->setParam('column_id', 5);
$event = array(
@@ -25,7 +25,7 @@ class ActionTaskAssignCurrentUser extends Base
public function testBadColumn()
{
- $action = new Action\TaskAssignCurrentUser(3, new Task($this->registry), new Acl($this->registry));
+ $action = new Action\TaskAssignCurrentUser($this->registry, 3, Task::EVENT_CREATE);
$action->setParam('column_id', 5);
$event = array(
@@ -39,7 +39,7 @@ class ActionTaskAssignCurrentUser extends Base
public function testExecute()
{
- $action = new Action\TaskAssignCurrentUser(1, new Task($this->registry), new Acl($this->registry));
+ $action = new Action\TaskAssignCurrentUser($this->registry, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
$_SESSION = array(
'user' => array('id' => 5)
diff --git a/tests/units/ActionTaskAssignSpecificUserTest.php b/tests/units/ActionTaskAssignSpecificUserTest.php
index 6fd454d5..de8daf11 100644
--- a/tests/units/ActionTaskAssignSpecificUserTest.php
+++ b/tests/units/ActionTaskAssignSpecificUserTest.php
@@ -9,7 +9,7 @@ class ActionTaskAssignSpecificUser extends Base
{
public function testBadProject()
{
- $action = new Action\TaskAssignSpecificUser(3, new Task($this->registry));
+ $action = new Action\TaskAssignSpecificUser($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -24,7 +24,7 @@ class ActionTaskAssignSpecificUser extends Base
public function testBadColumn()
{
- $action = new Action\TaskAssignSpecificUser(3, new Task($this->registry));
+ $action = new Action\TaskAssignSpecificUser($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -38,7 +38,7 @@ class ActionTaskAssignSpecificUser extends Base
public function testExecute()
{
- $action = new Action\TaskAssignSpecificUser(1, new Task($this->registry));
+ $action = new Action\TaskAssignSpecificUser($this->registry, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
$action->setParam('user_id', 1);
diff --git a/tests/units/ActionTaskCloseTest.php b/tests/units/ActionTaskCloseTest.php
index a3a1eecc..73ff57f3 100644
--- a/tests/units/ActionTaskCloseTest.php
+++ b/tests/units/ActionTaskCloseTest.php
@@ -4,12 +4,51 @@ require_once __DIR__.'/Base.php';
use Model\Task;
use Model\Project;
+use Model\GithubWebhook;
class ActionTaskCloseTest extends Base
{
+ public function testExecutable()
+ {
+ $action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
+ $action->setParam('column_id', 5);
+
+ $event = array(
+ 'project_id' => 3,
+ 'task_id' => 3,
+ 'column_id' => 5,
+ );
+
+ $this->assertTrue($action->isExecutable($event));
+
+ $action = new Action\TaskClose($this->registry, 3, GithubWebhook::EVENT_COMMIT);
+
+ $event = array(
+ 'project_id' => 3,
+ 'task_id' => 3,
+ );
+
+ $this->assertTrue($action->isExecutable($event));
+ }
+
+ public function testBadEvent()
+ {
+ $action = new Action\TaskClose($this->registry, 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($event));
+ }
+
public function testBadProject()
{
- $action = new Action\TaskClose(3, new Task($this->registry));
+ $action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -24,7 +63,7 @@ class ActionTaskCloseTest extends Base
public function testBadColumn()
{
- $action = new Action\TaskClose(3, new Task($this->registry));
+ $action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -38,7 +77,7 @@ class ActionTaskCloseTest extends Base
public function testExecute()
{
- $action = new Action\TaskClose(1, new Task($this->registry));
+ $action = new Action\TaskClose($this->registry, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
// We create a task in the first column
diff --git a/tests/units/ActionTaskDuplicateAnotherProjectTest.php b/tests/units/ActionTaskDuplicateAnotherProjectTest.php
index 4d995b64..75aeedf8 100644
--- a/tests/units/ActionTaskDuplicateAnotherProjectTest.php
+++ b/tests/units/ActionTaskDuplicateAnotherProjectTest.php
@@ -9,7 +9,7 @@ class ActionTaskDuplicateAnotherProject extends Base
{
public function testBadProject()
{
- $action = new Action\TaskDuplicateAnotherProject(3, new Task($this->registry));
+ $action = new Action\TaskDuplicateAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -24,7 +24,7 @@ class ActionTaskDuplicateAnotherProject extends Base
public function testBadColumn()
{
- $action = new Action\TaskDuplicateAnotherProject(3, new Task($this->registry));
+ $action = new Action\TaskDuplicateAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -38,7 +38,7 @@ class ActionTaskDuplicateAnotherProject extends Base
public function testExecute()
{
- $action = new Action\TaskDuplicateAnotherProject(1, new Task($this->registry));
+ $action = new Action\TaskDuplicateAnotherProject($this->registry, 1, Task::EVENT_MOVE_COLUMN);
// We create a task in the first column
$t = new Task($this->registry);
diff --git a/tests/units/ActionTaskMoveAnotherProjectTest.php b/tests/units/ActionTaskMoveAnotherProjectTest.php
index e6a938de..b395a279 100644
--- a/tests/units/ActionTaskMoveAnotherProjectTest.php
+++ b/tests/units/ActionTaskMoveAnotherProjectTest.php
@@ -9,7 +9,7 @@ class ActionTaskMoveAnotherProject extends Base
{
public function testBadProject()
{
- $action = new Action\TaskMoveAnotherProject(3, new Task($this->registry));
+ $action = new Action\TaskMoveAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -24,7 +24,7 @@ class ActionTaskMoveAnotherProject extends Base
public function testBadColumn()
{
- $action = new Action\TaskMoveAnotherProject(3, new Task($this->registry));
+ $action = new Action\TaskMoveAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -38,7 +38,7 @@ class ActionTaskMoveAnotherProject extends Base
public function testExecute()
{
- $action = new Action\TaskMoveAnotherProject(1, new Task($this->registry));
+ $action = new Action\TaskMoveAnotherProject($this->registry, 1, Task::EVENT_MOVE_COLUMN);
// We create a task in the first column
$t = new Task($this->registry);
diff --git a/tests/units/ActionTest.php b/tests/units/ActionTest.php
index 23148c44..f155d0c0 100644
--- a/tests/units/ActionTest.php
+++ b/tests/units/ActionTest.php
@@ -95,92 +95,6 @@ class ActionTest extends Base
$this->assertEquals(0, $t1['is_active']);
}
- public function testEventMovePosition()
- {
- $task = new Task($this->registry);
- $board = new Board($this->registry);
- $project = new Project($this->registry);
- $action = new Action($this->registry);
-
- // We create a project
- $this->assertEquals(1, $project->create(array('name' => 'unit_test')));
-
- // We create a task
- $this->assertEquals(1, $task->create(array(
- 'title' => 'unit_test 0',
- 'project_id' => 1,
- 'owner_id' => 1,
- 'color_id' => 'red',
- 'column_id' => 1,
- 'category_id' => 1,
- )));
-
- $this->assertEquals(2, $task->create(array(
- 'title' => 'unit_test 1',
- 'project_id' => 1,
- 'owner_id' => 1,
- 'color_id' => 'yellow',
- 'column_id' => 1,
- 'category_id' => 1,
- )));
-
- // We create a new action, when the category_id=2 then the color_id should be green
- $this->assertTrue($action->create(array(
- 'project_id' => 1,
- 'event_name' => Task::EVENT_MOVE_POSITION,
- 'action_name' => 'TaskAssignColorCategory',
- 'params' => array(
- 'category_id' => 1,
- 'color_id' => 'green',
- )
- )));
-
- // We bind events
- $action->attachEvents();
-
- $this->assertTrue($this->registry->shared('event')->hasListener(Task::EVENT_MOVE_POSITION, 'Action\TaskAssignColorCategory'));
-
- // Our task should have the color red and position=1
- $t1 = $task->getById(1);
- $this->assertEquals(1, $t1['position']);
- $this->assertEquals(1, $t1['is_active']);
- $this->assertEquals('red', $t1['color_id']);
-
- $t1 = $task->getById(2);
- $this->assertEquals(2, $t1['position']);
- $this->assertEquals(1, $t1['is_active']);
- $this->assertEquals('yellow', $t1['color_id']);
-
- // We move our tasks
- $this->assertTrue($task->movePosition(1, 1, 1, 10)); // task #1 to the end of the column
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_POSITION));
-
- $t1 = $task->getById(1);
- $this->assertEquals(2, $t1['position']);
- $this->assertEquals(1, $t1['is_active']);
- $this->assertEquals('green', $t1['color_id']);
-
- $t1 = $task->getById(2);
- $this->assertEquals(1, $t1['position']);
- $this->assertEquals(1, $t1['is_active']);
- $this->assertEquals('yellow', $t1['color_id']);
-
- $this->registry->shared('event')->clearTriggeredEvents();
- $this->assertTrue($task->movePosition(1, 2, 1, 44)); // task #2 to position 1
- $this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_POSITION));
- $this->assertEquals('Action\TaskAssignColorCategory', $this->registry->shared('event')->getLastListenerExecuted());
-
- $t1 = $task->getById(1);
- $this->assertEquals(1, $t1['position']);
- $this->assertEquals(1, $t1['is_active']);
- $this->assertEquals('green', $t1['color_id']);
-
- $t1 = $task->getById(2);
- $this->assertEquals(2, $t1['position']);
- $this->assertEquals(1, $t1['is_active']);
- $this->assertEquals('green', $t1['color_id']);
- }
-
public function testExecuteMultipleActions()
{
$task = new Task($this->registry);