diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-12-31 12:37:15 -0500 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-12-31 12:37:15 -0500 |
commit | 772804add8095eea9b3ec2a832c2f82fbb9a6fd5 (patch) | |
tree | 782a414d15f9091d04bcf3960a957f952958e548 /tests | |
parent | 66f150d887a34d2b51ff14f22d0fd41a34f8cc77 (diff) |
Acl refactoring
Diffstat (limited to 'tests')
-rw-r--r-- | tests/units/AclTest.php | 253 | ||||
-rw-r--r-- | tests/units/ActionTaskAssignCurrentUserTest.php | 6 | ||||
-rw-r--r-- | tests/units/HelperTest.php | 2 | ||||
-rw-r--r-- | tests/units/NotificationTest.php | 26 | ||||
-rw-r--r-- | tests/units/ProjectPermissionTest.php | 62 | ||||
-rw-r--r-- | tests/units/TaskDuplicationTest.php | 12 | ||||
-rw-r--r-- | tests/units/TaskExportTest.php | 1 | ||||
-rw-r--r-- | tests/units/UserSessionTest.php | 45 |
8 files changed, 300 insertions, 107 deletions
diff --git a/tests/units/AclTest.php b/tests/units/AclTest.php index 99d1a849..3c18beae 100644 --- a/tests/units/AclTest.php +++ b/tests/units/AclTest.php @@ -2,111 +2,222 @@ require_once __DIR__.'/Base.php'; +use Core\Session; use Model\Acl; +use Model\Project; +use Model\ProjectPermission; +use Model\User; class AclTest extends Base { - public function testAllowedAction() + public function testMatchAcl() { $acl_rules = array( 'controller1' => array('action1', 'action3'), + 'controller3' => '*', + 'controller5' => '-', + 'controller6' => array(), ); $acl = new Acl($this->container); - $this->assertTrue($acl->isAllowedAction($acl_rules, 'controller1', 'action1')); - $this->assertTrue($acl->isAllowedAction($acl_rules, 'controller1', 'action3')); - $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller1', 'action2')); - $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller2', 'action2')); - $this->assertFalse($acl->isAllowedAction($acl_rules, 'controller2', 'action3')); + $this->assertTrue($acl->matchAcl($acl_rules, 'controller1', 'aCtiOn1')); + $this->assertTrue($acl->matchAcl($acl_rules, 'controller1', 'action1')); + $this->assertTrue($acl->matchAcl($acl_rules, 'controller1', 'action3')); + $this->assertFalse($acl->matchAcl($acl_rules, 'controller1', 'action2')); + $this->assertFalse($acl->matchAcl($acl_rules, 'controller2', 'action2')); + $this->assertFalse($acl->matchAcl($acl_rules, 'controller2', 'action3')); + $this->assertTrue($acl->matchAcl($acl_rules, 'controller3', 'anything')); + $this->assertFalse($acl->matchAcl($acl_rules, 'controller4', 'anything')); + $this->assertFalse($acl->matchAcl($acl_rules, 'controller5', 'anything')); + $this->assertFalse($acl->matchAcl($acl_rules, 'controller6', 'anything')); } - public function testIsAdmin() + public function testPublicActions() { $acl = new Acl($this->container); + $this->assertTrue($acl->isPublicAction('board', 'readonly')); + $this->assertFalse($acl->isPublicAction('board', 'show')); + } + + public function testAdminActions() + { + $acl = new Acl($this->container); + $this->assertFalse($acl->isAdminAction('board', 'show')); + $this->assertFalse($acl->isAdminAction('task', 'show')); + $this->assertTrue($acl->isAdminAction('config', 'api')); + $this->assertTrue($acl->isAdminAction('config', 'anything')); + $this->assertTrue($acl->isAdminAction('config', 'anything')); + $this->assertTrue($acl->isAdminAction('user', 'save')); + } - $_SESSION = array(); - $this->assertFalse($acl->isAdminUser()); + public function testManagerActions() + { + $acl = new Acl($this->container); + $this->assertFalse($acl->isManagerAction('board', 'readonly')); + $this->assertFalse($acl->isManagerAction('project', 'remove')); + $this->assertFalse($acl->isManagerAction('project', 'show')); + $this->assertTrue($acl->isManagerAction('project', 'disable')); + $this->assertTrue($acl->isManagerAction('category', 'index')); + $this->assertTrue($acl->isManagerAction('project', 'users')); + $this->assertTrue($acl->isManagerAction('task', 'remove')); + $this->assertFalse($acl->isManagerAction('app', 'index')); + } + + public function testPageAccessNoSession() + { + $acl = new Acl($this->container); + $this->assertFalse($acl->isAllowed('board', 'readonly')); + $this->assertFalse($acl->isAllowed('task', 'show')); + $this->assertFalse($acl->isAllowed('config', 'application')); + $this->assertFalse($acl->isAllowed('project', 'users')); + $this->assertFalse($acl->isAllowed('task', 'remove')); + $this->assertTrue($acl->isAllowed('app', 'index')); + } + + public function testPageAccessEmptySession() + { + $acl = new Acl($this->container); + $session = new Session; - $_SESSION = array('user' => array()); - $this->assertFalse($acl->isAdminUser()); + $session['user'] = array(); - $_SESSION = array('user' => array('is_admin' => '1')); - $this->assertFalse($acl->isAdminUser()); + $this->assertFalse($acl->isAllowed('board', 'readonly')); + $this->assertFalse($acl->isAllowed('task', 'show')); + $this->assertFalse($acl->isAllowed('config', 'application')); + $this->assertFalse($acl->isAllowed('project', 'users')); + $this->assertFalse($acl->isAllowed('task', 'remove')); + $this->assertTrue($acl->isAllowed('app', 'index')); + } - $_SESSION = array('user' => array('is_admin' => false)); - $this->assertFalse($acl->isAdminUser()); + public function testPageAccessAdminUser() + { + $acl = new Acl($this->container); + $session = new Session; - $_SESSION = array('user' => array('is_admin' => '2')); - $this->assertFalse($acl->isAdminUser()); + $session['user'] = array( + 'is_admin' => true, + ); - $_SESSION = array('user' => array('is_admin' => true)); - $this->assertTrue($acl->isAdminUser()); + $this->assertTrue($acl->isAllowed('board', 'readonly')); + $this->assertTrue($acl->isAllowed('task', 'readonly')); + $this->assertTrue($acl->isAllowed('webhook', 'github')); + $this->assertTrue($acl->isAllowed('task', 'show')); + $this->assertTrue($acl->isAllowed('task', 'update')); + $this->assertTrue($acl->isAllowed('project', 'show')); + $this->assertTrue($acl->isAllowed('config', 'application')); + $this->assertTrue($acl->isAllowed('project', 'users')); + $this->assertTrue($acl->isAllowed('category', 'edit')); + $this->assertTrue($acl->isAllowed('task', 'remove')); + $this->assertTrue($acl->isAllowed('app', 'index')); } - public function testIsUser() + public function testPageAccessManager() { $acl = new Acl($this->container); + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $u = new User($this->container); + $session = new Session; + + // We create our user + $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); + + // We create a project and set our user as project manager + $this->assertEquals(1, $p->create(array('name' => 'UnitTest'), 2, true)); + $this->assertTrue($pp->isMember(1, 2)); + $this->assertTrue($pp->isManager(1, 2)); + + // We fake a session for him + $session['user'] = array( + 'id' => 2, + 'is_admin' => false, + ); - $_SESSION = array(); - $this->assertFalse($acl->isRegularUser()); + $this->assertTrue($acl->isAllowed('board', 'readonly', 1)); + $this->assertTrue($acl->isAllowed('task', 'readonly', 1)); + $this->assertTrue($acl->isAllowed('webhook', 'github', 1)); + $this->assertTrue($acl->isAllowed('task', 'show', 1)); + $this->assertFalse($acl->isAllowed('task', 'show', 2)); + $this->assertTrue($acl->isAllowed('task', 'update', 1)); + $this->assertTrue($acl->isAllowed('project', 'show', 1)); + $this->assertFalse($acl->isAllowed('config', 'application', 1)); + $this->assertTrue($acl->isAllowed('project', 'users', 1)); + $this->assertFalse($acl->isAllowed('project', 'users', 2)); + $this->assertTrue($acl->isAllowed('category', 'edit', 1)); + $this->assertTrue($acl->isAllowed('task', 'remove', 1)); + $this->assertTrue($acl->isAllowed('app', 'index', 1)); + } - $_SESSION = array('user' => array()); - $this->assertFalse($acl->isRegularUser()); + public function testPageAccessMember() + { + $acl = new Acl($this->container); + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $u = new User($this->container); - $_SESSION = array('user' => array('is_admin' => true)); - $this->assertFalse($acl->isRegularUser()); + // We create our user + $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - $_SESSION = array('user' => array('is_admin' => true)); - $this->assertFalse($acl->isRegularUser()); + // We create a project and set our user as member + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); + $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); + $this->assertTrue($pp->addMember(1, 2)); + $this->assertTrue($pp->isMember(1, 2)); + $this->assertFalse($pp->isManager(1, 2)); - $_SESSION = array('user' => array('is_admin' => '2')); - $this->assertFalse($acl->isRegularUser()); + $session = new Session; - $_SESSION = array('user' => array('is_admin' => false)); - $this->assertTrue($acl->isRegularUser()); + $session['user'] = array( + 'id' => 2, + 'is_admin' => false, + ); + + $this->assertTrue($acl->isAllowed('board', 'readonly', 1)); + $this->assertTrue($acl->isAllowed('task', 'readonly', 1)); + $this->assertTrue($acl->isAllowed('webhook', 'github', 1)); + $this->assertFalse($acl->isAllowed('board', 'show', 2)); + $this->assertTrue($acl->isAllowed('board', 'show', 1)); + $this->assertFalse($acl->isAllowed('task', 'show', 2)); + $this->assertTrue($acl->isAllowed('task', 'show', 1)); + $this->assertTrue($acl->isAllowed('task', 'update', 1)); + $this->assertTrue($acl->isAllowed('project', 'show', 1)); + $this->assertFalse($acl->isAllowed('config', 'application', 1)); + $this->assertFalse($acl->isAllowed('project', 'users', 1)); + $this->assertFalse($acl->isAllowed('task', 'remove', 1)); + $this->assertTrue($acl->isAllowed('app', 'index', 1)); } - public function testIsPageAllowed() + public function testPageAccessNotMember() { $acl = new Acl($this->container); + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $u = new User($this->container); + + // We create our user + $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); + + // We create a project and set our user as member + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); + $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); + $this->assertFalse($pp->isMember(1, 2)); + $this->assertFalse($pp->isManager(1, 2)); + + $session = new Session; + + $session['user'] = array( + 'id' => 2, + 'is_admin' => false, + ); - // Public access - $_SESSION = array(); - $this->assertFalse($acl->isPageAccessAllowed('user', 'create')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'save')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'remove')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'confirm')); - $this->assertFalse($acl->isPageAccessAllowed('app', 'index')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'index')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'login')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'check')); - $this->assertTrue($acl->isPageAccessAllowed('webhook', 'task')); - $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly')); - - // Regular user - $_SESSION = array('user' => array('is_admin' => false)); - $this->assertFalse($acl->isPageAccessAllowed('user', 'create')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'save')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'remove')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'confirm')); - $this->assertTrue($acl->isPageAccessAllowed('app', 'index')); - $this->assertFalse($acl->isPageAccessAllowed('user', 'index')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'login')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'check')); - $this->assertTrue($acl->isPageAccessAllowed('webhook', 'task')); - $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly')); - - // Admin user - $_SESSION = array('user' => array('is_admin' => true)); - $this->assertTrue($acl->isPageAccessAllowed('user', 'create')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'save')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'remove')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'confirm')); - $this->assertTrue($acl->isPageAccessAllowed('app', 'index')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'index')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'login')); - $this->assertTrue($acl->isPageAccessAllowed('user', 'check')); - $this->assertTrue($acl->isPageAccessAllowed('task', 'add')); - $this->assertTrue($acl->isPageAccessAllowed('board', 'readonly')); + $this->assertFalse($acl->isAllowed('board', 'show', 2)); + $this->assertFalse($acl->isAllowed('board', 'show', 1)); + $this->assertFalse($acl->isAllowed('task', 'show', 1)); + $this->assertFalse($acl->isAllowed('task', 'update', 1)); + $this->assertFalse($acl->isAllowed('project', 'show', 1)); + $this->assertFalse($acl->isAllowed('config', 'application', 1)); + $this->assertFalse($acl->isAllowed('project', 'users', 1)); + $this->assertFalse($acl->isAllowed('task', 'remove', 1)); + $this->assertTrue($acl->isAllowed('app', 'index', 1)); } } diff --git a/tests/units/ActionTaskAssignCurrentUserTest.php b/tests/units/ActionTaskAssignCurrentUserTest.php index 374277ce..f32fc77c 100644 --- a/tests/units/ActionTaskAssignCurrentUserTest.php +++ b/tests/units/ActionTaskAssignCurrentUserTest.php @@ -7,7 +7,7 @@ use Model\Task; use Model\TaskCreation; use Model\TaskFinder; use Model\Project; -use Model\Acl; +use Model\UserSession; class ActionTaskAssignCurrentUser extends Base { @@ -52,9 +52,9 @@ class ActionTaskAssignCurrentUser extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); - $a = new Acl($this->container); + $us = new UserSession($this->container); - $this->assertEquals(5, $a->getUserId()); + $this->assertEquals(5, $us->getId()); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); diff --git a/tests/units/HelperTest.php b/tests/units/HelperTest.php index 72f84a24..2ae75684 100644 --- a/tests/units/HelperTest.php +++ b/tests/units/HelperTest.php @@ -13,7 +13,7 @@ class HelperTest extends Base $this->assertEquals('<p>Test</p>', $h->markdown('Test')); $this->assertEquals( - '<p>Task <a href="?controller=task&action=show&task_id=123" class="" title="" >#123</a></p>', + '<p>Task #123</p>', $h->markdown('Task #123') ); diff --git a/tests/units/NotificationTest.php b/tests/units/NotificationTest.php index d8e623e1..37285212 100644 --- a/tests/units/NotificationTest.php +++ b/tests/units/NotificationTest.php @@ -35,10 +35,10 @@ class NotificationTest extends Base $this->assertEmpty($n->getUsersWithNotification(1)); // We allow all users to be member of our projects - $this->assertTrue($pp->allowUser(1, 1)); - $this->assertTrue($pp->allowUser(1, 2)); - $this->assertTrue($pp->allowUser(1, 3)); - $this->assertTrue($pp->allowUser(1, 4)); + $this->assertTrue($pp->addMember(1, 1)); + $this->assertTrue($pp->addMember(1, 2)); + $this->assertTrue($pp->addMember(1, 3)); + $this->assertTrue($pp->addMember(1, 4)); $this->assertNotEmpty($pp->getMembers(1)); $users = $n->getUsersWithNotification(1); @@ -73,15 +73,15 @@ class NotificationTest extends Base $this->assertNotFalse($u->create(array('username' => 'user4'))); // We allow all users to be member of our projects - $this->assertTrue($pp->allowUser(1, 1)); - $this->assertTrue($pp->allowUser(1, 2)); - $this->assertTrue($pp->allowUser(1, 3)); - $this->assertTrue($pp->allowUser(1, 4)); - - $this->assertTrue($pp->allowUser(2, 1)); - $this->assertTrue($pp->allowUser(2, 2)); - $this->assertTrue($pp->allowUser(2, 3)); - $this->assertTrue($pp->allowUser(2, 4)); + $this->assertTrue($pp->addMember(1, 1)); + $this->assertTrue($pp->addMember(1, 2)); + $this->assertTrue($pp->addMember(1, 3)); + $this->assertTrue($pp->addMember(1, 4)); + + $this->assertTrue($pp->addMember(2, 1)); + $this->assertTrue($pp->addMember(2, 2)); + $this->assertTrue($pp->addMember(2, 3)); + $this->assertTrue($pp->addMember(2, 4)); $users = $n->getUsersList(1); $this->assertNotEmpty($users); diff --git a/tests/units/ProjectPermissionTest.php b/tests/units/ProjectPermissionTest.php index b169b63e..3cbd6bec 100644 --- a/tests/units/ProjectPermissionTest.php +++ b/tests/units/ProjectPermissionTest.php @@ -62,14 +62,14 @@ class ProjectPermissionTest extends Base $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); // We allow the admin user - $this->assertTrue($pp->allowUser(1, 1)); - $this->assertTrue($pp->allowUser(1, 2)); + $this->assertTrue($pp->addMember(1, 1)); + $this->assertTrue($pp->addMember(1, 2)); // Non-existant project - $this->assertFalse($pp->allowUser(50, 1)); + $this->assertFalse($pp->addMember(50, 1)); // Non-existant user - $this->assertFalse($pp->allowUser(1, 50)); + $this->assertFalse($pp->addMember(1, 50)); // Both users should be allowed $this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $pp->getMembers(1)); @@ -89,7 +89,7 @@ class ProjectPermissionTest extends Base $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); // We revoke our admin user (not existing row) - $this->assertFalse($pp->revokeUser(1, 1)); + $this->assertFalse($pp->revokeMember(1, 1)); // We should have nobody in the users list $this->assertEmpty($pp->getMembers(1)); @@ -99,7 +99,7 @@ class ProjectPermissionTest extends Base $this->assertFalse($pp->isUserAllowed(1, 2)); // We allow only the regular user - $this->assertTrue($pp->allowUser(1, 2)); + $this->assertTrue($pp->addMember(1, 2)); // All users should be allowed (admin and regular) $this->assertTrue($pp->isUserAllowed(1, 1)); @@ -109,13 +109,13 @@ class ProjectPermissionTest extends Base $this->assertEquals(array('2' => 'unittest'), $pp->getMembers(1)); // We allow our admin, we should have both in the list - $this->assertTrue($pp->allowUser(1, 1)); + $this->assertTrue($pp->addMember(1, 1)); $this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $pp->getMembers(1)); $this->assertTrue($pp->isUserAllowed(1, 1)); $this->assertTrue($pp->isUserAllowed(1, 2)); // We revoke the regular user - $this->assertTrue($pp->revokeUser(1, 2)); + $this->assertTrue($pp->revokeMember(1, 2)); // Only admin should be allowed $this->assertTrue($pp->isUserAllowed(1, 1)); @@ -125,7 +125,7 @@ class ProjectPermissionTest extends Base $this->assertEquals(array('1' => 'admin'), $pp->getMembers(1)); // We revoke the admin user - $this->assertTrue($pp->revokeUser(1, 1)); + $this->assertTrue($pp->revokeMember(1, 1)); $this->assertEmpty($pp->getMembers(1)); // Only admin should be allowed again @@ -133,6 +133,42 @@ class ProjectPermissionTest extends Base $this->assertFalse($pp->isUserAllowed(1, 2)); } + public function testManager() + { + $p = new Project($this->container); + $pp = new ProjectPermission($this->container); + $u = new User($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); + $this->assertFalse($pp->isMember(1, 2)); + $this->assertFalse($pp->isManager(1, 2)); + + $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'), 1, true)); + $this->assertFalse($pp->isMember(2, 2)); + $this->assertFalse($pp->isManager(2, 2)); + + $this->assertEquals(3, $p->create(array('name' => 'UnitTest3'), 2, true)); + $this->assertTrue($pp->isMember(3, 2)); + $this->assertTrue($pp->isManager(3, 2)); + + $this->assertEquals(4, $p->create(array('name' => 'UnitTest4'))); + + $this->assertTrue($pp->addManager(4, 2)); + $this->assertTrue($pp->isMember(4, 2)); + $this->assertTrue($pp->isManager(4, 2)); + + $this->assertEquals(5, $p->create(array('name' => 'UnitTest5'))); + $this->assertTrue($pp->addMember(5, 2)); + $this->assertTrue($pp->changeRole(5, 2, 1)); + $this->assertTrue($pp->isMember(5, 2)); + $this->assertTrue($pp->isManager(5, 2)); + $this->assertTrue($pp->changeRole(5, 2, 0)); + $this->assertTrue($pp->isMember(5, 2)); + $this->assertFalse($pp->isManager(5, 2)); + } + public function testUsersList() { $p = new Project($this->container); @@ -151,7 +187,7 @@ class ProjectPermissionTest extends Base ); // We allow only the regular user - $this->assertTrue($pp->allowUser(1, 2)); + $this->assertTrue($pp->addMember(1, 2)); $this->assertEquals( array(0 => 'Unassigned', 2 => 'unittest'), @@ -159,7 +195,7 @@ class ProjectPermissionTest extends Base ); // We allow the admin user - $this->assertTrue($pp->allowUser(1, 1)); + $this->assertTrue($pp->addMember(1, 1)); $this->assertEquals( array(0 => 'Unassigned', 1 => 'admin', 2 => 'unittest'), @@ -167,7 +203,7 @@ class ProjectPermissionTest extends Base ); // We revoke only the regular user - $this->assertTrue($pp->revokeUser(1, 2)); + $this->assertTrue($pp->revokeMember(1, 2)); $this->assertEquals( array(0 => 'Unassigned', 1 => 'admin'), @@ -175,7 +211,7 @@ class ProjectPermissionTest extends Base ); // We revoke only the admin user, we should have everybody - $this->assertTrue($pp->revokeUser(1, 1)); + $this->assertTrue($pp->revokeMember(1, 1)); $this->assertEquals( array(0 => 'Unassigned'), diff --git a/tests/units/TaskDuplicationTest.php b/tests/units/TaskDuplicationTest.php index 6f1ee0e2..bc455873 100644 --- a/tests/units/TaskDuplicationTest.php +++ b/tests/units/TaskDuplicationTest.php @@ -240,8 +240,8 @@ class TaskDuplicationTest extends Base // We create a new user for our project $user = new User($this->container); $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest'))); - $this->assertTrue($pp->allowUser(1, 2)); - $this->assertTrue($pp->allowUser(2, 2)); + $this->assertTrue($pp->addMember(1, 2)); + $this->assertTrue($pp->addMember(2, 2)); $this->assertTrue($pp->isUserAllowed(1, 2)); $this->assertTrue($pp->isUserAllowed(2, 2)); @@ -363,8 +363,8 @@ class TaskDuplicationTest extends Base // We create a new user for our project $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest'))); - $this->assertTrue($pp->allowUser(1, 2)); - $this->assertTrue($pp->allowUser(2, 2)); + $this->assertTrue($pp->addMember(1, 2)); + $this->assertTrue($pp->addMember(2, 2)); $this->assertTrue($pp->isUserAllowed(1, 2)); $this->assertTrue($pp->isUserAllowed(2, 2)); @@ -398,8 +398,8 @@ class TaskDuplicationTest extends Base // We create a new user for our project $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest'))); - $this->assertTrue($pp->allowUser(1, 2)); - $this->assertTrue($pp->allowUser(2, 2)); + $this->assertTrue($pp->addMember(1, 2)); + $this->assertTrue($pp->addMember(2, 2)); $this->assertTrue($pp->isUserAllowed(1, 2)); $this->assertTrue($pp->isUserAllowed(2, 2)); diff --git a/tests/units/TaskExportTest.php b/tests/units/TaskExportTest.php index 963c031d..3892f2bd 100644 --- a/tests/units/TaskExportTest.php +++ b/tests/units/TaskExportTest.php @@ -48,6 +48,7 @@ class TaskExportTest extends Base } $rows = $e->export(1, strtotime('-1 day'), strtotime('+1 day')); + $this->assertEquals($i, count($rows)); $this->assertEquals('Task Id', $rows[0][0]); $this->assertEquals(1, $rows[1][0]); diff --git a/tests/units/UserSessionTest.php b/tests/units/UserSessionTest.php new file mode 100644 index 00000000..45f1bfde --- /dev/null +++ b/tests/units/UserSessionTest.php @@ -0,0 +1,45 @@ +<?php + +require_once __DIR__.'/Base.php'; + +use Core\Session; +use Model\UserSession; + +class UserSessionTest extends Base +{ + public function testIsAdmin() + { + $s = new Session; + $us = new UserSession($this->container); + + $this->assertFalse($us->isAdmin()); + + $s['user'] = array(); + $this->assertFalse($us->isAdmin()); + + $s['user'] = array('is_admin' => '1'); + $this->assertFalse($us->isAdmin()); + + $s['user'] = array('is_admin' => false); + $this->assertFalse($us->isAdmin()); + + $s['user'] = array('is_admin' => '2'); + $this->assertFalse($us->isAdmin()); + + $s['user'] = array('is_admin' => true); + $this->assertTrue($us->isAdmin()); + } + + public function testLastSeenProject() + { + $us = new UserSession($this->container); + + $this->assertEquals(0, $us->getLastSeenProjectId()); + + $us->storeLastSeenProjectId(33); + $this->assertEquals(33, $us->getLastSeenProjectId()); + + $us->storeLastSeenProjectId(66); + $this->assertEquals(66, $us->getLastSeenProjectId()); + } +} |