summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-11-22 18:22:10 -0500
committerFrédéric Guillot <fred@kanboard.net>2014-11-22 18:22:10 -0500
commit77e10d25829f3523a168bf61424fac99a539f8be (patch)
tree9b3d274146fa9543c4734a945e61b9d975960ff6 /tests
parent15038cdb10f8c691edc7980fd1aed32dcbed3f9f (diff)
Improve API to return id instead of a boolean
Diffstat (limited to 'tests')
-rw-r--r--tests/functionals/ApiTest.php64
-rw-r--r--tests/units/CommentTest.php10
-rw-r--r--tests/units/NotificationTest.php16
-rw-r--r--tests/units/ProjectPermissionTest.php4
-rw-r--r--tests/units/TaskPermissionTest.php4
-rw-r--r--tests/units/UserTest.php8
6 files changed, 65 insertions, 41 deletions
diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php
index 262d289e..3b1c5241 100644
--- a/tests/functionals/ApiTest.php
+++ b/tests/functionals/ApiTest.php
@@ -162,12 +162,15 @@ class Api extends PHPUnit_Framework_TestCase
'column_id' => 2,
);
- //$this->assertTrue($this->client->execute('createTask', $task));
- $this->assertTrue($this->client->createTask($task));
+ $task_id = $this->client->createTask($task);
+
+ $this->assertNotFalse($task_id);
+ $this->assertInternalType('int', $task_id);
+ $this->assertTrue($task_id > 0);
}
/**
- * @expectedException BadFunctionCallException
+ * @expectedException InvalidArgumentException
*/
public function testCreateTaskWithBadParams()
{
@@ -207,12 +210,15 @@ class Api extends PHPUnit_Framework_TestCase
public function testUpdateTask()
{
$task = $this->client->getTask(1);
- $task['color_id'] = 'green';
- $task['column_id'] = 1;
- $task['description'] = 'test';
- $task['date_due'] = '';
- $this->assertTrue($this->client->execute('updateTask', $task));
+ $values = array();
+ $values['id'] = $task['id'];
+ $values['color_id'] = 'green';
+ $values['column_id'] = 1;
+ $values['description'] = 'test';
+ $values['date_due'] = '';
+
+ $this->assertTrue($this->client->execute('updateTask', $values));
}
public function testRemoveTask()
@@ -241,11 +247,14 @@ class Api extends PHPUnit_Framework_TestCase
'password' => '123456',
);
- $this->assertTrue($this->client->execute('createUser', $user));
+ $user_id = $this->client->execute('createUser', $user);
+ $this->assertNotFalse($user_id);
+ $this->assertInternalType('int', $user_id);
+ $this->assertTrue($user_id > 0);
}
/**
- * @expectedException BadFunctionCallException
+ * @expectedException InvalidArgumentException
*/
public function testCreateUserWithBadParams()
{
@@ -296,7 +305,7 @@ class Api extends PHPUnit_Framework_TestCase
public function testGetAllowedUsers()
{
- $users = $this->client->getAllowedUsers(1);
+ $users = $this->client->getMembers(1);
$this->assertNotFalse($users);
$this->assertEquals(array(), $users);
}
@@ -305,7 +314,7 @@ class Api extends PHPUnit_Framework_TestCase
{
$this->assertTrue($this->client->allowUser(1, 2));
- $users = $this->client->getAllowedUsers(1);
+ $users = $this->client->getMembers(1);
$this->assertNotFalse($users);
$this->assertEquals(array(2 => 'Titi'), $users);
}
@@ -314,7 +323,7 @@ class Api extends PHPUnit_Framework_TestCase
{
$this->assertTrue($this->client->revokeUser(1, 2));
- $users = $this->client->getAllowedUsers(1);
+ $users = $this->client->getMembers(1);
$this->assertNotFalse($users);
$this->assertEquals(array(), $users);
}
@@ -329,7 +338,7 @@ class Api extends PHPUnit_Framework_TestCase
'column_id' => 1,
);
- $this->assertTrue($this->client->execute('createTask', $task));
+ $this->assertNotFalse($this->client->execute('createTask', $task));
$tasks = $this->client->getAllTasks(1, 1);
$this->assertNotEmpty($tasks);
@@ -341,7 +350,11 @@ class Api extends PHPUnit_Framework_TestCase
'content' => 'boo',
);
- $this->assertTrue($this->client->execute('createComment', $comment));
+ $comment_id = $this->client->execute('createComment', $comment);
+
+ $this->assertNotFalse($comment_id);
+ $this->assertInternalType('int', $comment_id);
+ $this->assertTrue($comment_id > 0);
}
public function testGetComment()
@@ -375,7 +388,11 @@ class Api extends PHPUnit_Framework_TestCase
'content' => 'blabla',
);
- $this->assertTrue($this->client->execute('createComment', $comment));
+ $comment_id = $this->client->createComment($comment);
+
+ $this->assertNotFalse($comment_id);
+ $this->assertInternalType('int', $comment_id);
+ $this->assertTrue($comment_id > 0);
$comments = $this->client->getAllComments($task_id);
$this->assertNotFalse($comments);
@@ -410,7 +427,11 @@ class Api extends PHPUnit_Framework_TestCase
'title' => 'subtask #1',
);
- $this->assertTrue($this->client->execute('createSubtask', $subtask));
+ $subtask_id = $this->client->createSubtask($subtask);
+
+ $this->assertNotFalse($subtask_id);
+ $this->assertInternalType('int', $subtask_id);
+ $this->assertTrue($subtask_id > 0);
}
public function testGetSubtask()
@@ -444,7 +465,7 @@ class Api extends PHPUnit_Framework_TestCase
'title' => 'Subtask #2',
);
- $this->assertTrue($this->client->execute('createSubtask', $subtask));
+ $this->assertNotFalse($this->client->execute('createSubtask', $subtask));
$subtasks = $this->client->getAllSubtasks($this->getTaskId());
$this->assertNotFalse($subtasks);
@@ -483,7 +504,10 @@ class Api extends PHPUnit_Framework_TestCase
'project_id' => 1,
);
- $this->assertTrue($this->client->execute('createCategory', $category));
+ $cat_id = $this->client->execute('createCategory', $category);
+ $this->assertNotFalse($cat_id);
+ $this->assertInternalType('int', $cat_id);
+ $this->assertTrue($cat_id > 0);
// Duplicate
@@ -496,7 +520,7 @@ class Api extends PHPUnit_Framework_TestCase
}
/**
- * @expectedException BadFunctionCallException
+ * @expectedException InvalidArgumentException
*/
public function testCategoryCreationWithBadParams()
{
diff --git a/tests/units/CommentTest.php b/tests/units/CommentTest.php
index 8846c0b8..36ff1352 100644
--- a/tests/units/CommentTest.php
+++ b/tests/units/CommentTest.php
@@ -17,7 +17,7 @@ class CommentTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
- $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
+ $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'bla bla', 'user_id' => 1)));
$comment = $c->getById(1);
@@ -37,9 +37,9 @@ class CommentTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
- $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
- $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1)));
- $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1)));
+ $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+ $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c2', 'user_id' => 1)));
+ $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c3', 'user_id' => 1)));
$comments = $c->getAll(1);
@@ -60,7 +60,7 @@ class CommentTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1)));
- $this->assertTrue($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
+ $this->assertNotFalse($c->create(array('task_id' => 1, 'comment' => 'c1', 'user_id' => 1)));
$this->assertTrue($c->update(array('id' => 1, 'comment' => 'bla')));
$comment = $c->getById(1);
diff --git a/tests/units/NotificationTest.php b/tests/units/NotificationTest.php
index 770a9829..d8e623e1 100644
--- a/tests/units/NotificationTest.php
+++ b/tests/units/NotificationTest.php
@@ -19,16 +19,16 @@ class NotificationTest extends Base
$this->assertEquals(1, $p->create(array('name' => 'UnitTest1')));
// Email + Notifications enabled
- $this->assertTrue($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
+ $this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
// No email + Notifications enabled
- $this->assertTrue($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
+ $this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
// Email + Notifications enabled
- $this->assertTrue($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
+ $this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
// No email + notifications disabled
- $this->assertTrue($u->create(array('username' => 'user4')));
+ $this->assertNotFalse($u->create(array('username' => 'user4')));
// Nobody is member of any projects
$this->assertEmpty($pp->getMembers(1));
@@ -61,16 +61,16 @@ class NotificationTest extends Base
$this->assertEquals(3, $p->create(array('name' => 'UnitTest3', 'is_everybody_allowed' => 1)));
// Email + Notifications enabled
- $this->assertTrue($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
+ $this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1)));
// No email + Notifications enabled
- $this->assertTrue($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
+ $this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1)));
// Email + Notifications enabled
- $this->assertTrue($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
+ $this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1)));
// No email + notifications disabled
- $this->assertTrue($u->create(array('username' => 'user4')));
+ $this->assertNotFalse($u->create(array('username' => 'user4')));
// We allow all users to be member of our projects
$this->assertTrue($pp->allowUser(1, 1));
diff --git a/tests/units/ProjectPermissionTest.php b/tests/units/ProjectPermissionTest.php
index 394e0ac5..b169b63e 100644
--- a/tests/units/ProjectPermissionTest.php
+++ b/tests/units/ProjectPermissionTest.php
@@ -11,8 +11,8 @@ class ProjectPermissionTest extends Base
public function testAllowEverybody()
{
$user = new User($this->container);
- $this->assertTrue($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
- $this->assertTrue($user->create(array('username' => 'unittest#2', 'password' => 'unittest')));
+ $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest')));
+ $this->assertNotFalse($user->create(array('username' => 'unittest#2', 'password' => 'unittest')));
$p = new Project($this->container);
$pp = new ProjectPermission($this->container);
diff --git a/tests/units/TaskPermissionTest.php b/tests/units/TaskPermissionTest.php
index 963864b2..4b0b2b61 100644
--- a/tests/units/TaskPermissionTest.php
+++ b/tests/units/TaskPermissionTest.php
@@ -20,8 +20,8 @@ class TaskPermissionTest extends Base
$p = new Project($this->container);
$u = new User($this->container);
- $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456')));
- $this->assertTrue($u->create(array('username' => 'toto2', 'password' => '123456')));
+ $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)));
diff --git a/tests/units/UserTest.php b/tests/units/UserTest.php
index ebb76a92..6e535a35 100644
--- a/tests/units/UserTest.php
+++ b/tests/units/UserTest.php
@@ -73,8 +73,8 @@ class UserTest extends Base
public function testCreate()
{
$u = new User($this->container);
- $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
- $this->assertTrue($u->create(array('username' => 'titi', 'is_ldap_user' => 1)));
+ $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
+ $this->assertNotFalse($u->create(array('username' => 'titi', 'is_ldap_user' => 1)));
$this->assertFalse($u->create(array('username' => 'toto')));
$user = $u->getById(1);
@@ -105,7 +105,7 @@ class UserTest extends Base
public function testUpdate()
{
$u = new User($this->container);
- $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
+ $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
$this->assertTrue($u->update(array('id' => 2, 'username' => 'biloute')));
$user = $u->getById(2);
@@ -124,7 +124,7 @@ class UserTest extends Base
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
- $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
+ $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2)));