diff options
Diffstat (limited to 'tests/units/Action')
-rw-r--r-- | tests/units/Action/CommentCreationTest.php | 124 | ||||
-rw-r--r-- | tests/units/Action/TaskAssignColorCategoryTest.php | 80 | ||||
-rw-r--r-- | tests/units/Action/TaskAssignColorColumnTest.php | 41 | ||||
-rw-r--r-- | tests/units/Action/TaskAssignColorLinkTest.php | 47 | ||||
-rw-r--r-- | tests/units/Action/TaskAssignColorUserTest.php | 72 | ||||
-rw-r--r-- | tests/units/Action/TaskAssignCurrentUserTest.php | 77 | ||||
-rw-r--r-- | tests/units/Action/TaskAssignSpecificUserTest.php | 70 | ||||
-rw-r--r-- | tests/units/Action/TaskCloseTest.php | 108 | ||||
-rw-r--r-- | tests/units/Action/TaskDuplicateAnotherProjectTest.php | 94 | ||||
-rw-r--r-- | tests/units/Action/TaskEmailTest.php | 149 | ||||
-rw-r--r-- | tests/units/Action/TaskMoveAnotherProjectTest.php | 88 | ||||
-rw-r--r-- | tests/units/Action/TaskMoveColumnCategoryChangeTest.php | 61 | ||||
-rw-r--r-- | tests/units/Action/TaskUpdateStartDateTest.php | 45 |
13 files changed, 1056 insertions, 0 deletions
diff --git a/tests/units/Action/CommentCreationTest.php b/tests/units/Action/CommentCreationTest.php new file mode 100644 index 00000000..6b5fe1ea --- /dev/null +++ b/tests/units/Action/CommentCreationTest.php @@ -0,0 +1,124 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Event\GenericEvent; +use Model\Task; +use Model\TaskCreation; +use Model\Comment; +use Model\Project; +use Integration\GithubWebhook; + +class CommentCreationTest extends Base +{ + public function testWithoutRequiredParams() + { + $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $p = new Project($this->container); + $c = new Comment($this->container); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->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, + 'user_id' => 1, + ); + + // Our event should be executed + $this->assertFalse($action->execute(new GenericEvent($event))); + + $comment = $c->getById(1); + $this->assertEmpty($comment); + } + + public function testWithCommitMessage() + { + $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $p = new Project($this->container); + $c = new Comment($this->container); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->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, + 'commit_comment' => 'plop', + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + $comment = $c->getById(1); + $this->assertNotEmpty($comment); + $this->assertEquals(1, $comment['task_id']); + $this->assertEquals(0, $comment['user_id']); + $this->assertEquals('plop', $comment['comment']); + } + + public function testWithUser() + { + $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $p = new Project($this->container); + $c = new Comment($this->container); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->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, + 'user_id' => 1, + 'comment' => 'youpi', + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + $comment = $c->getById(1); + $this->assertNotEmpty($comment); + $this->assertEquals(1, $comment['task_id']); + $this->assertEquals(1, $comment['user_id']); + $this->assertEquals('youpi', $comment['comment']); + } + + public function testWithNoUser() + { + $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $p = new Project($this->container); + $c = new Comment($this->container); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->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, + 'user_id' => 0, + 'comment' => 'youpi', + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + $comment = $c->getById(1); + $this->assertNotEmpty($comment); + $this->assertEquals(1, $comment['task_id']); + $this->assertEquals(0, $comment['user_id']); + $this->assertEquals('youpi', $comment['comment']); + } +} diff --git a/tests/units/Action/TaskAssignColorCategoryTest.php b/tests/units/Action/TaskAssignColorCategoryTest.php new file mode 100644 index 00000000..44d23943 --- /dev/null +++ b/tests/units/Action/TaskAssignColorCategoryTest.php @@ -0,0 +1,80 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; +use Model\Category; +use Event\GenericEvent; + +class TaskAssignColorCategory extends Base +{ + public function testBadProject() + { + $action = new Action\TaskAssignColorCategory($this->container, 3, Task::EVENT_CREATE_UPDATE); + + $event = array( + 'project_id' => 2, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertFalse($action->isExecutable($event)); + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskAssignColorCategory($this->container, 1, Task::EVENT_CREATE_UPDATE); + $action->setParam('category_id', 1); + $action->setParam('color_id', 'blue'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $c = new Category($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $c->create(array('name' => 'c1', 'project_id' => 1))); + $this->assertEquals(2, $c->create(array('name' => 'c2', 'project_id' => 1))); + $this->assertEquals(1, $tc->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(new GenericEvent($event))); + + // Our task should be assigned to the ategory_id=1 and have the green color + $task = $tf->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(new GenericEvent($event))); + + // Our task should have the blue color + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('blue', $task['color_id']); + } +} diff --git a/tests/units/Action/TaskAssignColorColumnTest.php b/tests/units/Action/TaskAssignColorColumnTest.php new file mode 100644 index 00000000..55767327 --- /dev/null +++ b/tests/units/Action/TaskAssignColorColumnTest.php @@ -0,0 +1,41 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Event\GenericEvent; +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; + +class TaskAssignColorColumnTest extends Base +{ + public function testColorChange() + { + $action = new Action\TaskAssignColorColumn($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + $action->setParam('color_id', 'green'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'yellow'))); + + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + 'color_id' => 'green', + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should have color green + $task = $tf->getById(1); + $this->assertEquals('green', $task['color_id']); + } +} diff --git a/tests/units/Action/TaskAssignColorLinkTest.php b/tests/units/Action/TaskAssignColorLinkTest.php new file mode 100644 index 00000000..c78af5bb --- /dev/null +++ b/tests/units/Action/TaskAssignColorLinkTest.php @@ -0,0 +1,47 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Event\TaskLinkEvent; +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\TaskLink; +use Model\Project; + +class TaskAssignColorLinkTest extends Base +{ + public function testExecute() + { + $action = new Action\TaskAssignColorLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE); + $action->setParam('link_id', 2); + $action->setParam('color_id', 'green'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $tl = new TaskLink($this->container); + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); + + // The color should be yellow + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('yellow', $task['color_id']); + + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'link_id' => 2, + ); + + // Our event should be executed + $this->assertTrue($action->execute(new TaskLinkEvent($event))); + + // The color should be green + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('green', $task['color_id']); + } +} diff --git a/tests/units/Action/TaskAssignColorUserTest.php b/tests/units/Action/TaskAssignColorUserTest.php new file mode 100644 index 00000000..896b48fc --- /dev/null +++ b/tests/units/Action/TaskAssignColorUserTest.php @@ -0,0 +1,72 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; +use Event\GenericEvent; + +class TaskAssignColorUser extends Base +{ + public function testBadProject() + { + $action = new Action\TaskAssignColorUser($this->container, 3, Task::EVENT_CREATE); + + $event = array( + 'project_id' => 2, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertFalse($action->isExecutable($event)); + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskAssignColorUser($this->container, 1, Task::EVENT_ASSIGNEE_CHANGE); + $action->setParam('user_id', 1); + $action->setParam('color_id', 'blue'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green'))); + + // We change the assignee + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'owner_id' => 5, + ); + + // Our event should NOT be executed + $this->assertFalse($action->execute(new GenericEvent($event))); + + // Our task should be assigned to nobody and have the green color + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals('green', $task['color_id']); + + // We change the assignee + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'owner_id' => 1, + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should be assigned to nobody and have the blue color + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['owner_id']); + $this->assertEquals('blue', $task['color_id']); + } +} diff --git a/tests/units/Action/TaskAssignCurrentUserTest.php b/tests/units/Action/TaskAssignCurrentUserTest.php new file mode 100644 index 00000000..9ea816d4 --- /dev/null +++ b/tests/units/Action/TaskAssignCurrentUserTest.php @@ -0,0 +1,77 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Event\GenericEvent; +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; +use Model\UserSession; + +class TaskAssignCurrentUser extends Base +{ + public function testBadProject() + { + $action = new Action\TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE); + $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(new GenericEvent($event))); + } + + public function testBadColumn() + { + $action = new Action\TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 3, + ); + + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskAssignCurrentUser($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + $_SESSION = array( + 'user' => array('id' => 5) + ); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $us = new UserSession($this->container); + + $this->assertEquals(5, $us->getId()); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->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(new GenericEvent($event))); + + // Our task should be assigned to the user 5 (from the session) + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['id']); + $this->assertEquals(5, $task['owner_id']); + } +} diff --git a/tests/units/Action/TaskAssignSpecificUserTest.php b/tests/units/Action/TaskAssignSpecificUserTest.php new file mode 100644 index 00000000..ae8de177 --- /dev/null +++ b/tests/units/Action/TaskAssignSpecificUserTest.php @@ -0,0 +1,70 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Event\GenericEvent; +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; + +class TaskAssignSpecificUser extends Base +{ + public function testBadProject() + { + $action = new Action\TaskAssignSpecificUser($this->container, 3, Task::EVENT_MOVE_COLUMN); + $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(new GenericEvent($event))); + } + + public function testBadColumn() + { + $action = new Action\TaskAssignSpecificUser($this->container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 3, + ); + + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskAssignSpecificUser($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->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(new GenericEvent($event))); + + // Our task should be assigned to the user 1 + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['owner_id']); + } +} diff --git a/tests/units/Action/TaskCloseTest.php b/tests/units/Action/TaskCloseTest.php new file mode 100644 index 00000000..8cee6f13 --- /dev/null +++ b/tests/units/Action/TaskCloseTest.php @@ -0,0 +1,108 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Event\GenericEvent; +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; +use Integration\GithubWebhook; + +class TaskCloseTest extends Base +{ + public function testExecutable() + { + $action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertTrue($action->isExecutable($event)); + + $action = new Action\TaskClose($this->container, 3, GithubWebhook::EVENT_COMMIT); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + ); + + $this->assertTrue($action->isExecutable($event)); + } + + public function testBadEvent() + { + $action = new Action\TaskClose($this->container, 3, Task::EVENT_UPDATE); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 5, + ); + + $this->assertFalse($action->isExecutable($event)); + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testBadProject() + { + $action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN); + $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(new GenericEvent($event))); + } + + public function testBadColumn() + { + $action = new Action\TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 3, + ); + + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskClose($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->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(new GenericEvent($event))); + + // Our task should be closed + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['is_active']); + } +} diff --git a/tests/units/Action/TaskDuplicateAnotherProjectTest.php b/tests/units/Action/TaskDuplicateAnotherProjectTest.php new file mode 100644 index 00000000..37eb4052 --- /dev/null +++ b/tests/units/Action/TaskDuplicateAnotherProjectTest.php @@ -0,0 +1,94 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Event\GenericEvent; +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; + +class TaskDuplicateAnotherProject extends Base +{ + public function testBadProject() + { + $action = new Action\TaskDuplicateAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN); + $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(new GenericEvent($event))); + } + + public function testBadColumn() + { + $action = new Action\TaskDuplicateAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 3, + ); + + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskDuplicateAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'project 1'))); + $this->assertEquals(2, $p->create(array('name' => 'project 2'))); + $this->assertEquals(1, $tc->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(new GenericEvent($event))); + + // Our task should be assigned to the project 1 + $task = $tf->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->hasRequiredCondition($event)); + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should be assigned to the project 1 + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['project_id']); + + // We should have another task assigned to the project 2 + $task = $tf->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + } +} diff --git a/tests/units/Action/TaskEmailTest.php b/tests/units/Action/TaskEmailTest.php new file mode 100644 index 00000000..d74e1af2 --- /dev/null +++ b/tests/units/Action/TaskEmailTest.php @@ -0,0 +1,149 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Event\GenericEvent; +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; +use Model\User; + +class TaskEmailTest extends Base +{ + public function testNoEmail() + { + $action = new Action\TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); + $action->setParam('subject', 'My email subject'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $u = new User($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->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, + ); + + // Email should be not be sent + $this->container['emailClient']->expects($this->never())->method('send'); + + // Our event should be executed + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testWrongColumn() + { + $action = new Action\TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); + $action->setParam('subject', 'My email subject'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $u = new User($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->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' => 3, + ); + + // Email should be not be sent + $this->container['emailClient']->expects($this->never())->method('send'); + + // Our event should be executed + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testMoveColumn() + { + $action = new Action\TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); + $action->setParam('subject', 'My email subject'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $u = new User($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost'))); + + // We create an event to move the task to the 2nd column + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + ); + + // Email should be sent + $this->container['emailClient']->expects($this->once()) + ->method('send') + ->with( + $this->equalTo('admin@localhost'), + $this->equalTo('admin'), + $this->equalTo('My email subject'), + $this->stringContains('test') + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + } + + public function testTaskClose() + { + $action = new Action\TaskEmail($this->container, 1, Task::EVENT_CLOSE); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); + $action->setParam('subject', 'My email subject'); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $u = new User($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost'))); + + // We create an event + $event = array( + 'project_id' => 1, + 'task_id' => 1, + 'column_id' => 2, + ); + + // Email should be sent + $this->container['emailClient']->expects($this->once()) + ->method('send') + ->with( + $this->equalTo('admin@localhost'), + $this->equalTo('admin'), + $this->equalTo('My email subject'), + $this->stringContains('test') + ); + + // Our event should be executed + $this->assertTrue($action->execute(new GenericEvent($event))); + } +}
\ No newline at end of file diff --git a/tests/units/Action/TaskMoveAnotherProjectTest.php b/tests/units/Action/TaskMoveAnotherProjectTest.php new file mode 100644 index 00000000..78bc6570 --- /dev/null +++ b/tests/units/Action/TaskMoveAnotherProjectTest.php @@ -0,0 +1,88 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Event\GenericEvent; +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; + +class TaskMoveAnotherProject extends Base +{ + public function testBadProject() + { + $action = new Action\TaskMoveAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN); + $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(new GenericEvent($event))); + } + + public function testBadColumn() + { + $action = new Action\TaskMoveAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 5); + + $event = array( + 'project_id' => 3, + 'task_id' => 3, + 'column_id' => 3, + ); + + $this->assertFalse($action->execute(new GenericEvent($event))); + } + + public function testExecute() + { + $action = new Action\TaskMoveAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'project 1'))); + $this->assertEquals(2, $p->create(array('name' => 'project 2'))); + $this->assertEquals(1, $tc->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(new GenericEvent($event))); + + // Our task should be assigned to the project 1 + $task = $tf->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(new GenericEvent($event))); + + // Our task should be assigned to the project 2 + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['project_id']); + } +} diff --git a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php new file mode 100644 index 00000000..4b7dec68 --- /dev/null +++ b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php @@ -0,0 +1,61 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Event\GenericEvent; +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; +use Model\Category; +use Integration\GithubWebhook; + +class TaskMoveColumnCategoryChangeTest extends Base +{ + public function testExecute() + { + $action = new Action\TaskMoveColumnCategoryChange($this->container, 1, Task::EVENT_UPDATE); + $action->setParam('dest_column_id', 3); + $action->setParam('category_id', 1); + + $this->assertEquals(3, $action->getParam('dest_column_id')); + $this->assertEquals(1, $action->getParam('category_id')); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $c = new Category($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $c->create(array('name' => 'bug', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + + // No category should be assigned + column_id=1 + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEmpty($task['category_id']); + $this->assertEquals(1, $task['column_id']); + + // We create an event to move the task to the 2nd column + $event = array( + 'task_id' => 1, + 'column_id' => 1, + 'project_id' => 1, + 'category_id' => 1, + ); + + // Our event should be executed + $this->assertTrue($action->hasCompatibleEvent()); + $this->assertTrue($action->hasRequiredProject($event)); + $this->assertTrue($action->hasRequiredParameters($event)); + $this->assertTrue($action->hasRequiredCondition($event)); + $this->assertTrue($action->isExecutable($event)); + $this->assertTrue($action->execute(new GenericEvent($event))); + + // Our task should be moved to the other column + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(3, $task['column_id']); + } +} diff --git a/tests/units/Action/TaskUpdateStartDateTest.php b/tests/units/Action/TaskUpdateStartDateTest.php new file mode 100644 index 00000000..14f3b5b7 --- /dev/null +++ b/tests/units/Action/TaskUpdateStartDateTest.php @@ -0,0 +1,45 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Event\GenericEvent; +use Model\Task; +use Model\TaskCreation; +use Model\TaskFinder; +use Model\Project; + +class TaskUpdateStartDateTest extends Base +{ + public function testExecute() + { + $action = new Action\TaskUpdateStartDate($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action->setParam('column_id', 2); + + // We create a task in the first column + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + + // The start date must be empty + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEmpty($task['date_started']); + + // 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(new GenericEvent($event))); + + // Our task should be updated + $task = $tf->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(time(), $task['date_started'], '', 2); + } +} |