diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ActionTaskAssignColorCategoryTest.php | 76 | ||||
-rw-r--r-- | tests/ActionTaskAssignColorUserTest.php | 16 | ||||
-rw-r--r-- | tests/ActionTest.php | 55 | ||||
-rw-r--r-- | tests/Base.php | 2 |
4 files changed, 132 insertions, 17 deletions
diff --git a/tests/ActionTaskAssignColorCategoryTest.php b/tests/ActionTaskAssignColorCategoryTest.php new file mode 100644 index 00000000..18b4311e --- /dev/null +++ b/tests/ActionTaskAssignColorCategoryTest.php @@ -0,0 +1,76 @@ +<?php + +require_once __DIR__.'/Base.php'; + +use Model\Task; +use Model\Project; +use Model\Category; + +class ActionTaskAssignColorCategory extends Base +{ + public function testBadProject() + { + $action = new Action\TaskAssignColorCategory(3, new Task($this->db, $this->event)); + + $event = array( + 'project_id' => 2, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertFalse($action->isExecutable($event)); + $this->assertFalse($action->execute($event)); + } + + public function testExecute() + { + $action = new Action\TaskAssignColorCategory(1, new Task($this->db, $this->event)); + $action->setParam('category_id', 1); + $action->setParam('color_id', 'blue'); + + // We create a task in the first column + $t = new Task($this->db, $this->event); + $p = new Project($this->db, $this->event); + $c = new Category($this->db, $this->event); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $c->create(array('name' => 'c1'))); + $this->assertEquals(2, $c->create(array('name' => 'c2'))); + $this->assertEquals(1, $t->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($event)); + + // Our task should be assigned to the ategory_id=1 and have the green color + $task = $t->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($event)); + + // Our task should have the blue color + $task = $t->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('blue', $task['color_id']); + } +} diff --git a/tests/ActionTaskAssignColorUserTest.php b/tests/ActionTaskAssignColorUserTest.php index 769ecc66..04e3172f 100644 --- a/tests/ActionTaskAssignColorUserTest.php +++ b/tests/ActionTaskAssignColorUserTest.php @@ -10,7 +10,6 @@ class ActionTaskAssignColorUser extends Base public function testBadProject() { $action = new Action\TaskAssignColorUser(3, new Task($this->db, $this->event)); - $action->setParam('column_id', 5); $event = array( 'project_id' => 2, @@ -22,24 +21,9 @@ class ActionTaskAssignColorUser extends Base $this->assertFalse($action->execute($event)); } - public function testBadColumn() - { - $action = new Action\TaskAssignColorUser(3, new Task($this->db, $this->event)); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 3, - ); - - $this->assertFalse($action->execute($event)); - } - public function testExecute() { $action = new Action\TaskAssignColorUser(1, new Task($this->db, $this->event)); - $action->setParam('column_id', 2); $action->setParam('user_id', 1); $action->setParam('color_id', 'blue'); diff --git a/tests/ActionTest.php b/tests/ActionTest.php index 2757a069..391f0e25 100644 --- a/tests/ActionTest.php +++ b/tests/ActionTest.php @@ -6,6 +6,7 @@ use Model\Action; use Model\Project; use Model\Board; use Model\Task; +use Model\Category; class ActionTest extends Base { @@ -45,7 +46,7 @@ class ActionTest extends Base $this->assertEquals(4, $actions[0]['params'][0]['value']); } - public function testExecuteAction() + public function testEventMoveColumn() { $task = new Task($this->db, $this->event); $board = new Board($this->db, $this->event); @@ -91,6 +92,56 @@ class ActionTest extends Base $this->assertEquals(0, $t1['is_active']); } + public function testEventMovePosition() + { + $task = new Task($this->db, $this->event); + $board = new Board($this->db, $this->event); + $project = new Project($this->db, $this->event); + $action = new Action($this->db, $this->event); + + // 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', + 'project_id' => 1, + 'owner_id' => 1, + 'color_id' => 'red', + 'column_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' => 'TaskClose', + 'params' => array( + 'column_id' => 1, + 'color_id' => 'green', + ) + ))); + + // We bind events + $action->attachEvents(); + + $this->assertTrue($this->event->hasListener(Task::EVENT_MOVE_POSITION, 'Action\TaskClose')); + + // Our task should have the color red and position=0 + $t1 = $task->getById(1); + $this->assertEquals(0, $t1['position']); + $this->assertEquals(1, $t1['is_active']); + + // We move our task + $task->move(1, 1, 2); + $this->assertEquals(Task::EVENT_CLOSE, $this->event->getLastTriggeredEvent()); + + // Our task should be green and have the position 2 + $t1 = $task->getById(1); + $this->assertEquals(2, $t1['position']); + $this->assertEquals(0, $t1['is_active']); + } + public function testExecuteMultipleActions() { $task = new Task($this->db, $this->event); @@ -161,4 +212,6 @@ class ActionTest extends Base $this->assertEquals(2, $t2['project_id']); $this->assertEquals('unit_test', $t2['title']); } + + } diff --git a/tests/Base.php b/tests/Base.php index 9c8cfc4a..ce088b22 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -20,11 +20,13 @@ require_once __DIR__.'/../app/Model/Project.php'; require_once __DIR__.'/../app/Model/User.php'; require_once __DIR__.'/../app/Model/Board.php'; require_once __DIR__.'/../app/Model/Action.php'; +require_once __DIR__.'/../app/Model/Category.php'; require_once __DIR__.'/../app/Action/Base.php'; require_once __DIR__.'/../app/Action/TaskClose.php'; require_once __DIR__.'/../app/Action/TaskAssignSpecificUser.php'; require_once __DIR__.'/../app/Action/TaskAssignColorUser.php'; +require_once __DIR__.'/../app/Action/TaskAssignColorCategory.php'; require_once __DIR__.'/../app/Action/TaskAssignCurrentUser.php'; require_once __DIR__.'/../app/Action/TaskDuplicateAnotherProject.php'; |