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 | 84 | ||||
-rw-r--r-- | tests/Base.php | 4 | ||||
-rw-r--r-- | tests/TaskTest.php | 19 |
5 files changed, 172 insertions, 27 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..2eb12784 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); @@ -85,12 +86,89 @@ class ActionTest extends Base // We move our task $task->move(1, 4, 1); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_COLUMN)); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_UPDATE)); + // Our task should be closed $t1 = $task->getById(1); $this->assertEquals(4, $t1['column_id']); $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 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->event->hasListener(Task::EVENT_MOVE_POSITION, 'Action\TaskAssignColorCategory')); + + // 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']); + $this->assertEquals('red', $t1['color_id']); + + $t1 = $task->getById(2); + $this->assertEquals(1, $t1['position']); + $this->assertEquals(1, $t1['is_active']); + $this->assertEquals('yellow', $t1['color_id']); + + // We move our tasks + $task->move(1, 1, 1); // task #1 to position 1 + $task->move(2, 1, 0); // task #2 to position 0 + + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_POSITION)); + + // Both tasks should be green + $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(0, $t1['position']); + $this->assertEquals(1, $t1['is_active']); + $this->assertEquals('green', $t1['color_id']); + } + public function testExecuteMultipleActions() { $task = new Task($this->db, $this->event); @@ -146,7 +224,9 @@ class ActionTest extends Base // We move our task $task->move(1, 4, 1); - $this->assertEquals(Task::EVENT_CREATE, $this->event->getLastTriggeredEvent()); + + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_CLOSE)); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_COLUMN)); // Our task should be closed $t1 = $task->getById(1); diff --git a/tests/Base.php b/tests/Base.php index 9c8cfc4a..d4065982 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -4,6 +4,8 @@ if (version_compare(PHP_VERSION, '5.5.0', '<')) { require __DIR__.'/../vendor/password.php'; } +require_once __DIR__.'/../app/Core/Security.php'; + require_once __DIR__.'/../vendor/PicoDb/Database.php'; require_once __DIR__.'/../app/Schema/Sqlite.php'; @@ -20,11 +22,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'; diff --git a/tests/TaskTest.php b/tests/TaskTest.php index 2f645131..da7e6a70 100644 --- a/tests/TaskTest.php +++ b/tests/TaskTest.php @@ -110,7 +110,7 @@ class TaskTest extends Base // We duplicate our task $this->assertEquals(2, $t->duplicate(1)); - $this->assertEquals(Task::EVENT_CREATE, $this->event->getLastTriggeredEvent()); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE)); // Check the values of the duplicated task $task = $t->getById(2); @@ -136,7 +136,7 @@ class TaskTest extends Base // We duplicate our task to the 2nd project $this->assertEquals(2, $t->duplicateToAnotherProject(1, 2)); - $this->assertEquals(Task::EVENT_CREATE, $this->event->getLastTriggeredEvent()); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE)); // Check the values of the duplicated task $task = $t->getById(2); @@ -157,30 +157,31 @@ class TaskTest extends Base // We create task $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - $this->assertEquals(Task::EVENT_CREATE, $this->event->getLastTriggeredEvent()); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE)); // We update a task $this->assertTrue($t->update(array('title' => 'test2', 'id' => 1))); - $this->assertEquals(Task::EVENT_UPDATE, $this->event->getLastTriggeredEvent()); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_UPDATE)); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE_UPDATE)); // We close our task $this->assertTrue($t->close(1)); - $this->assertEquals(Task::EVENT_CLOSE, $this->event->getLastTriggeredEvent()); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_CLOSE)); // We open our task $this->assertTrue($t->open(1)); - $this->assertEquals(Task::EVENT_OPEN, $this->event->getLastTriggeredEvent()); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_OPEN)); // We change the column of our task $this->assertTrue($t->move(1, 2, 1)); - $this->assertEquals(Task::EVENT_MOVE_COLUMN, $this->event->getLastTriggeredEvent()); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_COLUMN)); // We change the position of our task $this->assertTrue($t->move(1, 2, 2)); - $this->assertEquals(Task::EVENT_MOVE_POSITION, $this->event->getLastTriggeredEvent()); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_POSITION)); // We change the column and the position of our task $this->assertTrue($t->move(1, 1, 3)); - $this->assertEquals(Task::EVENT_MOVE_COLUMN, $this->event->getLastTriggeredEvent()); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_COLUMN)); } } |