Added application and project roles validation for API procedure calls
This commit is contained in:
@@ -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