summaryrefslogtreecommitdiff
path: root/tests/units/Model/ActionTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/Model/ActionTest.php')
-rw-r--r--tests/units/Model/ActionTest.php701
1 files changed, 410 insertions, 291 deletions
diff --git a/tests/units/Model/ActionTest.php b/tests/units/Model/ActionTest.php
index 30f6b22c..ed687846 100644
--- a/tests/units/Model/ActionTest.php
+++ b/tests/units/Model/ActionTest.php
@@ -4,387 +4,506 @@ require_once __DIR__.'/../Base.php';
use Kanboard\Model\Action;
use Kanboard\Model\Project;
-use Kanboard\Model\Board;
use Kanboard\Model\Task;
-use Kanboard\Model\TaskPosition;
-use Kanboard\Model\TaskCreation;
-use Kanboard\Model\TaskFinder;
-use Kanboard\Model\Category;
use Kanboard\Model\User;
-use Kanboard\Model\ProjectPermission;
-use Kanboard\Integration\GithubWebhook;
-use Kanboard\Integration\BitbucketWebhook;
+use Kanboard\Model\Column;
+use Kanboard\Model\Category;
+use Kanboard\Model\ProjectUserRole;
+use Kanboard\Core\Security\Role;
class ActionTest extends Base
{
- public function testGetActions()
+ public function testCreate()
{
- $a = new Action($this->container);
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
- $actions = $a->getAvailableActions();
- $this->assertNotEmpty($actions);
- $this->assertEquals('Add a comment log when moving the task between columns', current($actions));
- $this->assertEquals('TaskLogMoveAnotherColumn', key($actions));
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
}
- public function testExtendActions()
+ public function testRemove()
{
- $a = new Action($this->container);
- $a->extendActions('MyClass', 'Description');
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
- $actions = $a->getAvailableActions();
- $this->assertNotEmpty($actions);
- $this->assertContains('Description', $actions);
- $this->assertArrayHasKey('MyClass', $actions);
+ $this->assertNotEmpty($actionModel->getById(1));
+ $this->assertTrue($actionModel->remove(1));
+ $this->assertEmpty($actionModel->getById(1));
}
- public function testGetEvents()
+ public function testGetById()
{
- $a = new Action($this->container);
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
- $events = $a->getAvailableEvents();
- $this->assertNotEmpty($events);
- $this->assertEquals('Bitbucket commit received', current($events));
- $this->assertEquals(BitbucketWebhook::EVENT_COMMIT, key($events));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $action = $actionModel->getById(1);
+ $this->assertNotEmpty($action);
+ $this->assertEquals(1, $action['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $action['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $action['event_name']);
+ $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $action['params']);
}
- public function testGetCompatibleEvents()
+ public function testGetAll()
{
- $a = new Action($this->container);
- $events = $a->getCompatibleEvents('TaskAssignSpecificUser');
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $this->assertNotEmpty($events);
- $this->assertCount(2, $events);
- $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE, $events);
- $this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN, $events);
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $this->assertEquals(2, $actionModel->create(array(
+ 'project_id' => 2,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 6, 'color_id' => 'blue'),
+ )));
+
+ $actions = $actionModel->getAll();
+ $this->assertCount(2, $actions);
+
+ $this->assertEquals(1, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']);
+
+ $this->assertEquals(2, $actions[1]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[1]['action_name']);
+ $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[1]['event_name']);
+ $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[1]['params']);
}
- public function testResolveDuplicatedParameters()
+ public function testGetAllByProject()
{
- $p = new Project($this->container);
- $pp = new ProjectPermission($this->container);
- $a = new Action($this->container);
- $c = new Category($this->container);
- $u = new User($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(2, $p->create(array('name' => 'P2')));
-
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
-
- $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 2)));
- $this->assertEquals(3, $c->create(array('name' => 'C1', 'project_id' => 2)));
-
- $this->assertEquals(2, $u->create(array('username' => 'unittest1')));
- $this->assertEquals(3, $u->create(array('username' => 'unittest2')));
-
- $this->assertTrue($pp->addMember(1, 2));
- $this->assertTrue($pp->addMember(1, 3));
- $this->assertTrue($pp->addMember(2, 3));
-
- // anything
- $this->assertEquals('blah', $a->resolveParameters(array('name' => 'foobar', 'value' => 'blah'), 2));
-
- // project_id
- $this->assertEquals(2, $a->resolveParameters(array('name' => 'project_id', 'value' => 'blah'), 2));
-
- // category_id
- $this->assertEquals(3, $a->resolveParameters(array('name' => 'category_id', 'value' => 1), 2));
- $this->assertFalse($a->resolveParameters(array('name' => 'category_id', 'value' => 0), 2));
- $this->assertFalse($a->resolveParameters(array('name' => 'category_id', 'value' => 5), 2));
-
- // column_id
- $this->assertFalse($a->resolveParameters(array('name' => 'column_id', 'value' => 10), 2));
- $this->assertFalse($a->resolveParameters(array('name' => 'column_id', 'value' => 0), 2));
- $this->assertEquals(5, $a->resolveParameters(array('name' => 'column_id', 'value' => 1), 2));
- $this->assertEquals(6, $a->resolveParameters(array('name' => 'dest_column_id', 'value' => 2), 2));
- $this->assertEquals(7, $a->resolveParameters(array('name' => 'dst_column_id', 'value' => 3), 2));
- $this->assertEquals(8, $a->resolveParameters(array('name' => 'src_column_id', 'value' => 4), 2));
-
- // user_id
- $this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 10), 2));
- $this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 0), 2));
- $this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 2), 2));
- $this->assertFalse($a->resolveParameters(array('name' => 'owner_id', 'value' => 2), 2));
- $this->assertEquals(3, $a->resolveParameters(array('name' => 'user_id', 'value' => 3), 2));
- $this->assertEquals(3, $a->resolveParameters(array('name' => 'owner_id', 'value' => 3), 2));
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $this->assertEquals(2, $actionModel->create(array(
+ 'project_id' => 2,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 6, 'color_id' => 'blue'),
+ )));
+
+ $actions = $actionModel->getAllByProject(1);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(1, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']);
+
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']);
}
- public function testDuplicateSuccess()
+ public function testGetAllByUser()
{
- $p = new Project($this->container);
- $pp = new ProjectPermission($this->container);
- $a = new Action($this->container);
- $u = new User($this->container);
+ $projectModel = new Project($this->container);
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $userModel = new User($this->container);
+ $actionModel = new Action($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(2, $p->create(array('name' => 'P2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(3, $projectModel->create(array('name' => 'test4', 'is_active' => 0)));
- $this->assertEquals(2, $u->create(array('username' => 'unittest1')));
- $this->assertEquals(3, $u->create(array('username' => 'unittest2')));
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+ $this->assertEquals(3, $userModel->create(array('username' => 'user2')));
- $this->assertTrue($pp->addMember(1, 2));
- $this->assertTrue($pp->addMember(1, 3));
- $this->assertTrue($pp->addMember(2, 3));
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_VIEWER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 3, Role::PROJECT_MANAGER));
+ $this->assertTrue($projectUserRoleModel->addUser(3, 3, Role::PROJECT_MANAGER));
- $this->assertEquals(1, $a->create(array(
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
- 'event_name' => Task::EVENT_CREATE_UPDATE,
- 'action_name' => 'TaskAssignSpecificUser',
- 'params' => array(
- 'column_id' => 1,
- 'user_id' => 3,
- )
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
)));
- $action = $a->getById(1);
- $this->assertNotEmpty($action);
- $this->assertNotEmpty($action['params']);
- $this->assertEquals(1, $action['project_id']);
+ $this->assertEquals(2, $actionModel->create(array(
+ 'project_id' => 2,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 6, 'color_id' => 'blue'),
+ )));
- $this->assertTrue($a->duplicate(1, 2));
+ $this->assertEquals(3, $actionModel->create(array(
+ 'project_id' => 3,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 10, 'color_id' => 'green'),
+ )));
- $action = $a->getById(2);
- $this->assertNotEmpty($action);
- $this->assertNotEmpty($action['params']);
- $this->assertEquals(2, $action['project_id']);
- $this->assertEquals(Task::EVENT_CREATE_UPDATE, $action['event_name']);
- $this->assertEquals('TaskAssignSpecificUser', $action['action_name']);
- $this->assertEquals('column_id', $action['params'][0]['name']);
- $this->assertEquals(5, $action['params'][0]['value']);
- $this->assertEquals('user_id', $action['params'][1]['name']);
- $this->assertEquals(3, $action['params'][1]['value']);
+ $actions = $actionModel->getAllByUser(1);
+ $this->assertCount(0, $actions);
+
+ $actions = $actionModel->getAllByUser(2);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(1, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']);
+
+ $actions = $actionModel->getAllByUser(3);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']);
}
- public function testDuplicateUnableToResolveParams()
+ public function testDuplicateWithColumnAndColorParameter()
{
- $p = new Project($this->container);
- $pp = new ProjectPermission($this->container);
- $a = new Action($this->container);
- $u = new User($this->container);
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(2, $p->create(array('name' => 'P2')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $this->assertEquals(2, $u->create(array('username' => 'unittest1')));
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
- $this->assertTrue($pp->addMember(1, 2));
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']);
+ }
+
+ public function testDuplicateWithColumnsParameter()
+ {
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
- $this->assertEquals(1, $a->create(array(
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
- 'event_name' => Task::EVENT_CREATE_UPDATE,
- 'action_name' => 'TaskAssignSpecificUser',
- 'params' => array(
- 'column_id' => 1,
- 'user_id' => 2,
- )
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('src_column_id' => 1, 'dst_column_id' => 2, 'dest_column_id' => 3),
)));
- $action = $a->getById(1);
- $this->assertNotEmpty($action);
- $this->assertNotEmpty($action['params']);
- $this->assertEquals(1, $action['project_id']);
- $this->assertEquals('user_id', $action['params'][1]['name']);
- $this->assertEquals(2, $action['params'][1]['value']);
+ $this->assertTrue($actionModel->duplicate(1, 2));
- $this->assertTrue($a->duplicate(1, 2));
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
- $action = $a->getById(2);
- $this->assertEmpty($action);
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']);
+ $this->assertEquals(array('src_column_id' => 5, 'dst_column_id' => 6, 'dest_column_id' => 7), $actions[0]['params']);
}
- public function testDuplicateMixedResults()
+ public function testDuplicateWithColumnParameterNotfound()
{
- $p = new Project($this->container);
- $pp = new ProjectPermission($this->container);
- $a = new Action($this->container);
- $u = new User($this->container);
- $c = new Category($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'P1')));
- $this->assertEquals(2, $p->create(array('name' => 'P2')));
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+ $columnModel = new Column($this->container);
- $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
- $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 2)));
- $this->assertEquals(3, $c->create(array('name' => 'C1', 'project_id' => 2)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $this->assertEquals(2, $u->create(array('username' => 'unittest1')));
+ $this->assertTrue($columnModel->update(2, 'My unique column'));
- $this->assertTrue($pp->addMember(1, 2));
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
- $this->assertEquals(1, $a->create(array(
+ $this->assertEquals(2, $actionModel->create(array(
'project_id' => 1,
- 'event_name' => Task::EVENT_CREATE_UPDATE,
- 'action_name' => 'TaskAssignSpecificUser',
- 'params' => array(
- 'column_id' => 1,
- 'user_id' => 2,
- )
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 2, 'color_id' => 'green'),
)));
- $action = $a->getById(1);
- $this->assertNotEmpty($action);
- $this->assertNotEmpty($action['params']);
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']);
+ }
+
+ public function testDuplicateWithProjectParameter()
+ {
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
- $this->assertEquals(2, $a->create(array(
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(3, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
- 'event_name' => Task::EVENT_CREATE_UPDATE,
- 'action_name' => 'TaskAssignCategoryColor',
- 'params' => array(
- 'color_id' => 'blue',
- 'category_id' => 1,
- )
+ 'event_name' => Task::EVENT_CLOSE,
+ 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject',
+ 'params' => array('column_id' => 1, 'project_id' => 3),
)));
- $action = $a->getById(2);
- $this->assertNotEmpty($action);
- $this->assertNotEmpty($action['params']);
- $this->assertEquals('category_id', $action['params'][1]['name']);
- $this->assertEquals(1, $action['params'][1]['value']);
+ $this->assertTrue($actionModel->duplicate(1, 2));
- $actions = $a->getAllByProject(1);
- $this->assertNotEmpty($actions);
- $this->assertCount(2, $actions);
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
- $this->assertTrue($a->duplicate(1, 2));
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskDuplicateAnotherProject', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CLOSE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 5, 'project_id' => 3), $actions[0]['params']);
+ }
- $actions = $a->getAllByProject(2);
- $this->assertNotEmpty($actions);
- $this->assertCount(1, $actions);
+ public function testDuplicateWithProjectParameterIdenticalToDestination()
+ {
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
- $actions = $a->getAll();
- $this->assertNotEmpty($actions);
- $this->assertCount(3, $actions);
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- $action = $a->getById($actions[2]['id']);
- $this->assertNotEmpty($action);
- $this->assertNotEmpty($action['params']);
- $this->assertEquals('color_id', $action['params'][0]['name']);
- $this->assertEquals('blue', $action['params'][0]['value']);
- $this->assertEquals('category_id', $action['params'][1]['name']);
- $this->assertEquals(3, $action['params'][1]['value']);
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_CLOSE,
+ 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject',
+ 'params' => array('column_id' => 1, 'project_id' => 2),
+ )));
+
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(0, $actions);
}
- public function testSingleAction()
+ public function testDuplicateWithUserParameter()
{
- $tp = new TaskPosition($this->container);
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $board = new Board($this->container);
- $project = new Project($this->container);
- $action = new Action($this->container);
-
- // We create a project
- $this->assertEquals(1, $project->create(array('name' => 'unit_test')));
-
- // We create a new action
- $this->assertEquals(1, $action->create(array(
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER));
+
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
'event_name' => Task::EVENT_MOVE_COLUMN,
- 'action_name' => 'TaskClose',
- 'params' => array(
- 'column_id' => 4,
- )
+ 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser',
+ 'params' => array('column_id' => 1, 'user_id' => 2),
)));
- // We create a task
- $this->assertEquals(1, $tc->create(array(
- 'title' => 'unit_test',
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignSpecificUser', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 5, 'user_id' => 2), $actions[0]['params']);
+ }
+
+ public function testDuplicateWithUserParameterButNotAssignable()
+ {
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+ $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_VIEWER));
+
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
- 'owner_id' => 1,
- 'color_id' => 'red',
- 'column_id' => 1,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser',
+ 'params' => array('column_id' => 1, 'user_id' => 2),
)));
- // We attach events
- $action->attachEvents();
+ $this->assertTrue($actionModel->duplicate(1, 2));
- // Our task should be open
- $t1 = $tf->getById(1);
- $this->assertEquals(1, $t1['is_active']);
- $this->assertEquals(1, $t1['column_id']);
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(0, $actions);
+ }
+
+ public function testDuplicateWithUserParameterButNotAvailable()
+ {
+ $projectUserRoleModel = new ProjectUserRole($this->container);
+ $userModel = new User($this->container);
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
- // We move our task
- $tp->movePosition(1, 1, 4, 1);
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
- // Our task should be closed
- $t1 = $tf->getById(1);
- $this->assertEquals(4, $t1['column_id']);
- $this->assertEquals(0, $t1['is_active']);
+ $this->assertEquals(2, $userModel->create(array('username' => 'user1')));
+
+ $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => Task::EVENT_MOVE_COLUMN,
+ 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser',
+ 'params' => array('column_id' => 1, 'owner_id' => 2),
+ )));
+
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(0, $actions);
}
- public function testMultipleActions()
+ public function testDuplicateWithCategoryParameter()
{
- $tp = new TaskPosition($this->container);
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $b = new Board($this->container);
- $p = new Project($this->container);
- $a = new Action($this->container);
- $g = new GithubWebhook($this->container);
-
- // We create a project
- $this->assertEquals(1, $p->create(array('name' => 'unit_test')));
-
- // We create a new action
- $this->assertEquals(1, $a->create(array(
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+ $categoryModel = new Category($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
+ $this->assertEquals(2, $categoryModel->create(array('name' => 'c1', 'project_id' => 2)));
+
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
- 'event_name' => GithubWebhook::EVENT_ISSUE_OPENED,
- 'action_name' => 'TaskCreation',
- 'params' => array()
+ 'event_name' => Task::EVENT_CREATE_UPDATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorCategory',
+ 'params' => array('column_id' => 1, 'category_id' => 1),
)));
- $this->assertEquals(2, $a->create(array(
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(1, $actions);
+
+ $this->assertEquals(2, $actions[0]['project_id']);
+ $this->assertEquals('\Kanboard\Action\TaskAssignColorCategory', $actions[0]['action_name']);
+ $this->assertEquals(Task::EVENT_CREATE_UPDATE, $actions[0]['event_name']);
+ $this->assertEquals(array('column_id' => 5, 'category_id' => 2), $actions[0]['params']);
+ }
+
+ public function testDuplicateWithCategoryParameterButDifferentName()
+ {
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+ $categoryModel = new Category($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
+ $this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 2)));
+
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
- 'event_name' => GithubWebhook::EVENT_ISSUE_LABEL_CHANGE,
- 'action_name' => 'TaskAssignCategoryLabel',
- 'params' => array(
- 'label' => 'bug',
- 'category_id' => 1,
- )
+ 'event_name' => Task::EVENT_CREATE_UPDATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorCategory',
+ 'params' => array('column_id' => 1, 'category_id' => 1),
)));
- $this->assertEquals(3, $a->create(array(
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(0, $actions);
+ }
+
+ public function testDuplicateWithCategoryParameterButNotFound()
+ {
+ $projectModel = new Project($this->container);
+ $actionModel = new Action($this->container);
+ $categoryModel = new Category($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
+
+ $this->assertEquals(1, $actionModel->create(array(
'project_id' => 1,
'event_name' => Task::EVENT_CREATE_UPDATE,
- 'action_name' => 'TaskAssignColorCategory',
- 'params' => array(
- 'color_id' => 'red',
- 'category_id' => 1,
- )
+ 'action_name' => '\Kanboard\Action\TaskAssignColorCategory',
+ 'params' => array('column_id' => 1, 'category_id' => 1),
)));
- // We attach events
- $a->attachEvents();
- $g->setProjectId(1);
-
- // We create a Github issue
- $issue = array(
- 'number' => 123,
- 'title' => 'Bugs everywhere',
- 'body' => 'There is a bug!',
- 'html_url' => 'http://localhost/',
- );
-
- $this->assertTrue($g->handleIssueOpened($issue));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['is_active']);
- $this->assertEquals(0, $task['category_id']);
- $this->assertEquals('yellow', $task['color_id']);
-
- // We assign a label to our issue
- $label = array(
- 'name' => 'bug',
- );
-
- $this->assertTrue($g->handleIssueLabeled($issue, $label));
-
- $task = $tf->getById(1);
- $this->assertNotEmpty($task);
- $this->assertEquals(1, $task['is_active']);
- $this->assertEquals(1, $task['category_id']);
- $this->assertEquals('red', $task['color_id']);
+ $this->assertTrue($actionModel->duplicate(1, 2));
+
+ $actions = $actionModel->getAllByProject(2);
+ $this->assertCount(0, $actions);
}
}