Improve unit tests

This commit is contained in:
Frederic Guillot
2015-09-05 23:30:56 -04:00
parent 94b38dd94b
commit 710f2c7bb0
72 changed files with 281 additions and 151 deletions

View File

@@ -0,0 +1,124 @@
<?php
require_once __DIR__.'/../Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\Comment;
use Model\Project;
use Integration\GithubWebhook;
class CommentCreationTest extends Base
{
public function testWithoutRequiredParams()
{
$action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
// We create a task in the first column
$tc = new TaskCreation($this->container);
$p = new Project($this->container);
$c = new Comment($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
// We create an event to move the task to the 2nd column
$event = array(
'project_id' => 1,
'task_id' => 1,
'user_id' => 1,
);
// Our event should be executed
$this->assertFalse($action->execute(new GenericEvent($event)));
$comment = $c->getById(1);
$this->assertEmpty($comment);
}
public function testWithCommitMessage()
{
$action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
// We create a task in the first column
$tc = new TaskCreation($this->container);
$p = new Project($this->container);
$c = new Comment($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
// We create an event to move the task to the 2nd column
$event = array(
'project_id' => 1,
'task_id' => 1,
'commit_comment' => 'plop',
);
// Our event should be executed
$this->assertTrue($action->execute(new GenericEvent($event)));
$comment = $c->getById(1);
$this->assertNotEmpty($comment);
$this->assertEquals(1, $comment['task_id']);
$this->assertEquals(0, $comment['user_id']);
$this->assertEquals('plop', $comment['comment']);
}
public function testWithUser()
{
$action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
// We create a task in the first column
$tc = new TaskCreation($this->container);
$p = new Project($this->container);
$c = new Comment($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
// We create an event to move the task to the 2nd column
$event = array(
'project_id' => 1,
'task_id' => 1,
'user_id' => 1,
'comment' => 'youpi',
);
// Our event should be executed
$this->assertTrue($action->execute(new GenericEvent($event)));
$comment = $c->getById(1);
$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 Action\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']);
}
}

View File

@@ -0,0 +1,80 @@
<?php
require_once __DIR__.'/../Base.php';
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
use Model\Category;
use Event\GenericEvent;
class TaskAssignColorCategory extends Base
{
public function testBadProject()
{
$action = new Action\TaskAssignColorCategory($this->container, 3, Task::EVENT_CREATE_UPDATE);
$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 testExecute()
{
$action = new Action\TaskAssignColorCategory($this->container, 1, Task::EVENT_CREATE_UPDATE);
$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']);
}
}

View File

@@ -0,0 +1,41 @@
<?php
require_once __DIR__.'/../Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
class TaskAssignColorColumnTest extends Base
{
public function testColorChange()
{
$action = new Action\TaskAssignColorColumn($this->container, 1, Task::EVENT_MOVE_COLUMN);
$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->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'yellow')));
$event = array(
'project_id' => 1,
'task_id' => 1,
'column_id' => 2,
'color_id' => 'green',
);
// Our event should be executed
$this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should have color green
$task = $tf->getById(1);
$this->assertEquals('green', $task['color_id']);
}
}

View File

@@ -0,0 +1,47 @@
<?php
require_once __DIR__.'/../Base.php';
use Event\TaskLinkEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\TaskLink;
use Model\Project;
class TaskAssignColorLinkTest extends Base
{
public function testExecute()
{
$action = new Action\TaskAssignColorLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE);
$action->setParam('link_id', 2);
$action->setParam('color_id', 'green');
// We create a task in the first column
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$tl = new TaskLink($this->container);
$p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
// The color should be yellow
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals('yellow', $task['color_id']);
$event = array(
'project_id' => 1,
'task_id' => 1,
'link_id' => 2,
);
// Our event should be executed
$this->assertTrue($action->execute(new TaskLinkEvent($event)));
// The color should be green
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals('green', $task['color_id']);
}
}

View File

@@ -0,0 +1,72 @@
<?php
require_once __DIR__.'/../Base.php';
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
use Event\GenericEvent;
class TaskAssignColorUser extends Base
{
public function testBadProject()
{
$action = new Action\TaskAssignColorUser($this->container, 3, Task::EVENT_CREATE);
$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 testExecute()
{
$action = new Action\TaskAssignColorUser($this->container, 1, Task::EVENT_ASSIGNEE_CHANGE);
$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']);
}
}

View File

@@ -0,0 +1,77 @@
<?php
require_once __DIR__.'/../Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
use Model\UserSession;
class TaskAssignCurrentUser extends Base
{
public function testBadProject()
{
$action = new Action\TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE);
$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 Action\TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE);
$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 Action\TaskAssignCurrentUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
$_SESSION = array(
'user' => array('id' => 5)
);
// We create a task in the first column
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
$us = new UserSession($this->container);
$this->assertEquals(5, $us->getId());
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
// 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);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['id']);
$this->assertEquals(5, $task['owner_id']);
}
}

View File

@@ -0,0 +1,70 @@
<?php
require_once __DIR__.'/../Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
class TaskAssignSpecificUser extends Base
{
public function testBadProject()
{
$action = new Action\TaskAssignSpecificUser($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 Action\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 Action\TaskAssignSpecificUser($this->container, 1, Task::EVENT_MOVE_COLUMN);
$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)));
// 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);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['owner_id']);
}
}

View File

@@ -0,0 +1,108 @@
<?php
require_once __DIR__.'/../Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
use Integration\GithubWebhook;
class TaskCloseTest extends Base
{
public function testExecutable()
{
$action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
'project_id' => 3,
'task_id' => 3,
'column_id' => 5,
);
$this->assertTrue($action->isExecutable($event));
$action = new Action\TaskClose($this->container, 3, GithubWebhook::EVENT_COMMIT);
$event = array(
'project_id' => 3,
'task_id' => 3,
);
$this->assertTrue($action->isExecutable($event));
}
public function testBadEvent()
{
$action = new Action\TaskClose($this->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 Action\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 Action\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 Action\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);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['is_active']);
}
}

View File

@@ -0,0 +1,94 @@
<?php
require_once __DIR__.'/../Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
class TaskDuplicateAnotherProject extends Base
{
public function testBadProject()
{
$action = new Action\TaskDuplicateAnotherProject($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 Action\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 Action\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->setParam('project_id', 2);
$this->assertTrue($action->hasRequiredCondition($event));
$this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be assigned to the project 1
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['project_id']);
// We should have another task assigned to the project 2
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(2, $task['project_id']);
}
}

View File

@@ -0,0 +1,149 @@
<?php
require_once __DIR__.'/../Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
use Model\User;
class TaskEmailTest extends Base
{
public function testNoEmail()
{
$action = new Action\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' => 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 Action\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 Action\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(
$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)));
}
public function testTaskClose()
{
$action = new Action\TaskEmail($this->container, 1, Task::EVENT_CLOSE);
$action->setParam('column_id', 2);
$action->setParam('user_id', 1);
$action->setParam('subject', 'My email subject');
// We create a task in the first column
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
$u = new User($this->container);
$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)));
}
}

View File

@@ -0,0 +1,88 @@
<?php
require_once __DIR__.'/../Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
class TaskMoveAnotherProject extends Base
{
public function testBadProject()
{
$action = new Action\TaskMoveAnotherProject($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 Action\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 Action\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->setParam('project_id', 2);
$this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be assigned to the project 2
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(2, $task['project_id']);
}
}

View File

@@ -0,0 +1,61 @@
<?php
require_once __DIR__.'/../Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
use Model\Category;
use Integration\GithubWebhook;
class TaskMoveColumnCategoryChangeTest extends Base
{
public function testExecute()
{
$action = new Action\TaskMoveColumnCategoryChange($this->container, 1, Task::EVENT_UPDATE);
$action->setParam('dest_column_id', 3);
$action->setParam('category_id', 1);
$this->assertEquals(3, $action->getParam('dest_column_id'));
$this->assertEquals(1, $action->getParam('category_id'));
// 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);
$this->assertNotEmpty($task);
$this->assertEmpty($task['category_id']);
$this->assertEquals(1, $task['column_id']);
// We create an event to move the task to the 2nd column
$event = array(
'task_id' => 1,
'column_id' => 1,
'project_id' => 1,
'category_id' => 1,
);
// Our event should be executed
$this->assertTrue($action->hasCompatibleEvent());
$this->assertTrue($action->hasRequiredProject($event));
$this->assertTrue($action->hasRequiredParameters($event));
$this->assertTrue($action->hasRequiredCondition($event));
$this->assertTrue($action->isExecutable($event));
$this->assertTrue($action->execute(new GenericEvent($event)));
// Our task should be moved to the other column
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(3, $task['column_id']);
}
}

View File

@@ -0,0 +1,45 @@
<?php
require_once __DIR__.'/../Base.php';
use Event\GenericEvent;
use Model\Task;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Project;
class TaskUpdateStartDateTest extends Base
{
public function testExecute()
{
$action = new Action\TaskUpdateStartDate($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)));
// The start date must be empty
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEmpty($task['date_started']);
// 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 updated
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(time(), $task['date_started'], '', 2);
}
}