From 7c5b900bd83b6b9bdb5656eb169381ff46f8106a Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Fri, 20 Jun 2014 15:41:05 -0300 Subject: First API implementation --- tests/AclTest.php | 112 ------ tests/ActionTaskAssignColorCategoryTest.php | 76 ---- tests/ActionTaskAssignColorUserTest.php | 70 ---- tests/ActionTaskAssignCurrentUserTest.php | 73 ---- tests/ActionTaskAssignSpecificUserTest.php | 66 ---- tests/ActionTaskCloseTest.php | 65 ---- tests/ActionTaskDuplicateAnotherProjectTest.php | 89 ----- tests/ActionTest.php | 244 ------------ tests/Base.php | 57 --- tests/BoardTest.php | 77 ---- tests/CommentTest.php | 116 ------ tests/ProjectTest.php | 162 -------- tests/TaskTest.php | 187 --------- tests/functionals/ApiTest.php | 417 +++++++++++++++++++++ tests/units/AclTest.php | 112 ++++++ tests/units/ActionTaskAssignColorCategoryTest.php | 76 ++++ tests/units/ActionTaskAssignColorUserTest.php | 70 ++++ tests/units/ActionTaskAssignCurrentUserTest.php | 73 ++++ tests/units/ActionTaskAssignSpecificUserTest.php | 66 ++++ tests/units/ActionTaskCloseTest.php | 65 ++++ .../ActionTaskDuplicateAnotherProjectTest.php | 89 +++++ tests/units/ActionTest.php | 244 ++++++++++++ tests/units/Base.php | 57 +++ tests/units/BoardTest.php | 77 ++++ tests/units/CommentTest.php | 116 ++++++ tests/units/ProjectTest.php | 162 ++++++++ tests/units/TaskTest.php | 187 +++++++++ 27 files changed, 1811 insertions(+), 1394 deletions(-) delete mode 100644 tests/AclTest.php delete mode 100644 tests/ActionTaskAssignColorCategoryTest.php delete mode 100644 tests/ActionTaskAssignColorUserTest.php delete mode 100644 tests/ActionTaskAssignCurrentUserTest.php delete mode 100644 tests/ActionTaskAssignSpecificUserTest.php delete mode 100644 tests/ActionTaskCloseTest.php delete mode 100644 tests/ActionTaskDuplicateAnotherProjectTest.php delete mode 100644 tests/ActionTest.php delete mode 100644 tests/Base.php delete mode 100644 tests/BoardTest.php delete mode 100644 tests/CommentTest.php delete mode 100644 tests/ProjectTest.php delete mode 100644 tests/TaskTest.php create mode 100644 tests/functionals/ApiTest.php create mode 100644 tests/units/AclTest.php create mode 100644 tests/units/ActionTaskAssignColorCategoryTest.php create mode 100644 tests/units/ActionTaskAssignColorUserTest.php create mode 100644 tests/units/ActionTaskAssignCurrentUserTest.php create mode 100644 tests/units/ActionTaskAssignSpecificUserTest.php create mode 100644 tests/units/ActionTaskCloseTest.php create mode 100644 tests/units/ActionTaskDuplicateAnotherProjectTest.php create mode 100644 tests/units/ActionTest.php create mode 100644 tests/units/Base.php create mode 100644 tests/units/BoardTest.php create mode 100644 tests/units/CommentTest.php create mode 100644 tests/units/ProjectTest.php create mode 100644 tests/units/TaskTest.php (limited to 'tests') diff --git a/tests/AclTest.php b/tests/AclTest.php deleted file mode 100644 index a2c1c111..00000000 --- a/tests/AclTest.php +++ /dev/null @@ -1,112 +0,0 @@ - array('action1', 'action3'), - ); - - $acl = new Acl($this->db, $this->event); - $this->assertTrue($acl->isAllowedAction($acl_rules, 'controller1', 'action1')); - $this->assertTrue($acl->isAllowedAction($acl_rules, 'controller1', 'action3')); - $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller1', 'action2')); - $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller2', 'action2')); - $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller2', 'action3')); - } - - public function testIsAdmin() - { - $acl = new Acl($this->db, $this->event); - - $_SESSION = array(); - $this->assertFalse($acl->isAdminUser()); - - $_SESSION = array('user' => array()); - $this->assertFalse($acl->isAdminUser()); - - $_SESSION = array('user' => array('is_admin' => '1')); - $this->assertFalse($acl->isAdminUser()); - - $_SESSION = array('user' => array('is_admin' => false)); - $this->assertFalse($acl->isAdminUser()); - - $_SESSION = array('user' => array('is_admin' => '2')); - $this->assertFalse($acl->isAdminUser()); - - $_SESSION = array('user' => array('is_admin' => true)); - $this->assertTrue($acl->isAdminUser()); - } - - public function testIsUser() - { - $acl = new Acl($this->db, $this->event); - - $_SESSION = array(); - $this->assertFalse($acl->isRegularUser()); - - $_SESSION = array('user' => array()); - $this->assertFalse($acl->isRegularUser()); - - $_SESSION = array('user' => array('is_admin' => true)); - $this->assertFalse($acl->isRegularUser()); - - $_SESSION = array('user' => array('is_admin' => true)); - $this->assertFalse($acl->isRegularUser()); - - $_SESSION = array('user' => array('is_admin' => '2')); - $this->assertFalse($acl->isRegularUser()); - - $_SESSION = array('user' => array('is_admin' => false)); - $this->assertTrue($acl->isRegularUser()); - } - - public function testIsPageAllowed() - { - $acl = new Acl($this->db, $this->event); - - // Public access - $_SESSION = array(); - $this->assertFalse($acl->isPageAccessAllowed('user', 'create')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'save')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'remove')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'confirm')); - $this->assertFalse($acl->isPageAccessAllowed('app', 'index')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'index')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'login')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'check')); - $this->assertTrue($acl->isPageAccessAllowed('task', 'add')); - $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly')); - - // Regular user - $_SESSION = array('user' => array('is_admin' => false)); - $this->assertFalse($acl->isPageAccessAllowed('user', 'create')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'save')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'remove')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'confirm')); - $this->assertTrue($acl->isPageAccessAllowed('app', 'index')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'index')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'login')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'check')); - $this->assertTrue($acl->isPageAccessAllowed('task', 'add')); - $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly')); - - // Admin user - $_SESSION = array('user' => array('is_admin' => true)); - $this->assertTrue($acl->isPageAccessAllowed('user', 'create')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'save')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'remove')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'confirm')); - $this->assertTrue($acl->isPageAccessAllowed('app', 'index')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'index')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'login')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'check')); - $this->assertTrue($acl->isPageAccessAllowed('task', 'add')); - $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly')); - } -} diff --git a/tests/ActionTaskAssignColorCategoryTest.php b/tests/ActionTaskAssignColorCategoryTest.php deleted file mode 100644 index 18b4311e..00000000 --- a/tests/ActionTaskAssignColorCategoryTest.php +++ /dev/null @@ -1,76 +0,0 @@ -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 deleted file mode 100644 index 04e3172f..00000000 --- a/tests/ActionTaskAssignColorUserTest.php +++ /dev/null @@ -1,70 +0,0 @@ -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\TaskAssignColorUser(1, new Task($this->db, $this->event)); - $action->setParam('user_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); - $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 - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - 'owner_id' => 5, - ); - - // Our event should NOT be executed - $this->assertFalse($action->execute($event)); - - // Our task should be assigned to nobody and have the green color - $task = $t->getById(1); - $this->assertNotEmpty($task); - $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 - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - 'owner_id' => 1, - ); - - // Our event should be executed - $this->assertTrue($action->execute($event)); - - // Our task should be assigned to nobody and have the blue color - $task = $t->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals('blue', $task['color_id']); - } -} diff --git a/tests/ActionTaskAssignCurrentUserTest.php b/tests/ActionTaskAssignCurrentUserTest.php deleted file mode 100644 index 0780b603..00000000 --- a/tests/ActionTaskAssignCurrentUserTest.php +++ /dev/null @@ -1,73 +0,0 @@ -db, $this->event), new Acl($this->db, $this->event)); - $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($event)); - } - - public function testBadColumn() - { - $action = new Action\TaskAssignCurrentUser(3, new Task($this->db, $this->event), new Acl($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\TaskAssignCurrentUser(1, new Task($this->db, $this->event), new Acl($this->db, $this->event)); - $action->setParam('column_id', 2); - $_SESSION = array( - 'user' => array('id' => 5) - ); - - // We create a task in the first column - $t = new Task($this->db, $this->event); - $p = new Project($this->db, $this->event); - $a = new Acl($this->db, $this->event); - - $this->assertEquals(5, $a->getUserId()); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $t->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($event)); - - // Our task should be assigned to the user 5 (from the session) - $task = $t->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['id']); - $this->assertEquals(5, $task['owner_id']); - } -} diff --git a/tests/ActionTaskAssignSpecificUserTest.php b/tests/ActionTaskAssignSpecificUserTest.php deleted file mode 100644 index 3a919978..00000000 --- a/tests/ActionTaskAssignSpecificUserTest.php +++ /dev/null @@ -1,66 +0,0 @@ -db, $this->event)); - $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($event)); - } - - public function testBadColumn() - { - $action = new Action\TaskAssignSpecificUser(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\TaskAssignSpecificUser(1, new Task($this->db, $this->event)); - $action->setParam('column_id', 2); - $action->setParam('user_id', 1); - - // We create a task in the first column - $t = new Task($this->db, $this->event); - $p = new Project($this->db, $this->event); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $t->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($event)); - - // Our task should be assigned to the user 1 - $task = $t->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['owner_id']); - } -} diff --git a/tests/ActionTaskCloseTest.php b/tests/ActionTaskCloseTest.php deleted file mode 100644 index 0c864f42..00000000 --- a/tests/ActionTaskCloseTest.php +++ /dev/null @@ -1,65 +0,0 @@ -db, $this->event)); - $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($event)); - } - - public function testBadColumn() - { - $action = new Action\TaskClose(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\TaskClose(1, new Task($this->db, $this->event)); - $action->setParam('column_id', 2); - - // We create a task in the first column - $t = new Task($this->db, $this->event); - $p = new Project($this->db, $this->event); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $t->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($event)); - - // Our task should be closed - $task = $t->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['is_active']); - } -} diff --git a/tests/ActionTaskDuplicateAnotherProjectTest.php b/tests/ActionTaskDuplicateAnotherProjectTest.php deleted file mode 100644 index 0b2e4bd5..00000000 --- a/tests/ActionTaskDuplicateAnotherProjectTest.php +++ /dev/null @@ -1,89 +0,0 @@ -db, $this->event)); - $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($event)); - } - - public function testBadColumn() - { - $action = new Action\TaskDuplicateAnotherProject(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\TaskDuplicateAnotherProject(1, new Task($this->db, $this->event)); - - // We create a task in the first column - $t = new Task($this->db, $this->event); - $p = new Project($this->db, $this->event); - $this->assertEquals(1, $p->create(array('name' => 'project 1'))); - $this->assertEquals(2, $p->create(array('name' => 'project 2'))); - $this->assertEquals(1, $t->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($event)); - - // Our task should be assigned to the project 1 - $task = $t->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($event)); - - // Our task should be assigned to the project 1 - $task = $t->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['project_id']); - - // We should have another task assigned to the project 2 - $task = $t->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['project_id']); - } -} diff --git a/tests/ActionTest.php b/tests/ActionTest.php deleted file mode 100644 index 2eb12784..00000000 --- a/tests/ActionTest.php +++ /dev/null @@ -1,244 +0,0 @@ -db, $this->event); - $board = new Board($this->db, $this->event); - $project = new Project($this->db, $this->event); - - $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, - 'event_name' => Task::EVENT_MOVE_COLUMN, - 'action_name' => 'TaskClose', - 'params' => array( - 'column_id' => 4, - ) - ))); - - // 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() - { - $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 - $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 - $action->attachEvents(); - - // Our task should be open - $t1 = $task->getById(1); - $this->assertEquals(1, $t1['is_active']); - $this->assertEquals(1, $t1['column_id']); - - // 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); - $board = new Board($this->db, $this->event); - $project = new Project($this->db, $this->event); - $action = new Action($this->db, $this->event); - - // 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 task - $this->assertEquals(1, $task->create(array( - 'title' => 'unit_test', - 'project_id' => 1, - 'owner_id' => 1, - 'color_id' => 'red', - 'column_id' => 1, - ))); - - // We create 2 actions - $this->assertTrue($action->create(array( - 'project_id' => 1, - 'event_name' => Task::EVENT_CLOSE, - 'action_name' => 'TaskDuplicateAnotherProject', - 'params' => array( - 'column_id' => 4, - 'project_id' => 2, - ) - ))); - - $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 - $action->attachEvents(); - - // Events should be attached - $this->assertTrue($this->event->hasListener(Task::EVENT_CLOSE, 'Action\TaskDuplicateAnotherProject')); - $this->assertTrue($this->event->hasListener(Task::EVENT_MOVE_COLUMN, 'Action\TaskClose')); - - // Our task should be open, linked to the first project and in the first column - $t1 = $task->getById(1); - $this->assertEquals(1, $t1['is_active']); - $this->assertEquals(1, $t1['column_id']); - $this->assertEquals(1, $t1['project_id']); - - // We move our task - $task->move(1, 4, 1); - - $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); - $this->assertEquals(4, $t1['column_id']); - $this->assertEquals(0, $t1['is_active']); - - // Our task should be duplicated to the 2nd project - $t2 = $task->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']); - } -} diff --git a/tests/Base.php b/tests/Base.php deleted file mode 100644 index d4065982..00000000 --- a/tests/Base.php +++ /dev/null @@ -1,57 +0,0 @@ -db = $this->getDbConnection(); - $this->event = new \Core\Event; - } - - public function getDbConnection() - { - $db = new \PicoDb\Database(array( - 'driver' => 'sqlite', - 'filename' => ':memory:' - )); - - if ($db->schema()->check(\Schema\VERSION)) { - return $db; - } - else { - die('Unable to migrate database schema!'); - } - } -} diff --git a/tests/BoardTest.php b/tests/BoardTest.php deleted file mode 100644 index d5686b3f..00000000 --- a/tests/BoardTest.php +++ /dev/null @@ -1,77 +0,0 @@ -db, $this->event); - $b = new Board($this->db, $this->event); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); - $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); - - // We get the columns of the project 2 - $columns = $b->getColumns(2); - $columns_id = array_keys($b->getColumnsList(2)); - $this->assertNotEmpty($columns); - - // Initial order: 5, 6, 7, 8 - - // Move the column 1 down - $this->assertEquals(1, $columns[0]['position']); - $this->assertEquals($columns_id[0], $columns[0]['id']); - - $this->assertEquals(2, $columns[1]['position']); - $this->assertEquals($columns_id[1], $columns[1]['id']); - - $this->assertTrue($b->moveDown(2, $columns[0]['id'])); - $columns = $b->getColumns(2); // Sorted by position - - // New order: 6, 5, 7, 8 - - $this->assertEquals(1, $columns[0]['position']); - $this->assertEquals($columns_id[1], $columns[0]['id']); - - $this->assertEquals(2, $columns[1]['position']); - $this->assertEquals($columns_id[0], $columns[1]['id']); - - // Move the column 3 up - $this->assertTrue($b->moveUp(2, $columns[2]['id'])); - $columns = $b->getColumns(2); - - // New order: 6, 7, 5, 8 - - $this->assertEquals(1, $columns[0]['position']); - $this->assertEquals($columns_id[1], $columns[0]['id']); - - $this->assertEquals(2, $columns[1]['position']); - $this->assertEquals($columns_id[2], $columns[1]['id']); - - $this->assertEquals(3, $columns[2]['position']); - $this->assertEquals($columns_id[0], $columns[2]['id']); - - // Move column 1 up (must do nothing because it's the first column) - $this->assertFalse($b->moveUp(2, $columns[0]['id'])); - $columns = $b->getColumns(2); - - // Order: 6, 7, 5, 8 - - $this->assertEquals(1, $columns[0]['position']); - $this->assertEquals($columns_id[1], $columns[0]['id']); - - // Move column 4 down (must do nothing because it's the last column) - $this->assertFalse($b->moveDown(2, $columns[3]['id'])); - $columns = $b->getColumns(2); - - // Order: 6, 7, 5, 8 - - $this->assertEquals(4, $columns[3]['position']); - $this->assertEquals($columns_id[3], $columns[3]['id']); - } -} diff --git a/tests/CommentTest.php b/tests/CommentTest.php deleted file mode 100644 index 46f05abc..00000000 --- a/tests/CommentTest.php +++ /dev/null @@ -1,116 +0,0 @@ -db, $this->event); - $t = new Task($this->db, $this->event); - $p = new Project($this->db, $this->event); - - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1))); - - $comment = $c->getById(1); - - $this->assertNotEmpty($comment); - $this->assertEquals('bla bla', $comment['comment']); - $this->assertEquals(1, $comment['task_id']); - $this->assertEquals(1, $comment['user_id']); - $this->assertEquals('admin', $comment['username']); - $this->assertNotEmpty($comment['date']); - } - - public function testGetAll() - { - $c = new Comment($this->db, $this->event); - $t = new Task($this->db, $this->event); - $p = new Project($this->db, $this->event); - - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1))); - $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1))); - $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1))); - - $comments = $c->getAll(1); - - $this->assertNotEmpty($comments); - $this->assertEquals(3, count($comments)); - $this->assertEquals(1, $comments[0]['id']); - $this->assertEquals(2, $comments[1]['id']); - $this->assertEquals(3, $comments[2]['id']); - } - - public function testUpdate() - { - $c = new Comment($this->db, $this->event); - $t = new Task($this->db, $this->event); - $p = new Project($this->db, $this->event); - - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1))); - $this->assertTrue($c->update(array('id' => 1, 'comment' => 'bla'))); - - $comment = $c->getById(1); - $this->assertNotEmpty($comment); - $this->assertEquals('bla', $comment['comment']); - } - - public function testValidateCreation() - { - $c = new Comment($this->db, $this->event); - - $result = $c->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla')); - $this->assertTrue($result[0]); - - $result = $c->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => '')); - $this->assertFalse($result[0]); - - $result = $c->validateCreation(array('user_id' => 1, 'task_id' => 'a', 'comment' => 'bla')); - $this->assertFalse($result[0]); - - $result = $c->validateCreation(array('user_id' => 'b', 'task_id' => 1, 'comment' => 'bla')); - $this->assertFalse($result[0]); - - $result = $c->validateCreation(array('user_id' => 1, 'comment' => 'bla')); - $this->assertFalse($result[0]); - - $result = $c->validateCreation(array('task_id' => 1, 'comment' => 'bla')); - $this->assertFalse($result[0]); - - $result = $c->validateCreation(array('comment' => 'bla')); - $this->assertFalse($result[0]); - - $result = $c->validateCreation(array()); - $this->assertFalse($result[0]); - } - - public function testValidateModification() - { - $c = new Comment($this->db, $this->event); - - $result = $c->validateModification(array('id' => 1, 'comment' => 'bla')); - $this->assertTrue($result[0]); - - $result = $c->validateModification(array('id' => 1, 'comment' => '')); - $this->assertFalse($result[0]); - - $result = $c->validateModification(array('comment' => 'bla')); - $this->assertFalse($result[0]); - - $result = $c->validateModification(array('id' => 'b', 'comment' => 'bla')); - $this->assertFalse($result[0]); - - $result = $c->validateModification(array()); - $this->assertFalse($result[0]); - } -} diff --git a/tests/ProjectTest.php b/tests/ProjectTest.php deleted file mode 100644 index 5ca8177c..00000000 --- a/tests/ProjectTest.php +++ /dev/null @@ -1,162 +0,0 @@ -db, $this->event); - - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertNotEmpty($p->getById(1)); - } - - public function testAllowEverybody() - { - // We create a regular user - $user = new User($this->db, $this->event); - $user->create(array('username' => 'unittest', 'password' => 'unittest')); - - $p = new Project($this->db, $this->event); - $this->assertEmpty($p->getAllowedUsers(1)); // Nobody is specified for the given project - $this->assertTrue($p->isUserAllowed(1, 1)); // Everybody should be allowed - $this->assertTrue($p->isUserAllowed(1, 2)); // Everybody should be allowed - } - - public function testAllowUser() - { - $p = new Project($this->db, $this->event); - $user = new User($this->db, $this->event); - $user->create(array('username' => 'unittest', 'password' => 'unittest')); - - // We create a project - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - - // We allow the admin user - $this->assertTrue($p->allowUser(1, 1)); - - // Non-existant project - $this->assertFalse($p->allowUser(50, 1)); - - // Non-existant user - $this->assertFalse($p->allowUser(1, 50)); - - // Our admin user should be allowed - $this->assertEquals(array('1' => 'admin'), $p->getAllowedUsers(1)); - $this->assertTrue($p->isUserAllowed(1, 1)); - - // Our regular user should be forbidden - $this->assertFalse($p->isUserAllowed(1, 2)); - } - - public function testRevokeUser() - { - $p = new Project($this->db, $this->event); - - $user = new User($this->db, $this->event); - $user->create(array('username' => 'unittest', 'password' => 'unittest')); - - // We create a project - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - - // We revoke our admin user - $this->assertTrue($p->revokeUser(1, 1)); - - // We should have nobody in the users list - $this->assertEmpty($p->getAllowedUsers(1)); - - // Our admin user and our regular user should be allowed - $this->assertTrue($p->isUserAllowed(1, 1)); - $this->assertTrue($p->isUserAllowed(1, 2)); - - // We allow only the regular user - $this->assertTrue($p->allowUser(1, 2)); - - // All users should be allowed (admin and regular) - $this->assertTrue($p->isUserAllowed(1, 1)); - $this->assertTrue($p->isUserAllowed(1, 2)); - - // However, we should have only our regular user in the list - $this->assertEquals(array('2' => 'unittest'), $p->getAllowedUsers(1)); - - // We allow our admin, we should have both in the list - $this->assertTrue($p->allowUser(1, 1)); - $this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $p->getAllowedUsers(1)); - $this->assertTrue($p->isUserAllowed(1, 1)); - $this->assertTrue($p->isUserAllowed(1, 2)); - - // We revoke the regular user - $this->assertTrue($p->revokeUser(1, 2)); - - // Only admin should be allowed - $this->assertTrue($p->isUserAllowed(1, 1)); - $this->assertFalse($p->isUserAllowed(1, 2)); - - // We should have only admin in the list - $this->assertEquals(array('1' => 'admin'), $p->getAllowedUsers(1)); - - // We revoke the admin user - $this->assertTrue($p->revokeUser(1, 1)); - $this->assertEmpty($p->getAllowedUsers(1)); - - // Everybody should be allowed again - $this->assertTrue($p->isUserAllowed(1, 1)); - $this->assertTrue($p->isUserAllowed(1, 2)); - } - - public function testUsersList() - { - $p = new Project($this->db, $this->event); - - $user = new User($this->db, $this->event); - $user->create(array('username' => 'unittest', 'password' => 'unittest')); - - // We create project - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - - // No restriction, we should have everybody - $this->assertEquals( - array('Unassigned', 'admin', 'unittest'), - $p->getUsersList(1) - ); - - // We allow only the regular user - $this->assertTrue($p->allowUser(1, 2)); - - $this->assertEquals( - array(0 => 'Unassigned', 2 => 'unittest'), - $p->getUsersList(1) - ); - - // We allow the admin user - $this->assertTrue($p->allowUser(1, 1)); - - $this->assertEquals( - array(0 => 'Unassigned', 1 => 'admin', 2 => 'unittest'), - $p->getUsersList(1) - ); - - // We revoke only the regular user - $this->assertTrue($p->revokeUser(1, 2)); - - $this->assertEquals( - array(0 => 'Unassigned', 1 => 'admin'), - $p->getUsersList(1) - ); - - // We revoke only the admin user, we should have everybody - $this->assertTrue($p->revokeUser(1, 1)); - - $this->assertEquals( - array(0 => 'Unassigned', 1 => 'admin', 2 => 'unittest'), - $p->getUsersList(1) - ); - } -} diff --git a/tests/TaskTest.php b/tests/TaskTest.php deleted file mode 100644 index da7e6a70..00000000 --- a/tests/TaskTest.php +++ /dev/null @@ -1,187 +0,0 @@ -db, $this->event); - $p = new Project($this->db, $this->event); - - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $t->create(array('title' => 'test a', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'description' => 'biloute'))); - $this->assertEquals(2, $t->create(array('title' => 'test b', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2, 'description' => 'toto et titi sont dans un bateau'))); - - $tasks = $t->find(array(array('column' => 'project_id', 'operator' => 'eq', 'value' => '1'))); - $this->assertNotFalse($tasks); - $this->assertEquals(2, count($tasks)); - $this->assertEquals(1, $tasks[0]['id']); - $this->assertEquals(2, $tasks[1]['id']); - - $tasks = $t->find(array( - array('column' => 'project_id', 'operator' => 'eq', 'value' => '1'), - array('column' => 'owner_id', 'operator' => 'eq', 'value' => '2'), - )); - $this->assertEquals(1, count($tasks)); - $this->assertEquals(2, $tasks[0]['id']); - - $tasks = $t->find(array( - array('column' => 'project_id', 'operator' => 'eq', 'value' => '1'), - array('column' => 'title', 'operator' => 'like', 'value' => '%b%'), - )); - $this->assertEquals(1, count($tasks)); - $this->assertEquals(2, $tasks[0]['id']); - - // Condition with OR - $search = 'bateau'; - $filters = array( - array('column' => 'project_id', 'operator' => 'eq', 'value' => 1), - 'or' => array( - array('column' => 'title', 'operator' => 'like', 'value' => '%'.$search.'%'), - array('column' => 'description', 'operator' => 'like', 'value' => '%'.$search.'%'), - ) - ); - - $tasks = $t->find($filters); - $this->assertEquals(1, count($tasks)); - $this->assertEquals(2, $tasks[0]['id']); - - $search = 'toto et titi'; - $filters = array( - array('column' => 'project_id', 'operator' => 'eq', 'value' => 1), - 'or' => array( - array('column' => 'title', 'operator' => 'like', 'value' => '%'.$search.'%'), - array('column' => 'description', 'operator' => 'like', 'value' => '%'.$search.'%'), - ) - ); - - $tasks = $t->find($filters); - $this->assertEquals(1, count($tasks)); - $this->assertEquals(2, $tasks[0]['id']); - - $search = 'john'; - $filters = array( - array('column' => 'project_id', 'operator' => 'eq', 'value' => 1), - 'or' => array( - array('column' => 'title', 'operator' => 'like', 'value' => '%'.$search.'%'), - array('column' => 'description', 'operator' => 'like', 'value' => '%'.$search.'%'), - ) - ); - - $tasks = $t->find($filters); - $this->assertEquals(0, count($tasks)); - } - - public function testDateFormat() - { - $t = new Task($this->db, $this->event); - - $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('2014-03-05', 'Y-m-d'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('2014_03_05', 'Y_m_d'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('05/03/2014', 'd/m/Y'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('03/05/2014', 'm/d/Y'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('3/5/2014', 'm/d/Y'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('5/3/2014', 'd/m/Y'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('5/3/14', 'd/m/y'))); - $this->assertEquals(0, $t->getValidDate('5/3/14', 'd/m/Y')); - $this->assertEquals(0, $t->getValidDate('5-3-2014', 'd/m/Y')); - - $this->assertEquals('2014-03-05', date('Y-m-d', $t->parseDate('2014-03-05'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $t->parseDate('2014_03_05'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $t->parseDate('03/05/2014'))); - } - - public function testDuplicateTask() - { - $t = new Task($this->db, $this->event); - $p = new Project($this->db, $this->event); - - // We create a task and a project - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2))); - - $task = $t->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['position']); - - // We duplicate our task - $this->assertEquals(2, $t->duplicate(1)); - $this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE)); - - // Check the values of the duplicated task - $task = $t->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(Task::STATUS_OPEN, $task['is_active']); - $this->assertEquals(1, $task['project_id']); - $this->assertEquals(1, $task['owner_id']); - $this->assertEquals(1, $task['position']); - $this->assertEquals(2, $task['category_id']); - } - - public function testDuplicateToAnotherProject() - { - $t = new Task($this->db, $this->event); - $p = new Project($this->db, $this->event); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(2, $p->create(array('name' => 'test2'))); - - // We create a task - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1, 'category_id' => 1))); - - // We duplicate our task to the 2nd project - $this->assertEquals(2, $t->duplicateToAnotherProject(1, 2)); - $this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE)); - - // Check the values of the duplicated task - $task = $t->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals(0, $task['category_id']); - $this->assertEquals(2, $task['project_id']); - $this->assertEquals('test', $task['title']); - } - - public function testEvents() - { - $t = new Task($this->db, $this->event); - $p = new Project($this->db, $this->event); - - // We create a project - $this->assertEquals(1, $p->create(array('name' => 'test'))); - - // We create task - $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - $this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE)); - - // We update a task - $this->assertTrue($t->update(array('title' => 'test2', 'id' => 1))); - $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->assertTrue($this->event->isEventTriggered(Task::EVENT_CLOSE)); - - // We open our task - $this->assertTrue($t->open(1)); - $this->assertTrue($this->event->isEventTriggered(Task::EVENT_OPEN)); - - // We change the column of our task - $this->assertTrue($t->move(1, 2, 1)); - $this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_COLUMN)); - - // We change the position of our task - $this->assertTrue($t->move(1, 2, 2)); - $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->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_COLUMN)); - } -} diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php new file mode 100644 index 00000000..89d525a2 --- /dev/null +++ b/tests/functionals/ApiTest.php @@ -0,0 +1,417 @@ +client = new JsonRPC\Client(self::URL, 5, true); + $this->client->authentication('jsonrpc', self::KEY); + + $pdo = new PDO('sqlite:data/db.sqlite'); + $pdo->exec('UPDATE config SET api_token="'.self::KEY.'"'); + } + + public function testRemoveAll() + { + $projects = $this->client->getAllProjects(); + + if ($projects) { + foreach ($projects as $project) { + $this->client->removeProject($project['id']); + } + } + } + + public function testCreateProject() + { + $this->assertTrue($this->client->createProject('API test')); + } + + public function testGetProjectById() + { + $project = $this->client->getProjectById(1); + $this->assertNotEmpty($project); + $this->assertEquals(1, $project['id']); + } + + public function testUpdateProject() + { + $project = $this->client->getProjectById(1); + $this->assertNotEmpty($project); + $this->assertTrue($this->client->updateProject(array('id' => 1, 'name' => 'API test 2', 'is_active' => 0))); + + $project = $this->client->getProjectById(1); + $this->assertEquals('API test 2', $project['name']); + $this->assertEquals(0, $project['is_active']); + + $this->assertTrue($this->client->updateProject(array('id' => 1, 'name' => 'API test', 'is_active' => 1))); + + $project = $this->client->getProjectById(1); + $this->assertEquals('API test', $project['name']); + $this->assertEquals(1, $project['is_active']); + } + + public function testGetBoard() + { + $board = $this->client->getBoard(1); + $this->assertTrue(is_array($board)); + $this->assertEquals(4, count($board)); + } + + public function testGetColumns() + { + $columns = $this->client->getColumns(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals(4, count($columns)); + $this->assertEquals('Done', $columns[3]['title']); + } + + public function testMoveColumnUp() + { + $this->assertTrue($this->client->moveColumnUp(1, 4)); + + $columns = $this->client->getColumns(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals('Done', $columns[2]['title']); + $this->assertEquals('Work in progress', $columns[3]['title']); + } + + public function testMoveColumnDown() + { + $this->assertTrue($this->client->moveColumnDown(1, 4)); + + $columns = $this->client->getColumns(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals('Work in progress', $columns[2]['title']); + $this->assertEquals('Done', $columns[3]['title']); + } + + public function testUpdateColumn() + { + $this->assertTrue($this->client->updateColumn(4, array('title' => 'Boo', 'task_limit' => 2))); + + $columns = $this->client->getColumns(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals('Boo', $columns[3]['title']); + $this->assertEquals(2, $columns[3]['task_limit']); + } + + public function testAddColumn() + { + $this->assertTrue($this->client->addColumn(1, array('title' => 'New column'))); + + $columns = $this->client->getColumns(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals(5, count($columns)); + $this->assertEquals('New column', $columns[4]['title']); + } + + public function testRemoveColumn() + { + $this->assertTrue($this->client->removeColumn(5)); + + $columns = $this->client->getColumns(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals(4, count($columns)); + } + + public function testCreateTask() + { + $task = array( + 'title' => 'Task #1', + 'color_id' => 'blue', + 'owner_id' => 1, + 'project_id' => 1, + 'column_id' => 2, + ); + + $this->assertTrue($this->client->createTask($task)); + + $task = array( + 'title' => 'Task #1', + 'color_id' => 'blue', + 'owner_id' => 1, + ); + + $this->assertFalse($this->client->createTask($task)); + } + + public function testGetTask() + { + $task = $this->client->getTask(1); + + $this->assertNotFalse($task); + $this->assertTrue(is_array($task)); + $this->assertEquals('Task #1', $task['title']); + } + + public function testGetAllTasks() + { + $tasks = $this->client->getAllTasks(1, array(1)); + + $this->assertNotFalse($tasks); + $this->assertTrue(is_array($tasks)); + $this->assertEquals('Task #1', $tasks[0]['title']); + + $tasks = $this->client->getAllTasks(2, array(1, 2)); + + $this->assertNotFalse($tasks); + $this->assertTrue(is_array($tasks)); + $this->assertEmpty($tasks); + } + + public function testUpdateTask() + { + $task = $this->client->getTask(1); + $task['color_id'] = 'green'; + $task['column_id'] = 1; + $task['description'] = 'test'; + + $this->assertTrue($this->client->updateTask($task)); + } + + public function testRemoveTask() + { + $this->assertTrue($this->client->removeTask(1)); + } + + public function testRemoveUsers() + { + $users = $this->client->getAllUsers(); + $this->assertNotFalse($users); + $this->assertNotEmpty($users); + + foreach ($users as $user) { + if ($user['id'] > 1) { + $this->assertTrue($this->client->removeUser($user['id'])); + } + } + } + + public function testCreateUser() + { + $user = array( + 'username' => 'toto', + 'name' => 'Toto', + 'password' => '123456', + 'confirmation' => '123456', + ); + + $this->assertTrue($this->client->createUser($user)); + + $user = array( + 'username' => 'titi', + 'name' => 'Titi', + 'password' => '123456', + 'confirmation' => '789', + ); + + $this->assertFalse($this->client->createUser($user)); + } + + public function testGetUser() + { + $user = $this->client->getUser(2); + + $this->assertNotFalse($user); + $this->assertTrue(is_array($user)); + $this->assertEquals('toto', $user['username']); + } + + public function testUpdateUser() + { + $user = $this->client->getUser(2); + $user['username'] = 'titi'; + $user['name'] = 'Titi'; + unset($user['password']); + + $this->assertTrue($this->client->updateUser($user)); + + $user = $this->client->getUser(2); + + $this->assertNotFalse($user); + $this->assertTrue(is_array($user)); + $this->assertEquals('titi', $user['username']); + $this->assertEquals('Titi', $user['name']); + } + + public function testGetAllowedUsers() + { + $users = $this->client->getAllowedUsers(1); + $this->assertNotFalse($users); + $this->assertEquals(array(1 => 'admin', 2 => 'titi'), $users); + } + + public function testAllowedUser() + { + $this->assertTrue($this->client->allowUser(1, 2)); + + $users = $this->client->getAllowedUsers(1); + $this->assertNotFalse($users); + $this->assertEquals(array(2 => 'titi'), $users); + } + + public function testRevokeUser() + { + $this->assertTrue($this->client->revokeUser(1, 2)); + + $users = $this->client->getAllowedUsers(1); + $this->assertNotFalse($users); + $this->assertEquals(array(1 => 'admin', 2 => 'titi'), $users); + } + + public function testCreateComment() + { + $task = array( + 'title' => 'Task with comment', + 'color_id' => 'red', + 'owner_id' => 1, + 'project_id' => 1, + 'column_id' => 1, + ); + + $this->assertTrue($this->client->createTask($task)); + + $comment = array( + 'task_id' => 1, + 'user_id' => 2, + 'comment' => 'boo', + ); + + $this->assertTrue($this->client->createComment($comment)); + } + + public function testGetComment() + { + $comment = $this->client->getComment(1); + $this->assertNotFalse($comment); + $this->assertNotEmpty($comment); + $this->assertEquals(1, $comment['task_id']); + $this->assertEquals(2, $comment['user_id']); + $this->assertEquals('boo', $comment['comment']); + } + + public function testUpdateComment() + { + $comment = $this->client->getComment(1); + $comment['comment'] = 'test'; + + $this->assertTrue($this->client->updateComment($comment)); + + $comment = $this->client->getComment(1); + $this->assertEquals('test', $comment['comment']); + } + + public function testGetAllComments() + { + $comment = array( + 'task_id' => 1, + 'user_id' => 1, + 'comment' => 'blabla', + ); + + $this->assertTrue($this->client->createComment($comment)); + + $comments = $this->client->getAllComments(1); + $this->assertNotFalse($comments); + $this->assertNotEmpty($comments); + $this->assertTrue(is_array($comments)); + $this->assertEquals(2, count($comments)); + } + + public function testRemoveComment() + { + $this->assertTrue($this->client->removeComment(1)); + + $comments = $this->client->getAllComments(1); + $this->assertNotFalse($comments); + $this->assertNotEmpty($comments); + $this->assertTrue(is_array($comments)); + $this->assertEquals(1, count($comments)); + } + + public function testCreateSubtask() + { + $subtask = array( + 'task_id' => 1, + 'title' => 'subtask #1', + ); + + $this->assertTrue($this->client->createSubtask($subtask)); + } + + public function testGetSubtask() + { + $subtask = $this->client->getSubtask(1); + $this->assertNotFalse($subtask); + $this->assertNotEmpty($subtask); + $this->assertEquals(1, $subtask['task_id']); + $this->assertEquals(0, $subtask['user_id']); + $this->assertEquals('subtask #1', $subtask['title']); + } + + public function testUpdateSubtask() + { + $subtask = $this->client->getSubtask(1); + $subtask['title'] = 'test'; + + $this->assertTrue($this->client->updateSubtask($subtask)); + + $subtask = $this->client->getSubtask(1); + $this->assertEquals('test', $subtask['title']); + } + + public function testGetAllSubtasks() + { + $subtask = array( + 'task_id' => 1, + 'user_id' => 2, + 'title' => 'Subtask #2', + ); + + $this->assertTrue($this->client->createSubtask($subtask)); + + $subtasks = $this->client->getAllSubtasks(1); + $this->assertNotFalse($subtasks); + $this->assertNotEmpty($subtasks); + $this->assertTrue(is_array($subtasks)); + $this->assertEquals(2, count($subtasks)); + } + + public function testRemoveSubtask() + { + $this->assertTrue($this->client->removeSubtask(1)); + + $subtasks = $this->client->getAllSubtasks(1); + $this->assertNotFalse($subtasks); + $this->assertNotEmpty($subtasks); + $this->assertTrue(is_array($subtasks)); + $this->assertEquals(1, count($subtasks)); + } +/* + public function testAutomaticActions() + { + $task = array( + 'title' => 'Task #1', + 'color_id' => 'blue', + 'owner_id' => 0, + 'project_id' => 1, + 'column_id' => 1, + ); + + $this->assertTrue($this->client->createTask($task)); + + $tasks = $this->client->getAllTasks(1, array(1)); + $task = $tasks[count($tasks) - 1]; + $task['column_id'] = 3; + + $this->assertTrue($this->client->updateTask($task)); + }*/ +} diff --git a/tests/units/AclTest.php b/tests/units/AclTest.php new file mode 100644 index 00000000..a2c1c111 --- /dev/null +++ b/tests/units/AclTest.php @@ -0,0 +1,112 @@ + array('action1', 'action3'), + ); + + $acl = new Acl($this->db, $this->event); + $this->assertTrue($acl->isAllowedAction($acl_rules, 'controller1', 'action1')); + $this->assertTrue($acl->isAllowedAction($acl_rules, 'controller1', 'action3')); + $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller1', 'action2')); + $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller2', 'action2')); + $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller2', 'action3')); + } + + public function testIsAdmin() + { + $acl = new Acl($this->db, $this->event); + + $_SESSION = array(); + $this->assertFalse($acl->isAdminUser()); + + $_SESSION = array('user' => array()); + $this->assertFalse($acl->isAdminUser()); + + $_SESSION = array('user' => array('is_admin' => '1')); + $this->assertFalse($acl->isAdminUser()); + + $_SESSION = array('user' => array('is_admin' => false)); + $this->assertFalse($acl->isAdminUser()); + + $_SESSION = array('user' => array('is_admin' => '2')); + $this->assertFalse($acl->isAdminUser()); + + $_SESSION = array('user' => array('is_admin' => true)); + $this->assertTrue($acl->isAdminUser()); + } + + public function testIsUser() + { + $acl = new Acl($this->db, $this->event); + + $_SESSION = array(); + $this->assertFalse($acl->isRegularUser()); + + $_SESSION = array('user' => array()); + $this->assertFalse($acl->isRegularUser()); + + $_SESSION = array('user' => array('is_admin' => true)); + $this->assertFalse($acl->isRegularUser()); + + $_SESSION = array('user' => array('is_admin' => true)); + $this->assertFalse($acl->isRegularUser()); + + $_SESSION = array('user' => array('is_admin' => '2')); + $this->assertFalse($acl->isRegularUser()); + + $_SESSION = array('user' => array('is_admin' => false)); + $this->assertTrue($acl->isRegularUser()); + } + + public function testIsPageAllowed() + { + $acl = new Acl($this->db, $this->event); + + // Public access + $_SESSION = array(); + $this->assertFalse($acl->isPageAccessAllowed('user', 'create')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'save')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'remove')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'confirm')); + $this->assertFalse($acl->isPageAccessAllowed('app', 'index')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'index')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'login')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'check')); + $this->assertTrue($acl->isPageAccessAllowed('task', 'add')); + $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly')); + + // Regular user + $_SESSION = array('user' => array('is_admin' => false)); + $this->assertFalse($acl->isPageAccessAllowed('user', 'create')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'save')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'remove')); + $this->assertFalse($acl->isPageAccessAllowed('user', 'confirm')); + $this->assertTrue($acl->isPageAccessAllowed('app', 'index')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'index')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'login')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'check')); + $this->assertTrue($acl->isPageAccessAllowed('task', 'add')); + $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly')); + + // Admin user + $_SESSION = array('user' => array('is_admin' => true)); + $this->assertTrue($acl->isPageAccessAllowed('user', 'create')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'save')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'remove')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'confirm')); + $this->assertTrue($acl->isPageAccessAllowed('app', 'index')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'index')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'login')); + $this->assertTrue($acl->isPageAccessAllowed('user', 'check')); + $this->assertTrue($acl->isPageAccessAllowed('task', 'add')); + $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly')); + } +} diff --git a/tests/units/ActionTaskAssignColorCategoryTest.php b/tests/units/ActionTaskAssignColorCategoryTest.php new file mode 100644 index 00000000..18b4311e --- /dev/null +++ b/tests/units/ActionTaskAssignColorCategoryTest.php @@ -0,0 +1,76 @@ +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/units/ActionTaskAssignColorUserTest.php b/tests/units/ActionTaskAssignColorUserTest.php new file mode 100644 index 00000000..04e3172f --- /dev/null +++ b/tests/units/ActionTaskAssignColorUserTest.php @@ -0,0 +1,70 @@ +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\TaskAssignColorUser(1, new Task($this->db, $this->event)); + $action->setParam('user_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); + $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 + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + 'owner_id' => 5, + ); + + // Our event should NOT be executed + $this->assertFalse($action->execute($event)); + + // Our task should be assigned to nobody and have the green color + $task = $t->getById(1); + $this->assertNotEmpty($task); + $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 + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + 'owner_id' => 1, + ); + + // Our event should be executed + $this->assertTrue($action->execute($event)); + + // Our task should be assigned to nobody and have the blue color + $task = $t->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals('blue', $task['color_id']); + } +} diff --git a/tests/units/ActionTaskAssignCurrentUserTest.php b/tests/units/ActionTaskAssignCurrentUserTest.php new file mode 100644 index 00000000..0780b603 --- /dev/null +++ b/tests/units/ActionTaskAssignCurrentUserTest.php @@ -0,0 +1,73 @@ +db, $this->event), new Acl($this->db, $this->event)); + $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($event)); + } + + public function testBadColumn() + { + $action = new Action\TaskAssignCurrentUser(3, new Task($this->db, $this->event), new Acl($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\TaskAssignCurrentUser(1, new Task($this->db, $this->event), new Acl($this->db, $this->event)); + $action->setParam('column_id', 2); + $_SESSION = array( + 'user' => array('id' => 5) + ); + + // We create a task in the first column + $t = new Task($this->db, $this->event); + $p = new Project($this->db, $this->event); + $a = new Acl($this->db, $this->event); + + $this->assertEquals(5, $a->getUserId()); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $t->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($event)); + + // Our task should be assigned to the user 5 (from the session) + $task = $t->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['id']); + $this->assertEquals(5, $task['owner_id']); + } +} diff --git a/tests/units/ActionTaskAssignSpecificUserTest.php b/tests/units/ActionTaskAssignSpecificUserTest.php new file mode 100644 index 00000000..3a919978 --- /dev/null +++ b/tests/units/ActionTaskAssignSpecificUserTest.php @@ -0,0 +1,66 @@ +db, $this->event)); + $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($event)); + } + + public function testBadColumn() + { + $action = new Action\TaskAssignSpecificUser(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\TaskAssignSpecificUser(1, new Task($this->db, $this->event)); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); + + // We create a task in the first column + $t = new Task($this->db, $this->event); + $p = new Project($this->db, $this->event); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $t->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($event)); + + // Our task should be assigned to the user 1 + $task = $t->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['owner_id']); + } +} diff --git a/tests/units/ActionTaskCloseTest.php b/tests/units/ActionTaskCloseTest.php new file mode 100644 index 00000000..0c864f42 --- /dev/null +++ b/tests/units/ActionTaskCloseTest.php @@ -0,0 +1,65 @@ +db, $this->event)); + $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($event)); + } + + public function testBadColumn() + { + $action = new Action\TaskClose(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\TaskClose(1, new Task($this->db, $this->event)); + $action->setParam('column_id', 2); + + // We create a task in the first column + $t = new Task($this->db, $this->event); + $p = new Project($this->db, $this->event); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $t->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($event)); + + // Our task should be closed + $task = $t->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['is_active']); + } +} diff --git a/tests/units/ActionTaskDuplicateAnotherProjectTest.php b/tests/units/ActionTaskDuplicateAnotherProjectTest.php new file mode 100644 index 00000000..0b2e4bd5 --- /dev/null +++ b/tests/units/ActionTaskDuplicateAnotherProjectTest.php @@ -0,0 +1,89 @@ +db, $this->event)); + $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($event)); + } + + public function testBadColumn() + { + $action = new Action\TaskDuplicateAnotherProject(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\TaskDuplicateAnotherProject(1, new Task($this->db, $this->event)); + + // We create a task in the first column + $t = new Task($this->db, $this->event); + $p = new Project($this->db, $this->event); + $this->assertEquals(1, $p->create(array('name' => 'project 1'))); + $this->assertEquals(2, $p->create(array('name' => 'project 2'))); + $this->assertEquals(1, $t->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($event)); + + // Our task should be assigned to the project 1 + $task = $t->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($event)); + + // Our task should be assigned to the project 1 + $task = $t->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['project_id']); + + // We should have another task assigned to the project 2 + $task = $t->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + } +} diff --git a/tests/units/ActionTest.php b/tests/units/ActionTest.php new file mode 100644 index 00000000..2eb12784 --- /dev/null +++ b/tests/units/ActionTest.php @@ -0,0 +1,244 @@ +db, $this->event); + $board = new Board($this->db, $this->event); + $project = new Project($this->db, $this->event); + + $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, + 'event_name' => Task::EVENT_MOVE_COLUMN, + 'action_name' => 'TaskClose', + 'params' => array( + 'column_id' => 4, + ) + ))); + + // 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() + { + $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 + $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 + $action->attachEvents(); + + // Our task should be open + $t1 = $task->getById(1); + $this->assertEquals(1, $t1['is_active']); + $this->assertEquals(1, $t1['column_id']); + + // 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); + $board = new Board($this->db, $this->event); + $project = new Project($this->db, $this->event); + $action = new Action($this->db, $this->event); + + // 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 task + $this->assertEquals(1, $task->create(array( + 'title' => 'unit_test', + 'project_id' => 1, + 'owner_id' => 1, + 'color_id' => 'red', + 'column_id' => 1, + ))); + + // We create 2 actions + $this->assertTrue($action->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CLOSE, + 'action_name' => 'TaskDuplicateAnotherProject', + 'params' => array( + 'column_id' => 4, + 'project_id' => 2, + ) + ))); + + $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 + $action->attachEvents(); + + // Events should be attached + $this->assertTrue($this->event->hasListener(Task::EVENT_CLOSE, 'Action\TaskDuplicateAnotherProject')); + $this->assertTrue($this->event->hasListener(Task::EVENT_MOVE_COLUMN, 'Action\TaskClose')); + + // Our task should be open, linked to the first project and in the first column + $t1 = $task->getById(1); + $this->assertEquals(1, $t1['is_active']); + $this->assertEquals(1, $t1['column_id']); + $this->assertEquals(1, $t1['project_id']); + + // We move our task + $task->move(1, 4, 1); + + $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); + $this->assertEquals(4, $t1['column_id']); + $this->assertEquals(0, $t1['is_active']); + + // Our task should be duplicated to the 2nd project + $t2 = $task->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']); + } +} diff --git a/tests/units/Base.php b/tests/units/Base.php new file mode 100644 index 00000000..1f8109ed --- /dev/null +++ b/tests/units/Base.php @@ -0,0 +1,57 @@ +db = $this->getDbConnection(); + $this->event = new \Core\Event; + } + + public function getDbConnection() + { + $db = new \PicoDb\Database(array( + 'driver' => 'sqlite', + 'filename' => ':memory:' + )); + + if ($db->schema()->check(\Schema\VERSION)) { + return $db; + } + else { + die('Unable to migrate database schema!'); + } + } +} diff --git a/tests/units/BoardTest.php b/tests/units/BoardTest.php new file mode 100644 index 00000000..d5686b3f --- /dev/null +++ b/tests/units/BoardTest.php @@ -0,0 +1,77 @@ +db, $this->event); + $b = new Board($this->db, $this->event); + + // We create 2 projects + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); + $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); + + // We get the columns of the project 2 + $columns = $b->getColumns(2); + $columns_id = array_keys($b->getColumnsList(2)); + $this->assertNotEmpty($columns); + + // Initial order: 5, 6, 7, 8 + + // Move the column 1 down + $this->assertEquals(1, $columns[0]['position']); + $this->assertEquals($columns_id[0], $columns[0]['id']); + + $this->assertEquals(2, $columns[1]['position']); + $this->assertEquals($columns_id[1], $columns[1]['id']); + + $this->assertTrue($b->moveDown(2, $columns[0]['id'])); + $columns = $b->getColumns(2); // Sorted by position + + // New order: 6, 5, 7, 8 + + $this->assertEquals(1, $columns[0]['position']); + $this->assertEquals($columns_id[1], $columns[0]['id']); + + $this->assertEquals(2, $columns[1]['position']); + $this->assertEquals($columns_id[0], $columns[1]['id']); + + // Move the column 3 up + $this->assertTrue($b->moveUp(2, $columns[2]['id'])); + $columns = $b->getColumns(2); + + // New order: 6, 7, 5, 8 + + $this->assertEquals(1, $columns[0]['position']); + $this->assertEquals($columns_id[1], $columns[0]['id']); + + $this->assertEquals(2, $columns[1]['position']); + $this->assertEquals($columns_id[2], $columns[1]['id']); + + $this->assertEquals(3, $columns[2]['position']); + $this->assertEquals($columns_id[0], $columns[2]['id']); + + // Move column 1 up (must do nothing because it's the first column) + $this->assertFalse($b->moveUp(2, $columns[0]['id'])); + $columns = $b->getColumns(2); + + // Order: 6, 7, 5, 8 + + $this->assertEquals(1, $columns[0]['position']); + $this->assertEquals($columns_id[1], $columns[0]['id']); + + // Move column 4 down (must do nothing because it's the last column) + $this->assertFalse($b->moveDown(2, $columns[3]['id'])); + $columns = $b->getColumns(2); + + // Order: 6, 7, 5, 8 + + $this->assertEquals(4, $columns[3]['position']); + $this->assertEquals($columns_id[3], $columns[3]['id']); + } +} diff --git a/tests/units/CommentTest.php b/tests/units/CommentTest.php new file mode 100644 index 00000000..46f05abc --- /dev/null +++ b/tests/units/CommentTest.php @@ -0,0 +1,116 @@ +db, $this->event); + $t = new Task($this->db, $this->event); + $p = new Project($this->db, $this->event); + + $this->assertEquals(1, $p->create(array('name' => 'test1'))); + $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1))); + + $comment = $c->getById(1); + + $this->assertNotEmpty($comment); + $this->assertEquals('bla bla', $comment['comment']); + $this->assertEquals(1, $comment['task_id']); + $this->assertEquals(1, $comment['user_id']); + $this->assertEquals('admin', $comment['username']); + $this->assertNotEmpty($comment['date']); + } + + public function testGetAll() + { + $c = new Comment($this->db, $this->event); + $t = new Task($this->db, $this->event); + $p = new Project($this->db, $this->event); + + $this->assertEquals(1, $p->create(array('name' => 'test1'))); + $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1))); + $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1))); + $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1))); + + $comments = $c->getAll(1); + + $this->assertNotEmpty($comments); + $this->assertEquals(3, count($comments)); + $this->assertEquals(1, $comments[0]['id']); + $this->assertEquals(2, $comments[1]['id']); + $this->assertEquals(3, $comments[2]['id']); + } + + public function testUpdate() + { + $c = new Comment($this->db, $this->event); + $t = new Task($this->db, $this->event); + $p = new Project($this->db, $this->event); + + $this->assertEquals(1, $p->create(array('name' => 'test1'))); + $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); + $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1))); + $this->assertTrue($c->update(array('id' => 1, 'comment' => 'bla'))); + + $comment = $c->getById(1); + $this->assertNotEmpty($comment); + $this->assertEquals('bla', $comment['comment']); + } + + public function testValidateCreation() + { + $c = new Comment($this->db, $this->event); + + $result = $c->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla')); + $this->assertTrue($result[0]); + + $result = $c->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => '')); + $this->assertFalse($result[0]); + + $result = $c->validateCreation(array('user_id' => 1, 'task_id' => 'a', 'comment' => 'bla')); + $this->assertFalse($result[0]); + + $result = $c->validateCreation(array('user_id' => 'b', 'task_id' => 1, 'comment' => 'bla')); + $this->assertFalse($result[0]); + + $result = $c->validateCreation(array('user_id' => 1, 'comment' => 'bla')); + $this->assertFalse($result[0]); + + $result = $c->validateCreation(array('task_id' => 1, 'comment' => 'bla')); + $this->assertFalse($result[0]); + + $result = $c->validateCreation(array('comment' => 'bla')); + $this->assertFalse($result[0]); + + $result = $c->validateCreation(array()); + $this->assertFalse($result[0]); + } + + public function testValidateModification() + { + $c = new Comment($this->db, $this->event); + + $result = $c->validateModification(array('id' => 1, 'comment' => 'bla')); + $this->assertTrue($result[0]); + + $result = $c->validateModification(array('id' => 1, 'comment' => '')); + $this->assertFalse($result[0]); + + $result = $c->validateModification(array('comment' => 'bla')); + $this->assertFalse($result[0]); + + $result = $c->validateModification(array('id' => 'b', 'comment' => 'bla')); + $this->assertFalse($result[0]); + + $result = $c->validateModification(array()); + $this->assertFalse($result[0]); + } +} diff --git a/tests/units/ProjectTest.php b/tests/units/ProjectTest.php new file mode 100644 index 00000000..5ca8177c --- /dev/null +++ b/tests/units/ProjectTest.php @@ -0,0 +1,162 @@ +db, $this->event); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + $this->assertNotEmpty($p->getById(1)); + } + + public function testAllowEverybody() + { + // We create a regular user + $user = new User($this->db, $this->event); + $user->create(array('username' => 'unittest', 'password' => 'unittest')); + + $p = new Project($this->db, $this->event); + $this->assertEmpty($p->getAllowedUsers(1)); // Nobody is specified for the given project + $this->assertTrue($p->isUserAllowed(1, 1)); // Everybody should be allowed + $this->assertTrue($p->isUserAllowed(1, 2)); // Everybody should be allowed + } + + public function testAllowUser() + { + $p = new Project($this->db, $this->event); + $user = new User($this->db, $this->event); + $user->create(array('username' => 'unittest', 'password' => 'unittest')); + + // We create a project + $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + + // We allow the admin user + $this->assertTrue($p->allowUser(1, 1)); + + // Non-existant project + $this->assertFalse($p->allowUser(50, 1)); + + // Non-existant user + $this->assertFalse($p->allowUser(1, 50)); + + // Our admin user should be allowed + $this->assertEquals(array('1' => 'admin'), $p->getAllowedUsers(1)); + $this->assertTrue($p->isUserAllowed(1, 1)); + + // Our regular user should be forbidden + $this->assertFalse($p->isUserAllowed(1, 2)); + } + + public function testRevokeUser() + { + $p = new Project($this->db, $this->event); + + $user = new User($this->db, $this->event); + $user->create(array('username' => 'unittest', 'password' => 'unittest')); + + // We create a project + $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + + // We revoke our admin user + $this->assertTrue($p->revokeUser(1, 1)); + + // We should have nobody in the users list + $this->assertEmpty($p->getAllowedUsers(1)); + + // Our admin user and our regular user should be allowed + $this->assertTrue($p->isUserAllowed(1, 1)); + $this->assertTrue($p->isUserAllowed(1, 2)); + + // We allow only the regular user + $this->assertTrue($p->allowUser(1, 2)); + + // All users should be allowed (admin and regular) + $this->assertTrue($p->isUserAllowed(1, 1)); + $this->assertTrue($p->isUserAllowed(1, 2)); + + // However, we should have only our regular user in the list + $this->assertEquals(array('2' => 'unittest'), $p->getAllowedUsers(1)); + + // We allow our admin, we should have both in the list + $this->assertTrue($p->allowUser(1, 1)); + $this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $p->getAllowedUsers(1)); + $this->assertTrue($p->isUserAllowed(1, 1)); + $this->assertTrue($p->isUserAllowed(1, 2)); + + // We revoke the regular user + $this->assertTrue($p->revokeUser(1, 2)); + + // Only admin should be allowed + $this->assertTrue($p->isUserAllowed(1, 1)); + $this->assertFalse($p->isUserAllowed(1, 2)); + + // We should have only admin in the list + $this->assertEquals(array('1' => 'admin'), $p->getAllowedUsers(1)); + + // We revoke the admin user + $this->assertTrue($p->revokeUser(1, 1)); + $this->assertEmpty($p->getAllowedUsers(1)); + + // Everybody should be allowed again + $this->assertTrue($p->isUserAllowed(1, 1)); + $this->assertTrue($p->isUserAllowed(1, 2)); + } + + public function testUsersList() + { + $p = new Project($this->db, $this->event); + + $user = new User($this->db, $this->event); + $user->create(array('username' => 'unittest', 'password' => 'unittest')); + + // We create project + $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + + // No restriction, we should have everybody + $this->assertEquals( + array('Unassigned', 'admin', 'unittest'), + $p->getUsersList(1) + ); + + // We allow only the regular user + $this->assertTrue($p->allowUser(1, 2)); + + $this->assertEquals( + array(0 => 'Unassigned', 2 => 'unittest'), + $p->getUsersList(1) + ); + + // We allow the admin user + $this->assertTrue($p->allowUser(1, 1)); + + $this->assertEquals( + array(0 => 'Unassigned', 1 => 'admin', 2 => 'unittest'), + $p->getUsersList(1) + ); + + // We revoke only the regular user + $this->assertTrue($p->revokeUser(1, 2)); + + $this->assertEquals( + array(0 => 'Unassigned', 1 => 'admin'), + $p->getUsersList(1) + ); + + // We revoke only the admin user, we should have everybody + $this->assertTrue($p->revokeUser(1, 1)); + + $this->assertEquals( + array(0 => 'Unassigned', 1 => 'admin', 2 => 'unittest'), + $p->getUsersList(1) + ); + } +} diff --git a/tests/units/TaskTest.php b/tests/units/TaskTest.php new file mode 100644 index 00000000..da7e6a70 --- /dev/null +++ b/tests/units/TaskTest.php @@ -0,0 +1,187 @@ +db, $this->event); + $p = new Project($this->db, $this->event); + + $this->assertEquals(1, $p->create(array('name' => 'test1'))); + $this->assertEquals(1, $t->create(array('title' => 'test a', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'description' => 'biloute'))); + $this->assertEquals(2, $t->create(array('title' => 'test b', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2, 'description' => 'toto et titi sont dans un bateau'))); + + $tasks = $t->find(array(array('column' => 'project_id', 'operator' => 'eq', 'value' => '1'))); + $this->assertNotFalse($tasks); + $this->assertEquals(2, count($tasks)); + $this->assertEquals(1, $tasks[0]['id']); + $this->assertEquals(2, $tasks[1]['id']); + + $tasks = $t->find(array( + array('column' => 'project_id', 'operator' => 'eq', 'value' => '1'), + array('column' => 'owner_id', 'operator' => 'eq', 'value' => '2'), + )); + $this->assertEquals(1, count($tasks)); + $this->assertEquals(2, $tasks[0]['id']); + + $tasks = $t->find(array( + array('column' => 'project_id', 'operator' => 'eq', 'value' => '1'), + array('column' => 'title', 'operator' => 'like', 'value' => '%b%'), + )); + $this->assertEquals(1, count($tasks)); + $this->assertEquals(2, $tasks[0]['id']); + + // Condition with OR + $search = 'bateau'; + $filters = array( + array('column' => 'project_id', 'operator' => 'eq', 'value' => 1), + 'or' => array( + array('column' => 'title', 'operator' => 'like', 'value' => '%'.$search.'%'), + array('column' => 'description', 'operator' => 'like', 'value' => '%'.$search.'%'), + ) + ); + + $tasks = $t->find($filters); + $this->assertEquals(1, count($tasks)); + $this->assertEquals(2, $tasks[0]['id']); + + $search = 'toto et titi'; + $filters = array( + array('column' => 'project_id', 'operator' => 'eq', 'value' => 1), + 'or' => array( + array('column' => 'title', 'operator' => 'like', 'value' => '%'.$search.'%'), + array('column' => 'description', 'operator' => 'like', 'value' => '%'.$search.'%'), + ) + ); + + $tasks = $t->find($filters); + $this->assertEquals(1, count($tasks)); + $this->assertEquals(2, $tasks[0]['id']); + + $search = 'john'; + $filters = array( + array('column' => 'project_id', 'operator' => 'eq', 'value' => 1), + 'or' => array( + array('column' => 'title', 'operator' => 'like', 'value' => '%'.$search.'%'), + array('column' => 'description', 'operator' => 'like', 'value' => '%'.$search.'%'), + ) + ); + + $tasks = $t->find($filters); + $this->assertEquals(0, count($tasks)); + } + + public function testDateFormat() + { + $t = new Task($this->db, $this->event); + + $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('2014-03-05', 'Y-m-d'))); + $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('2014_03_05', 'Y_m_d'))); + $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('05/03/2014', 'd/m/Y'))); + $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('03/05/2014', 'm/d/Y'))); + $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('3/5/2014', 'm/d/Y'))); + $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('5/3/2014', 'd/m/Y'))); + $this->assertEquals('2014-03-05', date('Y-m-d', $t->getValidDate('5/3/14', 'd/m/y'))); + $this->assertEquals(0, $t->getValidDate('5/3/14', 'd/m/Y')); + $this->assertEquals(0, $t->getValidDate('5-3-2014', 'd/m/Y')); + + $this->assertEquals('2014-03-05', date('Y-m-d', $t->parseDate('2014-03-05'))); + $this->assertEquals('2014-03-05', date('Y-m-d', $t->parseDate('2014_03_05'))); + $this->assertEquals('2014-03-05', date('Y-m-d', $t->parseDate('03/05/2014'))); + } + + public function testDuplicateTask() + { + $t = new Task($this->db, $this->event); + $p = new Project($this->db, $this->event); + + // We create a task and a project + $this->assertEquals(1, $p->create(array('name' => 'test1'))); + $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1, 'category_id' => 2))); + + $task = $t->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['position']); + + // We duplicate our task + $this->assertEquals(2, $t->duplicate(1)); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE)); + + // Check the values of the duplicated task + $task = $t->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(Task::STATUS_OPEN, $task['is_active']); + $this->assertEquals(1, $task['project_id']); + $this->assertEquals(1, $task['owner_id']); + $this->assertEquals(1, $task['position']); + $this->assertEquals(2, $task['category_id']); + } + + public function testDuplicateToAnotherProject() + { + $t = new Task($this->db, $this->event); + $p = new Project($this->db, $this->event); + + // We create 2 projects + $this->assertEquals(1, $p->create(array('name' => 'test1'))); + $this->assertEquals(2, $p->create(array('name' => 'test2'))); + + // We create a task + $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1, 'category_id' => 1))); + + // We duplicate our task to the 2nd project + $this->assertEquals(2, $t->duplicateToAnotherProject(1, 2)); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE)); + + // Check the values of the duplicated task + $task = $t->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals(0, $task['category_id']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals('test', $task['title']); + } + + public function testEvents() + { + $t = new Task($this->db, $this->event); + $p = new Project($this->db, $this->event); + + // We create a project + $this->assertEquals(1, $p->create(array('name' => 'test'))); + + // We create task + $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_CREATE)); + + // We update a task + $this->assertTrue($t->update(array('title' => 'test2', 'id' => 1))); + $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->assertTrue($this->event->isEventTriggered(Task::EVENT_CLOSE)); + + // We open our task + $this->assertTrue($t->open(1)); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_OPEN)); + + // We change the column of our task + $this->assertTrue($t->move(1, 2, 1)); + $this->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_COLUMN)); + + // We change the position of our task + $this->assertTrue($t->move(1, 2, 2)); + $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->assertTrue($this->event->isEventTriggered(Task::EVENT_MOVE_COLUMN)); + } +} -- cgit v1.2.3