Improve automatic actions (check for compatible events/actions/parameters)

This commit is contained in:
Frédéric Guillot
2014-09-28 14:26:40 -04:00
parent 0c8de6a3f5
commit 03fa01ac7b
33 changed files with 485 additions and 361 deletions

View File

@@ -10,7 +10,7 @@ class ActionTaskAssignColorCategory extends Base
{
public function testBadProject()
{
$action = new Action\TaskAssignColorCategory(3, new Task($this->registry));
$action = new Action\TaskAssignColorCategory($this->registry, 3, Task::EVENT_CREATE_UPDATE);
$event = array(
'project_id' => 2,
@@ -24,7 +24,7 @@ class ActionTaskAssignColorCategory extends Base
public function testExecute()
{
$action = new Action\TaskAssignColorCategory(1, new Task($this->registry));
$action = new Action\TaskAssignColorCategory($this->registry, 1, Task::EVENT_CREATE_UPDATE);
$action->setParam('category_id', 1);
$action->setParam('color_id', 'blue');

View File

@@ -9,7 +9,7 @@ class ActionTaskAssignColorUser extends Base
{
public function testBadProject()
{
$action = new Action\TaskAssignColorUser(3, new Task($this->registry));
$action = new Action\TaskAssignColorUser($this->registry, 3, Task::EVENT_CREATE);
$event = array(
'project_id' => 2,
@@ -23,7 +23,7 @@ class ActionTaskAssignColorUser extends Base
public function testExecute()
{
$action = new Action\TaskAssignColorUser(1, new Task($this->registry));
$action = new Action\TaskAssignColorUser($this->registry, 1, Task::EVENT_ASSIGNEE_CHANGE);
$action->setParam('user_id', 1);
$action->setParam('color_id', 'blue');
@@ -33,11 +33,10 @@ class ActionTaskAssignColorUser extends Base
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green')));
// We create an event to move the task to the 2nd column with a user id 5
// We change the assignee
$event = array(
'project_id' => 1,
'task_id' => 1,
'column_id' => 2,
'owner_id' => 5,
);
@@ -50,11 +49,10 @@ class ActionTaskAssignColorUser extends Base
$this->assertEquals(0, $task['owner_id']);
$this->assertEquals('green', $task['color_id']);
// We create an event to move the task to the 2nd column with a user id 1
// We change the assignee
$event = array(
'project_id' => 1,
'task_id' => 1,
'column_id' => 2,
'owner_id' => 1,
);

View File

@@ -10,7 +10,7 @@ class ActionTaskAssignCurrentUser extends Base
{
public function testBadProject()
{
$action = new Action\TaskAssignCurrentUser(3, new Task($this->registry), new Acl($this->registry));
$action = new Action\TaskAssignCurrentUser($this->registry, 3, Task::EVENT_CREATE);
$action->setParam('column_id', 5);
$event = array(
@@ -25,7 +25,7 @@ class ActionTaskAssignCurrentUser extends Base
public function testBadColumn()
{
$action = new Action\TaskAssignCurrentUser(3, new Task($this->registry), new Acl($this->registry));
$action = new Action\TaskAssignCurrentUser($this->registry, 3, Task::EVENT_CREATE);
$action->setParam('column_id', 5);
$event = array(
@@ -39,7 +39,7 @@ class ActionTaskAssignCurrentUser extends Base
public function testExecute()
{
$action = new Action\TaskAssignCurrentUser(1, new Task($this->registry), new Acl($this->registry));
$action = new Action\TaskAssignCurrentUser($this->registry, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
$_SESSION = array(
'user' => array('id' => 5)

View File

@@ -9,7 +9,7 @@ class ActionTaskAssignSpecificUser extends Base
{
public function testBadProject()
{
$action = new Action\TaskAssignSpecificUser(3, new Task($this->registry));
$action = new Action\TaskAssignSpecificUser($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -24,7 +24,7 @@ class ActionTaskAssignSpecificUser extends Base
public function testBadColumn()
{
$action = new Action\TaskAssignSpecificUser(3, new Task($this->registry));
$action = new Action\TaskAssignSpecificUser($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -38,7 +38,7 @@ class ActionTaskAssignSpecificUser extends Base
public function testExecute()
{
$action = new Action\TaskAssignSpecificUser(1, new Task($this->registry));
$action = new Action\TaskAssignSpecificUser($this->registry, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
$action->setParam('user_id', 1);

View File

@@ -4,12 +4,51 @@ require_once __DIR__.'/Base.php';
use Model\Task;
use Model\Project;
use Model\GithubWebhook;
class ActionTaskCloseTest extends Base
{
public function testExecutable()
{
$action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
'project_id' => 3,
'task_id' => 3,
'column_id' => 5,
);
$this->assertTrue($action->isExecutable($event));
$action = new Action\TaskClose($this->registry, 3, GithubWebhook::EVENT_COMMIT);
$event = array(
'project_id' => 3,
'task_id' => 3,
);
$this->assertTrue($action->isExecutable($event));
}
public function testBadEvent()
{
$action = new Action\TaskClose($this->registry, 3, Task::EVENT_UPDATE);
$action->setParam('column_id', 5);
$event = array(
'project_id' => 3,
'task_id' => 3,
'column_id' => 5,
);
$this->assertFalse($action->isExecutable($event));
$this->assertFalse($action->execute($event));
}
public function testBadProject()
{
$action = new Action\TaskClose(3, new Task($this->registry));
$action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -24,7 +63,7 @@ class ActionTaskCloseTest extends Base
public function testBadColumn()
{
$action = new Action\TaskClose(3, new Task($this->registry));
$action = new Action\TaskClose($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -38,7 +77,7 @@ class ActionTaskCloseTest extends Base
public function testExecute()
{
$action = new Action\TaskClose(1, new Task($this->registry));
$action = new Action\TaskClose($this->registry, 1, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 2);
// We create a task in the first column

View File

@@ -9,7 +9,7 @@ class ActionTaskDuplicateAnotherProject extends Base
{
public function testBadProject()
{
$action = new Action\TaskDuplicateAnotherProject(3, new Task($this->registry));
$action = new Action\TaskDuplicateAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -24,7 +24,7 @@ class ActionTaskDuplicateAnotherProject extends Base
public function testBadColumn()
{
$action = new Action\TaskDuplicateAnotherProject(3, new Task($this->registry));
$action = new Action\TaskDuplicateAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -38,7 +38,7 @@ class ActionTaskDuplicateAnotherProject extends Base
public function testExecute()
{
$action = new Action\TaskDuplicateAnotherProject(1, new Task($this->registry));
$action = new Action\TaskDuplicateAnotherProject($this->registry, 1, Task::EVENT_MOVE_COLUMN);
// We create a task in the first column
$t = new Task($this->registry);

View File

@@ -9,7 +9,7 @@ class ActionTaskMoveAnotherProject extends Base
{
public function testBadProject()
{
$action = new Action\TaskMoveAnotherProject(3, new Task($this->registry));
$action = new Action\TaskMoveAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -24,7 +24,7 @@ class ActionTaskMoveAnotherProject extends Base
public function testBadColumn()
{
$action = new Action\TaskMoveAnotherProject(3, new Task($this->registry));
$action = new Action\TaskMoveAnotherProject($this->registry, 3, Task::EVENT_MOVE_COLUMN);
$action->setParam('column_id', 5);
$event = array(
@@ -38,7 +38,7 @@ class ActionTaskMoveAnotherProject extends Base
public function testExecute()
{
$action = new Action\TaskMoveAnotherProject(1, new Task($this->registry));
$action = new Action\TaskMoveAnotherProject($this->registry, 1, Task::EVENT_MOVE_COLUMN);
// We create a task in the first column
$t = new Task($this->registry);

View File

@@ -95,92 +95,6 @@ class ActionTest extends Base
$this->assertEquals(0, $t1['is_active']);
}
public function testEventMovePosition()
{
$task = new Task($this->registry);
$board = new Board($this->registry);
$project = new Project($this->registry);
$action = new Action($this->registry);
// We create a project
$this->assertEquals(1, $project->create(array('name' => 'unit_test')));
// We create a task
$this->assertEquals(1, $task->create(array(
'title' => 'unit_test 0',
'project_id' => 1,
'owner_id' => 1,
'color_id' => 'red',
'column_id' => 1,
'category_id' => 1,
)));
$this->assertEquals(2, $task->create(array(
'title' => 'unit_test 1',
'project_id' => 1,
'owner_id' => 1,
'color_id' => 'yellow',
'column_id' => 1,
'category_id' => 1,
)));
// We create a new action, when the category_id=2 then the color_id should be green
$this->assertTrue($action->create(array(
'project_id' => 1,
'event_name' => Task::EVENT_MOVE_POSITION,
'action_name' => 'TaskAssignColorCategory',
'params' => array(
'category_id' => 1,
'color_id' => 'green',
)
)));
// We bind events
$action->attachEvents();
$this->assertTrue($this->registry->shared('event')->hasListener(Task::EVENT_MOVE_POSITION, 'Action\TaskAssignColorCategory'));
// Our task should have the color red and position=1
$t1 = $task->getById(1);
$this->assertEquals(1, $t1['position']);
$this->assertEquals(1, $t1['is_active']);
$this->assertEquals('red', $t1['color_id']);
$t1 = $task->getById(2);
$this->assertEquals(2, $t1['position']);
$this->assertEquals(1, $t1['is_active']);
$this->assertEquals('yellow', $t1['color_id']);
// We move our tasks
$this->assertTrue($task->movePosition(1, 1, 1, 10)); // task #1 to the end of the column
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_POSITION));
$t1 = $task->getById(1);
$this->assertEquals(2, $t1['position']);
$this->assertEquals(1, $t1['is_active']);
$this->assertEquals('green', $t1['color_id']);
$t1 = $task->getById(2);
$this->assertEquals(1, $t1['position']);
$this->assertEquals(1, $t1['is_active']);
$this->assertEquals('yellow', $t1['color_id']);
$this->registry->shared('event')->clearTriggeredEvents();
$this->assertTrue($task->movePosition(1, 2, 1, 44)); // task #2 to position 1
$this->assertTrue($this->registry->shared('event')->isEventTriggered(Task::EVENT_MOVE_POSITION));
$this->assertEquals('Action\TaskAssignColorCategory', $this->registry->shared('event')->getLastListenerExecuted());
$t1 = $task->getById(1);
$this->assertEquals(1, $t1['position']);
$this->assertEquals(1, $t1['is_active']);
$this->assertEquals('green', $t1['color_id']);
$t1 = $task->getById(2);
$this->assertEquals(2, $t1['position']);
$this->assertEquals(1, $t1['is_active']);
$this->assertEquals('green', $t1['color_id']);
}
public function testExecuteMultipleActions()
{
$task = new Task($this->registry);