diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-02-29 22:40:26 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-02-29 22:40:26 -0500 |
commit | 6ef83d0e058d653322a8f9eb1131e665fb9b2a70 (patch) | |
tree | 2800a74b20b83db3f89879a82111136051744fe3 /tests/units/Model | |
parent | fafc272085be0d62acb693b47ae9c86dc1c7a417 (diff) |
Add unit test for transition model
Diffstat (limited to 'tests/units/Model')
24 files changed, 186 insertions, 34 deletions
diff --git a/tests/units/Model/CategoryTest.php b/tests/units/Model/CategoryTest.php index 85d9eaae..3a64e26c 100644 --- a/tests/units/Model/CategoryTest.php +++ b/tests/units/Model/CategoryTest.php @@ -2,12 +2,10 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; use Kanboard\Model\Category; -use Kanboard\Model\User; class CategoryTest extends Base { diff --git a/tests/units/Model/CommentTest.php b/tests/units/Model/CommentTest.php index ec4e7a56..bb96e4f4 100644 --- a/tests/units/Model/CommentTest.php +++ b/tests/units/Model/CommentTest.php @@ -2,7 +2,6 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\Project; use Kanboard\Model\Comment; diff --git a/tests/units/Model/ConfigTest.php b/tests/units/Model/ConfigTest.php index 447c9238..6ccdbef9 100644 --- a/tests/units/Model/ConfigTest.php +++ b/tests/units/Model/ConfigTest.php @@ -3,7 +3,6 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Model\Config; -use Kanboard\Core\Session\SessionManager; class ConfigTest extends Base { diff --git a/tests/units/Model/NotificationTest.php b/tests/units/Model/NotificationTest.php index 03ee5867..d5ec7735 100644 --- a/tests/units/Model/NotificationTest.php +++ b/tests/units/Model/NotificationTest.php @@ -6,7 +6,6 @@ use Kanboard\Model\TaskFinder; use Kanboard\Model\TaskCreation; use Kanboard\Model\Subtask; use Kanboard\Model\Comment; -use Kanboard\Model\User; use Kanboard\Model\TaskFile; use Kanboard\Model\Task; use Kanboard\Model\Project; diff --git a/tests/units/Model/ProjectActivityTest.php b/tests/units/Model/ProjectActivityTest.php index 04d3004d..27ea039d 100644 --- a/tests/units/Model/ProjectActivityTest.php +++ b/tests/units/Model/ProjectActivityTest.php @@ -7,8 +7,6 @@ use Kanboard\Model\TaskFinder; use Kanboard\Model\TaskCreation; use Kanboard\Model\ProjectActivity; use Kanboard\Model\Project; -use Kanboard\Model\Subtask; -use Kanboard\Model\Comment; class ProjectActivityTest extends Base { diff --git a/tests/units/Model/ProjectDailyColumnStatsTest.php b/tests/units/Model/ProjectDailyColumnStatsTest.php index 5e8ec3e8..1a0e826c 100644 --- a/tests/units/Model/ProjectDailyColumnStatsTest.php +++ b/tests/units/Model/ProjectDailyColumnStatsTest.php @@ -7,7 +7,6 @@ use Kanboard\Model\ProjectDailyColumnStats; use Kanboard\Model\Config; use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskStatus; class ProjectDailyColumnStatsTest extends Base { diff --git a/tests/units/Model/ProjectDailyStatsTest.php b/tests/units/Model/ProjectDailyStatsTest.php index 9efdb199..573878c2 100644 --- a/tests/units/Model/ProjectDailyStatsTest.php +++ b/tests/units/Model/ProjectDailyStatsTest.php @@ -4,7 +4,6 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Model\Project; use Kanboard\Model\ProjectDailyStats; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskStatus; diff --git a/tests/units/Model/SubtaskTest.php b/tests/units/Model/SubtaskTest.php index 78945fd1..eb9747d4 100644 --- a/tests/units/Model/SubtaskTest.php +++ b/tests/units/Model/SubtaskTest.php @@ -2,12 +2,9 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\Subtask; use Kanboard\Model\Project; -use Kanboard\Model\Category; -use Kanboard\Model\User; use Kanboard\Core\User\UserSession; class SubtaskTest extends Base diff --git a/tests/units/Model/SubtaskTimeTrackingTest.php b/tests/units/Model/SubtaskTimeTrackingTest.php index 40461eea..9fa8d5b0 100644 --- a/tests/units/Model/SubtaskTimeTrackingTest.php +++ b/tests/units/Model/SubtaskTimeTrackingTest.php @@ -7,8 +7,6 @@ use Kanboard\Model\TaskCreation; use Kanboard\Model\Subtask; use Kanboard\Model\SubtaskTimeTracking; use Kanboard\Model\Project; -use Kanboard\Model\Category; -use Kanboard\Model\User; class SubtaskTimeTrackingTest extends Base { diff --git a/tests/units/Model/SwimlaneTest.php b/tests/units/Model/SwimlaneTest.php index f8b496cf..71c13e40 100644 --- a/tests/units/Model/SwimlaneTest.php +++ b/tests/units/Model/SwimlaneTest.php @@ -3,7 +3,6 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Model\Project; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Swimlane; diff --git a/tests/units/Model/TaskCreationTest.php b/tests/units/Model/TaskCreationTest.php index 781a7147..04d23930 100644 --- a/tests/units/Model/TaskCreationTest.php +++ b/tests/units/Model/TaskCreationTest.php @@ -6,7 +6,6 @@ use Kanboard\Model\Config; use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskStatus; use Kanboard\Model\Project; class TaskCreationTest extends Base diff --git a/tests/units/Model/TaskDuplicationTest.php b/tests/units/Model/TaskDuplicationTest.php index 8649c6b0..5ceb357e 100644 --- a/tests/units/Model/TaskDuplicationTest.php +++ b/tests/units/Model/TaskDuplicationTest.php @@ -7,7 +7,6 @@ use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskDuplication; use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskStatus; use Kanboard\Model\Project; use Kanboard\Model\ProjectUserRole; use Kanboard\Model\Category; diff --git a/tests/units/Model/TaskExportTest.php b/tests/units/Model/TaskExportTest.php index b40b0771..559d53ef 100644 --- a/tests/units/Model/TaskExportTest.php +++ b/tests/units/Model/TaskExportTest.php @@ -2,12 +2,10 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskExport; use Kanboard\Model\Project; use Kanboard\Model\Category; -use Kanboard\Model\User; use Kanboard\Model\Swimlane; class TaskExportTest extends Base diff --git a/tests/units/Model/TaskFileTest.php b/tests/units/Model/TaskFileTest.php index b7db96a9..b900e8f3 100644 --- a/tests/units/Model/TaskFileTest.php +++ b/tests/units/Model/TaskFileTest.php @@ -2,7 +2,6 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; use Kanboard\Model\TaskFile; use Kanboard\Model\TaskCreation; use Kanboard\Model\Project; diff --git a/tests/units/Model/TaskFilterTest.php b/tests/units/Model/TaskFilterTest.php index daa193b2..9e291c31 100644 --- a/tests/units/Model/TaskFilterTest.php +++ b/tests/units/Model/TaskFilterTest.php @@ -10,7 +10,6 @@ use Kanboard\Model\TaskLink; use Kanboard\Core\DateParser; use Kanboard\Model\Category; use Kanboard\Model\Subtask; -use Kanboard\Model\Config; use Kanboard\Model\Swimlane; class TaskFilterTest extends Base diff --git a/tests/units/Model/TaskFinderTest.php b/tests/units/Model/TaskFinderTest.php index b21a4ea3..0ed211ed 100644 --- a/tests/units/Model/TaskFinderTest.php +++ b/tests/units/Model/TaskFinderTest.php @@ -2,12 +2,9 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; -use Kanboard\Model\Category; -use Kanboard\Model\User; class TaskFinderTest extends Base { diff --git a/tests/units/Model/TaskLinkTest.php b/tests/units/Model/TaskLinkTest.php index 192a4298..8dd71830 100644 --- a/tests/units/Model/TaskLinkTest.php +++ b/tests/units/Model/TaskLinkTest.php @@ -2,7 +2,6 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Link; use Kanboard\Model\TaskFinder; use Kanboard\Model\TaskLink; use Kanboard\Model\TaskCreation; diff --git a/tests/units/Model/TaskModificationTest.php b/tests/units/Model/TaskModificationTest.php index 119201f0..315125d5 100644 --- a/tests/units/Model/TaskModificationTest.php +++ b/tests/units/Model/TaskModificationTest.php @@ -6,7 +6,6 @@ use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskModification; use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskStatus; use Kanboard\Model\Project; class TaskModificationTest extends Base diff --git a/tests/units/Model/TaskPermissionTest.php b/tests/units/Model/TaskPermissionTest.php index 0b093bbb..82cd581e 100644 --- a/tests/units/Model/TaskPermissionTest.php +++ b/tests/units/Model/TaskPermissionTest.php @@ -2,12 +2,10 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\TaskPermission; use Kanboard\Model\Project; -use Kanboard\Model\Category; use Kanboard\Model\User; use Kanboard\Core\User\UserSession; diff --git a/tests/units/Model/TransitionExportTest.php b/tests/units/Model/TransitionExportTest.php new file mode 100644 index 00000000..98b4356d --- /dev/null +++ b/tests/units/Model/TransitionExportTest.php @@ -0,0 +1,45 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Transition; +use Kanboard\Model\TransitionExport; +use Kanboard\Model\Project; + +class TransitionExportTest extends Base +{ + public function testExport() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $transitionModel = new Transition($this->container); + $transitionExportModel = new TransitionExport($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $task_event = array( + 'project_id' => 1, + 'task_id' => 1, + 'src_column_id' => 1, + 'dst_column_id' => 2, + 'date_moved' => time() - 3600 + ); + + $this->assertTrue($transitionModel->save(1, $task_event)); + + $export = $transitionExportModel->export(1, date('Y-m-d'), date('Y-m-d')); + $this->assertCount(2, $export); + + $this->assertEquals( + array('Id', 'Task Title', 'Source column', 'Destination column', 'Executer', 'Date', 'Time spent'), + $export[0] + ); + + $this->assertEquals( + array(1, 'test', 'Backlog', 'Ready', 'admin', date('m/d/Y H:i', time()), 1.0), + $export[1] + ); + } +} diff --git a/tests/units/Model/TransitionTest.php b/tests/units/Model/TransitionTest.php new file mode 100644 index 00000000..0c262e78 --- /dev/null +++ b/tests/units/Model/TransitionTest.php @@ -0,0 +1,141 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Transition; +use Kanboard\Model\Project; + +class TransitionTest extends Base +{ + public function testSave() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $transitionModel = new Transition($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $task_event = array( + 'project_id' => 1, + 'task_id' => 1, + 'src_column_id' => 1, + 'dst_column_id' => 2, + 'date_moved' => time() - 3600 + ); + + $this->assertTrue($transitionModel->save(1, $task_event)); + + $transitions = $transitionModel->getAllByTask(1); + $this->assertCount(1, $transitions); + $this->assertEquals('Backlog', $transitions[0]['src_column']); + $this->assertEquals('Ready', $transitions[0]['dst_column']); + $this->assertEquals('', $transitions[0]['name']); + $this->assertEquals('admin', $transitions[0]['username']); + $this->assertEquals(1, $transitions[0]['user_id']); + $this->assertEquals(time(), $transitions[0]['date'], '', 3); + $this->assertEquals(3600, $transitions[0]['time_spent']); + } + + public function testGetTimeSpentByTask() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $transitionModel = new Transition($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $task_event = array( + 'project_id' => 1, + 'task_id' => 1, + 'src_column_id' => 1, + 'dst_column_id' => 2, + 'date_moved' => time() - 3600 + ); + + $this->assertTrue($transitionModel->save(1, $task_event)); + + $task_event = array( + 'project_id' => 1, + 'task_id' => 1, + 'src_column_id' => 2, + 'dst_column_id' => 3, + 'date_moved' => time() - 1200 + ); + + $this->assertTrue($transitionModel->save(1, $task_event)); + + $expected = array( + '1' => 3600, + '2' => 1200, + ); + + $this->assertEquals($expected, $transitionModel->getTimeSpentByTask(1)); + } + + public function testGetAllByProject() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $transitionModel = new Transition($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test1'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test2'))); + + $task_event = array( + 'project_id' => 1, + 'src_column_id' => 1, + 'dst_column_id' => 2, + 'date_moved' => time() - 3600 + ); + + $this->assertTrue($transitionModel->save(1, array('task_id' => 1) + $task_event)); + $this->assertTrue($transitionModel->save(1, array('task_id' => 2) + $task_event)); + + $task_event = array( + 'project_id' => 1, + 'src_column_id' => 2, + 'dst_column_id' => 3, + 'date_moved' => time() - 1200 + ); + + $this->assertTrue($transitionModel->save(1, array('task_id' => 1) + $task_event)); + $this->assertTrue($transitionModel->save(1, array('task_id' => 2) + $task_event)); + + $transitions = $transitionModel->getAllByProjectAndDate(1, date('Y-m-d'), date('Y-m-d')); + $this->assertCount(4, $transitions); + + $this->assertEquals(2, $transitions[0]['id']); + $this->assertEquals(1, $transitions[1]['id']); + $this->assertEquals(2, $transitions[2]['id']); + $this->assertEquals(1, $transitions[3]['id']); + + $this->assertEquals('test2', $transitions[0]['title']); + $this->assertEquals('test1', $transitions[1]['title']); + $this->assertEquals('test2', $transitions[2]['title']); + $this->assertEquals('test1', $transitions[3]['title']); + + $this->assertEquals('Ready', $transitions[0]['src_column']); + $this->assertEquals('Ready', $transitions[1]['src_column']); + $this->assertEquals('Backlog', $transitions[2]['src_column']); + $this->assertEquals('Backlog', $transitions[3]['src_column']); + + $this->assertEquals('Work in progress', $transitions[0]['dst_column']); + $this->assertEquals('Work in progress', $transitions[1]['dst_column']); + $this->assertEquals('Ready', $transitions[2]['dst_column']); + $this->assertEquals('Ready', $transitions[3]['dst_column']); + + $this->assertEquals('admin', $transitions[0]['username']); + $this->assertEquals('admin', $transitions[1]['username']); + $this->assertEquals('admin', $transitions[2]['username']); + $this->assertEquals('admin', $transitions[3]['username']); + + $this->assertEquals(1200, $transitions[0]['time_spent']); + $this->assertEquals(1200, $transitions[1]['time_spent']); + $this->assertEquals(3600, $transitions[2]['time_spent']); + $this->assertEquals(3600, $transitions[3]['time_spent']); + } +} diff --git a/tests/units/Model/UserNotificationTest.php b/tests/units/Model/UserNotificationTest.php index e1928661..53034e20 100644 --- a/tests/units/Model/UserNotificationTest.php +++ b/tests/units/Model/UserNotificationTest.php @@ -4,8 +4,6 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Model\TaskFinder; use Kanboard\Model\TaskCreation; -use Kanboard\Model\Subtask; -use Kanboard\Model\Comment; use Kanboard\Model\User; use Kanboard\Model\Group; use Kanboard\Model\GroupMember; @@ -16,7 +14,6 @@ use Kanboard\Model\ProjectUserRole; use Kanboard\Model\ProjectGroupRole; use Kanboard\Model\UserNotification; use Kanboard\Model\UserNotificationFilter; -use Kanboard\Model\UserNotificationType; use Kanboard\Subscriber\UserNotificationSubscriber; use Kanboard\Core\Security\Role; diff --git a/tests/units/Model/UserTest.php b/tests/units/Model/UserTest.php index e411da0c..7501f2e0 100644 --- a/tests/units/Model/UserTest.php +++ b/tests/units/Model/UserTest.php @@ -5,7 +5,6 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Model\User; use Kanboard\Model\Subtask; use Kanboard\Model\Comment; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; diff --git a/tests/units/Model/UserUnreadNotificationTest.php b/tests/units/Model/UserUnreadNotificationTest.php index 62889bf0..918ab411 100644 --- a/tests/units/Model/UserUnreadNotificationTest.php +++ b/tests/units/Model/UserUnreadNotificationTest.php @@ -4,8 +4,6 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Model\TaskFinder; use Kanboard\Model\TaskCreation; -use Kanboard\Model\Subtask; -use Kanboard\Model\Comment; use Kanboard\Model\User; use Kanboard\Model\Task; use Kanboard\Model\Project; |