Improve Automatic Actions plugin api
This commit is contained in:
@@ -875,7 +875,7 @@ class Api extends PHPUnit_Framework_TestCase
|
||||
$actions = $this->client->getAvailableActions();
|
||||
$this->assertNotEmpty($actions);
|
||||
$this->assertInternalType('array', $actions);
|
||||
$this->assertArrayHasKey('TaskLogMoveAnotherColumn', $actions);
|
||||
$this->assertArrayHasKey('\Kanboard\Action\TaskClose', $actions);
|
||||
}
|
||||
|
||||
public function testGetAvailableActionEvents()
|
||||
@@ -888,7 +888,7 @@ class Api extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testGetCompatibleActionEvents()
|
||||
{
|
||||
$events = $this->client->getCompatibleActionEvents('TaskClose');
|
||||
$events = $this->client->getCompatibleActionEvents('\Kanboard\Action\TaskCloseColumn');
|
||||
$this->assertNotEmpty($events);
|
||||
$this->assertInternalType('array', $events);
|
||||
$this->assertArrayHasKey('task.move.column', $events);
|
||||
@@ -896,7 +896,7 @@ class Api extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function testCreateAction()
|
||||
{
|
||||
$action_id = $this->client->createAction(1, 'task.move.column', 'TaskClose', array('column_id' => 1));
|
||||
$action_id = $this->client->createAction(1, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1));
|
||||
$this->assertNotFalse($action_id);
|
||||
$this->assertEquals(1, $action_id);
|
||||
}
|
||||
|
||||
144
tests/units/Action/BaseActionTest.php
Normal file
144
tests/units/Action/BaseActionTest.php
Normal file
@@ -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'));
|
||||
}
|
||||
}
|
||||
58
tests/units/Action/CommentCreationMoveTaskColumnTest.php
Normal file
58
tests/units/Action/CommentCreationMoveTaskColumnTest.php
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
$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);
|
||||
|
||||
// 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)));
|
||||
$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));
|
||||
|
||||
// We create an event to move the task to the 2nd column
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'user_id' => 1,
|
||||
);
|
||||
$event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'comment' => 'test123', 'reference' => 'ref123', 'user_id' => 2));
|
||||
|
||||
// Our event should be executed
|
||||
$this->assertFalse($action->execute(new GenericEvent($event)));
|
||||
$action = new CommentCreation($this->container);
|
||||
$action->setProjectId(1);
|
||||
$action->addEvent('test.event', 'Test Event');
|
||||
|
||||
$comment = $c->getById(1);
|
||||
$this->assertEmpty($comment);
|
||||
}
|
||||
$this->assertTrue($action->execute($event, 'test.event'));
|
||||
|
||||
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);
|
||||
$comment = $commentModel->getById(1);
|
||||
$this->assertNotEmpty($comment);
|
||||
$this->assertEquals(1, $comment['task_id']);
|
||||
$this->assertEquals('test123', $comment['comment']);
|
||||
$this->assertEquals('ref123', $comment['reference']);
|
||||
$this->assertEquals(2, $comment['user_id']);
|
||||
}
|
||||
|
||||
public function testWithUserNotAssignable()
|
||||
{
|
||||
$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('test123', $comment['comment']);
|
||||
$this->assertEquals('', $comment['reference']);
|
||||
$this->assertEquals(0, $comment['user_id']);
|
||||
$this->assertEquals('plop', $comment['comment']);
|
||||
}
|
||||
|
||||
public function testWithUser()
|
||||
public function testWithNoComment()
|
||||
{
|
||||
$action = new CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_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);
|
||||
|
||||
// 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)));
|
||||
$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')));
|
||||
|
||||
// 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',
|
||||
);
|
||||
$event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
|
||||
|
||||
// Our event should be executed
|
||||
$this->assertTrue($action->execute(new GenericEvent($event)));
|
||||
$action = new CommentCreation($this->container);
|
||||
$action->setProjectId(1);
|
||||
$action->addEvent('test.event', 'Test Event');
|
||||
|
||||
$comment = $c->getById(1);
|
||||
$this->assertNotEmpty($comment);
|
||||
$this->assertEquals(1, $comment['task_id']);
|
||||
$this->assertEquals(1, $comment['user_id']);
|
||||
$this->assertEquals('youpi', $comment['comment']);
|
||||
}
|
||||
|
||||
public function testWithNoUser()
|
||||
{
|
||||
$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']);
|
||||
$this->assertFalse($action->execute($event, 'test.event'));
|
||||
}
|
||||
}
|
||||
|
||||
60
tests/units/Action/TaskAssignCategoryColorTest.php
Normal file
60
tests/units/Action/TaskAssignCategoryColorTest.php
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
85
tests/units/Action/TaskAssignCategoryLabelTest.php
Normal file
85
tests/units/Action/TaskAssignCategoryLabelTest.php
Normal file
@@ -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'));
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,8 @@ class TaskAssignCategoryLinkTest extends Base
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
$action = new TaskAssignCategoryLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE);
|
||||
$action = new TaskAssignCategoryLink($this->container);
|
||||
$action->setProjectId(1);
|
||||
$action->setParam('category_id', 1);
|
||||
$action->setParam('link_id', 2);
|
||||
|
||||
@@ -28,30 +29,28 @@ class TaskAssignCategoryLinkTest extends Base
|
||||
$this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(0, $task['category_id']);
|
||||
|
||||
$event = array(
|
||||
$event = new TaskLinkEvent(array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'opposite_task_id' => 2,
|
||||
'link_id' => 2,
|
||||
);
|
||||
));
|
||||
|
||||
$this->assertTrue($action->execute(new TaskLinkEvent($event)));
|
||||
$this->assertTrue($action->execute($event, TaskLink::EVENT_CREATE_UPDATE));
|
||||
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals(1, $task['category_id']);
|
||||
}
|
||||
|
||||
public function testThatLinkDontMatch()
|
||||
public function testWhenLinkDontMatch()
|
||||
{
|
||||
$tc = new TaskCreation($this->container);
|
||||
$tf = new TaskFinder($this->container);
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
$action = new TaskAssignCategoryLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE);
|
||||
$action = new TaskAssignCategoryLink($this->container);
|
||||
$action->setProjectId(1);
|
||||
$action->setParam('category_id', 1);
|
||||
$action->setParam('link_id', 1);
|
||||
|
||||
@@ -59,14 +58,14 @@ class TaskAssignCategoryLinkTest extends Base
|
||||
$this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1)));
|
||||
|
||||
$event = array(
|
||||
$event = new TaskLinkEvent(array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'opposite_task_id' => 2,
|
||||
'link_id' => 2,
|
||||
);
|
||||
));
|
||||
|
||||
$this->assertFalse($action->execute(new TaskLinkEvent($event)));
|
||||
$this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE));
|
||||
}
|
||||
|
||||
public function testThatExistingCategoryWillNotChange()
|
||||
@@ -76,7 +75,8 @@ class TaskAssignCategoryLinkTest extends Base
|
||||
$p = new Project($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
$action = new TaskAssignCategoryLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE);
|
||||
$action = new TaskAssignCategoryLink($this->container);
|
||||
$action->setProjectId(1);
|
||||
$action->setParam('category_id', 2);
|
||||
$action->setParam('link_id', 2);
|
||||
|
||||
@@ -85,13 +85,13 @@ class TaskAssignCategoryLinkTest extends Base
|
||||
$this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
|
||||
$this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'category_id' => 1)));
|
||||
|
||||
$event = array(
|
||||
$event = new TaskLinkEvent(array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'opposite_task_id' => 2,
|
||||
'link_id' => 2,
|
||||
);
|
||||
));
|
||||
|
||||
$this->assertFalse($action->execute(new TaskLinkEvent($event)));
|
||||
$this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
$action = new TaskAssignColorCategory($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('red', $task['color_id']);
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
public function testWithWrongCategory()
|
||||
{
|
||||
$action = new TaskAssignColorCategory($this->container, 1, Task::EVENT_CREATE_UPDATE);
|
||||
$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')));
|
||||
|
||||
$event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'category_id' => 2));
|
||||
|
||||
$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->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)));
|
||||
|
||||
// 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,
|
||||
);
|
||||
|
||||
// Our event should NOT be executed
|
||||
$this->assertFalse($action->execute(new GenericEvent($event)));
|
||||
|
||||
// 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']);
|
||||
|
||||
// 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)));
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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']);
|
||||
}
|
||||
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'column_id' => 2,
|
||||
'color_id' => 'green',
|
||||
);
|
||||
public function testWithWrongCategory()
|
||||
{
|
||||
$projectModel = new Project($this->container);
|
||||
$taskCreationModel = new TaskCreation($this->container);
|
||||
$taskFinderModel = new TaskFinder($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 have color green
|
||||
$task = $tf->getById(1);
|
||||
$this->assertEquals('green', $task['color_id']);
|
||||
$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);
|
||||
|
||||
$this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
$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);
|
||||
$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)));
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
|
||||
|
||||
// The color should be yellow
|
||||
$task = $tf->getById(1);
|
||||
$event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'link_id' => 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('yellow', $task['color_id']);
|
||||
$this->assertEquals('red', $task['color_id']);
|
||||
}
|
||||
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'link_id' => 2,
|
||||
);
|
||||
public function testWithWrongLink()
|
||||
{
|
||||
$projectModel = new Project($this->container);
|
||||
$taskCreationModel = new TaskCreation($this->container);
|
||||
$taskFinderModel = new TaskFinder($this->container);
|
||||
|
||||
// Our event should be executed
|
||||
$this->assertTrue($action->execute(new TaskLinkEvent($event)));
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
|
||||
|
||||
// The color should be green
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals('green', $task['color_id']);
|
||||
$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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
$action = new TaskAssignColorUser($this->container);
|
||||
$action->setProjectId(1);
|
||||
$action->setParam('color_id', 'red');
|
||||
$action->setParam('user_id', 1);
|
||||
|
||||
$this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE));
|
||||
|
||||
$task = $taskFinderModel->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals('red', $task['color_id']);
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
public function testWithWrongUser()
|
||||
{
|
||||
$action = new TaskAssignColorUser($this->container, 1, Task::EVENT_ASSIGNEE_CHANGE);
|
||||
$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, 'owner_id' => 2));
|
||||
|
||||
$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')));
|
||||
|
||||
// We change the assignee
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'owner_id' => 5,
|
||||
);
|
||||
|
||||
// Our event should NOT be executed
|
||||
$this->assertFalse($action->execute(new GenericEvent($event)));
|
||||
|
||||
// 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']);
|
||||
|
||||
// We change the assignee
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'owner_id' => 1,
|
||||
);
|
||||
|
||||
// Our event should be executed
|
||||
$this->assertTrue($action->execute(new GenericEvent($event)));
|
||||
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
||||
75
tests/units/Action/TaskAssignCurrentUserColumnTest.php
Normal file
75
tests/units/Action/TaskAssignCurrentUserColumnTest.php
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -3,73 +3,51 @@
|
||||
require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Kanboard\Event\GenericEvent;
|
||||
use Kanboard\Model\Task;
|
||||
use Kanboard\Model\TaskCreation;
|
||||
use Kanboard\Model\TaskFinder;
|
||||
use Kanboard\Model\Project;
|
||||
use Kanboard\Core\User\UserSession;
|
||||
use Kanboard\Model\Task;
|
||||
use Kanboard\Action\TaskAssignCurrentUser;
|
||||
|
||||
class TaskAssignCurrentUserTest extends Base
|
||||
{
|
||||
public function testBadProject()
|
||||
public function testChangeUser()
|
||||
{
|
||||
$action = new TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE);
|
||||
$action->setParam('column_id', 5);
|
||||
$this->container['sessionStorage']->user = array('id' => 1);
|
||||
|
||||
$event = array(
|
||||
'project_id' => 2,
|
||||
'task_id' => 3,
|
||||
'column_id' => 5,
|
||||
);
|
||||
$projectModel = new Project($this->container);
|
||||
$taskCreationModel = new TaskCreation($this->container);
|
||||
$taskFinderModel = new TaskFinder($this->container);
|
||||
|
||||
$this->assertFalse($action->isExecutable($event));
|
||||
$this->assertFalse($action->execute(new GenericEvent($event)));
|
||||
}
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
|
||||
$this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
|
||||
|
||||
public function testBadColumn()
|
||||
{
|
||||
$action = new TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE);
|
||||
$action->setParam('column_id', 5);
|
||||
$event = new GenericEvent(array('project_id' => 1, 'task_id' => 1));
|
||||
|
||||
$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));
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
$this->container['sessionStorage']->user = array('id' => 5);
|
||||
|
||||
$action = new TaskAssignCurrentUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
|
||||
$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)));
|
||||
|
||||
// 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
|
||||
$this->assertTrue($action->execute(new GenericEvent($event)));
|
||||
|
||||
// Our task should be assigned to the user 5 (from the session)
|
||||
$task = $tf->getById(1);
|
||||
$task = $taskFinderModel->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['id']);
|
||||
$this->assertEquals(5, $task['owner_id']);
|
||||
$this->assertEquals(1, $task['owner_id']);
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
$action = new TaskAssignCurrentUser($this->container);
|
||||
$action->setProjectId(1);
|
||||
|
||||
$this->assertFalse($action->execute($event, Task::EVENT_CREATE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
$event = array(
|
||||
'project_id' => 3,
|
||||
'task_id' => 3,
|
||||
'column_id' => 3,
|
||||
);
|
||||
|
||||
$this->assertFalse($action->execute(new GenericEvent($event)));
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
$action = new TaskAssignSpecificUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
|
||||
$action = new TaskAssignSpecificUser($this->container);
|
||||
$action->setProjectId(1);
|
||||
$action->setParam('column_id', 2);
|
||||
$action->setParam('user_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);
|
||||
$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));
|
||||
|
||||
// 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
|
||||
$this->assertTrue($action->execute(new GenericEvent($event)));
|
||||
|
||||
// Our task should be assigned to the user 1
|
||||
$task = $tf->getById(1);
|
||||
$task = $taskFinderModel->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['owner_id']);
|
||||
}
|
||||
|
||||
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 TaskAssignSpecificUser($this->container);
|
||||
$action->setProjectId(1);
|
||||
$action->setParam('column_id', 2);
|
||||
$action->setParam('user_id', 1);
|
||||
|
||||
$this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN));
|
||||
}
|
||||
}
|
||||
|
||||
62
tests/units/Action/TaskAssignUserTest.php
Normal file
62
tests/units/Action/TaskAssignUserTest.php
Normal file
@@ -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'));
|
||||
}
|
||||
}
|
||||
53
tests/units/Action/TaskCloseColumnTest.php
Normal file
53
tests/units/Action/TaskCloseColumnTest.php
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
$action = new TaskClose($this->container, 1, Task::EVENT_MOVE_COLUMN);
|
||||
$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)));
|
||||
|
||||
// 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
|
||||
$this->assertTrue($action->execute(new GenericEvent($event)));
|
||||
|
||||
// Our task should be closed
|
||||
$task = $tf->getById(1);
|
||||
$task = $taskFinderModel->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(0, $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 TaskClose($this->container);
|
||||
$action->setProjectId(1);
|
||||
$action->addEvent('test.event', 'Test Event');
|
||||
|
||||
$this->assertFalse($action->execute($event, 'test.event'));
|
||||
}
|
||||
}
|
||||
|
||||
49
tests/units/Action/TaskCreationTest.php
Normal file
49
tests/units/Action/TaskCreationTest.php
Normal file
@@ -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'));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
$event = array(
|
||||
'project_id' => 3,
|
||||
'task_id' => 3,
|
||||
'column_id' => 3,
|
||||
);
|
||||
|
||||
$this->assertFalse($action->execute(new GenericEvent($event)));
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
$action = new TaskDuplicateAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN);
|
||||
|
||||
// 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)));
|
||||
|
||||
// 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)));
|
||||
|
||||
// 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)));
|
||||
$action->setParam('column_id', 2);
|
||||
|
||||
// Our task should be assigned to the project 1
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(1, $task['project_id']);
|
||||
$this->assertTrue($action->execute($event, Task::EVENT_CLOSE));
|
||||
|
||||
// We should have another task assigned to the project 2
|
||||
$task = $tf->getById(2);
|
||||
$task = $taskFinderModel->getById(2);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals('test', $task['title']);
|
||||
$this->assertEquals(2, $task['project_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));
|
||||
|
||||
$action = new TaskDuplicateAnotherProject($this->container);
|
||||
$action->setProjectId(1);
|
||||
$action->setParam('project_id', 2);
|
||||
$action->setParam('column_id', 2);
|
||||
|
||||
$this->assertFalse($action->execute($event, Task::EVENT_CLOSE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
$userModel = new User($this->container);
|
||||
$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')));
|
||||
$this->assertTrue($userModel->update(array('id' => 1, 'email' => 'admin@localhost')));
|
||||
|
||||
$event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
|
||||
|
||||
$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)));
|
||||
|
||||
// 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 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 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->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);
|
||||
$projectModel = new Project($this->container);
|
||||
$taskCreationModel = new TaskCreation($this->container);
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
|
||||
|
||||
$event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3));
|
||||
|
||||
$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
|
||||
$event = array(
|
||||
'project_id' => 1,
|
||||
'task_id' => 1,
|
||||
'column_id' => 2,
|
||||
);
|
||||
|
||||
// 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')
|
||||
);
|
||||
|
||||
// Our event should be executed
|
||||
$this->assertTrue($action->execute(new GenericEvent($event)));
|
||||
$this->assertFalse($action->execute($event, Task::EVENT_CLOSE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
$event = array(
|
||||
'project_id' => 3,
|
||||
'task_id' => 3,
|
||||
'column_id' => 3,
|
||||
);
|
||||
|
||||
$this->assertFalse($action->execute(new GenericEvent($event)));
|
||||
}
|
||||
|
||||
public function testExecute()
|
||||
{
|
||||
$action = new TaskMoveAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN);
|
||||
|
||||
// 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)));
|
||||
|
||||
// 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)));
|
||||
|
||||
// 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->assertTrue($action->execute($event, Task::EVENT_CLOSE));
|
||||
|
||||
$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 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));
|
||||
|
||||
$action = new TaskMoveAnotherProject($this->container);
|
||||
$action->setProjectId(1);
|
||||
$action->setParam('project_id', 2);
|
||||
$action->setParam('column_id', 2);
|
||||
|
||||
$this->assertFalse($action->execute($event, Task::EVENT_CLOSE));
|
||||
}
|
||||
}
|
||||
|
||||
56
tests/units/Action/TaskMoveColumnAssignedTest.php
Normal file
56
tests/units/Action/TaskMoveColumnAssignedTest.php
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -3,60 +3,84 @@
|
||||
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\Category;
|
||||
use Kanboard\Integration\GithubWebhook;
|
||||
use Kanboard\Model\Task;
|
||||
use Kanboard\Model\TaskFinder;
|
||||
use Kanboard\Model\TaskCreation;
|
||||
use Kanboard\Model\Project;
|
||||
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);
|
||||
$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' => 1, 'category_id' => 1));
|
||||
|
||||
$action = new TaskMoveColumnCategoryChange($this->container);
|
||||
$action->setProjectId(1);
|
||||
$action->setParam('category_id', 1);
|
||||
$action->setParam('dest_column_id', 2);
|
||||
|
||||
$this->assertEquals(3, $action->getParam('dest_column_id'));
|
||||
$this->assertEquals(1, $action->getParam('category_id'));
|
||||
$this->assertTrue($action->execute($event, Task::EVENT_UPDATE));
|
||||
|
||||
// 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->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)));
|
||||
|
||||
// No category should be assigned + column_id=1
|
||||
$task = $tf->getById(1);
|
||||
$task = $taskFinderModel->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEmpty($task['category_id']);
|
||||
$this->assertEquals(1, $task['column_id']);
|
||||
$this->assertEquals('test', $task['title']);
|
||||
$this->assertEquals(2, $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,
|
||||
);
|
||||
public function testWithWrongColumn()
|
||||
{
|
||||
$projectModel = new Project($this->container);
|
||||
$taskCreationModel = new TaskCreation($this->container);
|
||||
$taskFinderModel = new TaskFinder($this->container);
|
||||
$categoryModel = new Category($this->container);
|
||||
|
||||
// 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)));
|
||||
$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')));
|
||||
|
||||
// Our task should be moved to the other column
|
||||
$task = $tf->getById(1);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals(3, $task['column_id']);
|
||||
$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));
|
||||
}
|
||||
}
|
||||
|
||||
74
tests/units/Action/TaskMoveColumnUnAssignedTest.php
Normal file
74
tests/units/Action/TaskMoveColumnUnAssignedTest.php
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
51
tests/units/Action/TaskOpenTest.php
Normal file
51
tests/units/Action/TaskOpenTest.php
Normal file
@@ -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'));
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
157
tests/units/Core/Action/ActionManagerTest.php
Normal file
157
tests/units/Core/Action/ActionManagerTest.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../../Base.php';
|
||||
|
||||
use Kanboard\Core\Action\ActionManager;
|
||||
use Kanboard\Action\TaskAssignColorColumn;
|
||||
use Kanboard\Action\TaskClose;
|
||||
use Kanboard\Action\TaskCloseColumn;
|
||||
use Kanboard\Action\TaskUpdateStartDate;
|
||||
use Kanboard\Model\Action;
|
||||
use Kanboard\Model\Task;
|
||||
use Kanboard\Model\Project;
|
||||
use Kanboard\Model\ProjectUserRole;
|
||||
use Kanboard\Core\Security\Role;
|
||||
|
||||
class ActionManagerTest extends Base
|
||||
{
|
||||
public function testRegister()
|
||||
{
|
||||
$actionManager = new ActionManager($this->container);
|
||||
$actionTaskClose = new TaskClose($this->container);
|
||||
|
||||
$actionManager->register($actionTaskClose);
|
||||
$this->assertInstanceOf(get_class($actionTaskClose), $actionManager->getAction($actionTaskClose->getName()));
|
||||
}
|
||||
|
||||
public function testGetActionNotFound()
|
||||
{
|
||||
$this->setExpectedException('RuntimeException', 'Automatic Action Not Found: foobar');
|
||||
$actionManager = new ActionManager($this->container);
|
||||
$actionManager->getAction('foobar');
|
||||
}
|
||||
|
||||
public function testGetAvailableActions()
|
||||
{
|
||||
$actionManager = new ActionManager($this->container);
|
||||
$actionTaskClose1 = new TaskClose($this->container);
|
||||
$actionTaskClose2 = new TaskClose($this->container);
|
||||
$actionTaskUpdateStartDate = new TaskUpdateStartDate($this->container);
|
||||
|
||||
$actionManager
|
||||
->register($actionTaskClose1)
|
||||
->register($actionTaskClose2)
|
||||
->register($actionTaskUpdateStartDate);
|
||||
|
||||
$actions = $actionManager->getAvailableActions();
|
||||
$this->assertCount(2, $actions);
|
||||
$this->assertArrayHasKey($actionTaskClose1->getName(), $actions);
|
||||
$this->assertArrayHasKey($actionTaskUpdateStartDate->getName(), $actions);
|
||||
$this->assertNotEmpty($actions[$actionTaskClose1->getName()]);
|
||||
$this->assertNotEmpty($actions[$actionTaskUpdateStartDate->getName()]);
|
||||
}
|
||||
|
||||
public function testGetAvailableParameters()
|
||||
{
|
||||
$actionManager = new ActionManager($this->container);
|
||||
|
||||
$actionManager
|
||||
->register(new TaskCloseColumn($this->container))
|
||||
->register(new TaskUpdateStartDate($this->container));
|
||||
|
||||
$params = $actionManager->getAvailableParameters(array(
|
||||
array('action_name' => '\Kanboard\Action\TaskCloseColumn'),
|
||||
array('action_name' => '\Kanboard\Action\TaskUpdateStartDate'),
|
||||
));
|
||||
|
||||
$this->assertCount(2, $params);
|
||||
$this->assertArrayHasKey('column_id', $params['\Kanboard\Action\TaskCloseColumn']);
|
||||
$this->assertArrayHasKey('column_id', $params['\Kanboard\Action\TaskUpdateStartDate']);
|
||||
$this->assertNotEmpty($params['\Kanboard\Action\TaskCloseColumn']['column_id']);
|
||||
$this->assertNotEmpty($params['\Kanboard\Action\TaskUpdateStartDate']['column_id']);
|
||||
}
|
||||
|
||||
public function testGetCompatibleEvents()
|
||||
{
|
||||
$actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container);
|
||||
$actionManager = new ActionManager($this->container);
|
||||
$actionManager->register($actionTaskAssignColorColumn);
|
||||
|
||||
$events = $actionManager->getCompatibleEvents('\\'.get_class($actionTaskAssignColorColumn));
|
||||
$this->assertCount(2, $events);
|
||||
$this->assertArrayHasKey(Task::EVENT_CREATE, $events);
|
||||
$this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN, $events);
|
||||
$this->assertNotEmpty($events[Task::EVENT_CREATE]);
|
||||
$this->assertNotEmpty($events[Task::EVENT_MOVE_COLUMN]);
|
||||
}
|
||||
|
||||
public function testAttachEventsWithoutUserSession()
|
||||
{
|
||||
$projectModel = new Project($this->container);
|
||||
$actionModel = new Action($this->container);
|
||||
$actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container);
|
||||
$actionManager = new ActionManager($this->container);
|
||||
$actionManager->register($actionTaskAssignColorColumn);
|
||||
|
||||
$actions = $actionManager->getAvailableActions();
|
||||
|
||||
$actionManager->attachEvents();
|
||||
$this->assertEmpty($this->container['dispatcher']->getListeners());
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' =>'test')));
|
||||
$this->assertEquals(1, $actionModel->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_CREATE,
|
||||
'action_name' => key($actions),
|
||||
'params' => array('column_id' => 1, 'color_id' => 'red'),
|
||||
)));
|
||||
|
||||
$actionManager->attachEvents();
|
||||
$listeners = $this->container['dispatcher']->getListeners(Task::EVENT_CREATE);
|
||||
$this->assertCount(1, $listeners);
|
||||
$this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]);
|
||||
|
||||
$this->assertEquals(1, $listeners[0][0]->getProjectId());
|
||||
}
|
||||
|
||||
public function testAttachEventsWithLoggedUser()
|
||||
{
|
||||
$this->container['sessionStorage']->user = array('id' => 1);
|
||||
|
||||
$projectModel = new Project($this->container);
|
||||
$projectUserRoleModel = new ProjectUserRole($this->container);
|
||||
$actionModel = new Action($this->container);
|
||||
$actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container);
|
||||
$actionManager = new ActionManager($this->container);
|
||||
$actionManager->register($actionTaskAssignColorColumn);
|
||||
|
||||
$actions = $actionManager->getAvailableActions();
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' =>'test1')));
|
||||
$this->assertEquals(2, $projectModel->create(array('name' =>'test2')));
|
||||
|
||||
$this->assertTrue($projectUserRoleModel->addUser(2, 1, Role::PROJECT_MEMBER));
|
||||
|
||||
$this->assertEquals(1, $actionModel->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_CREATE,
|
||||
'action_name' => key($actions),
|
||||
'params' => array('column_id' => 1, 'color_id' => 'red'),
|
||||
)));
|
||||
|
||||
$this->assertEquals(2, $actionModel->create(array(
|
||||
'project_id' => 2,
|
||||
'event_name' => Task::EVENT_MOVE_COLUMN,
|
||||
'action_name' => key($actions),
|
||||
'params' => array('column_id' => 1, 'color_id' => 'red'),
|
||||
)));
|
||||
|
||||
$actionManager->attachEvents();
|
||||
|
||||
$listeners = $this->container['dispatcher']->getListeners(Task::EVENT_MOVE_COLUMN);
|
||||
$this->assertCount(1, $listeners);
|
||||
$this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]);
|
||||
|
||||
$this->assertEquals(2, $listeners[0][0]->getProjectId());
|
||||
}
|
||||
}
|
||||
18
tests/units/Core/Event/EventManagerTest.php
Normal file
18
tests/units/Core/Event/EventManagerTest.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../../Base.php';
|
||||
|
||||
use Kanboard\Core\Event\EventManager;
|
||||
|
||||
class EventManagerTest extends Base
|
||||
{
|
||||
public function testAddEvent()
|
||||
{
|
||||
$eventManager = new EventManager;
|
||||
$eventManager->register('my.event', 'My Event');
|
||||
|
||||
$events = $eventManager->getAll();
|
||||
$this->assertArrayHasKey('my.event', $events);
|
||||
$this->assertEquals('My Event', $events['my.event']);
|
||||
}
|
||||
}
|
||||
@@ -319,7 +319,7 @@ class BitbucketWebhookTest extends Base
|
||||
$this->assertEquals(1, $data['project_id']);
|
||||
$this->assertEquals(2, $data['task_id']);
|
||||
$this->assertEquals('test2', $data['title']);
|
||||
$this->assertEquals("Test another commit #2\n\n\n[Commit made by @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6)", $data['commit_comment']);
|
||||
$this->assertEquals("Test another commit #2\n\n\n[Commit made by @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6)", $data['comment']);
|
||||
$this->assertEquals("Test another commit #2\n", $data['commit_message']);
|
||||
$this->assertEquals('https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6', $data['commit_url']);
|
||||
}
|
||||
|
||||
@@ -453,7 +453,7 @@ class GithubWebhookTest extends Base
|
||||
$this->assertEquals(1, $data['project_id']);
|
||||
$this->assertEquals(1, $data['task_id']);
|
||||
$this->assertEquals('boo', $data['title']);
|
||||
$this->assertEquals("Update README to fix #1\n\n[Commit made by @fguillot on Github](https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6)", $data['commit_comment']);
|
||||
$this->assertEquals("Update README to fix #1\n\n[Commit made by @fguillot on Github](https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6)", $data['comment']);
|
||||
$this->assertEquals('Update README to fix #1', $data['commit_message']);
|
||||
$this->assertEquals('https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6', $data['commit_url']);
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ class GitlabWebhookTest extends Base
|
||||
$this->assertEquals(1, $data['project_id']);
|
||||
$this->assertEquals(2, $data['task_id']);
|
||||
$this->assertEquals('test2', $data['title']);
|
||||
$this->assertEquals("Fix bug #2\n\n[Commit made by @Fred on Gitlab](https://gitlab.com/minicoders/test-webhook/commit/48aafa75eef9ad253aa254b0c82c987a52ebea78)", $data['commit_comment']);
|
||||
$this->assertEquals("Fix bug #2\n\n[Commit made by @Fred on Gitlab](https://gitlab.com/minicoders/test-webhook/commit/48aafa75eef9ad253aa254b0c82c987a52ebea78)", $data['comment']);
|
||||
$this->assertEquals("Fix bug #2", $data['commit_message']);
|
||||
$this->assertEquals('https://gitlab.com/minicoders/test-webhook/commit/48aafa75eef9ad253aa254b0c82c987a52ebea78', $data['commit_url']);
|
||||
}
|
||||
|
||||
@@ -4,388 +4,506 @@ require_once __DIR__.'/../Base.php';
|
||||
|
||||
use Kanboard\Model\Action;
|
||||
use Kanboard\Model\Project;
|
||||
use Kanboard\Model\Board;
|
||||
use Kanboard\Model\Task;
|
||||
use Kanboard\Model\TaskPosition;
|
||||
use Kanboard\Model\TaskCreation;
|
||||
use Kanboard\Model\TaskFinder;
|
||||
use Kanboard\Model\Category;
|
||||
use Kanboard\Model\User;
|
||||
use Kanboard\Model\Board;
|
||||
use Kanboard\Model\Category;
|
||||
use Kanboard\Model\ProjectUserRole;
|
||||
use Kanboard\Integration\GithubWebhook;
|
||||
use Kanboard\Integration\BitbucketWebhook;
|
||||
use Kanboard\Core\Security\Role;
|
||||
|
||||
class ActionTest extends Base
|
||||
{
|
||||
public function testGetActions()
|
||||
public function testCreate()
|
||||
{
|
||||
$a = new Action($this->container);
|
||||
$projectModel = new Project($this->container);
|
||||
$actionModel = new Action($this->container);
|
||||
|
||||
$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, $projectModel->create(array('name' => 'test')));
|
||||
|
||||
public function testExtendActions()
|
||||
{
|
||||
$a = new Action($this->container);
|
||||
$a->extendActions('MyClass', 'Description');
|
||||
|
||||
$actions = $a->getAvailableActions();
|
||||
$this->assertNotEmpty($actions);
|
||||
$this->assertContains('Description', $actions);
|
||||
$this->assertArrayHasKey('MyClass', $actions);
|
||||
}
|
||||
|
||||
public function testGetEvents()
|
||||
{
|
||||
$a = new Action($this->container);
|
||||
|
||||
$events = $a->getAvailableEvents();
|
||||
$this->assertNotEmpty($events);
|
||||
$this->assertEquals('Bitbucket commit received', current($events));
|
||||
$this->assertEquals(BitbucketWebhook::EVENT_COMMIT, key($events));
|
||||
}
|
||||
|
||||
public function testGetCompatibleEvents()
|
||||
{
|
||||
$a = new Action($this->container);
|
||||
$events = $a->getCompatibleEvents('TaskAssignSpecificUser');
|
||||
|
||||
$this->assertNotEmpty($events);
|
||||
$this->assertCount(2, $events);
|
||||
$this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE, $events);
|
||||
$this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN, $events);
|
||||
}
|
||||
|
||||
public function testResolveDuplicatedParameters()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectUserRole($this->container);
|
||||
$a = new Action($this->container);
|
||||
$c = new Category($this->container);
|
||||
$u = new User($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'P2')));
|
||||
|
||||
$this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
|
||||
|
||||
$this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 2)));
|
||||
$this->assertEquals(3, $c->create(array('name' => 'C1', 'project_id' => 2)));
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'unittest1')));
|
||||
$this->assertEquals(3, $u->create(array('username' => 'unittest2')));
|
||||
|
||||
$this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
|
||||
$this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER));
|
||||
$this->assertTrue($pp->addUser(2, 3, Role::PROJECT_MEMBER));
|
||||
|
||||
// anything
|
||||
$this->assertEquals('blah', $a->resolveParameters(array('name' => 'foobar', 'value' => 'blah'), 2));
|
||||
|
||||
// project_id
|
||||
$this->assertEquals(2, $a->resolveParameters(array('name' => 'project_id', 'value' => 'blah'), 2));
|
||||
|
||||
// category_id
|
||||
$this->assertEquals(3, $a->resolveParameters(array('name' => 'category_id', 'value' => 1), 2));
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'category_id', 'value' => 0), 2));
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'category_id', 'value' => 5), 2));
|
||||
|
||||
// column_id
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'column_id', 'value' => 10), 2));
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'column_id', 'value' => 0), 2));
|
||||
$this->assertEquals(5, $a->resolveParameters(array('name' => 'column_id', 'value' => 1), 2));
|
||||
$this->assertEquals(6, $a->resolveParameters(array('name' => 'dest_column_id', 'value' => 2), 2));
|
||||
$this->assertEquals(7, $a->resolveParameters(array('name' => 'dst_column_id', 'value' => 3), 2));
|
||||
$this->assertEquals(8, $a->resolveParameters(array('name' => 'src_column_id', 'value' => 4), 2));
|
||||
|
||||
// user_id
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 10), 2));
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 0), 2));
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 2), 2));
|
||||
$this->assertFalse($a->resolveParameters(array('name' => 'owner_id', 'value' => 2), 2));
|
||||
$this->assertEquals(3, $a->resolveParameters(array('name' => 'user_id', 'value' => 3), 2));
|
||||
$this->assertEquals(3, $a->resolveParameters(array('name' => 'owner_id', 'value' => 3), 2));
|
||||
}
|
||||
|
||||
public function testDuplicateSuccess()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectUserRole($this->container);
|
||||
$a = new Action($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(2, $u->create(array('username' => 'unittest1')));
|
||||
$this->assertEquals(3, $u->create(array('username' => 'unittest2')));
|
||||
|
||||
$this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
|
||||
$this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER));
|
||||
$this->assertTrue($pp->addUser(2, 3, Role::PROJECT_MEMBER));
|
||||
|
||||
$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'),
|
||||
)));
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$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'),
|
||||
)));
|
||||
|
||||
$action = $a->getById(1);
|
||||
$this->assertNotEmpty($actionModel->getById(1));
|
||||
$this->assertTrue($actionModel->remove(1));
|
||||
$this->assertEmpty($actionModel->getById(1));
|
||||
}
|
||||
|
||||
public function testGetById()
|
||||
{
|
||||
$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'),
|
||||
)));
|
||||
|
||||
$action = $actionModel->getById(1);
|
||||
$this->assertNotEmpty($action);
|
||||
$this->assertNotEmpty($action['params']);
|
||||
$this->assertEquals(1, $action['project_id']);
|
||||
|
||||
$this->assertTrue($a->duplicate(1, 2));
|
||||
|
||||
$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']);
|
||||
$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 testDuplicateUnableToResolveParams()
|
||||
public function testGetAll()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectUserRole($this->container);
|
||||
$a = new Action($this->container);
|
||||
$u = new User($this->container);
|
||||
$projectModel = new Project($this->container);
|
||||
$actionModel = new Action($this->container);
|
||||
|
||||
$this->assertEquals(1, $p->create(array('name' => 'P1')));
|
||||
$this->assertEquals(2, $p->create(array('name' => 'P2')));
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertEquals(2, $u->create(array('username' => 'unittest1')));
|
||||
|
||||
$this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
|
||||
|
||||
$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' => 2,
|
||||
)
|
||||
'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('user_id', $action['params'][1]['name']);
|
||||
$this->assertEquals(2, $action['params'][1]['value']);
|
||||
|
||||
$this->assertTrue($a->duplicate(1, 2));
|
||||
|
||||
$action = $a->getById(2);
|
||||
$this->assertEmpty($action);
|
||||
}
|
||||
|
||||
public function testDuplicateMixedResults()
|
||||
{
|
||||
$p = new Project($this->container);
|
||||
$pp = new ProjectUserRole($this->container);
|
||||
$a = new Action($this->container);
|
||||
$u = new User($this->container);
|
||||
$c = new Category($this->container);
|
||||
|
||||
$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->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER));
|
||||
|
||||
$this->assertEquals(1, $a->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_CREATE_UPDATE,
|
||||
'action_name' => 'TaskAssignSpecificUser',
|
||||
'params' => array(
|
||||
'column_id' => 1,
|
||||
'user_id' => 2,
|
||||
)
|
||||
$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'),
|
||||
)));
|
||||
|
||||
$action = $a->getById(1);
|
||||
$this->assertNotEmpty($action);
|
||||
$this->assertNotEmpty($action['params']);
|
||||
|
||||
$this->assertEquals(2, $a->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_CREATE_UPDATE,
|
||||
'action_name' => 'TaskAssignCategoryColor',
|
||||
'params' => array(
|
||||
'color_id' => 'blue',
|
||||
'category_id' => 1,
|
||||
)
|
||||
)));
|
||||
|
||||
$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']);
|
||||
|
||||
$actions = $a->getAllByProject(1);
|
||||
$this->assertNotEmpty($actions);
|
||||
$actions = $actionModel->getAll();
|
||||
$this->assertCount(2, $actions);
|
||||
|
||||
$this->assertTrue($a->duplicate(1, 2));
|
||||
$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 = $a->getAllByProject(2);
|
||||
$this->assertNotEmpty($actions);
|
||||
$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 testGetAllByProject()
|
||||
{
|
||||
$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);
|
||||
|
||||
$actions = $a->getAll();
|
||||
$this->assertNotEmpty($actions);
|
||||
$this->assertCount(3, $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']);
|
||||
|
||||
$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']);
|
||||
|
||||
$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 testSingleAction()
|
||||
public function testGetAllByUser()
|
||||
{
|
||||
$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);
|
||||
$projectModel = new Project($this->container);
|
||||
$projectUserRoleModel = new ProjectUserRole($this->container);
|
||||
$userModel = new User($this->container);
|
||||
$actionModel = new Action($this->container);
|
||||
|
||||
// We create a project
|
||||
$this->assertEquals(1, $project->create(array('name' => 'unit_test')));
|
||||
$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)));
|
||||
|
||||
// We create a new action
|
||||
$this->assertEquals(1, $action->create(array(
|
||||
$this->assertEquals(2, $userModel->create(array('username' => 'user1')));
|
||||
$this->assertEquals(3, $userModel->create(array('username' => 'user2')));
|
||||
|
||||
$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, $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'),
|
||||
)));
|
||||
|
||||
$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'),
|
||||
)));
|
||||
|
||||
$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 testDuplicateWithColumnAndColorParameter()
|
||||
{
|
||||
$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->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, $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('src_column_id' => 1, 'dst_column_id' => 2, 'dest_column_id' => 3),
|
||||
)));
|
||||
|
||||
$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('src_column_id' => 5, 'dst_column_id' => 6, 'dest_column_id' => 7), $actions[0]['params']);
|
||||
}
|
||||
|
||||
public function testDuplicateWithColumnParameterNotfound()
|
||||
{
|
||||
$projectModel = new Project($this->container);
|
||||
$actionModel = new Action($this->container);
|
||||
$boardModel = new Board($this->container);
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertTrue($boardModel->updateColumn(2, 'My unique column'));
|
||||
|
||||
$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' => 1,
|
||||
'event_name' => Task::EVENT_MOVE_COLUMN,
|
||||
'action_name' => 'TaskClose',
|
||||
'params' => array(
|
||||
'column_id' => 4,
|
||||
)
|
||||
'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
|
||||
'params' => array('column_id' => 2, 'color_id' => 'green'),
|
||||
)));
|
||||
|
||||
// We create a task
|
||||
$this->assertEquals(1, $tc->create(array(
|
||||
'title' => 'unit_test',
|
||||
'project_id' => 1,
|
||||
'owner_id' => 1,
|
||||
'color_id' => 'red',
|
||||
'column_id' => 1,
|
||||
)));
|
||||
$this->assertTrue($actionModel->duplicate(1, 2));
|
||||
|
||||
// We attach events
|
||||
$action->attachEvents();
|
||||
$actions = $actionModel->getAllByProject(2);
|
||||
$this->assertCount(1, $actions);
|
||||
|
||||
// Our task should be open
|
||||
$t1 = $tf->getById(1);
|
||||
$this->assertEquals(1, $t1['is_active']);
|
||||
$this->assertEquals(1, $t1['column_id']);
|
||||
|
||||
// We move our task
|
||||
$tp->movePosition(1, 1, 4, 1);
|
||||
|
||||
// Our task should be closed
|
||||
$t1 = $tf->getById(1);
|
||||
$this->assertEquals(4, $t1['column_id']);
|
||||
$this->assertEquals(0, $t1['is_active']);
|
||||
$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 testMultipleActions()
|
||||
public function testDuplicateWithProjectParameter()
|
||||
{
|
||||
$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);
|
||||
$projectModel = new Project($this->container);
|
||||
$actionModel = new Action($this->container);
|
||||
|
||||
// We create a project
|
||||
$this->assertEquals(1, $p->create(array('name' => 'unit_test')));
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
|
||||
$this->assertEquals(3, $projectModel->create(array('name' => 'test2')));
|
||||
|
||||
// We create a new action
|
||||
$this->assertEquals(1, $a->create(array(
|
||||
$this->assertEquals(1, $actionModel->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => GithubWebhook::EVENT_ISSUE_OPENED,
|
||||
'action_name' => 'TaskCreation',
|
||||
'params' => array()
|
||||
'event_name' => Task::EVENT_CLOSE,
|
||||
'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject',
|
||||
'params' => array('column_id' => 1, 'project_id' => 3),
|
||||
)));
|
||||
|
||||
$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\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']);
|
||||
}
|
||||
|
||||
public function testDuplicateWithProjectParameterIdenticalToDestination()
|
||||
{
|
||||
$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' => GithubWebhook::EVENT_ISSUE_LABEL_CHANGE,
|
||||
'action_name' => 'TaskAssignCategoryLabel',
|
||||
'params' => array(
|
||||
'label' => 'bug',
|
||||
'category_id' => 1,
|
||||
)
|
||||
'event_name' => Task::EVENT_CLOSE,
|
||||
'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject',
|
||||
'params' => array('column_id' => 1, 'project_id' => 2),
|
||||
)));
|
||||
|
||||
$this->assertEquals(3, $a->create(array(
|
||||
$this->assertTrue($actionModel->duplicate(1, 2));
|
||||
|
||||
$actions = $actionModel->getAllByProject(2);
|
||||
$this->assertCount(0, $actions);
|
||||
}
|
||||
|
||||
public function testDuplicateWithUserParameter()
|
||||
{
|
||||
$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' => '\Kanboard\Action\TaskAssignSpecificUser',
|
||||
'params' => array('column_id' => 1, 'user_id' => 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\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,
|
||||
'event_name' => Task::EVENT_MOVE_COLUMN,
|
||||
'action_name' => '\Kanboard\Action\TaskAssignSpecificUser',
|
||||
'params' => array('column_id' => 1, 'user_id' => 2),
|
||||
)));
|
||||
|
||||
$this->assertTrue($actionModel->duplicate(1, 2));
|
||||
|
||||
$actions = $actionModel->getAllByProject(2);
|
||||
$this->assertCount(0, $actions);
|
||||
}
|
||||
|
||||
public function testDuplicateWithUserParameterButNotAvailable()
|
||||
{
|
||||
$projectUserRoleModel = new ProjectUserRole($this->container);
|
||||
$userModel = new User($this->container);
|
||||
$projectModel = new Project($this->container);
|
||||
$actionModel = new Action($this->container);
|
||||
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertEquals(2, $userModel->create(array('username' => 'user1')));
|
||||
|
||||
$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 testDuplicateWithCategoryParameter()
|
||||
{
|
||||
$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' => 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);
|
||||
$this->assertTrue($actionModel->duplicate(1, 2));
|
||||
|
||||
// We create a Github issue
|
||||
$issue = array(
|
||||
'number' => 123,
|
||||
'title' => 'Bugs everywhere',
|
||||
'body' => 'There is a bug!',
|
||||
'html_url' => 'http://localhost/',
|
||||
);
|
||||
$actions = $actionModel->getAllByProject(2);
|
||||
$this->assertCount(1, $actions);
|
||||
|
||||
$this->assertTrue($g->handleIssueOpened($issue));
|
||||
$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']);
|
||||
}
|
||||
|
||||
$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']);
|
||||
public function testDuplicateWithCategoryParameterButDifferentName()
|
||||
{
|
||||
$projectModel = new Project($this->container);
|
||||
$actionModel = new Action($this->container);
|
||||
$categoryModel = new Category($this->container);
|
||||
|
||||
// We assign a label to our issue
|
||||
$label = array(
|
||||
'name' => 'bug',
|
||||
);
|
||||
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
|
||||
$this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
|
||||
|
||||
$this->assertTrue($g->handleIssueLabeled($issue, $label));
|
||||
$this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1)));
|
||||
$this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 2)));
|
||||
|
||||
$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->assertEquals(1, $actionModel->create(array(
|
||||
'project_id' => 1,
|
||||
'event_name' => Task::EVENT_CREATE_UPDATE,
|
||||
'action_name' => '\Kanboard\Action\TaskAssignColorCategory',
|
||||
'params' => array('column_id' => 1, 'category_id' => 1),
|
||||
)));
|
||||
|
||||
$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' => '\Kanboard\Action\TaskAssignColorCategory',
|
||||
'params' => array('column_id' => 1, 'category_id' => 1),
|
||||
)));
|
||||
|
||||
$this->assertTrue($actionModel->duplicate(1, 2));
|
||||
|
||||
$actions = $actionModel->getAllByProject(2);
|
||||
$this->assertCount(0, $actions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ class ProjectDuplicationTest extends Base
|
||||
$this->assertNotEmpty($actions);
|
||||
$this->assertEquals('TaskAssignCurrentUser', $actions[0]['action_name']);
|
||||
$this->assertNotEmpty($actions[0]['params']);
|
||||
$this->assertEquals(6, $actions[0]['params'][0]['value']);
|
||||
$this->assertEquals(6, $actions[0]['params']['column_id']);
|
||||
}
|
||||
|
||||
public function testCloneProjectWithActionTaskAssignColorCategory()
|
||||
@@ -195,8 +195,8 @@ class ProjectDuplicationTest extends Base
|
||||
$this->assertNotEmpty($actions);
|
||||
$this->assertEquals('TaskAssignColorCategory', $actions[0]['action_name']);
|
||||
$this->assertNotEmpty($actions[0]['params']);
|
||||
$this->assertEquals('blue', $actions[0]['params'][0]['value']);
|
||||
$this->assertEquals(5, $actions[0]['params'][1]['value']);
|
||||
$this->assertEquals('blue', $actions[0]['params']['color_id']);
|
||||
$this->assertEquals(5, $actions[0]['params']['category_id']);
|
||||
}
|
||||
|
||||
public function testCloneProjectWithSwimlanesAndTasks()
|
||||
|
||||
Reference in New Issue
Block a user