From 486238b5485d61cdc4e66244632f91357d014059 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 12 Dec 2015 17:46:11 -0500 Subject: API: check project membership for task operations --- tests/functionals/ApiTest.php | 38 +++++++++++++++++++++++++++++--------- tests/functionals/UserApiTest.php | 11 +++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php index 9be22023..fbb703c9 100644 --- a/tests/functionals/ApiTest.php +++ b/tests/functionals/ApiTest.php @@ -366,6 +366,33 @@ class Api extends PHPUnit_Framework_TestCase $this->assertEquals('Swimlane A', $swimlanes[2]['name']); } + public function testCreateTaskWithWrongMember() + { + $task = array( + 'title' => 'Task #1', + 'color_id' => 'blue', + 'owner_id' => 1, + 'project_id' => 1, + 'column_id' => 2, + ); + + $task_id = $this->client->createTask($task); + + $this->assertFalse($task_id); + } + + public function testGetAllowedUsers() + { + $users = $this->client->getMembers(1); + $this->assertNotFalse($users); + $this->assertEquals(array(), $users); + } + + public function testAddMember() + { + $this->assertTrue($this->client->allowUser(1, 1)); + } + public function testCreateTask() { $task = array( @@ -573,20 +600,13 @@ class Api extends PHPUnit_Framework_TestCase $this->assertEquals('titi@localhost', $user['email']); } - public function testGetAllowedUsers() - { - $users = $this->client->getMembers(1); - $this->assertNotFalse($users); - $this->assertEquals(array(), $users); - } - public function testAllowedUser() { $this->assertTrue($this->client->allowUser(1, 2)); $users = $this->client->getMembers(1); $this->assertNotFalse($users); - $this->assertEquals(array(2 => 'Titi'), $users); + $this->assertEquals(array(1 => 'admin', 2 => 'Titi'), $users); } public function testRevokeUser() @@ -595,7 +615,7 @@ class Api extends PHPUnit_Framework_TestCase $users = $this->client->getMembers(1); $this->assertNotFalse($users); - $this->assertEquals(array(), $users); + $this->assertEquals(array(1 => 'admin'), $users); } public function testCreateComment() diff --git a/tests/functionals/UserApiTest.php b/tests/functionals/UserApiTest.php index 8a80c706..3c7fc04e 100644 --- a/tests/functionals/UserApiTest.php +++ b/tests/functionals/UserApiTest.php @@ -163,6 +163,12 @@ class UserApi extends PHPUnit_Framework_TestCase $this->assertEquals(2, $this->admin->createTask('my admin title', 1)); } + public function testCreateTaskWithWrongMember() + { + $this->assertFalse($this->user->createTask(array('title' => 'something', 'project_id' => 2, 'owner_id' => 1))); + $this->assertFalse($this->app->createTask(array('title' => 'something', 'project_id' => 1, 'owner_id' => 2))); + } + public function testGetTask() { $task = $this->user->getTask(1); @@ -218,6 +224,11 @@ class UserApi extends PHPUnit_Framework_TestCase $this->assertTrue($this->user->moveTaskPosition(2, 1, 2, 1)); } + public function testUpdateTaskWithWrongMember() + { + $this->assertFalse($this->user->updateTask(array('id' => 1, 'title' => 'new title', 'reference' => 'test', 'owner_id' => 1))); + } + public function testUpdateTask() { $this->assertTrue($this->user->updateTask(array('id' => 1, 'title' => 'new title', 'reference' => 'test', 'owner_id' => 2))); -- cgit v1.2.3 From ff26cce361f123de7fa9f1bc9989bad88f19b7f3 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 13 Dec 2015 11:12:03 -0500 Subject: Add new boolean value for CSV import --- app/Core/Csv.php | 2 +- tests/units/Core/CsvTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/app/Core/Csv.php b/app/Core/Csv.php index 28c1997b..e45af24c 100644 --- a/app/Core/Csv.php +++ b/app/Core/Csv.php @@ -93,7 +93,7 @@ class Csv { if (! empty($value)) { $value = trim(strtolower($value)); - return $value === '1' || $value{0} === 't' ? 1 : 0; + return $value === '1' || $value{0} === 't' || $value{0} === 'y' ? 1 : 0; } return 0; diff --git a/tests/units/Core/CsvTest.php b/tests/units/Core/CsvTest.php index 7276de7f..da0be4a3 100644 --- a/tests/units/Core/CsvTest.php +++ b/tests/units/Core/CsvTest.php @@ -14,6 +14,10 @@ class CsvTest extends Base $this->assertEquals(1, Csv::getBooleanValue('TRUE')); $this->assertEquals(1, Csv::getBooleanValue('true')); $this->assertEquals(1, Csv::getBooleanValue('T')); + $this->assertEquals(1, Csv::getBooleanValue('Y')); + $this->assertEquals(1, Csv::getBooleanValue('y')); + $this->assertEquals(1, Csv::getBooleanValue('yes')); + $this->assertEquals(1, Csv::getBooleanValue('Yes')); $this->assertEquals(0, Csv::getBooleanValue('0')); $this->assertEquals(0, Csv::getBooleanValue('123')); -- cgit v1.2.3 From f01e2f4b781651b2fbb9e1dc079c7eaaae14a4d2 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Mon, 14 Dec 2015 21:12:08 -0500 Subject: Fix wrong constant name that cause a PHP error in project management section --- ChangeLog | 7 +++ app/Model/ProjectPermission.php | 6 +-- tests/units/Model/ProjectPermissionTest.php | 66 +++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/ChangeLog b/ChangeLog index 7ad0649d..89043cf0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Version 1.0.23 (unreleased) +--------------------------- + +Bug fixes: + +- Fix wrong constant name that cause a PHP error in project management section + Version 1.0.22 -------------- diff --git a/app/Model/ProjectPermission.php b/app/Model/ProjectPermission.php index b311c10b..f74b8587 100644 --- a/app/Model/ProjectPermission.php +++ b/app/Model/ProjectPermission.php @@ -28,10 +28,10 @@ class ProjectPermission extends Base return $this ->db - ->table(self::TABLE) + ->table(ProjectUserRole::TABLE) ->join(User::TABLE, 'id', 'user_id') ->join(Project::TABLE, 'id', 'project_id') - ->eq(self::TABLE.'.role', $role) + ->eq(ProjectUserRole::TABLE.'.role', $role) ->eq(Project::TABLE.'.is_private', 0) ->in(Project::TABLE.'.id', $project_ids) ->columns( @@ -88,7 +88,7 @@ class ProjectPermission extends Base */ public function isMember($project_id, $user_id) { - return in_array($this->projectUserRole->getUSerRole($project_id, $user_id), array(Role::PROJECT_MEMBER, Role::PROJECT_MANAGER)); + return in_array($this->projectUserRole->getUserRole($project_id, $user_id), array(Role::PROJECT_MEMBER, Role::PROJECT_MANAGER)); } /** diff --git a/tests/units/Model/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionTest.php index 8f118cd9..0f5996b5 100644 --- a/tests/units/Model/ProjectPermissionTest.php +++ b/tests/units/Model/ProjectPermissionTest.php @@ -13,6 +13,72 @@ use Kanboard\Core\Security\Role; class ProjectPermissionTest extends Base { + public function testGetQueryByRole() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermission = new ProjectPermission($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + $this->assertEquals(3, $projectModel->create(array('name' => 'Project 3'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + + $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MANAGER)); + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MANAGER)); + $this->assertTrue($userRoleModel->addUser(1, 4, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 5, Role::PROJECT_MEMBER)); + + $this->assertTrue($userRoleModel->addUser(2, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(2, 3, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(2, 5, Role::PROJECT_MANAGER)); + + $this->assertTrue($userRoleModel->addUser(3, 4, Role::PROJECT_MANAGER)); + $this->assertTrue($userRoleModel->addUser(3, 5, Role::PROJECT_VIEWER)); + + $this->assertEmpty($projectPermission->getQueryByRole(array(), Role::PROJECT_MANAGER)->findAll()); + + $users = $projectPermission->getQueryByRole(array(1, 2), Role::PROJECT_MANAGER)->findAll(); + $this->assertCount(3, $users); + $this->assertEquals('user 1', $users[0]['username']); + $this->assertEquals('Project 1', $users[0]['project_name']); + $this->assertEquals('user 2', $users[1]['username']); + $this->assertEquals('Project 1', $users[1]['project_name']); + $this->assertEquals('user 4', $users[2]['username']); + $this->assertEquals('Project 2', $users[2]['project_name']); + + $users = $projectPermission->getQueryByRole(array(1), Role::PROJECT_MANAGER)->findAll(); + $this->assertCount(2, $users); + $this->assertEquals('user 1', $users[0]['username']); + $this->assertEquals('Project 1', $users[0]['project_name']); + $this->assertEquals('user 2', $users[1]['username']); + $this->assertEquals('Project 1', $users[1]['project_name']); + + $users = $projectPermission->getQueryByRole(array(1, 2, 3), Role::PROJECT_MEMBER)->findAll(); + $this->assertCount(4, $users); + $this->assertEquals('user 3', $users[0]['username']); + $this->assertEquals('Project 1', $users[0]['project_name']); + $this->assertEquals('user 4', $users[1]['username']); + $this->assertEquals('Project 1', $users[1]['project_name']); + $this->assertEquals('user 1', $users[2]['username']); + $this->assertEquals('Project 2', $users[2]['project_name']); + $this->assertEquals('user 2', $users[3]['username']); + $this->assertEquals('Project 2', $users[3]['project_name']); + + $users = $projectPermission->getQueryByRole(array(1, 2, 3), Role::PROJECT_VIEWER)->findAll(); + $this->assertCount(1, $users); + $this->assertEquals('user 4', $users[0]['username']); + $this->assertEquals('Project 3', $users[0]['project_name']); + } + public function testDuplicate() { $userModel = new User($this->container); -- cgit v1.2.3 From b377adc3125eaa49e02d09e2f51cef6f0e1f6182 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Mon, 14 Dec 2015 21:43:38 -0500 Subject: Add unit tests for ProjectPermission model --- tests/units/Model/ProjectPermissionTest.php | 111 ++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) (limited to 'tests') diff --git a/tests/units/Model/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionTest.php index 0f5996b5..77419bec 100644 --- a/tests/units/Model/ProjectPermissionTest.php +++ b/tests/units/Model/ProjectPermissionTest.php @@ -79,6 +79,117 @@ class ProjectPermissionTest extends Base $this->assertEquals('Project 3', $users[0]['project_name']); } + public function testEverybodyAllowed() + { + $projectModel = new Project($this->container); + $projectPermission = new ProjectPermission($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2', 'is_everybody_allowed' => 1))); + + $this->assertFalse($projectPermission->isEverybodyAllowed(1)); + $this->assertTrue($projectPermission->isEverybodyAllowed(2)); + } + + public function testIsUserAllowed() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $groupMemberModel = new GroupMember($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermission = new ProjectPermission($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(1, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 2)); + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 4, Role::PROJECT_MANAGER)); + + $this->assertTrue($projectPermission->isUserAllowed(1, 2)); + $this->assertTrue($projectPermission->isUserAllowed(1, 3)); + $this->assertTrue($projectPermission->isUserAllowed(1, 4)); + $this->assertFalse($projectPermission->isUserAllowed(1, 5)); + + $this->assertFalse($projectPermission->isUserAllowed(2, 2)); + $this->assertFalse($projectPermission->isUserAllowed(2, 3)); + $this->assertFalse($projectPermission->isUserAllowed(2, 4)); + $this->assertFalse($projectPermission->isUserAllowed(2, 5)); + } + + public function testIsMember() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $groupMemberModel = new GroupMember($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermission = new ProjectPermission($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(1, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 2)); + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 4, Role::PROJECT_MANAGER)); + + $this->assertFalse($projectPermission->isMember(1, 2)); + $this->assertTrue($projectPermission->isMember(1, 3)); + $this->assertTrue($projectPermission->isMember(1, 4)); + $this->assertFalse($projectPermission->isMember(1, 5)); + + $this->assertFalse($projectPermission->isMember(2, 2)); + $this->assertFalse($projectPermission->isMember(2, 3)); + $this->assertFalse($projectPermission->isMember(2, 4)); + $this->assertFalse($projectPermission->isMember(2, 5)); + } + + public function testGetActiveProjectIds() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $groupMemberModel = new GroupMember($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermission = new ProjectPermission($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2', 'is_active' => 0))); + + $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(2, 2, Role::PROJECT_VIEWER)); + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_VIEWER)); + + $this->assertEmpty($projectPermission->getActiveProjectIds(1)); + $this->assertEquals(array(1), $projectPermission->getActiveProjectIds(2)); + $this->assertEquals(array(1), $projectPermission->getActiveProjectIds(3)); + } + public function testDuplicate() { $userModel = new User($this->container); -- cgit v1.2.3