summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-06-26 10:25:13 -0400
committerFrederic Guillot <fred@kanboard.net>2016-06-26 10:25:13 -0400
commit4a230d331ec220fc32a48525afb308af0d9787fa (patch)
tree514aa3d703155b7f97a2c77147c9fd74cef60f84 /tests
parent922e0fb6de06a98774418612e0b0f75af72b6dbb (diff)
Added application and project roles validation for API procedure calls
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/ActionProcedureTest.php (renamed from tests/integration/ActionTest.php)4
-rw-r--r--tests/integration/AppProcedureTest.php (renamed from tests/integration/AppTest.php)4
-rw-r--r--tests/integration/BaseProcedureTest.php (renamed from tests/integration/BaseIntegrationTest.php)2
-rw-r--r--tests/integration/BoardProcedureTest.php (renamed from tests/integration/BoardTest.php)4
-rw-r--r--tests/integration/CategoryProcedureTest.php (renamed from tests/integration/CategoryTest.php)4
-rw-r--r--tests/integration/ColumnProcedureTest.php (renamed from tests/integration/ColumnTest.php)4
-rw-r--r--tests/integration/CommentProcedureTest.php (renamed from tests/integration/CommentTest.php)4
-rw-r--r--tests/integration/GroupMemberProcedureTest.php (renamed from tests/integration/GroupMemberTest.php)4
-rw-r--r--tests/integration/GroupProcedureTest.php (renamed from tests/integration/GroupTest.php)4
-rw-r--r--tests/integration/LinkProcedureTest.php (renamed from tests/integration/LinkTest.php)4
-rw-r--r--tests/integration/MeProcedureTest.php (renamed from tests/integration/MeTest.php)9
-rw-r--r--tests/integration/OverdueTaskProcedureTest.php (renamed from tests/integration/OverdueTaskTest.php)4
-rw-r--r--tests/integration/ProcedureAuthorizationTest.php306
-rw-r--r--tests/integration/ProjectPermissionProcedureTest.php (renamed from tests/integration/ProjectPermissionTest.php)4
-rw-r--r--tests/integration/ProjectProcedureTest.php (renamed from tests/integration/ProjectTest.php)4
-rw-r--r--tests/integration/SubtaskProcedureTest.php (renamed from tests/integration/SubtaskTest.php)4
-rw-r--r--tests/integration/SwimlaneProcedureTest.php (renamed from tests/integration/SwimlaneTest.php)4
-rw-r--r--tests/integration/TaskFileProcedureTest.php (renamed from tests/integration/TaskFileTest.php)4
-rw-r--r--tests/integration/TaskLinkProcedureTest.php (renamed from tests/integration/TaskLinkTest.php)4
-rw-r--r--tests/integration/TaskProcedureTest.php (renamed from tests/integration/TaskTest.php)4
-rw-r--r--tests/integration/UserProcedureTest.php (renamed from tests/integration/UserTest.php)4
-rw-r--r--tests/units/Model/ActionModelTest.php (renamed from tests/units/Model/ActionTest.php)20
-rw-r--r--tests/units/Model/CategoryModelTest.php (renamed from tests/units/Model/CategoryTest.php)14
-rw-r--r--tests/units/Model/CommentTest.php86
-rw-r--r--tests/units/Model/SubtaskModelTest.php (renamed from tests/units/Model/SubtaskTest.php)156
-rw-r--r--tests/units/Model/TaskFileModelTest.php (renamed from tests/units/Model/TaskFileTest.php)15
-rw-r--r--tests/units/Model/TaskLinkModelTest.php211
-rw-r--r--tests/units/Model/TaskLinkTest.php196
28 files changed, 736 insertions, 351 deletions
diff --git a/tests/integration/ActionTest.php b/tests/integration/ActionProcedureTest.php
index 7a5adc4a..432de3d3 100644
--- a/tests/integration/ActionTest.php
+++ b/tests/integration/ActionProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class ActionTest extends BaseIntegrationTest
+class ActionProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My project to test actions';
diff --git a/tests/integration/AppTest.php b/tests/integration/AppProcedureTest.php
index 287e6299..06135dac 100644
--- a/tests/integration/AppTest.php
+++ b/tests/integration/AppProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class AppTest extends BaseIntegrationTest
+class AppProcedureTest extends BaseProcedureTest
{
public function testGetTimezone()
{
diff --git a/tests/integration/BaseIntegrationTest.php b/tests/integration/BaseProcedureTest.php
index cd837173..e3382e82 100644
--- a/tests/integration/BaseIntegrationTest.php
+++ b/tests/integration/BaseProcedureTest.php
@@ -2,7 +2,7 @@
require_once __DIR__.'/../../vendor/autoload.php';
-abstract class BaseIntegrationTest extends PHPUnit_Framework_TestCase
+abstract class BaseProcedureTest extends PHPUnit_Framework_TestCase
{
protected $app = null;
protected $admin = null;
diff --git a/tests/integration/BoardTest.php b/tests/integration/BoardProcedureTest.php
index aa0f61ff..273e93c7 100644
--- a/tests/integration/BoardTest.php
+++ b/tests/integration/BoardProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class BoardTest extends BaseIntegrationTest
+class BoardProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My project to test board';
diff --git a/tests/integration/CategoryTest.php b/tests/integration/CategoryProcedureTest.php
index c1aec0bc..2f5294ba 100644
--- a/tests/integration/CategoryTest.php
+++ b/tests/integration/CategoryProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class CategoryTest extends BaseIntegrationTest
+class CategoryProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My project to test categories';
private $categoryId = 0;
diff --git a/tests/integration/ColumnTest.php b/tests/integration/ColumnProcedureTest.php
index 5a81badc..fb6a27c3 100644
--- a/tests/integration/ColumnTest.php
+++ b/tests/integration/ColumnProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class ColumnTest extends BaseIntegrationTest
+class ColumnProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My project to test columns';
private $columns = array();
diff --git a/tests/integration/CommentTest.php b/tests/integration/CommentProcedureTest.php
index 34376838..881d938c 100644
--- a/tests/integration/CommentTest.php
+++ b/tests/integration/CommentProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class CommentTest extends BaseIntegrationTest
+class CommentProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My project to test comments';
private $commentId = 0;
diff --git a/tests/integration/GroupMemberTest.php b/tests/integration/GroupMemberProcedureTest.php
index f79499a4..fe243533 100644
--- a/tests/integration/GroupMemberTest.php
+++ b/tests/integration/GroupMemberProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class GroupMemberTest extends BaseIntegrationTest
+class GroupMemberProcedureTest extends BaseProcedureTest
{
protected $username = 'user-group-member';
protected $groupName1 = 'My group member A';
diff --git a/tests/integration/GroupTest.php b/tests/integration/GroupProcedureTest.php
index ffcd7a71..610c121d 100644
--- a/tests/integration/GroupTest.php
+++ b/tests/integration/GroupProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class GroupTest extends BaseIntegrationTest
+class GroupProcedureTest extends BaseProcedureTest
{
public function testAll()
{
diff --git a/tests/integration/LinkTest.php b/tests/integration/LinkProcedureTest.php
index 16b16e50..fb07e694 100644
--- a/tests/integration/LinkTest.php
+++ b/tests/integration/LinkProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class LinkTest extends BaseIntegrationTest
+class LinkProcedureTest extends BaseProcedureTest
{
public function testGetAllLinks()
{
diff --git a/tests/integration/MeTest.php b/tests/integration/MeProcedureTest.php
index 047ebf85..2106419c 100644
--- a/tests/integration/MeTest.php
+++ b/tests/integration/MeProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class MeTest extends BaseIntegrationTest
+class MeProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My private project';
@@ -41,11 +41,6 @@ class MeTest extends BaseIntegrationTest
{
$projects = $this->user->getMyProjects();
$this->assertNotEmpty($projects);
- $this->assertCount(1, $projects);
- $this->assertEquals($this->projectName, $projects[0]['name']);
- $this->assertNotEmpty($projects[0]['url']['calendar']);
- $this->assertNotEmpty($projects[0]['url']['board']);
- $this->assertNotEmpty($projects[0]['url']['list']);
}
public function assertCreateTask()
diff --git a/tests/integration/OverdueTaskTest.php b/tests/integration/OverdueTaskProcedureTest.php
index 1dea5030..65f52301 100644
--- a/tests/integration/OverdueTaskTest.php
+++ b/tests/integration/OverdueTaskProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class OverdueTaskTest extends BaseIntegrationTest
+class OverdueTaskProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My project to test overdue tasks';
diff --git a/tests/integration/ProcedureAuthorizationTest.php b/tests/integration/ProcedureAuthorizationTest.php
new file mode 100644
index 00000000..a63e9d8c
--- /dev/null
+++ b/tests/integration/ProcedureAuthorizationTest.php
@@ -0,0 +1,306 @@
+<?php
+
+require_once __DIR__.'/BaseProcedureTest.php';
+
+class ProcedureAuthorizationTest extends BaseProcedureTest
+{
+ public function testApiCredentialDoNotHaveAccessToUserCredentialProcedure()
+ {
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->app->getMe();
+ }
+
+ public function testUserCredentialDoNotHaveAccessToAdminProcedures()
+ {
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->getUser(1);
+ }
+
+ public function testManagerCredentialDoNotHaveAccessToAdminProcedures()
+ {
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->getAllProjects();
+ }
+
+ public function testUserCredentialDoNotHaveAccessToManagerProcedures()
+ {
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->createProject('Team project creation are only for app managers');
+ }
+
+ public function testAppManagerCanCreateTeamProject()
+ {
+ $this->assertNotFalse($this->manager->createProject('Team project created by app manager'));
+ }
+
+ public function testAdminManagerCanCreateTeamProject()
+ {
+ $projectId = $this->admin->createProject('Team project created by admin');
+ $this->assertNotFalse($projectId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->assertNotNull($this->manager->getProjectById($projectId));
+ }
+
+ public function testProjectManagerCanUpdateHisProject()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Team project can be updated',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+ $this->assertEquals('project-manager', $this->app->getProjectUserRole($projectId, $this->managerUserId));
+ $this->assertNotNull($this->manager->getProjectById($projectId));
+
+ $this->assertTrue($this->manager->updateProject($projectId, 'My team project have been updated'));
+ }
+
+ public function testProjectAuthorizationForbidden()
+ {
+ $projectId = $this->manager->createProject('A team project without members');
+ $this->assertNotFalse($projectId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->getProjectById($projectId);
+ }
+
+ public function testProjectAuthorizationGranted()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'A team project with members',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId));
+ $this->assertNotNull($this->user->getProjectById($projectId));
+ }
+
+ public function testActionAuthorizationForbidden()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $actionId = $this->manager->createAction($projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1));
+ $this->assertNotFalse($actionId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeAction($projectId);
+ }
+
+ public function testActionAuthorizationForbiddenBecauseNotProjectManager()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $actionId = $this->manager->createAction($projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1));
+ $this->assertNotFalse($actionId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member'));
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeAction($actionId);
+ }
+
+ public function testActionAuthorizationGranted()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $actionId = $this->manager->createAction($projectId, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1));
+ $this->assertNotFalse($actionId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-manager'));
+ $this->assertTrue($this->user->removeAction($actionId));
+ }
+
+ public function testCategoryAuthorizationForbidden()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $categoryId = $this->manager->createCategory($projectId, 'Test');
+ $this->assertNotFalse($categoryId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeCategory($categoryId);
+ }
+
+ public function testCategoryAuthorizationForbiddenBecauseNotProjectManager()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $categoryId = $this->manager->createCategory($projectId, 'Test');
+ $this->assertNotFalse($categoryId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member'));
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeCategory($categoryId);
+ }
+
+ public function testCategoryAuthorizationGranted()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $categoryId = $this->manager->createCategory($projectId, 'Test');
+ $this->assertNotFalse($categoryId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-manager'));
+ $this->assertTrue($this->user->removeCategory($categoryId));
+ }
+
+ public function testColumnAuthorizationForbidden()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $columnId = $this->manager->addColumn($projectId, 'Test');
+ $this->assertNotFalse($columnId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeColumn($columnId);
+ }
+
+ public function testColumnAuthorizationForbiddenBecauseNotProjectManager()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $columnId = $this->manager->addColumn($projectId, 'Test');
+ $this->assertNotFalse($columnId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member'));
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeColumn($columnId);
+ }
+
+ public function testColumnAuthorizationGranted()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+
+ $columnId = $this->manager->addColumn($projectId, 'Test');
+ $this->assertNotFalse($columnId);
+
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-manager'));
+ $this->assertTrue($this->user->removeColumn($columnId));
+ }
+
+ public function testCommentAuthorizationForbidden()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-viewer'));
+
+ $taskId = $this->manager->createTask('My Task', $projectId);
+ $this->assertNotFalse($taskId);
+
+ $commentId = $this->manager->createComment($taskId, $this->userUserId, 'My comment');
+ $this->assertNotFalse($commentId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->updateComment($commentId, 'something else');
+ }
+
+ public function testCommentAuthorizationGranted()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member'));
+
+ $taskId = $this->user->createTask('My Task', $projectId);
+ $this->assertNotFalse($taskId);
+
+ $commentId = $this->user->createComment($taskId, $this->userUserId, 'My comment');
+ $this->assertNotFalse($commentId);
+
+ $this->assertTrue($this->user->updateComment($commentId, 'something else'));
+ }
+
+ public function testSubtaskAuthorizationForbidden()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-viewer'));
+
+ $taskId = $this->manager->createTask('My Task', $projectId);
+ $this->assertNotFalse($taskId);
+
+ $subtaskId = $this->manager->createSubtask($taskId, 'My subtask');
+ $this->assertNotFalse($subtaskId);
+
+ $this->setExpectedException('JsonRPC\Exception\AccessDeniedException');
+ $this->user->removeSubtask($subtaskId);
+ }
+
+ public function testSubtaskAuthorizationGranted()
+ {
+ $projectId = $this->manager->createProject(array(
+ 'name' => 'Test Project',
+ 'owner_id' => $this->managerUserId,
+ ));
+
+ $this->assertNotFalse($projectId);
+ $this->assertTrue($this->manager->addProjectUser($projectId, $this->userUserId, 'project-member'));
+
+ $taskId = $this->user->createTask('My Task', $projectId);
+ $this->assertNotFalse($taskId);
+
+ $subtaskId = $this->manager->createSubtask($taskId, 'My subtask');
+ $this->assertNotFalse($subtaskId);
+
+ $this->assertTrue($this->user->removeSubtask($subtaskId));
+ }
+}
diff --git a/tests/integration/ProjectPermissionTest.php b/tests/integration/ProjectPermissionProcedureTest.php
index 3ceda07d..74313dc4 100644
--- a/tests/integration/ProjectPermissionTest.php
+++ b/tests/integration/ProjectPermissionProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class ProjectPermissionTest extends BaseIntegrationTest
+class ProjectPermissionProcedureTest extends BaseProcedureTest
{
protected $projectName = 'Project with permission';
protected $username = 'user-project-permission';
diff --git a/tests/integration/ProjectTest.php b/tests/integration/ProjectProcedureTest.php
index 50d4fc53..1ebd48ae 100644
--- a/tests/integration/ProjectTest.php
+++ b/tests/integration/ProjectProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class ProjectTest extends BaseIntegrationTest
+class ProjectProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My team project';
diff --git a/tests/integration/SubtaskTest.php b/tests/integration/SubtaskProcedureTest.php
index 10082e60..7ab4ef0b 100644
--- a/tests/integration/SubtaskTest.php
+++ b/tests/integration/SubtaskProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class SubtaskTest extends BaseIntegrationTest
+class SubtaskProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My project to test subtasks';
private $subtaskId = 0;
diff --git a/tests/integration/SwimlaneTest.php b/tests/integration/SwimlaneProcedureTest.php
index 4f703414..e64342b4 100644
--- a/tests/integration/SwimlaneTest.php
+++ b/tests/integration/SwimlaneProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class SwimlaneTest extends BaseIntegrationTest
+class SwimlaneProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My project to test swimlanes';
private $swimlaneId = 0;
diff --git a/tests/integration/TaskFileTest.php b/tests/integration/TaskFileProcedureTest.php
index 7e9e943b..61155555 100644
--- a/tests/integration/TaskFileTest.php
+++ b/tests/integration/TaskFileProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class TaskFileTest extends BaseIntegrationTest
+class TaskFileProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My project to test task files';
protected $fileId;
diff --git a/tests/integration/TaskLinkTest.php b/tests/integration/TaskLinkProcedureTest.php
index 03bc437b..a25fced5 100644
--- a/tests/integration/TaskLinkTest.php
+++ b/tests/integration/TaskLinkProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class TaskLinkTest extends BaseIntegrationTest
+class TaskLinkProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My project to test task links';
protected $taskLinkId;
diff --git a/tests/integration/TaskTest.php b/tests/integration/TaskProcedureTest.php
index 6f1d9d62..f456ae52 100644
--- a/tests/integration/TaskTest.php
+++ b/tests/integration/TaskProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class TaskTest extends BaseIntegrationTest
+class TaskProcedureTest extends BaseProcedureTest
{
protected $projectName = 'My project to test tasks';
diff --git a/tests/integration/UserTest.php b/tests/integration/UserProcedureTest.php
index c407c918..290f87fb 100644
--- a/tests/integration/UserTest.php
+++ b/tests/integration/UserProcedureTest.php
@@ -1,8 +1,8 @@
<?php
-require_once __DIR__.'/BaseIntegrationTest.php';
+require_once __DIR__.'/BaseProcedureTest.php';
-class UserTest extends BaseIntegrationTest
+class UserProcedureTest extends BaseProcedureTest
{
public function testAll()
{
diff --git a/tests/units/Model/ActionTest.php b/tests/units/Model/ActionModelTest.php
index 5db18983..4e21a999 100644
--- a/tests/units/Model/ActionTest.php
+++ b/tests/units/Model/ActionModelTest.php
@@ -11,7 +11,7 @@ use Kanboard\Model\CategoryModel;
use Kanboard\Model\ProjectUserRoleModel;
use Kanboard\Core\Security\Role;
-class ActionTest extends Base
+class ActionModelTest extends Base
{
public function testCreate()
{
@@ -69,6 +69,24 @@ class ActionTest extends Base
$this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $action['params']);
}
+ public function testGetProjectId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $actionModel = new ActionModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+
+ $this->assertEquals(1, $actionModel->create(array(
+ 'project_id' => 1,
+ 'event_name' => TaskModel::EVENT_CREATE,
+ 'action_name' => '\Kanboard\Action\TaskAssignColorColumn',
+ 'params' => array('column_id' => 1, 'color_id' => 'red'),
+ )));
+
+ $this->assertEquals(1, $actionModel->getProjectId(1));
+ $this->assertSame(0, $actionModel->getProjectId(42));
+ }
+
public function testGetAll()
{
$projectModel = new ProjectModel($this->container);
diff --git a/tests/units/Model/CategoryTest.php b/tests/units/Model/CategoryModelTest.php
index 1fdc51f6..80a20af6 100644
--- a/tests/units/Model/CategoryTest.php
+++ b/tests/units/Model/CategoryModelTest.php
@@ -8,7 +8,7 @@ use Kanboard\Model\TaskFinderModel;
use Kanboard\Model\ProjectModel;
use Kanboard\Model\CategoryModel;
-class CategoryTest extends Base
+class CategoryModelTest extends Base
{
public function testCreation()
{
@@ -81,6 +81,18 @@ class CategoryTest extends Base
$this->assertSame(0, $categoryModel->getIdByName(1, 'Category #2'));
}
+ public function testGetProjectId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $categoryModel = new CategoryModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $categoryModel->create(array('name' => 'Category #1', 'project_id' => 1, 'description' => 'test')));
+
+ $this->assertEquals(1, $categoryModel->getProjectId(1));
+ $this->assertSame(0, $categoryModel->getProjectId(2));
+ }
+
public function testGetList()
{
$projectModel = new ProjectModel($this->container);
diff --git a/tests/units/Model/CommentTest.php b/tests/units/Model/CommentTest.php
index 7250ae0b..574b5a87 100644
--- a/tests/units/Model/CommentTest.php
+++ b/tests/units/Model/CommentTest.php
@@ -10,16 +10,16 @@ class CommentTest extends Base
{
public function testCreate()
{
- $c = new CommentModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $p = new ProjectModel($this->container);
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
- $this->assertEquals(1, $c->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
- $this->assertEquals(2, $c->create(array('task_id' => 1, 'comment' => 'bla bla')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
+ $this->assertEquals(2, $commentModel->create(array('task_id' => 1, 'comment' => 'bla bla')));
- $comment = $c->getById(1);
+ $comment = $commentModel->getById(1);
$this->assertNotEmpty($comment);
$this->assertEquals('bla bla', $comment['comment']);
$this->assertEquals(1, $comment['task_id']);
@@ -27,7 +27,7 @@ class CommentTest extends Base
$this->assertEquals('admin', $comment['username']);
$this->assertEquals(time(), $comment['date_creation'], '', 3);
- $comment = $c->getById(2);
+ $comment = $commentModel->getById(2);
$this->assertNotEmpty($comment);
$this->assertEquals('bla bla', $comment['comment']);
$this->assertEquals(1, $comment['task_id']);
@@ -38,17 +38,17 @@ class CommentTest extends Base
public function testGetAll()
{
- $c = new CommentModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $p = new ProjectModel($this->container);
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
- $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
- $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1)));
- $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+ $this->assertEquals(2, $commentModel->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1)));
+ $this->assertEquals(3, $commentModel->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1)));
- $comments = $c->getAll(1);
+ $comments = $commentModel->getAll(1);
$this->assertNotEmpty($comments);
$this->assertEquals(3, count($comments));
@@ -56,37 +56,51 @@ class CommentTest extends Base
$this->assertEquals(2, $comments[1]['id']);
$this->assertEquals(3, $comments[2]['id']);
- $this->assertEquals(3, $c->count(1));
+ $this->assertEquals(3, $commentModel->count(1));
}
public function testUpdate()
{
- $c = new CommentModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $p = new ProjectModel($this->container);
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
- $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
- $this->assertTrue($c->update(array('id' => 1, 'comment' => 'bla')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+ $this->assertTrue($commentModel->update(array('id' => 1, 'comment' => 'bla')));
- $comment = $c->getById(1);
+ $comment = $commentModel->getById(1);
$this->assertNotEmpty($comment);
$this->assertEquals('bla', $comment['comment']);
}
public function validateRemove()
{
- $c = new CommentModel($this->container);
- $tc = new TaskCreationModel($this->container);
- $p = new ProjectModel($this->container);
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->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->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
- $this->assertTrue($c->remove(1));
- $this->assertFalse($c->remove(1));
- $this->assertFalse($c->remove(1111));
+ $this->assertTrue($commentModel->remove(1));
+ $this->assertFalse($commentModel->remove(1));
+ $this->assertFalse($commentModel->remove(1111));
+ }
+
+ public function testGetProjectId()
+ {
+ $commentModel = new CommentModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
+ $this->assertEquals(1, $commentModel->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+
+ $this->assertEquals(1, $commentModel->getProjectId(1));
+ $this->assertSame(0, $commentModel->getProjectId(2));
}
}
diff --git a/tests/units/Model/SubtaskTest.php b/tests/units/Model/SubtaskModelTest.php
index b65ee609..6451189d 100644
--- a/tests/units/Model/SubtaskTest.php
+++ b/tests/units/Model/SubtaskModelTest.php
@@ -5,10 +5,9 @@ require_once __DIR__.'/../Base.php';
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\SubtaskModel;
use Kanboard\Model\ProjectModel;
-use Kanboard\Core\User\UserSession;
use Kanboard\Model\TaskFinderModel;
-class SubtaskTest extends Base
+class SubtaskModelTest extends Base
{
public function onSubtaskCreated($event)
{
@@ -70,18 +69,18 @@ class SubtaskTest extends Base
public function testCreation()
{
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
$this->container['dispatcher']->addListener(SubtaskModel::EVENT_CREATE, array($this, 'onSubtaskCreated'));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
- $subtask = $s->getById(1);
+ $subtask = $subtaskModel->getById(1);
$this->assertNotEmpty($subtask);
$this->assertEquals(1, $subtask['id']);
$this->assertEquals(1, $subtask['task_id']);
@@ -95,19 +94,19 @@ class SubtaskTest extends Base
public function testModification()
{
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
$this->container['dispatcher']->addListener(SubtaskModel::EVENT_UPDATE, array($this, 'onSubtaskUpdated'));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
- $this->assertTrue($s->update(array('id' => 1, 'user_id' => 1, 'status' => SubtaskModel::STATUS_INPROGRESS)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertTrue($subtaskModel->update(array('id' => 1, 'user_id' => 1, 'status' => SubtaskModel::STATUS_INPROGRESS)));
- $subtask = $s->getById(1);
+ $subtask = $subtaskModel->getById(1);
$this->assertNotEmpty($subtask);
$this->assertEquals(1, $subtask['id']);
$this->assertEquals(1, $subtask['task_id']);
@@ -121,61 +120,61 @@ class SubtaskTest extends Base
public function testRemove()
{
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
$this->container['dispatcher']->addListener(SubtaskModel::EVENT_DELETE, array($this, 'onSubtaskDeleted'));
- $subtask = $s->getById(1);
+ $subtask = $subtaskModel->getById(1);
$this->assertNotEmpty($subtask);
- $this->assertTrue($s->remove(1));
+ $this->assertTrue($subtaskModel->remove(1));
- $subtask = $s->getById(1);
+ $subtask = $subtaskModel->getById(1);
$this->assertEmpty($subtask);
}
public function testToggleStatusWithoutSession()
{
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
- $subtask = $s->getById(1);
+ $subtask = $subtaskModel->getById(1);
$this->assertNotEmpty($subtask);
$this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
$this->assertEquals(0, $subtask['user_id']);
$this->assertEquals(1, $subtask['task_id']);
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $s->toggleStatus(1));
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtaskModel->toggleStatus(1));
- $subtask = $s->getById(1);
+ $subtask = $subtaskModel->getById(1);
$this->assertNotEmpty($subtask);
$this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
$this->assertEquals(0, $subtask['user_id']);
$this->assertEquals(1, $subtask['task_id']);
- $this->assertEquals(SubtaskModel::STATUS_DONE, $s->toggleStatus(1));
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskModel->toggleStatus(1));
- $subtask = $s->getById(1);
+ $subtask = $subtaskModel->getById(1);
$this->assertNotEmpty($subtask);
$this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
$this->assertEquals(0, $subtask['user_id']);
$this->assertEquals(1, $subtask['task_id']);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $s->toggleStatus(1));
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskModel->toggleStatus(1));
- $subtask = $s->getById(1);
+ $subtask = $subtaskModel->getById(1);
$this->assertNotEmpty($subtask);
$this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
$this->assertEquals(0, $subtask['user_id']);
@@ -184,17 +183,16 @@ class SubtaskTest extends Base
public function testToggleStatusWithSession()
{
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($this->container);
- $us = new UserSession($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
- $subtask = $s->getById(1);
+ $subtask = $subtaskModel->getById(1);
$this->assertNotEmpty($subtask);
$this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
$this->assertEquals(0, $subtask['user_id']);
@@ -203,25 +201,25 @@ class SubtaskTest extends Base
// Set the current logged user
$this->container['sessionStorage']->user = array('id' => 1);
- $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $s->toggleStatus(1));
+ $this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtaskModel->toggleStatus(1));
- $subtask = $s->getById(1);
+ $subtask = $subtaskModel->getById(1);
$this->assertNotEmpty($subtask);
$this->assertEquals(SubtaskModel::STATUS_INPROGRESS, $subtask['status']);
$this->assertEquals(1, $subtask['user_id']);
$this->assertEquals(1, $subtask['task_id']);
- $this->assertEquals(SubtaskModel::STATUS_DONE, $s->toggleStatus(1));
+ $this->assertEquals(SubtaskModel::STATUS_DONE, $subtaskModel->toggleStatus(1));
- $subtask = $s->getById(1);
+ $subtask = $subtaskModel->getById(1);
$this->assertNotEmpty($subtask);
$this->assertEquals(SubtaskModel::STATUS_DONE, $subtask['status']);
$this->assertEquals(1, $subtask['user_id']);
$this->assertEquals(1, $subtask['task_id']);
- $this->assertEquals(SubtaskModel::STATUS_TODO, $s->toggleStatus(1));
+ $this->assertEquals(SubtaskModel::STATUS_TODO, $subtaskModel->toggleStatus(1));
- $subtask = $s->getById(1);
+ $subtask = $subtaskModel->getById(1);
$this->assertNotEmpty($subtask);
$this->assertEquals(SubtaskModel::STATUS_TODO, $subtask['status']);
$this->assertEquals(1, $subtask['user_id']);
@@ -230,19 +228,19 @@ class SubtaskTest extends Base
public function testCloseAll()
{
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1)));
- $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1)));
- $this->assertTrue($s->closeAll(1));
+ $this->assertTrue($subtaskModel->closeAll(1));
- $subtasks = $s->getAll(1);
+ $subtasks = $subtaskModel->getAll(1);
$this->assertNotEmpty($subtasks);
foreach ($subtasks as $subtask) {
@@ -252,24 +250,24 @@ class SubtaskTest extends Base
public function testDuplicate()
{
- $tc = new TaskCreationModel($this->container);
- $s = new SubtaskModel($this->container);
- $p = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
// We create a project
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
// We create 2 tasks
- $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0)));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'test 2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 0)));
// We create many subtasks for the first task
- $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1, 'another_subtask' => 'on')));
- $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => '', 'status' => 2, 'user_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_estimated' => 5, 'time_spent' => 3, 'status' => 1, 'another_subtask' => 'on')));
+ $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => '', 'time_spent' => '', 'status' => 2, 'user_id' => 1)));
// We duplicate our subtasks
- $this->assertTrue($s->duplicate(1, 2));
- $subtasks = $s->getAll(2);
+ $this->assertTrue($subtaskModel->duplicate(1, 2));
+ $subtasks = $subtaskModel->getAll(2);
$this->assertNotFalse($subtasks);
$this->assertNotEmpty($subtasks);
@@ -385,4 +383,18 @@ class SubtaskTest extends Base
$this->assertEquals(2, $task['time_spent']);
$this->assertEquals(3, $task['time_estimated']);
}
+
+ public function testGetProjectId()
+ {
+ $taskCreationModel = new TaskCreationModel($this->container);
+ $subtaskModel = new SubtaskModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1)));
+ $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1)));
+
+ $this->assertEquals(1, $subtaskModel->getProjectId(1));
+ $this->assertEquals(0, $subtaskModel->getProjectId(2));
+ }
}
diff --git a/tests/units/Model/TaskFileTest.php b/tests/units/Model/TaskFileModelTest.php
index 2faee95c..de12553f 100644
--- a/tests/units/Model/TaskFileTest.php
+++ b/tests/units/Model/TaskFileModelTest.php
@@ -6,7 +6,7 @@ use Kanboard\Model\TaskFileModel;
use Kanboard\Model\TaskCreationModel;
use Kanboard\Model\ProjectModel;
-class TaskFileTest extends Base
+class TaskFileModelTest extends Base
{
public function testCreation()
{
@@ -442,4 +442,17 @@ class TaskFileTest extends Base
$this->assertTrue($fileModel->removeAll(1));
}
+
+ public function testGetProjectId()
+ {
+ $projectModel = new ProjectModel($this->container);
+ $fileModel = new TaskFileModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
+ $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foobar', 10));
+ $this->assertEquals(1, $fileModel->getProjectId(1));
+ $this->assertEquals(0, $fileModel->getProjectId(2));
+ }
}
diff --git a/tests/units/Model/TaskLinkModelTest.php b/tests/units/Model/TaskLinkModelTest.php
new file mode 100644
index 00000000..78590891
--- /dev/null
+++ b/tests/units/Model/TaskLinkModelTest.php
@@ -0,0 +1,211 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Model\TaskFinderModel;
+use Kanboard\Model\TaskLinkModel;
+use Kanboard\Model\TaskCreationModel;
+use Kanboard\Model\ProjectModel;
+
+class TaskLinkModelTest extends Base
+{
+ // Check postgres issue: "Cardinality violation: 7 ERROR: more than one row returned by a subquery used as an expression"
+ public function testGetTaskWithMultipleMilestoneLink()
+ {
+ $taskFinderModel = new TaskFinderModel($this->container);
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C')));
+
+ $this->assertNotFalse($taskLinkModel->create(1, 2, 9));
+ $this->assertNotFalse($taskLinkModel->create(1, 3, 9));
+
+ $task = $taskFinderModel->getExtendedQuery()->findOne();
+ $this->assertNotEmpty($task);
+ }
+
+ public function testCreateTaskLinkWithNoOpposite()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 1));
+
+ $links = $taskLinkModel->getAll(1);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('relates to', $links[0]['label']);
+ $this->assertEquals('B', $links[0]['title']);
+ $this->assertEquals(2, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $links = $taskLinkModel->getAll(2);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('relates to', $links[0]['label']);
+ $this->assertEquals('A', $links[0]['title']);
+ $this->assertEquals(1, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $task_link = $taskLinkModel->getById(1);
+ $this->assertNotEmpty($task_link);
+ $this->assertEquals(1, $task_link['id']);
+ $this->assertEquals(1, $task_link['task_id']);
+ $this->assertEquals(2, $task_link['opposite_task_id']);
+ $this->assertEquals(1, $task_link['link_id']);
+
+ $opposite_task_link = $taskLinkModel->getOppositeTaskLink($task_link);
+ $this->assertNotEmpty($opposite_task_link);
+ $this->assertEquals(2, $opposite_task_link['id']);
+ $this->assertEquals(2, $opposite_task_link['task_id']);
+ $this->assertEquals(1, $opposite_task_link['opposite_task_id']);
+ $this->assertEquals(1, $opposite_task_link['link_id']);
+ }
+
+ public function testCreateTaskLinkWithOpposite()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
+
+ $links = $taskLinkModel->getAll(1);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('blocks', $links[0]['label']);
+ $this->assertEquals('B', $links[0]['title']);
+ $this->assertEquals(2, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $links = $taskLinkModel->getAll(2);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('is blocked by', $links[0]['label']);
+ $this->assertEquals('A', $links[0]['title']);
+ $this->assertEquals(1, $links[0]['task_id']);
+ $this->assertEquals(1, $links[0]['is_active']);
+
+ $task_link = $taskLinkModel->getById(1);
+ $this->assertNotEmpty($task_link);
+ $this->assertEquals(1, $task_link['id']);
+ $this->assertEquals(1, $task_link['task_id']);
+ $this->assertEquals(2, $task_link['opposite_task_id']);
+ $this->assertEquals(2, $task_link['link_id']);
+
+ $opposite_task_link = $taskLinkModel->getOppositeTaskLink($task_link);
+ $this->assertNotEmpty($opposite_task_link);
+ $this->assertEquals(2, $opposite_task_link['id']);
+ $this->assertEquals(2, $opposite_task_link['task_id']);
+ $this->assertEquals(1, $opposite_task_link['opposite_task_id']);
+ $this->assertEquals(3, $opposite_task_link['link_id']);
+ }
+
+ public function testGroupByLabel()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C')));
+
+ $this->assertNotFalse($taskLinkModel->create(1, 2, 2));
+ $this->assertNotFalse($taskLinkModel->create(1, 3, 2));
+
+ $links = $taskLinkModel->getAllGroupedByLabel(1);
+ $this->assertCount(1, $links);
+ $this->assertArrayHasKey('blocks', $links);
+ $this->assertCount(2, $links['blocks']);
+ $this->assertEquals('test', $links['blocks'][0]['project_name']);
+ $this->assertEquals('Backlog', $links['blocks'][0]['column_title']);
+ $this->assertEquals('blocks', $links['blocks'][0]['label']);
+ }
+
+ public function testUpdate()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
+ $this->assertEquals(2, $projectModel->create(array('name' => 'test2')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 2, 'title' => 'B')));
+ $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'C')));
+
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 5));
+ $this->assertTrue($taskLinkModel->update(1, 1, 3, 11));
+
+ $links = $taskLinkModel->getAll(1);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('is fixed by', $links[0]['label']);
+ $this->assertEquals('C', $links[0]['title']);
+ $this->assertEquals(3, $links[0]['task_id']);
+
+ $links = $taskLinkModel->getAll(2);
+ $this->assertEmpty($links);
+
+ $links = $taskLinkModel->getAll(3);
+ $this->assertNotEmpty($links);
+ $this->assertCount(1, $links);
+ $this->assertEquals('fixes', $links[0]['label']);
+ $this->assertEquals('A', $links[0]['title']);
+ $this->assertEquals(1, $links[0]['task_id']);
+ }
+
+ public function testRemove()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
+
+ $links = $taskLinkModel->getAll(1);
+ $this->assertNotEmpty($links);
+ $links = $taskLinkModel->getAll(2);
+ $this->assertNotEmpty($links);
+
+ $this->assertTrue($taskLinkModel->remove($links[0]['id']));
+
+ $links = $taskLinkModel->getAll(1);
+ $this->assertEmpty($links);
+ $links = $taskLinkModel->getAll(2);
+ $this->assertEmpty($links);
+ }
+
+ public function testGetProjectId()
+ {
+ $taskLinkModel = new TaskLinkModel($this->container);
+ $projectModel = new ProjectModel($this->container);
+ $taskCreationModel = new TaskCreationModel($this->container);
+
+ $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
+ $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'A')));
+ $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'B')));
+ $this->assertEquals(1, $taskLinkModel->create(1, 2, 2));
+
+ $this->assertEquals(1, $taskLinkModel->getProjectId(1));
+ $this->assertEquals(0, $taskLinkModel->getProjectId(42));
+ }
+}
diff --git a/tests/units/Model/TaskLinkTest.php b/tests/units/Model/TaskLinkTest.php
deleted file mode 100644
index bc574731..00000000
--- a/tests/units/Model/TaskLinkTest.php
+++ /dev/null
@@ -1,196 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskFinderModel;
-use Kanboard\Model\TaskLinkModel;
-use Kanboard\Model\TaskCreationModel;
-use Kanboard\Model\ProjectModel;
-
-class TaskLinkTest extends Base
-{
- // Check postgres issue: "Cardinality violation: 7 ERROR: more than one row returned by a subquery used as an expression"
- public function testGetTaskWithMultipleMilestoneLink()
- {
- $tf = new TaskFinderModel($this->container);
- $tl = new TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
- $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C')));
-
- $this->assertNotFalse($tl->create(1, 2, 9));
- $this->assertNotFalse($tl->create(1, 3, 9));
-
- $task = $tf->getExtendedQuery()->findOne();
- $this->assertNotEmpty($task);
- }
-
- public function testCreateTaskLinkWithNoOpposite()
- {
- $tl = new TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
- $this->assertEquals(1, $tl->create(1, 2, 1));
-
- $links = $tl->getAll(1);
- $this->assertNotEmpty($links);
- $this->assertCount(1, $links);
- $this->assertEquals('relates to', $links[0]['label']);
- $this->assertEquals('B', $links[0]['title']);
- $this->assertEquals(2, $links[0]['task_id']);
- $this->assertEquals(1, $links[0]['is_active']);
-
- $links = $tl->getAll(2);
- $this->assertNotEmpty($links);
- $this->assertCount(1, $links);
- $this->assertEquals('relates to', $links[0]['label']);
- $this->assertEquals('A', $links[0]['title']);
- $this->assertEquals(1, $links[0]['task_id']);
- $this->assertEquals(1, $links[0]['is_active']);
-
- $task_link = $tl->getById(1);
- $this->assertNotEmpty($task_link);
- $this->assertEquals(1, $task_link['id']);
- $this->assertEquals(1, $task_link['task_id']);
- $this->assertEquals(2, $task_link['opposite_task_id']);
- $this->assertEquals(1, $task_link['link_id']);
-
- $opposite_task_link = $tl->getOppositeTaskLink($task_link);
- $this->assertNotEmpty($opposite_task_link);
- $this->assertEquals(2, $opposite_task_link['id']);
- $this->assertEquals(2, $opposite_task_link['task_id']);
- $this->assertEquals(1, $opposite_task_link['opposite_task_id']);
- $this->assertEquals(1, $opposite_task_link['link_id']);
- }
-
- public function testCreateTaskLinkWithOpposite()
- {
- $tl = new TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
- $this->assertEquals(1, $tl->create(1, 2, 2));
-
- $links = $tl->getAll(1);
- $this->assertNotEmpty($links);
- $this->assertCount(1, $links);
- $this->assertEquals('blocks', $links[0]['label']);
- $this->assertEquals('B', $links[0]['title']);
- $this->assertEquals(2, $links[0]['task_id']);
- $this->assertEquals(1, $links[0]['is_active']);
-
- $links = $tl->getAll(2);
- $this->assertNotEmpty($links);
- $this->assertCount(1, $links);
- $this->assertEquals('is blocked by', $links[0]['label']);
- $this->assertEquals('A', $links[0]['title']);
- $this->assertEquals(1, $links[0]['task_id']);
- $this->assertEquals(1, $links[0]['is_active']);
-
- $task_link = $tl->getById(1);
- $this->assertNotEmpty($task_link);
- $this->assertEquals(1, $task_link['id']);
- $this->assertEquals(1, $task_link['task_id']);
- $this->assertEquals(2, $task_link['opposite_task_id']);
- $this->assertEquals(2, $task_link['link_id']);
-
- $opposite_task_link = $tl->getOppositeTaskLink($task_link);
- $this->assertNotEmpty($opposite_task_link);
- $this->assertEquals(2, $opposite_task_link['id']);
- $this->assertEquals(2, $opposite_task_link['task_id']);
- $this->assertEquals(1, $opposite_task_link['opposite_task_id']);
- $this->assertEquals(3, $opposite_task_link['link_id']);
- }
-
- public function testGroupByLabel()
- {
- $tl = new TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
-
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
- $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C')));
-
- $this->assertNotFalse($tl->create(1, 2, 2));
- $this->assertNotFalse($tl->create(1, 3, 2));
-
- $links = $tl->getAllGroupedByLabel(1);
- $this->assertCount(1, $links);
- $this->assertArrayHasKey('blocks', $links);
- $this->assertCount(2, $links['blocks']);
- $this->assertEquals('test', $links['blocks'][0]['project_name']);
- $this->assertEquals('Backlog', $links['blocks'][0]['column_title']);
- $this->assertEquals('blocks', $links['blocks'][0]['label']);
- }
-
- public function testUpdate()
- {
- $tl = new TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test1')));
- $this->assertEquals(2, $p->create(array('name' => 'test2')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
- $this->assertEquals(2, $tc->create(array('project_id' => 2, 'title' => 'B')));
- $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'C')));
-
- $this->assertEquals(1, $tl->create(1, 2, 5));
- $this->assertTrue($tl->update(1, 1, 3, 11));
-
- $links = $tl->getAll(1);
- $this->assertNotEmpty($links);
- $this->assertCount(1, $links);
- $this->assertEquals('is fixed by', $links[0]['label']);
- $this->assertEquals('C', $links[0]['title']);
- $this->assertEquals(3, $links[0]['task_id']);
-
- $links = $tl->getAll(2);
- $this->assertEmpty($links);
-
- $links = $tl->getAll(3);
- $this->assertNotEmpty($links);
- $this->assertCount(1, $links);
- $this->assertEquals('fixes', $links[0]['label']);
- $this->assertEquals('A', $links[0]['title']);
- $this->assertEquals(1, $links[0]['task_id']);
- }
-
- public function testRemove()
- {
- $tl = new TaskLinkModel($this->container);
- $p = new ProjectModel($this->container);
- $tc = new TaskCreationModel($this->container);
-
- $this->assertEquals(1, $p->create(array('name' => 'test')));
- $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A')));
- $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B')));
- $this->assertEquals(1, $tl->create(1, 2, 2));
-
- $links = $tl->getAll(1);
- $this->assertNotEmpty($links);
- $links = $tl->getAll(2);
- $this->assertNotEmpty($links);
-
- $this->assertTrue($tl->remove($links[0]['id']));
-
- $links = $tl->getAll(1);
- $this->assertEmpty($links);
- $links = $tl->getAll(2);
- $this->assertEmpty($links);
- }
-}