Add new API procedures for groups, roles and project permissions
This commit is contained in:
1112
tests/integration/ApiTest.php
Normal file
1112
tests/integration/ApiTest.php
Normal file
File diff suppressed because it is too large
Load Diff
34
tests/integration/AppTest.php
Normal file
34
tests/integration/AppTest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/Base.php';
|
||||
|
||||
class AppTest extends Base
|
||||
{
|
||||
public function testGetTimezone()
|
||||
{
|
||||
$this->assertEquals('UTC', $this->app->getTimezone());
|
||||
}
|
||||
|
||||
public function testGetVersion()
|
||||
{
|
||||
$this->assertEquals('master', $this->app->getVersion());
|
||||
}
|
||||
|
||||
public function testGetApplicationRoles()
|
||||
{
|
||||
$roles = $this->app->getApplicationRoles();
|
||||
$this->assertCount(3, $roles);
|
||||
$this->assertEquals('Administrator', $roles['app-admin']);
|
||||
$this->assertEquals('Manager', $roles['app-manager']);
|
||||
$this->assertEquals('User', $roles['app-user']);
|
||||
}
|
||||
|
||||
public function testGetProjectRoles()
|
||||
{
|
||||
$roles = $this->app->getProjectRoles();
|
||||
$this->assertCount(3, $roles);
|
||||
$this->assertEquals('Project Manager', $roles['project-manager']);
|
||||
$this->assertEquals('Project Member', $roles['project-member']);
|
||||
$this->assertEquals('Project Viewer', $roles['project-viewer']);
|
||||
}
|
||||
}
|
||||
62
tests/integration/Base.php
Normal file
62
tests/integration/Base.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/../../vendor/autoload.php';
|
||||
|
||||
abstract class Base extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $app = null;
|
||||
protected $admin = null;
|
||||
protected $user = null;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
if (DB_DRIVER === 'sqlite') {
|
||||
@unlink(DB_FILENAME);
|
||||
} elseif (DB_DRIVER === 'mysql') {
|
||||
$pdo = new PDO('mysql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
|
||||
$pdo->exec('DROP DATABASE '.DB_NAME);
|
||||
$pdo->exec('CREATE DATABASE '.DB_NAME);
|
||||
$pdo = null;
|
||||
} elseif (DB_DRIVER === 'postgres') {
|
||||
$pdo = new PDO('pgsql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD);
|
||||
$pdo->exec('DROP DATABASE '.DB_NAME);
|
||||
$pdo->exec('CREATE DATABASE '.DB_NAME.' WITH OWNER '.DB_USERNAME);
|
||||
$pdo = null;
|
||||
}
|
||||
|
||||
$service = new Kanboard\ServiceProvider\DatabaseProvider;
|
||||
|
||||
$db = $service->getInstance();
|
||||
$db->table('settings')->eq('option', 'api_token')->update(array('value' => API_KEY));
|
||||
$db->closeConnection();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->app = new JsonRPC\Client(API_URL);
|
||||
$this->app->authentication('jsonrpc', API_KEY);
|
||||
$this->app->debug = true;
|
||||
|
||||
$this->admin = new JsonRPC\Client(API_URL);
|
||||
$this->admin->authentication('admin', 'admin');
|
||||
// $this->admin->debug = true;
|
||||
|
||||
$this->user = new JsonRPC\Client(API_URL);
|
||||
$this->user->authentication('user', 'password');
|
||||
// $this->user->debug = true;
|
||||
}
|
||||
|
||||
protected function getProjectId()
|
||||
{
|
||||
$projects = $this->app->getAllProjects();
|
||||
$this->assertNotEmpty($projects);
|
||||
return $projects[0]['id'];
|
||||
}
|
||||
|
||||
protected function getGroupId()
|
||||
{
|
||||
$groups = $this->app->getAllGroups();
|
||||
$this->assertNotEmpty($groups);
|
||||
return $groups[0]['id'];
|
||||
}
|
||||
}
|
||||
39
tests/integration/GroupMemberTest.php
Normal file
39
tests/integration/GroupMemberTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/Base.php';
|
||||
|
||||
class GroupMemberTest extends Base
|
||||
{
|
||||
public function testAddMember()
|
||||
{
|
||||
$this->assertNotFalse($this->app->createGroup('My Group A'));
|
||||
$this->assertNotFalse($this->app->createGroup('My Group B'));
|
||||
|
||||
$groupId = $this->getGroupId();
|
||||
$this->assertTrue($this->app->addGroupMember($groupId, 1));
|
||||
}
|
||||
|
||||
public function testGetMembers()
|
||||
{
|
||||
$groups = $this->app->getAllGroups();
|
||||
$members = $this->app->getGroupMembers($groups[0]['id']);
|
||||
$this->assertCount(1, $members);
|
||||
$this->assertEquals('admin', $members[0]['username']);
|
||||
|
||||
$this->assertSame(array(), $this->app->getGroupMembers($groups[1]['id']));
|
||||
}
|
||||
|
||||
public function testIsGroupMember()
|
||||
{
|
||||
$groupId = $this->getGroupId();
|
||||
$this->assertTrue($this->app->isGroupMember($groupId, 1));
|
||||
$this->assertFalse($this->app->isGroupMember($groupId, 2));
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$groupId = $this->getGroupId();
|
||||
$this->assertTrue($this->app->removeGroupMember($groupId, 1));
|
||||
$this->assertFalse($this->app->isGroupMember($groupId, 1));
|
||||
}
|
||||
}
|
||||
48
tests/integration/GroupTest.php
Normal file
48
tests/integration/GroupTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/Base.php';
|
||||
|
||||
class GroupTest extends Base
|
||||
{
|
||||
public function testCreateGroup()
|
||||
{
|
||||
$this->assertNotFalse($this->app->createGroup('My Group A'));
|
||||
$this->assertNotFalse($this->app->createGroup('My Group B', '1234'));
|
||||
}
|
||||
|
||||
public function testGetter()
|
||||
{
|
||||
$groups = $this->app->getAllGroups();
|
||||
$this->assertCount(2, $groups);
|
||||
$this->assertEquals('My Group A', $groups[0]['name']);
|
||||
$this->assertEquals('', $groups[0]['external_id']);
|
||||
$this->assertEquals('My Group B', $groups[1]['name']);
|
||||
$this->assertEquals('1234', $groups[1]['external_id']);
|
||||
|
||||
$group = $this->app->getGroup($groups[0]['id']);
|
||||
$this->assertNotEmpty($group);
|
||||
$this->assertEquals('My Group A', $group['name']);
|
||||
$this->assertEquals('', $group['external_id']);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$groups = $this->app->getAllGroups();
|
||||
|
||||
$this->assertTrue($this->app->updateGroup(array('group_id' => $groups[0]['id'], 'name' => 'ABC', 'external_id' => 'something')));
|
||||
$this->assertTrue($this->app->updateGroup(array('group_id' => $groups[1]['id'], 'external_id' => '')));
|
||||
|
||||
$groups = $this->app->getAllGroups();
|
||||
$this->assertEquals('ABC', $groups[0]['name']);
|
||||
$this->assertEquals('something', $groups[0]['external_id']);
|
||||
$this->assertEquals('', $groups[1]['external_id']);
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$groups = $this->app->getAllGroups();
|
||||
$this->assertTrue($this->app->removeGroup($groups[0]['id']));
|
||||
$this->assertTrue($this->app->removeGroup($groups[1]['id']));
|
||||
$this->assertSame(array(), $this->app->getAllGroups());
|
||||
}
|
||||
}
|
||||
247
tests/integration/MeTest.php
Normal file
247
tests/integration/MeTest.php
Normal file
@@ -0,0 +1,247 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/Base.php';
|
||||
|
||||
class MeTest extends Base
|
||||
{
|
||||
public function testCreateProject()
|
||||
{
|
||||
$this->assertEquals(1, $this->app->createProject('team project'));
|
||||
}
|
||||
|
||||
public function testCreateUser()
|
||||
{
|
||||
$this->assertEquals(2, $this->app->createUser('user', 'password'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException JsonRPC\AccessDeniedException
|
||||
*/
|
||||
public function testNotAllowedAppProcedure()
|
||||
{
|
||||
$this->app->getMe();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException JsonRPC\AccessDeniedException
|
||||
*/
|
||||
public function testNotAllowedUserProcedure()
|
||||
{
|
||||
$this->user->getAllProjects();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException JsonRPC\AccessDeniedException
|
||||
*/
|
||||
public function testNotAllowedProjectForUser()
|
||||
{
|
||||
$this->user->getProjectById(1);
|
||||
}
|
||||
|
||||
public function testAllowedProjectForAdmin()
|
||||
{
|
||||
$this->assertNotEmpty($this->admin->getProjectById(1));
|
||||
}
|
||||
|
||||
public function testGetTimezone()
|
||||
{
|
||||
$this->assertEquals('UTC', $this->user->getTimezone());
|
||||
}
|
||||
|
||||
public function testGetVersion()
|
||||
{
|
||||
$this->assertEquals('master', $this->user->getVersion());
|
||||
}
|
||||
|
||||
public function testGetDefaultColor()
|
||||
{
|
||||
$this->assertEquals('yellow', $this->user->getDefaultTaskColor());
|
||||
}
|
||||
|
||||
public function testGetDefaultColors()
|
||||
{
|
||||
$colors = $this->user->getDefaultTaskColors();
|
||||
$this->assertNotEmpty($colors);
|
||||
$this->assertArrayHasKey('red', $colors);
|
||||
}
|
||||
|
||||
public function testGetColorList()
|
||||
{
|
||||
$colors = $this->user->getColorList();
|
||||
$this->assertNotEmpty($colors);
|
||||
$this->assertArrayHasKey('red', $colors);
|
||||
$this->assertEquals('Red', $colors['red']);
|
||||
}
|
||||
|
||||
public function testGetMe()
|
||||
{
|
||||
$profile = $this->user->getMe();
|
||||
$this->assertNotEmpty($profile);
|
||||
$this->assertEquals(2, $profile['id']);
|
||||
$this->assertEquals('user', $profile['username']);
|
||||
}
|
||||
|
||||
public function testCreateMyPrivateProject()
|
||||
{
|
||||
$this->assertEquals(2, $this->user->createMyPrivateProject('my project'));
|
||||
}
|
||||
|
||||
public function testGetMyProjectsList()
|
||||
{
|
||||
$projects = $this->user->getMyProjectsList();
|
||||
$this->assertNotEmpty($projects);
|
||||
$this->assertArrayNotHasKey(1, $projects);
|
||||
$this->assertArrayHasKey(2, $projects);
|
||||
$this->assertEquals('my project', $projects[2]);
|
||||
}
|
||||
|
||||
public function testGetMyProjects()
|
||||
{
|
||||
$projects = $this->user->getMyProjects();
|
||||
$this->assertNotEmpty($projects);
|
||||
$this->assertCount(1, $projects);
|
||||
$this->assertEquals(2, $projects[0]['id']);
|
||||
$this->assertEquals('my project', $projects[0]['name']);
|
||||
$this->assertNotEmpty($projects[0]['url']['calendar']);
|
||||
$this->assertNotEmpty($projects[0]['url']['board']);
|
||||
$this->assertNotEmpty($projects[0]['url']['list']);
|
||||
}
|
||||
|
||||
public function testGetProjectById()
|
||||
{
|
||||
$project = $this->user->getProjectById(2);
|
||||
$this->assertNotEmpty($project);
|
||||
$this->assertEquals('my project', $project['name']);
|
||||
$this->assertEquals(1, $project['is_private']);
|
||||
}
|
||||
|
||||
public function testCreateTask()
|
||||
{
|
||||
$this->assertEquals(1, $this->user->createTask('my user title', 2));
|
||||
$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);
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals('my user title', $task['title']);
|
||||
$this->assertEquals('yellow', $task['color_id']);
|
||||
$this->assertArrayHasKey('color', $task);
|
||||
$this->assertArrayHasKey('name', $task['color']);
|
||||
$this->assertArrayHasKey('border', $task['color']);
|
||||
$this->assertArrayHasKey('background', $task['color']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException JsonRPC\AccessDeniedException
|
||||
*/
|
||||
public function testGetAdminTask()
|
||||
{
|
||||
$this->user->getTask(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException JsonRPC\AccessDeniedException
|
||||
*/
|
||||
public function testGetProjectActivityDenied()
|
||||
{
|
||||
$this->user->getProjectActivity(1);
|
||||
}
|
||||
|
||||
public function testGetProjectActivityAllowed()
|
||||
{
|
||||
$activity = $this->user->getProjectActivity(2);
|
||||
$this->assertNotEmpty($activity);
|
||||
}
|
||||
|
||||
public function testGetMyActivityStream()
|
||||
{
|
||||
$activity = $this->user->getMyActivityStream();
|
||||
$this->assertNotEmpty($activity);
|
||||
}
|
||||
|
||||
public function testCloseTask()
|
||||
{
|
||||
$this->assertTrue($this->user->closeTask(1));
|
||||
}
|
||||
|
||||
public function testOpenTask()
|
||||
{
|
||||
$this->assertTrue($this->user->openTask(1));
|
||||
}
|
||||
|
||||
public function testMoveTaskPosition()
|
||||
{
|
||||
$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)));
|
||||
}
|
||||
|
||||
public function testGetbyReference()
|
||||
{
|
||||
$task = $this->user->getTaskByReference(2, 'test');
|
||||
$this->assertNotEmpty($task);
|
||||
$this->assertEquals('new title', $task['title']);
|
||||
$this->assertEquals(2, $task['column_id']);
|
||||
$this->assertEquals(1, $task['position']);
|
||||
}
|
||||
|
||||
public function testGetMyDashboard()
|
||||
{
|
||||
$dashboard = $this->user->getMyDashboard();
|
||||
$this->assertNotEmpty($dashboard);
|
||||
$this->assertArrayHasKey('projects', $dashboard);
|
||||
$this->assertArrayHasKey('tasks', $dashboard);
|
||||
$this->assertArrayHasKey('subtasks', $dashboard);
|
||||
$this->assertNotEmpty($dashboard['projects']);
|
||||
$this->assertNotEmpty($dashboard['tasks']);
|
||||
}
|
||||
|
||||
public function testGetBoard()
|
||||
{
|
||||
$this->assertNotEmpty($this->user->getBoard(2));
|
||||
}
|
||||
|
||||
public function testCreateOverdueTask()
|
||||
{
|
||||
$this->assertNotFalse($this->user->createTask(array(
|
||||
'title' => 'overdue task',
|
||||
'project_id' => 2,
|
||||
'date_due' => date('Y-m-d', strtotime('-2days')),
|
||||
'owner_id' => 2,
|
||||
)));
|
||||
}
|
||||
|
||||
public function testGetMyOverdueTasks()
|
||||
{
|
||||
$tasks = $this->user->getMyOverdueTasks();
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('overdue task', $tasks[0]['title']);
|
||||
$this->assertEquals('my project', $tasks[0]['project_name']);
|
||||
}
|
||||
|
||||
public function testGetOverdueTasksByProject()
|
||||
{
|
||||
$tasks = $this->user->getOverdueTasksByProject(2);
|
||||
$this->assertNotEmpty($tasks);
|
||||
$this->assertCount(1, $tasks);
|
||||
$this->assertEquals('overdue task', $tasks[0]['title']);
|
||||
$this->assertEquals('my project', $tasks[0]['project_name']);
|
||||
}
|
||||
}
|
||||
64
tests/integration/ProjectPermissionTest.php
Normal file
64
tests/integration/ProjectPermissionTest.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__.'/Base.php';
|
||||
|
||||
class ProjectPermissionTest extends Base
|
||||
{
|
||||
public function testGetProjectUsers()
|
||||
{
|
||||
$this->assertNotFalse($this->app->createProject('Test'));
|
||||
$this->assertNotFalse($this->app->createGroup('Test'));
|
||||
|
||||
$projectId = $this->getProjectId();
|
||||
$groupId = $this->getGroupId();
|
||||
|
||||
$this->assertTrue($this->app->addGroupMember($projectId, $groupId));
|
||||
$this->assertSame(array(), $this->app->getProjectUsers($projectId));
|
||||
}
|
||||
|
||||
public function testProjectUser()
|
||||
{
|
||||
$projectId = $this->getProjectId();
|
||||
$this->assertTrue($this->app->addProjectUser($projectId, 1));
|
||||
|
||||
$users = $this->app->getProjectUsers($projectId);
|
||||
$this->assertCount(1, $users);
|
||||
$this->assertEquals('admin', $users[1]);
|
||||
|
||||
$users = $this->app->getAssignableUsers($projectId);
|
||||
$this->assertCount(1, $users);
|
||||
$this->assertEquals('admin', $users[1]);
|
||||
|
||||
$this->assertTrue($this->app->changeProjectUserRole($projectId, 1, 'project-viewer'));
|
||||
|
||||
$users = $this->app->getAssignableUsers($projectId);
|
||||
$this->assertCount(0, $users);
|
||||
|
||||
$this->assertTrue($this->app->removeProjectUser($projectId, 1));
|
||||
$this->assertSame(array(), $this->app->getProjectUsers($projectId));
|
||||
}
|
||||
|
||||
public function testProjectGroup()
|
||||
{
|
||||
$projectId = $this->getProjectId();
|
||||
$groupId = $this->getGroupId();
|
||||
|
||||
$this->assertTrue($this->app->addProjectGroup($projectId, $groupId));
|
||||
|
||||
$users = $this->app->getProjectUsers($projectId);
|
||||
$this->assertCount(1, $users);
|
||||
$this->assertEquals('admin', $users[1]);
|
||||
|
||||
$users = $this->app->getAssignableUsers($projectId);
|
||||
$this->assertCount(1, $users);
|
||||
$this->assertEquals('admin', $users[1]);
|
||||
|
||||
$this->assertTrue($this->app->changeProjectGroupRole($projectId, $groupId, 'project-viewer'));
|
||||
|
||||
$users = $this->app->getAssignableUsers($projectId);
|
||||
$this->assertCount(0, $users);
|
||||
|
||||
$this->assertTrue($this->app->removeProjectGroup($projectId, 1));
|
||||
$this->assertSame(array(), $this->app->getProjectUsers($projectId));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user