Added application and project roles validation for API procedure calls
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
@@ -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;
|
||||
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
@@ -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();
|
||||
@@ -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;
|
||||
@@ -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';
|
||||
@@ -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()
|
||||
{
|
||||
@@ -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()
|
||||
{
|
||||
@@ -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()
|
||||
@@ -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';
|
||||
|
||||
306
tests/integration/ProcedureAuthorizationTest.php
Normal file
306
tests/integration/ProcedureAuthorizationTest.php
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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';
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
211
tests/units/Model/TaskLinkModelTest.php
Normal file
211
tests/units/Model/TaskLinkModelTest.php
Normal file
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user