summaryrefslogtreecommitdiff
path: root/tests/units
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-04 21:51:38 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-04 21:51:38 -0400
commit6bdc25490f02649242b1d96025f8da1f4c41884b (patch)
treeab30b54786c0c08f85facb6d0703f7837b4bc471 /tests/units
parent60c8867feeeefcf160fb1432419887f17a0d957b (diff)
Unify task drop-down menu between different views
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/Helper/UserHelperTest.php94
-rw-r--r--tests/units/Model/TaskPermissionTest.php103
2 files changed, 94 insertions, 103 deletions
diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php
index 9a9832b2..135f8ca6 100644
--- a/tests/units/Helper/UserHelperTest.php
+++ b/tests/units/Helper/UserHelperTest.php
@@ -2,11 +2,15 @@
require_once __DIR__.'/../Base.php';
+use Kanboard\Core\User\UserSession;
use Kanboard\Helper\UserHelper;
use Kanboard\Model\Project;
use Kanboard\Model\ProjectUserRole;
+use Kanboard\Model\TaskCreation;
+use Kanboard\Model\TaskFinder;
use Kanboard\Model\User as UserModel;
use Kanboard\Core\Security\Role;
+use Kanboard\Model\User;
class UserHelperTest extends Base
{
@@ -228,4 +232,94 @@ class UserHelperTest extends Base
$this->assertFalse($helper->hasProjectAccess('task', 'show', 2));
$this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 2));
}
+
+ public function testCanRemoveTask()
+ {
+ $taskCreationModel = new TaskCreation($this->container);
+ $taskFinderModel = new TaskFinder($this->container);
+ $helper = new UserHelper($this->container);
+ $projectModel = new Project($this->container);
+ $userModel = new User($this->container);
+ $userSessionModel = new UserSession($this->container);
+
+ $this->assertNotFalse($userModel->create(array('username' => 'toto', 'password' => '123456')));
+ $this->assertNotFalse($userModel->create(array('username' => 'toto2', 'password' => '123456')));
+ $this->assertEquals(1, $projectModel->create(array('name' => 'Project #1')));
+ $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Task #1', 'project_id' => 1, 'creator_id' => 1)));
+ $this->assertEquals(2, $taskCreationModel->create(array('title' => 'Task #2', 'project_id' => 1, 'creator_id' => 2)));
+ $this->assertEquals(3, $taskCreationModel->create(array('title' => 'Task #3', 'project_id' => 1, 'creator_id' => 3)));
+ $this->assertEquals(4, $taskCreationModel->create(array('title' => 'Task #4', 'project_id' => 1)));
+
+ // User #1 can remove everything
+ $user = $userModel->getById(1);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertTrue($helper->canRemoveTask($task));
+
+ // User #2 can't remove the task #1
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(1);
+ $this->assertNotEmpty($task);
+ $this->assertFalse($helper->canRemoveTask($task));
+
+ // User #1 can remove everything
+ $user = $userModel->getById(1);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertTrue($helper->canRemoveTask($task));
+
+ // User #2 can remove his own task
+ $user = $userModel->getbyId(2);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertTrue($helper->canRemoveTask($task));
+
+ // User #1 can remove everything
+ $user = $userModel->getById(1);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertTrue($helper->canRemoveTask($task));
+
+ // User #2 can't remove the task #3
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(3);
+ $this->assertNotEmpty($task);
+ $this->assertFalse($helper->canRemoveTask($task));
+
+ // User #1 can remove everything
+ $user = $userModel->getById(1);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(4);
+ $this->assertNotEmpty($task);
+ $this->assertTrue($helper->canRemoveTask($task));
+
+ // User #2 can't remove the task #4
+ $user = $userModel->getById(2);
+ $this->assertNotEmpty($user);
+ $userSessionModel->initialize($user);
+
+ $task = $taskFinderModel->getById(4);
+ $this->assertNotEmpty($task);
+ $this->assertFalse($helper->canRemoveTask($task));
+ }
}
diff --git a/tests/units/Model/TaskPermissionTest.php b/tests/units/Model/TaskPermissionTest.php
deleted file mode 100644
index 82cd581e..00000000
--- a/tests/units/Model/TaskPermissionTest.php
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Model\TaskCreation;
-use Kanboard\Model\TaskFinder;
-use Kanboard\Model\TaskPermission;
-use Kanboard\Model\Project;
-use Kanboard\Model\User;
-use Kanboard\Core\User\UserSession;
-
-class TaskPermissionTest extends Base
-{
- public function testPrepareCreation()
- {
- $tc = new TaskCreation($this->container);
- $tf = new TaskFinder($this->container);
- $tp = new TaskPermission($this->container);
- $p = new Project($this->container);
- $u = new User($this->container);
- $us = new UserSession($this->container);
-
- $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456')));
- $this->assertNotFalse($u->create(array('username' => 'toto2', 'password' => '123456')));
- $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
- $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'creator_id' => 1)));
- $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'creator_id' => 2)));
- $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'creator_id' => 3)));
- $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1)));
-
- // User #1 can remove everything
- $user = $u->getbyId(1);
- $this->assertNotEmpty($user);
- $us->initialize($user);
-
- $task = $tf->getbyId(1);
- $this->assertNotEmpty($task);
- $this->assertTrue($tp->canRemoveTask($task));
-
- // User #2 can't remove the task #1
- $user = $u->getbyId(2);
- $this->assertNotEmpty($user);
- $us->initialize($user);
-
- $task = $tf->getbyId(1);
- $this->assertNotEmpty($task);
- $this->assertFalse($tp->canRemoveTask($task));
-
- // User #1 can remove everything
- $user = $u->getbyId(1);
- $this->assertNotEmpty($user);
- $us->initialize($user);
-
- $task = $tf->getbyId(2);
- $this->assertNotEmpty($task);
- $this->assertTrue($tp->canRemoveTask($task));
-
- // User #2 can remove his own task
- $user = $u->getbyId(2);
- $this->assertNotEmpty($user);
- $us->initialize($user);
-
- $task = $tf->getbyId(2);
- $this->assertNotEmpty($task);
- $this->assertTrue($tp->canRemoveTask($task));
-
- // User #1 can remove everything
- $user = $u->getbyId(1);
- $this->assertNotEmpty($user);
- $us->initialize($user);
-
- $task = $tf->getbyId(3);
- $this->assertNotEmpty($task);
- $this->assertTrue($tp->canRemoveTask($task));
-
- // User #2 can't remove the task #3
- $user = $u->getbyId(2);
- $this->assertNotEmpty($user);
- $us->initialize($user);
-
- $task = $tf->getbyId(3);
- $this->assertNotEmpty($task);
- $this->assertFalse($tp->canRemoveTask($task));
-
- // User #1 can remove everything
- $user = $u->getbyId(1);
- $this->assertNotEmpty($user);
- $us->initialize($user);
-
- $task = $tf->getbyId(4);
- $this->assertNotEmpty($task);
- $this->assertTrue($tp->canRemoveTask($task));
-
- // User #2 can't remove the task #4
- $user = $u->getbyId(2);
- $this->assertNotEmpty($user);
- $us->initialize($user);
-
- $task = $tf->getbyId(4);
- $this->assertNotEmpty($task);
- $this->assertFalse($tp->canRemoveTask($task));
- }
-}