Improve Automatic Actions plugin api
This commit is contained in:
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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user