diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Base.php | 57 | ||||
-rw-r--r-- | tests/functionals/ApiTest.php | 417 | ||||
-rw-r--r-- | tests/units/AclTest.php (renamed from tests/AclTest.php) | 0 | ||||
-rw-r--r-- | tests/units/ActionTaskAssignColorCategoryTest.php (renamed from tests/ActionTaskAssignColorCategoryTest.php) | 0 | ||||
-rw-r--r-- | tests/units/ActionTaskAssignColorUserTest.php (renamed from tests/ActionTaskAssignColorUserTest.php) | 0 | ||||
-rw-r--r-- | tests/units/ActionTaskAssignCurrentUserTest.php (renamed from tests/ActionTaskAssignCurrentUserTest.php) | 0 | ||||
-rw-r--r-- | tests/units/ActionTaskAssignSpecificUserTest.php (renamed from tests/ActionTaskAssignSpecificUserTest.php) | 0 | ||||
-rw-r--r-- | tests/units/ActionTaskCloseTest.php (renamed from tests/ActionTaskCloseTest.php) | 0 | ||||
-rw-r--r-- | tests/units/ActionTaskDuplicateAnotherProjectTest.php (renamed from tests/ActionTaskDuplicateAnotherProjectTest.php) | 0 | ||||
-rw-r--r-- | tests/units/ActionTest.php (renamed from tests/ActionTest.php) | 0 | ||||
-rw-r--r-- | tests/units/Base.php | 57 | ||||
-rw-r--r-- | tests/units/BoardTest.php (renamed from tests/BoardTest.php) | 0 | ||||
-rw-r--r-- | tests/units/CommentTest.php (renamed from tests/CommentTest.php) | 0 | ||||
-rw-r--r-- | tests/units/ProjectTest.php (renamed from tests/ProjectTest.php) | 0 | ||||
-rw-r--r-- | tests/units/TaskTest.php (renamed from tests/TaskTest.php) | 0 |
15 files changed, 474 insertions, 57 deletions
diff --git a/tests/Base.php b/tests/Base.php deleted file mode 100644 index d4065982..00000000 --- a/tests/Base.php +++ /dev/null @@ -1,57 +0,0 @@ -<?php - -if (version_compare(PHP_VERSION, '5.5.0', '<')) { - require __DIR__.'/../vendor/password.php'; -} - -require_once __DIR__.'/../app/Core/Security.php'; - -require_once __DIR__.'/../vendor/PicoDb/Database.php'; -require_once __DIR__.'/../app/Schema/Sqlite.php'; - -require_once __DIR__.'/../app/Core/Listener.php'; -require_once __DIR__.'/../app/Core/Event.php'; -require_once __DIR__.'/../app/Core/Translator.php'; -require_once __DIR__.'/../app/translator.php'; - -require_once __DIR__.'/../app/Model/Base.php'; -require_once __DIR__.'/../app/Model/Task.php'; -require_once __DIR__.'/../app/Model/Acl.php'; -require_once __DIR__.'/../app/Model/Comment.php'; -require_once __DIR__.'/../app/Model/Project.php'; -require_once __DIR__.'/../app/Model/User.php'; -require_once __DIR__.'/../app/Model/Board.php'; -require_once __DIR__.'/../app/Model/Action.php'; -require_once __DIR__.'/../app/Model/Category.php'; - -require_once __DIR__.'/../app/Action/Base.php'; -require_once __DIR__.'/../app/Action/TaskClose.php'; -require_once __DIR__.'/../app/Action/TaskAssignSpecificUser.php'; -require_once __DIR__.'/../app/Action/TaskAssignColorUser.php'; -require_once __DIR__.'/../app/Action/TaskAssignColorCategory.php'; -require_once __DIR__.'/../app/Action/TaskAssignCurrentUser.php'; -require_once __DIR__.'/../app/Action/TaskDuplicateAnotherProject.php'; - -abstract class Base extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - $this->db = $this->getDbConnection(); - $this->event = new \Core\Event; - } - - public function getDbConnection() - { - $db = new \PicoDb\Database(array( - 'driver' => 'sqlite', - 'filename' => ':memory:' - )); - - if ($db->schema()->check(\Schema\VERSION)) { - return $db; - } - else { - die('Unable to migrate database schema!'); - } - } -} diff --git a/tests/functionals/ApiTest.php b/tests/functionals/ApiTest.php new file mode 100644 index 00000000..89d525a2 --- /dev/null +++ b/tests/functionals/ApiTest.php @@ -0,0 +1,417 @@ +<?php + +require_once __DIR__.'/../../vendor/JsonRPC/Client.php'; + +class Api extends PHPUnit_Framework_TestCase +{ + const URL = 'http://localhost:8000/jsonrpc.php'; + const KEY = '19ffd9709d03ce50675c3a43d1c49c1ac207f4bc45f06c5b2701fbdf8929'; + + private $client; + + public function setUp() + { + $this->client = new JsonRPC\Client(self::URL, 5, true); + $this->client->authentication('jsonrpc', self::KEY); + + $pdo = new PDO('sqlite:data/db.sqlite'); + $pdo->exec('UPDATE config SET api_token="'.self::KEY.'"'); + } + + public function testRemoveAll() + { + $projects = $this->client->getAllProjects(); + + if ($projects) { + foreach ($projects as $project) { + $this->client->removeProject($project['id']); + } + } + } + + public function testCreateProject() + { + $this->assertTrue($this->client->createProject('API test')); + } + + public function testGetProjectById() + { + $project = $this->client->getProjectById(1); + $this->assertNotEmpty($project); + $this->assertEquals(1, $project['id']); + } + + public function testUpdateProject() + { + $project = $this->client->getProjectById(1); + $this->assertNotEmpty($project); + $this->assertTrue($this->client->updateProject(array('id' => 1, 'name' => 'API test 2', 'is_active' => 0))); + + $project = $this->client->getProjectById(1); + $this->assertEquals('API test 2', $project['name']); + $this->assertEquals(0, $project['is_active']); + + $this->assertTrue($this->client->updateProject(array('id' => 1, 'name' => 'API test', 'is_active' => 1))); + + $project = $this->client->getProjectById(1); + $this->assertEquals('API test', $project['name']); + $this->assertEquals(1, $project['is_active']); + } + + public function testGetBoard() + { + $board = $this->client->getBoard(1); + $this->assertTrue(is_array($board)); + $this->assertEquals(4, count($board)); + } + + public function testGetColumns() + { + $columns = $this->client->getColumns(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals(4, count($columns)); + $this->assertEquals('Done', $columns[3]['title']); + } + + public function testMoveColumnUp() + { + $this->assertTrue($this->client->moveColumnUp(1, 4)); + + $columns = $this->client->getColumns(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals('Done', $columns[2]['title']); + $this->assertEquals('Work in progress', $columns[3]['title']); + } + + public function testMoveColumnDown() + { + $this->assertTrue($this->client->moveColumnDown(1, 4)); + + $columns = $this->client->getColumns(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals('Work in progress', $columns[2]['title']); + $this->assertEquals('Done', $columns[3]['title']); + } + + public function testUpdateColumn() + { + $this->assertTrue($this->client->updateColumn(4, array('title' => 'Boo', 'task_limit' => 2))); + + $columns = $this->client->getColumns(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals('Boo', $columns[3]['title']); + $this->assertEquals(2, $columns[3]['task_limit']); + } + + public function testAddColumn() + { + $this->assertTrue($this->client->addColumn(1, array('title' => 'New column'))); + + $columns = $this->client->getColumns(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals(5, count($columns)); + $this->assertEquals('New column', $columns[4]['title']); + } + + public function testRemoveColumn() + { + $this->assertTrue($this->client->removeColumn(5)); + + $columns = $this->client->getColumns(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals(4, count($columns)); + } + + public function testCreateTask() + { + $task = array( + 'title' => 'Task #1', + 'color_id' => 'blue', + 'owner_id' => 1, + 'project_id' => 1, + 'column_id' => 2, + ); + + $this->assertTrue($this->client->createTask($task)); + + $task = array( + 'title' => 'Task #1', + 'color_id' => 'blue', + 'owner_id' => 1, + ); + + $this->assertFalse($this->client->createTask($task)); + } + + public function testGetTask() + { + $task = $this->client->getTask(1); + + $this->assertNotFalse($task); + $this->assertTrue(is_array($task)); + $this->assertEquals('Task #1', $task['title']); + } + + public function testGetAllTasks() + { + $tasks = $this->client->getAllTasks(1, array(1)); + + $this->assertNotFalse($tasks); + $this->assertTrue(is_array($tasks)); + $this->assertEquals('Task #1', $tasks[0]['title']); + + $tasks = $this->client->getAllTasks(2, array(1, 2)); + + $this->assertNotFalse($tasks); + $this->assertTrue(is_array($tasks)); + $this->assertEmpty($tasks); + } + + public function testUpdateTask() + { + $task = $this->client->getTask(1); + $task['color_id'] = 'green'; + $task['column_id'] = 1; + $task['description'] = 'test'; + + $this->assertTrue($this->client->updateTask($task)); + } + + public function testRemoveTask() + { + $this->assertTrue($this->client->removeTask(1)); + } + + public function testRemoveUsers() + { + $users = $this->client->getAllUsers(); + $this->assertNotFalse($users); + $this->assertNotEmpty($users); + + foreach ($users as $user) { + if ($user['id'] > 1) { + $this->assertTrue($this->client->removeUser($user['id'])); + } + } + } + + public function testCreateUser() + { + $user = array( + 'username' => 'toto', + 'name' => 'Toto', + 'password' => '123456', + 'confirmation' => '123456', + ); + + $this->assertTrue($this->client->createUser($user)); + + $user = array( + 'username' => 'titi', + 'name' => 'Titi', + 'password' => '123456', + 'confirmation' => '789', + ); + + $this->assertFalse($this->client->createUser($user)); + } + + public function testGetUser() + { + $user = $this->client->getUser(2); + + $this->assertNotFalse($user); + $this->assertTrue(is_array($user)); + $this->assertEquals('toto', $user['username']); + } + + public function testUpdateUser() + { + $user = $this->client->getUser(2); + $user['username'] = 'titi'; + $user['name'] = 'Titi'; + unset($user['password']); + + $this->assertTrue($this->client->updateUser($user)); + + $user = $this->client->getUser(2); + + $this->assertNotFalse($user); + $this->assertTrue(is_array($user)); + $this->assertEquals('titi', $user['username']); + $this->assertEquals('Titi', $user['name']); + } + + public function testGetAllowedUsers() + { + $users = $this->client->getAllowedUsers(1); + $this->assertNotFalse($users); + $this->assertEquals(array(1 => 'admin', 2 => 'titi'), $users); + } + + public function testAllowedUser() + { + $this->assertTrue($this->client->allowUser(1, 2)); + + $users = $this->client->getAllowedUsers(1); + $this->assertNotFalse($users); + $this->assertEquals(array(2 => 'titi'), $users); + } + + public function testRevokeUser() + { + $this->assertTrue($this->client->revokeUser(1, 2)); + + $users = $this->client->getAllowedUsers(1); + $this->assertNotFalse($users); + $this->assertEquals(array(1 => 'admin', 2 => 'titi'), $users); + } + + public function testCreateComment() + { + $task = array( + 'title' => 'Task with comment', + 'color_id' => 'red', + 'owner_id' => 1, + 'project_id' => 1, + 'column_id' => 1, + ); + + $this->assertTrue($this->client->createTask($task)); + + $comment = array( + 'task_id' => 1, + 'user_id' => 2, + 'comment' => 'boo', + ); + + $this->assertTrue($this->client->createComment($comment)); + } + + public function testGetComment() + { + $comment = $this->client->getComment(1); + $this->assertNotFalse($comment); + $this->assertNotEmpty($comment); + $this->assertEquals(1, $comment['task_id']); + $this->assertEquals(2, $comment['user_id']); + $this->assertEquals('boo', $comment['comment']); + } + + public function testUpdateComment() + { + $comment = $this->client->getComment(1); + $comment['comment'] = 'test'; + + $this->assertTrue($this->client->updateComment($comment)); + + $comment = $this->client->getComment(1); + $this->assertEquals('test', $comment['comment']); + } + + public function testGetAllComments() + { + $comment = array( + 'task_id' => 1, + 'user_id' => 1, + 'comment' => 'blabla', + ); + + $this->assertTrue($this->client->createComment($comment)); + + $comments = $this->client->getAllComments(1); + $this->assertNotFalse($comments); + $this->assertNotEmpty($comments); + $this->assertTrue(is_array($comments)); + $this->assertEquals(2, count($comments)); + } + + public function testRemoveComment() + { + $this->assertTrue($this->client->removeComment(1)); + + $comments = $this->client->getAllComments(1); + $this->assertNotFalse($comments); + $this->assertNotEmpty($comments); + $this->assertTrue(is_array($comments)); + $this->assertEquals(1, count($comments)); + } + + public function testCreateSubtask() + { + $subtask = array( + 'task_id' => 1, + 'title' => 'subtask #1', + ); + + $this->assertTrue($this->client->createSubtask($subtask)); + } + + public function testGetSubtask() + { + $subtask = $this->client->getSubtask(1); + $this->assertNotFalse($subtask); + $this->assertNotEmpty($subtask); + $this->assertEquals(1, $subtask['task_id']); + $this->assertEquals(0, $subtask['user_id']); + $this->assertEquals('subtask #1', $subtask['title']); + } + + public function testUpdateSubtask() + { + $subtask = $this->client->getSubtask(1); + $subtask['title'] = 'test'; + + $this->assertTrue($this->client->updateSubtask($subtask)); + + $subtask = $this->client->getSubtask(1); + $this->assertEquals('test', $subtask['title']); + } + + public function testGetAllSubtasks() + { + $subtask = array( + 'task_id' => 1, + 'user_id' => 2, + 'title' => 'Subtask #2', + ); + + $this->assertTrue($this->client->createSubtask($subtask)); + + $subtasks = $this->client->getAllSubtasks(1); + $this->assertNotFalse($subtasks); + $this->assertNotEmpty($subtasks); + $this->assertTrue(is_array($subtasks)); + $this->assertEquals(2, count($subtasks)); + } + + public function testRemoveSubtask() + { + $this->assertTrue($this->client->removeSubtask(1)); + + $subtasks = $this->client->getAllSubtasks(1); + $this->assertNotFalse($subtasks); + $this->assertNotEmpty($subtasks); + $this->assertTrue(is_array($subtasks)); + $this->assertEquals(1, count($subtasks)); + } +/* + public function testAutomaticActions() + { + $task = array( + 'title' => 'Task #1', + 'color_id' => 'blue', + 'owner_id' => 0, + 'project_id' => 1, + 'column_id' => 1, + ); + + $this->assertTrue($this->client->createTask($task)); + + $tasks = $this->client->getAllTasks(1, array(1)); + $task = $tasks[count($tasks) - 1]; + $task['column_id'] = 3; + + $this->assertTrue($this->client->updateTask($task)); + }*/ +} diff --git a/tests/AclTest.php b/tests/units/AclTest.php index a2c1c111..a2c1c111 100644 --- a/tests/AclTest.php +++ b/tests/units/AclTest.php diff --git a/tests/ActionTaskAssignColorCategoryTest.php b/tests/units/ActionTaskAssignColorCategoryTest.php index 18b4311e..18b4311e 100644 --- a/tests/ActionTaskAssignColorCategoryTest.php +++ b/tests/units/ActionTaskAssignColorCategoryTest.php diff --git a/tests/ActionTaskAssignColorUserTest.php b/tests/units/ActionTaskAssignColorUserTest.php index 04e3172f..04e3172f 100644 --- a/tests/ActionTaskAssignColorUserTest.php +++ b/tests/units/ActionTaskAssignColorUserTest.php diff --git a/tests/ActionTaskAssignCurrentUserTest.php b/tests/units/ActionTaskAssignCurrentUserTest.php index 0780b603..0780b603 100644 --- a/tests/ActionTaskAssignCurrentUserTest.php +++ b/tests/units/ActionTaskAssignCurrentUserTest.php diff --git a/tests/ActionTaskAssignSpecificUserTest.php b/tests/units/ActionTaskAssignSpecificUserTest.php index 3a919978..3a919978 100644 --- a/tests/ActionTaskAssignSpecificUserTest.php +++ b/tests/units/ActionTaskAssignSpecificUserTest.php diff --git a/tests/ActionTaskCloseTest.php b/tests/units/ActionTaskCloseTest.php index 0c864f42..0c864f42 100644 --- a/tests/ActionTaskCloseTest.php +++ b/tests/units/ActionTaskCloseTest.php diff --git a/tests/ActionTaskDuplicateAnotherProjectTest.php b/tests/units/ActionTaskDuplicateAnotherProjectTest.php index 0b2e4bd5..0b2e4bd5 100644 --- a/tests/ActionTaskDuplicateAnotherProjectTest.php +++ b/tests/units/ActionTaskDuplicateAnotherProjectTest.php diff --git a/tests/ActionTest.php b/tests/units/ActionTest.php index 2eb12784..2eb12784 100644 --- a/tests/ActionTest.php +++ b/tests/units/ActionTest.php diff --git a/tests/units/Base.php b/tests/units/Base.php new file mode 100644 index 00000000..1f8109ed --- /dev/null +++ b/tests/units/Base.php @@ -0,0 +1,57 @@ +<?php + +if (version_compare(PHP_VERSION, '5.5.0', '<')) { + require __DIR__.'/../../vendor/password.php'; +} + +require_once __DIR__.'/../../app/Core/Security.php'; + +require_once __DIR__.'/../../vendor/PicoDb/Database.php'; +require_once __DIR__.'/../../app/Schema/Sqlite.php'; + +require_once __DIR__.'/../../app/Core/Listener.php'; +require_once __DIR__.'/../../app/Core/Event.php'; +require_once __DIR__.'/../../app/Core/Translator.php'; +require_once __DIR__.'/../../app/translator.php'; + +require_once __DIR__.'/../../app/Model/Base.php'; +require_once __DIR__.'/../../app/Model/Task.php'; +require_once __DIR__.'/../../app/Model/Acl.php'; +require_once __DIR__.'/../../app/Model/Comment.php'; +require_once __DIR__.'/../../app/Model/Project.php'; +require_once __DIR__.'/../../app/Model/User.php'; +require_once __DIR__.'/../../app/Model/Board.php'; +require_once __DIR__.'/../../app/Model/Action.php'; +require_once __DIR__.'/../../app/Model/Category.php'; + +require_once __DIR__.'/../../app/Action/Base.php'; +require_once __DIR__.'/../../app/Action/TaskClose.php'; +require_once __DIR__.'/../../app/Action/TaskAssignSpecificUser.php'; +require_once __DIR__.'/../../app/Action/TaskAssignColorUser.php'; +require_once __DIR__.'/../../app/Action/TaskAssignColorCategory.php'; +require_once __DIR__.'/../../app/Action/TaskAssignCurrentUser.php'; +require_once __DIR__.'/../../app/Action/TaskDuplicateAnotherProject.php'; + +abstract class Base extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->db = $this->getDbConnection(); + $this->event = new \Core\Event; + } + + public function getDbConnection() + { + $db = new \PicoDb\Database(array( + 'driver' => 'sqlite', + 'filename' => ':memory:' + )); + + if ($db->schema()->check(\Schema\VERSION)) { + return $db; + } + else { + die('Unable to migrate database schema!'); + } + } +} diff --git a/tests/BoardTest.php b/tests/units/BoardTest.php index d5686b3f..d5686b3f 100644 --- a/tests/BoardTest.php +++ b/tests/units/BoardTest.php diff --git a/tests/CommentTest.php b/tests/units/CommentTest.php index 46f05abc..46f05abc 100644 --- a/tests/CommentTest.php +++ b/tests/units/CommentTest.php diff --git a/tests/ProjectTest.php b/tests/units/ProjectTest.php index 5ca8177c..5ca8177c 100644 --- a/tests/ProjectTest.php +++ b/tests/units/ProjectTest.php diff --git a/tests/TaskTest.php b/tests/units/TaskTest.php index da7e6a70..da7e6a70 100644 --- a/tests/TaskTest.php +++ b/tests/units/TaskTest.php |