summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/integration.mysql.xml (renamed from tests/functionals.mysql.xml)2
-rw-r--r--tests/integration.postgres.xml (renamed from tests/functionals.postgres.xml)2
-rw-r--r--tests/integration.sqlite.xml (renamed from tests/functionals.sqlite.xml)2
-rw-r--r--tests/integration/ApiTest.php (renamed from tests/functionals/ApiTest.php)10
-rw-r--r--tests/integration/AppTest.php34
-rw-r--r--tests/integration/Base.php62
-rw-r--r--tests/integration/GroupMemberTest.php39
-rw-r--r--tests/integration/GroupTest.php48
-rw-r--r--tests/integration/MeTest.php (renamed from tests/functionals/UserApiTest.php)46
-rw-r--r--tests/integration/ProjectPermissionTest.php64
10 files changed, 252 insertions, 57 deletions
diff --git a/tests/functionals.mysql.xml b/tests/integration.mysql.xml
index a8877f92..30769371 100644
--- a/tests/functionals.mysql.xml
+++ b/tests/integration.mysql.xml
@@ -1,7 +1,7 @@
<phpunit stopOnError="true" stopOnFailure="true" colors="true">
<testsuites>
<testsuite name="Kanboard">
- <directory>functionals</directory>
+ <directory>integration</directory>
</testsuite>
</testsuites>
<php>
diff --git a/tests/functionals.postgres.xml b/tests/integration.postgres.xml
index 61da8574..ed8a3de3 100644
--- a/tests/functionals.postgres.xml
+++ b/tests/integration.postgres.xml
@@ -1,7 +1,7 @@
<phpunit stopOnError="true" stopOnFailure="true" colors="true">
<testsuites>
<testsuite name="Kanboard">
- <directory>functionals</directory>
+ <directory>integration</directory>
</testsuite>
</testsuites>
<php>
diff --git a/tests/functionals.sqlite.xml b/tests/integration.sqlite.xml
index 9da59b20..1964f822 100644
--- a/tests/functionals.sqlite.xml
+++ b/tests/integration.sqlite.xml
@@ -1,7 +1,7 @@
<phpunit stopOnError="true" stopOnFailure="true" colors="true">
<testsuites>
<testsuite name="Kanboard">
- <directory>functionals</directory>
+ <directory>integration</directory>
</testsuite>
</testsuites>
<php>
diff --git a/tests/functionals/ApiTest.php b/tests/integration/ApiTest.php
index b250254e..798bde42 100644
--- a/tests/functionals/ApiTest.php
+++ b/tests/integration/ApiTest.php
@@ -45,16 +45,6 @@ class Api extends PHPUnit_Framework_TestCase
return $tasks[0]['id'];
}
- public function testGetTimezone()
- {
- $this->assertEquals('Europe/Paris', $this->client->getTimezone());
- }
-
- public function testGetVersion()
- {
- $this->assertEquals('master', $this->client->getVersion());
- }
-
public function testRemoveAll()
{
$projects = $this->client->getAllProjects();
diff --git a/tests/integration/AppTest.php b/tests/integration/AppTest.php
new file mode 100644
index 00000000..6575fbb8
--- /dev/null
+++ b/tests/integration/AppTest.php
@@ -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']);
+ }
+}
diff --git a/tests/integration/Base.php b/tests/integration/Base.php
new file mode 100644
index 00000000..6facd9ce
--- /dev/null
+++ b/tests/integration/Base.php
@@ -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'];
+ }
+}
diff --git a/tests/integration/GroupMemberTest.php b/tests/integration/GroupMemberTest.php
new file mode 100644
index 00000000..e84c0734
--- /dev/null
+++ b/tests/integration/GroupMemberTest.php
@@ -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));
+ }
+}
diff --git a/tests/integration/GroupTest.php b/tests/integration/GroupTest.php
new file mode 100644
index 00000000..7a5bccc9
--- /dev/null
+++ b/tests/integration/GroupTest.php
@@ -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());
+ }
+}
diff --git a/tests/functionals/UserApiTest.php b/tests/integration/MeTest.php
index 3c7fc04e..21f61756 100644
--- a/tests/functionals/UserApiTest.php
+++ b/tests/integration/MeTest.php
@@ -1,51 +1,9 @@
<?php
-require_once __DIR__.'/../../vendor/autoload.php';
+require_once __DIR__.'/Base.php';
-class UserApi extends PHPUnit_Framework_TestCase
+class MeTest extends Base
{
- private $app = null;
- private $admin = null;
- private $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;
- }
-
public function testCreateProject()
{
$this->assertEquals(1, $this->app->createProject('team project'));
diff --git a/tests/integration/ProjectPermissionTest.php b/tests/integration/ProjectPermissionTest.php
new file mode 100644
index 00000000..b06ad4ad
--- /dev/null
+++ b/tests/integration/ProjectPermissionTest.php
@@ -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));
+ }
+}