summaryrefslogtreecommitdiff
path: root/tests/units/ActionTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/units/ActionTest.php')
-rw-r--r--tests/units/ActionTest.php164
1 files changed, 64 insertions, 100 deletions
diff --git a/tests/units/ActionTest.php b/tests/units/ActionTest.php
index 84f383f7..77a939e0 100644
--- a/tests/units/ActionTest.php
+++ b/tests/units/ActionTest.php
@@ -10,21 +10,22 @@ use Model\TaskPosition;
use Model\TaskCreation;
use Model\TaskFinder;
use Model\Category;
+use Model\GithubWebhook;
class ActionTest extends Base
{/*
- public function testFetchActions()
+ public function testSingleAction()
{
- $action = new Action($this->container);
+ $tp = new TaskPosition($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFinder($this->container);
$board = new Board($this->container);
$project = new Project($this->container);
+ $action = new Action($this->container);
+ // We create a project
$this->assertEquals(1, $project->create(array('name' => 'unit_test')));
- // We should have nothing
- $this->assertEmpty($action->getAll());
- $this->assertEmpty($action->getAllByProject(1));
-
// We create a new action
$this->assertTrue($action->create(array(
'project_id' => 1,
@@ -35,32 +36,6 @@ class ActionTest extends Base
)
)));
- // We should have our action
- $this->assertNotEmpty($action->getAll());
- $this->assertEquals($action->getAll(), $action->getAllByProject(1));
-
- $actions = $action->getAll();
-
- $this->assertEquals(1, count($actions));
- $this->assertEquals(1, $actions[0]['project_id']);
- $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']);
- $this->assertEquals('TaskClose', $actions[0]['action_name']);
- $this->assertEquals('column_id', $actions[0]['params'][0]['name']);
- $this->assertEquals(4, $actions[0]['params'][0]['value']);
- }
-
- public function testEventMoveColumn()
- {
- $tp = new TaskPosition($this->container);
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $board = new Board($this->container);
- $project = new Project($this->container);
- $action = new Action($this->container);
-
- // We create a project
- $this->assertEquals(1, $project->create(array('name' => 'unit_test')));
-
// We create a task
$this->assertEquals(1, $tc->create(array(
'title' => 'unit_test',
@@ -70,17 +45,7 @@ class ActionTest extends Base
'column_id' => 1,
)));
- // We create a new action
- $this->assertTrue($action->create(array(
- 'project_id' => 1,
- 'event_name' => Task::EVENT_MOVE_COLUMN,
- 'action_name' => 'TaskClose',
- 'params' => array(
- 'column_id' => 4,
- )
- )));
-
- // We bind events
+ // We attach events
$action->attachEvents();
// Our task should be open
@@ -91,87 +56,86 @@ class ActionTest extends Base
// We move our task
$tp->movePosition(1, 1, 4, 1);
- $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
- $this->assertFalse($this->container['event']->isEventTriggered(Task::EVENT_UPDATE));
-
// Our task should be closed
$t1 = $tf->getById(1);
$this->assertEquals(4, $t1['column_id']);
$this->assertEquals(0, $t1['is_active']);
}
*/
- public function testExecuteMultipleActions()
+ public function testMultipleActions()
{
$tp = new TaskPosition($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
- $board = new Board($this->container);
- $project = new Project($this->container);
- $action = new Action($this->container);
+ $b = new Board($this->container);
+ $p = new Project($this->container);
+ $a = new Action($this->container);
+ $c = new Category($this->container);
+ $g = new GithubWebhook($this->container);
- // We create 2 projects
- $this->assertEquals(1, $project->create(array('name' => 'unit_test1')));
- $this->assertEquals(2, $project->create(array('name' => 'unit_test2')));
+ // We create a project
+ $this->assertEquals(1, $p->create(array('name' => 'unit_test')));
+ $this->assertEquals(1, $c->create(array('name' => 'unit_test')));
- // We create a task
- $this->assertEquals(1, $tc->create(array(
- 'title' => 'unit_test',
+ // We create a new action
+ $this->assertTrue($a->create(array(
'project_id' => 1,
- 'owner_id' => 1,
- 'color_id' => 'red',
- 'column_id' => 1,
+ 'event_name' => GithubWebhook::EVENT_ISSUE_OPENED,
+ 'action_name' => 'TaskCreation',
+ 'params' => array()
)));
- // We create 2 actions
- $this->assertTrue($action->create(array(
+ $this->assertTrue($a->create(array(
'project_id' => 1,
- 'event_name' => Task::EVENT_CLOSE,
- 'action_name' => 'TaskDuplicateAnotherProject',
+ 'event_name' => GithubWebhook::EVENT_ISSUE_LABEL_CHANGE,
+ 'action_name' => 'TaskAssignCategoryLabel',
'params' => array(
- 'column_id' => 4,
- 'project_id' => 2,
+ 'label' => 'bug',
+ 'category_id' => 1,
)
)));
- $this->assertTrue($action->create(array(
+ $this->assertTrue($a->create(array(
'project_id' => 1,
- 'event_name' => Task::EVENT_MOVE_COLUMN,
- 'action_name' => 'TaskClose',
+ 'event_name' => Task::EVENT_CREATE_UPDATE,
+ 'action_name' => 'TaskAssignColorCategory',
'params' => array(
- 'column_id' => 4,
+ 'color_id' => 'red',
+ 'category_id' => 1,
)
)));
- // We bind events
- $action->attachEvents();
-
- // Events should be attached
- $this->assertTrue($this->container['event']->hasListener(Task::EVENT_CLOSE, 'Action\TaskDuplicateAnotherProject'));
- $this->assertTrue($this->container['event']->hasListener(Task::EVENT_MOVE_COLUMN, 'Action\TaskClose'));
-
- // Our task should be open, linked to the first project and in the first column
- $t1 = $tf->getById(1);
- $this->assertEquals(1, $t1['is_active']);
- $this->assertEquals(1, $t1['column_id']);
- $this->assertEquals(1, $t1['project_id']);
-
- // We move our task
- $tp->movePosition(1, 1, 4, 1);
-
- $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_MOVE_COLUMN));
- $this->assertTrue($this->container['event']->isEventTriggered(Task::EVENT_CLOSE));
-
- // Our task should be closed
- $t1 = $tf->getById(1);
- $this->assertEquals(4, $t1['column_id']);
- $this->assertEquals(0, $t1['is_active']);
-
- // Our task should be duplicated to the 2nd project
- $t2 = $tf->getById(2);
- $this->assertNotEmpty($t2);
- $this->assertNotEquals(4, $t2['column_id']);
- $this->assertEquals(1, $t2['is_active']);
- $this->assertEquals(2, $t2['project_id']);
- $this->assertEquals('unit_test', $t2['title']);
+ // We attach events
+ $a->attachEvents();
+ $g->setProjectId(1);
+
+ // We create a Github issue
+ $issue = array(
+ 'number' => 123,
+ 'title' => 'Bugs everywhere',
+ 'body' => 'There is a bug!',
+ 'html_url' => 'http://localhost/',
+ );
+
+ $this->assertTrue($g->handleIssueOpened($issue));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+ $this->assertEquals(0, $task['category_id']);
+ $this->assertEquals('yellow', $task['color_id']);
+
+ // We assign a label to our issue
+ $label = array(
+ 'name' => 'bug',
+ );
+
+ $this->assertTrue($g->handleIssueLabeled($issue, $label));
+
+ $task = $tf->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(1, $task['is_active']);
+ $this->assertEquals(1, $task['category_id']);
+ $this->assertEquals('red', $task['color_id']);
}
}