diff options
Diffstat (limited to 'tests/integration')
-rw-r--r-- | tests/integration/ApiTest.php | 928 | ||||
-rw-r--r-- | tests/integration/AppTest.php | 34 | ||||
-rw-r--r-- | tests/integration/Base.php | 62 | ||||
-rw-r--r-- | tests/integration/BoardTest.php | 21 | ||||
-rw-r--r-- | tests/integration/ColumnTest.php | 65 | ||||
-rw-r--r-- | tests/integration/GroupMemberTest.php | 39 | ||||
-rw-r--r-- | tests/integration/GroupTest.php | 48 | ||||
-rw-r--r-- | tests/integration/MeTest.php | 247 | ||||
-rw-r--r-- | tests/integration/ProjectPermissionTest.php | 64 | ||||
-rw-r--r-- | tests/integration/SwimlaneTest.php | 103 | ||||
-rw-r--r-- | tests/integration/TaskTest.php | 96 | ||||
-rw-r--r-- | tests/integration/UserTest.php | 18 |
12 files changed, 1725 insertions, 0 deletions
diff --git a/tests/integration/ApiTest.php b/tests/integration/ApiTest.php new file mode 100644 index 00000000..5fed0368 --- /dev/null +++ b/tests/integration/ApiTest.php @@ -0,0 +1,928 @@ +<?php + +require_once __DIR__.'/../../vendor/autoload.php'; + +class Api extends PHPUnit_Framework_TestCase +{ + private $client = 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->table('settings')->eq('option', 'application_timezone')->update(array('value' => 'Europe/Paris')); + $db->closeConnection(); + } + + public function setUp() + { + $this->client = new JsonRPC\Client(API_URL); + $this->client->authentication('jsonrpc', API_KEY); + // $this->client->debug = true; + } + + private function getTaskId() + { + $tasks = $this->client->getAllTasks(1, 1); + $this->assertNotEmpty($tasks); + + return $tasks[0]['id']; + } + + public function testRemoveAll() + { + $projects = $this->client->getAllProjects(); + + if ($projects) { + foreach ($projects as $project) { + $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); + $this->assertTrue($this->client->removeProject($project['id'])); + } + } + } + + public function testCreateProject() + { + $project_id = $this->client->createProject('API test'); + $this->assertNotFalse($project_id); + $this->assertInternalType('int', $project_id); + } + + public function testGetProjectById() + { + $project = $this->client->getProjectById(1); + $this->assertNotEmpty($project); + $this->assertEquals(1, $project['id']); + $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); + } + + public function testGetProjectByName() + { + $project = $this->client->getProjectByName('API test'); + $this->assertNotEmpty($project); + $this->assertEquals(1, $project['id']); + $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); + + $project = $this->client->getProjectByName(array('name' => 'API test')); + $this->assertNotEmpty($project); + $this->assertEquals(1, $project['id']); + + $project = $this->client->getProjectByName('None'); + $this->assertEmpty($project); + $this->assertNull($project); + } + + public function testGetAllProjects() + { + $projects = $this->client->getAllProjects(); + $this->assertNotEmpty($projects); + + foreach ($projects as $project) { + $this->assertEquals('http://127.0.0.1:8000/?controller=board&action=show&project_id='.$project['id'], $project['url']['board']); + $this->assertEquals('http://127.0.0.1:8000/?controller=calendar&action=show&project_id='.$project['id'], $project['url']['calendar']); + $this->assertEquals('http://127.0.0.1:8000/?controller=listing&action=show&project_id='.$project['id'], $project['url']['list']); + } + } + + public function testUpdateProject() + { + $project = $this->client->getProjectById(1); + $this->assertNotEmpty($project); + $this->assertTrue($this->client->execute('updateProject', array('id' => 1, 'name' => 'API test 2'))); + + $project = $this->client->getProjectById(1); + $this->assertEquals('API test 2', $project['name']); + + $this->assertTrue($this->client->execute('updateProject', array('id' => 1, 'name' => 'API test', 'description' => 'test'))); + + $project = $this->client->getProjectById(1); + $this->assertEquals('API test', $project['name']); + $this->assertEquals('test', $project['description']); + } + + public function testDisableProject() + { + $this->assertTrue($this->client->disableProject(1)); + $project = $this->client->getProjectById(1); + $this->assertNotEmpty($project); + $this->assertEquals(0, $project['is_active']); + } + + public function testEnableProject() + { + $this->assertTrue($this->client->enableProject(1)); + $project = $this->client->getProjectById(1); + $this->assertNotEmpty($project); + $this->assertEquals(1, $project['is_active']); + } + + public function testEnableProjectPublicAccess() + { + $this->assertTrue($this->client->enableProjectPublicAccess(1)); + $project = $this->client->getProjectById(1); + $this->assertNotEmpty($project); + $this->assertEquals(1, $project['is_public']); + $this->assertNotEmpty($project['token']); + } + + public function testDisableProjectPublicAccess() + { + $this->assertTrue($this->client->disableProjectPublicAccess(1)); + $project = $this->client->getProjectById(1); + $this->assertNotEmpty($project); + $this->assertEquals(0, $project['is_public']); + $this->assertEmpty($project['token']); + } + + public function testgetProjectActivities() + { + $activities = $this->client->getProjectActivities(array('project_ids' => array(1))); + $this->assertInternalType('array', $activities); + $this->assertCount(0, $activities); + } + + public function testgetProjectActivity() + { + $activities = $this->client->getProjectActivity(1); + $this->assertInternalType('array', $activities); + $this->assertCount(0, $activities); + } + + 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( + 'title' => 'Task #1', + 'color_id' => 'blue', + 'owner_id' => 1, + 'project_id' => 1, + 'column_id' => 2, + ); + + $task_id = $this->client->createTask($task); + + $this->assertNotFalse($task_id); + $this->assertInternalType('int', $task_id); + $this->assertTrue($task_id > 0); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testCreateTaskWithBadParams() + { + $task = array( + 'title' => 'Task #1', + 'color_id' => 'blue', + 'owner_id' => 1, + ); + + $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']); + $this->assertEquals('http://127.0.0.1:8000/?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']); + } + + public function testGetAllTasks() + { + $tasks = $this->client->getAllTasks(1, 1); + + $this->assertNotFalse($tasks); + $this->assertTrue(is_array($tasks)); + $this->assertEquals('Task #1', $tasks[0]['title']); + $this->assertEquals('http://127.0.0.1:8000/?controller=task&action=show&task_id='.$tasks[0]['id'].'&project_id='.$tasks[0]['project_id'], $tasks[0]['url']); + + $tasks = $this->client->getAllTasks(2, 0); + + $this->assertNotFalse($tasks); + $this->assertTrue(is_array($tasks)); + $this->assertEmpty($tasks); + } + + public function testMoveTaskSwimlane() + { + $task_id = $this->getTaskId(); + + $task = $this->client->getTask($task_id); + $this->assertNotFalse($task); + $this->assertTrue(is_array($task)); + $this->assertEquals(1, $task['position']); + $this->assertEquals(2, $task['column_id']); + $this->assertEquals(0, $task['swimlane_id']); + + $moved_timestamp = $task['date_moved']; + sleep(1); + $this->assertTrue($this->client->moveTaskPosition(1, $task_id, 4, 1, 2)); + + $task = $this->client->getTask($task_id); + $this->assertNotFalse($task); + $this->assertTrue(is_array($task)); + $this->assertEquals(1, $task['position']); + $this->assertEquals(4, $task['column_id']); + $this->assertEquals(2, $task['swimlane_id']); + $this->assertNotEquals($moved_timestamp, $task['date_moved']); + } + + public function testUpdateTask() + { + $task = $this->client->getTask(1); + + $values = array(); + $values['id'] = $task['id']; + $values['color_id'] = 'green'; + $values['description'] = 'test'; + $values['date_due'] = ''; + + $this->assertTrue($this->client->execute('updateTask', $values)); + } + + 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', + ); + + $user_id = $this->client->execute('createUser', $user); + $this->assertNotFalse($user_id); + $this->assertInternalType('int', $user_id); + $this->assertTrue($user_id > 0); + } + + public function testCreateManagerUser() + { + $user = array( + 'username' => 'manager', + 'name' => 'Manager', + 'password' => '123456', + 'role' => 'app-manager' + ); + + $user_id = $this->client->execute('createUser', $user); + $this->assertNotFalse($user_id); + $this->assertInternalType('int', $user_id); + $this->assertTrue($user_id > 0); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testCreateUserWithBadParams() + { + $user = array( + 'name' => 'Titi', + 'password' => '123456', + ); + + $this->assertNull($this->client->execute('createUser', $user)); + } + + public function testGetUser() + { + $user = $this->client->getUser(2); + $this->assertNotFalse($user); + $this->assertTrue(is_array($user)); + $this->assertEquals('toto', $user['username']); + + $user = $this->client->getUser(3); + $this->assertNotEmpty($user); + $this->assertEquals('app-manager', $user['role']); + + $this->assertNull($this->client->getUser(2222)); + } + + public function testGetUserByName() + { + $user = $this->client->getUserByName('toto'); + $this->assertNotFalse($user); + $this->assertTrue(is_array($user)); + $this->assertEquals(2, $user['id']); + + $user = $this->client->getUserByName('manager'); + $this->assertNotEmpty($user); + $this->assertEquals('app-manager', $user['role']); + + $this->assertNull($this->client->getUserByName('nonexistantusername')); + } + + public function testUpdateUser() + { + $user = array(); + $user['id'] = 2; + $user['username'] = 'titi'; + $user['name'] = 'Titi'; + + $this->assertTrue($this->client->execute('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']); + + $user = array(); + $user['id'] = 2; + $user['email'] = 'titi@localhost'; + + $this->assertTrue($this->client->execute('updateUser', $user)); + + $user = $this->client->getUser(2); + $this->assertNotFalse($user); + $this->assertTrue(is_array($user)); + $this->assertEquals('titi@localhost', $user['email']); + } + + public function testAllowedUser() + { + $this->assertTrue($this->client->allowUser(1, 2)); + + $users = $this->client->getMembers(1); + $this->assertNotFalse($users); + $this->assertEquals(array(1 => 'admin', 2 => 'Titi'), $users); + } + + public function testRevokeUser() + { + $this->assertTrue($this->client->revokeUser(1, 2)); + + $users = $this->client->getMembers(1); + $this->assertNotFalse($users); + $this->assertEquals(array(1 => 'admin'), $users); + } + + public function testCreateComment() + { + $task = array( + 'title' => 'Task with comment', + 'color_id' => 'red', + 'owner_id' => 1, + 'project_id' => 1, + 'column_id' => 1, + ); + + $this->assertNotFalse($this->client->execute('createTask', $task)); + + $tasks = $this->client->getAllTasks(1, 1); + $this->assertNotEmpty($tasks); + $this->assertEquals(1, count($tasks)); + + $comment = array( + 'task_id' => $tasks[0]['id'], + 'user_id' => 2, + 'content' => 'boo', + ); + + $comment_id = $this->client->execute('createComment', $comment); + + $this->assertNotFalse($comment_id); + $this->assertInternalType('int', $comment_id); + $this->assertTrue($comment_id > 0); + } + + public function testGetComment() + { + $comment = $this->client->getComment(1); + $this->assertNotFalse($comment); + $this->assertNotEmpty($comment); + $this->assertEquals(2, $comment['user_id']); + $this->assertEquals('boo', $comment['comment']); + } + + public function testUpdateComment() + { + $comment = array(); + $comment['id'] = 1; + $comment['content'] = 'test'; + + $this->assertTrue($this->client->execute('updateComment', $comment)); + + $comment = $this->client->getComment(1); + $this->assertEquals('test', $comment['comment']); + } + + public function testGetAllComments() + { + $task_id = $this->getTaskId(); + + $comment = array( + 'task_id' => $task_id, + 'user_id' => 1, + 'content' => 'blabla', + ); + + $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); + $this->assertNotEmpty($comments); + $this->assertTrue(is_array($comments)); + $this->assertEquals(2, count($comments)); + } + + public function testRemoveComment() + { + $task_id = $this->getTaskId(); + + $comments = $this->client->getAllComments($task_id); + $this->assertNotFalse($comments); + $this->assertNotEmpty($comments); + $this->assertTrue(is_array($comments)); + + foreach ($comments as $comment) { + $this->assertTrue($this->client->removeComment($comment['id'])); + } + + $comments = $this->client->getAllComments($task_id); + $this->assertNotFalse($comments); + $this->assertEmpty($comments); + $this->assertTrue(is_array($comments)); + } + + public function testCreateSubtask() + { + $subtask = array( + 'task_id' => $this->getTaskId(), + 'title' => 'subtask #1', + ); + + $subtask_id = $this->client->createSubtask($subtask); + + $this->assertNotFalse($subtask_id); + $this->assertInternalType('int', $subtask_id); + $this->assertTrue($subtask_id > 0); + } + + public function testGetSubtask() + { + $subtask = $this->client->getSubtask(1); + $this->assertNotFalse($subtask); + $this->assertNotEmpty($subtask); + $this->assertEquals($this->getTaskId(), $subtask['task_id']); + $this->assertEquals(0, $subtask['user_id']); + $this->assertEquals('subtask #1', $subtask['title']); + } + + public function testUpdateSubtask() + { + $subtask = array(); + $subtask['id'] = 1; + $subtask['task_id'] = $this->getTaskId(); + $subtask['title'] = 'test'; + + $this->assertTrue($this->client->execute('updateSubtask', $subtask)); + + $subtask = $this->client->getSubtask(1); + $this->assertEquals('test', $subtask['title']); + } + + public function testGetAllSubtasks() + { + $subtask = array( + 'task_id' => $this->getTaskId(), + 'user_id' => 2, + 'title' => 'Subtask #2', + ); + + $this->assertNotFalse($this->client->execute('createSubtask', $subtask)); + + $subtasks = $this->client->getAllSubtasks($this->getTaskId()); + $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($this->getTaskId()); + $this->assertNotFalse($subtasks); + $this->assertNotEmpty($subtasks); + $this->assertTrue(is_array($subtasks)); + $this->assertEquals(1, count($subtasks)); + } + + public function testMoveTaskPosition() + { + $task_id = $this->getTaskId(); + $this->assertTrue($this->client->moveTaskPosition(1, $task_id, 3, 1)); + + $task = $this->client->getTask($task_id); + $this->assertNotFalse($task); + $this->assertTrue(is_array($task)); + $this->assertEquals(1, $task['position']); + $this->assertEquals(3, $task['column_id']); + } + + public function testCategoryCreation() + { + $category = array( + 'name' => 'Category', + 'project_id' => 1, + ); + + $cat_id = $this->client->execute('createCategory', $category); + $this->assertNotFalse($cat_id); + $this->assertInternalType('int', $cat_id); + $this->assertTrue($cat_id > 0); + + // Duplicate + + $category = array( + 'name' => 'Category', + 'project_id' => 1, + ); + + $this->assertFalse($this->client->execute('createCategory', $category)); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testCategoryCreationWithBadParams() + { + // Missing project id + $category = array( + 'name' => 'Category', + ); + + $this->assertNull($this->client->execute('createCategory', $category)); + } + + public function testCategoryRead() + { + $category = $this->client->getCategory(1); + + $this->assertTrue(is_array($category)); + $this->assertNotEmpty($category); + $this->assertEquals(1, $category['id']); + $this->assertEquals('Category', $category['name']); + $this->assertEquals(1, $category['project_id']); + } + + public function testGetAllCategories() + { + $categories = $this->client->getAllCategories(1); + + $this->assertNotEmpty($categories); + $this->assertNotFalse($categories); + $this->assertTrue(is_array($categories)); + $this->assertEquals(1, count($categories)); + $this->assertEquals(1, $categories[0]['id']); + $this->assertEquals('Category', $categories[0]['name']); + $this->assertEquals(1, $categories[0]['project_id']); + } + + public function testCategoryUpdate() + { + $category = array( + 'id' => 1, + 'name' => 'Renamed category', + ); + + $this->assertTrue($this->client->execute('updateCategory', $category)); + + $category = $this->client->getCategory(1); + $this->assertTrue(is_array($category)); + $this->assertNotEmpty($category); + $this->assertEquals(1, $category['id']); + $this->assertEquals('Renamed category', $category['name']); + $this->assertEquals(1, $category['project_id']); + } + + public function testCategoryRemove() + { + $this->assertTrue($this->client->removeCategory(1)); + $this->assertFalse($this->client->removeCategory(1)); + $this->assertFalse($this->client->removeCategory(1111)); + } + + public function testGetAvailableActions() + { + $actions = $this->client->getAvailableActions(); + $this->assertNotEmpty($actions); + $this->assertInternalType('array', $actions); + $this->assertArrayHasKey('\Kanboard\Action\TaskCloseColumn', $actions); + } + + public function testGetAvailableActionEvents() + { + $events = $this->client->getAvailableActionEvents(); + $this->assertNotEmpty($events); + $this->assertInternalType('array', $events); + $this->assertArrayHasKey('task.move.column', $events); + } + + public function testGetCompatibleActionEvents() + { + $events = $this->client->getCompatibleActionEvents('\Kanboard\Action\TaskCloseColumn'); + $this->assertNotEmpty($events); + $this->assertInternalType('array', $events); + $this->assertArrayHasKey('task.move.column', $events); + } + + public function testCreateAction() + { + $action_id = $this->client->createAction(1, 'task.move.column', '\Kanboard\Action\TaskCloseColumn', array('column_id' => 1)); + $this->assertNotFalse($action_id); + $this->assertEquals(1, $action_id); + } + + public function testGetActions() + { + $actions = $this->client->getActions(1); + $this->assertNotEmpty($actions); + $this->assertInternalType('array', $actions); + $this->assertCount(1, $actions); + $this->assertArrayHasKey('id', $actions[0]); + $this->assertArrayHasKey('project_id', $actions[0]); + $this->assertArrayHasKey('event_name', $actions[0]); + $this->assertArrayHasKey('action_name', $actions[0]); + $this->assertArrayHasKey('params', $actions[0]); + $this->assertArrayHasKey('column_id', $actions[0]['params']); + } + + public function testRemoveAction() + { + $this->assertTrue($this->client->removeAction(1)); + + $actions = $this->client->getActions(1); + $this->assertEmpty($actions); + $this->assertCount(0, $actions); + } + + public function testGetAllLinks() + { + $links = $this->client->getAllLinks(); + $this->assertNotEmpty($links); + $this->assertArrayHasKey('id', $links[0]); + $this->assertArrayHasKey('label', $links[0]); + $this->assertArrayHasKey('opposite_id', $links[0]); + } + + public function testGetOppositeLink() + { + $link = $this->client->getOppositeLinkId(1); + $this->assertEquals(1, $link); + + $link = $this->client->getOppositeLinkId(2); + $this->assertEquals(3, $link); + } + + public function testGetLinkByLabel() + { + $link = $this->client->getLinkByLabel('blocks'); + $this->assertNotEmpty($link); + $this->assertEquals(2, $link['id']); + $this->assertEquals(3, $link['opposite_id']); + } + + public function testGetLinkById() + { + $link = $this->client->getLinkById(4); + $this->assertNotEmpty($link); + $this->assertEquals(4, $link['id']); + $this->assertEquals(5, $link['opposite_id']); + $this->assertEquals('duplicates', $link['label']); + } + + public function testCreateLink() + { + $link_id = $this->client->createLink(array('label' => 'test')); + $this->assertNotFalse($link_id); + $this->assertInternalType('int', $link_id); + + $link_id = $this->client->createLink(array('label' => 'foo', 'opposite_label' => 'bar')); + $this->assertNotFalse($link_id); + $this->assertInternalType('int', $link_id); + } + + public function testUpdateLink() + { + $link1 = $this->client->getLinkByLabel('bar'); + $this->assertNotEmpty($link1); + + $link2 = $this->client->getLinkByLabel('test'); + $this->assertNotEmpty($link2); + + $this->assertNotFalse($this->client->updateLink($link1['id'], $link2['id'], 'boo')); + + $link = $this->client->getLinkById($link1['id']); + $this->assertNotEmpty($link); + $this->assertEquals($link2['id'], $link['opposite_id']); + $this->assertEquals('boo', $link['label']); + + $this->assertTrue($this->client->removeLink($link1['id'])); + } + + public function testCreateTaskLink() + { + $task_id1 = $this->client->createTask(array('project_id' => 1, 'title' => 'A')); + $this->assertNotFalse($task_id1); + + $task_id2 = $this->client->createTask(array('project_id' => 1, 'title' => 'B')); + $this->assertNotFalse($task_id2); + + $task_id3 = $this->client->createTask(array('project_id' => 1, 'title' => 'C')); + $this->assertNotFalse($task_id3); + + $task_link_id = $this->client->createTaskLink($task_id1, $task_id2, 1); + $this->assertNotFalse($task_link_id); + + $task_link = $this->client->getTaskLinkById($task_link_id); + $this->assertNotEmpty($task_link); + $this->assertEquals($task_id1, $task_link['task_id']); + $this->assertEquals($task_id2, $task_link['opposite_task_id']); + $this->assertEquals(1, $task_link['link_id']); + + $task_links = $this->client->getAllTaskLinks($task_id1); + $this->assertNotEmpty($task_links); + $this->assertCount(1, $task_links); + + $this->assertTrue($this->client->updateTaskLink($task_link_id, $task_id1, $task_id3, 2)); + + $task_link = $this->client->getTaskLinkById($task_link_id); + $this->assertNotEmpty($task_link); + $this->assertEquals($task_id1, $task_link['task_id']); + $this->assertEquals($task_id3, $task_link['opposite_task_id']); + $this->assertEquals(2, $task_link['link_id']); + + $this->assertTrue($this->client->removeTaskLink($task_link_id)); + $this->assertEmpty($this->client->getAllTaskLinks($task_id1)); + } + + public function testCreateFile() + { + $this->assertNotFalse($this->client->createFile(1, $this->getTaskId(), 'My file', base64_encode('plain text file'))); + } + + public function testGetAllFiles() + { + $files = $this->client->getAllFiles(array('task_id' => $this->getTaskId())); + + $this->assertNotEmpty($files); + $this->assertCount(1, $files); + $this->assertEquals('My file', $files[0]['name']); + + $file = $this->client->getFile($files[0]['id']); + $this->assertNotEmpty($file); + $this->assertEquals('My file', $file['name']); + + $content = $this->client->downloadFile($file['id']); + $this->assertNotEmpty($content); + $this->assertEquals('plain text file', base64_decode($content)); + + $content = $this->client->downloadFile(1234567); + $this->assertEmpty($content); + + $this->assertTrue($this->client->removeFile($file['id'])); + $this->assertEmpty($this->client->getAllFiles(1)); + } + + public function testRemoveAllFiles() + { + $this->assertNotFalse($this->client->createFile(1, $this->getTaskId(), 'My file 1', base64_encode('plain text file'))); + $this->assertNotFalse($this->client->createFile(1, $this->getTaskId(), 'My file 2', base64_encode('plain text file'))); + + $files = $this->client->getAllFiles(array('task_id' => $this->getTaskId())); + $this->assertNotEmpty($files); + $this->assertCount(2, $files); + + $this->assertTrue($this->client->removeAllFiles(array('task_id' => $this->getTaskId()))); + + $files = $this->client->getAllFiles(array('task_id' => $this->getTaskId())); + $this->assertEmpty($files); + } + + public function testCreateTaskWithReference() + { + $task = array( + 'title' => 'Task with external ticket number', + 'reference' => 'TICKET-1234', + 'project_id' => 1, + 'description' => '[Link to my ticket](http://my-ticketing-system/1234)', + ); + + $task_id = $this->client->createTask($task); + + $this->assertNotFalse($task_id); + $this->assertInternalType('int', $task_id); + $this->assertTrue($task_id > 0); + } + + public function testGetTaskByReference() + { + $task = $this->client->getTaskByReference(array('project_id' => 1, 'reference' => 'TICKET-1234')); + + $this->assertNotEmpty($task); + $this->assertEquals('Task with external ticket number', $task['title']); + $this->assertEquals('TICKET-1234', $task['reference']); + $this->assertEquals('http://127.0.0.1:8000/?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'], $task['url']); + } + + public function testCreateOverdueTask() + { + $this->assertNotFalse($this->client->createTask(array( + 'title' => 'overdue task', + 'project_id' => 1, + 'date_due' => date('Y-m-d', strtotime('-2days')), + ))); + } + + public function testGetOverdueTasksByProject() + { + $tasks = $this->client->getOverdueTasksByProject(1); + $this->assertNotEmpty($tasks); + $this->assertCount(1, $tasks); + $this->assertEquals('overdue task', $tasks[0]['title']); + $this->assertEquals('API test', $tasks[0]['project_name']); + } + + public function testGetOverdueTasks() + { + $tasks = $this->client->getOverdueTasks(); + $this->assertNotEmpty($tasks); + $this->assertCount(1, $tasks); + $this->assertEquals('overdue task', $tasks[0]['title']); + $this->assertEquals('API test', $tasks[0]['project_name']); + } +} 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..983d0ed9 --- /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/BoardTest.php b/tests/integration/BoardTest.php new file mode 100644 index 00000000..bf8d50b9 --- /dev/null +++ b/tests/integration/BoardTest.php @@ -0,0 +1,21 @@ +<?php + +require_once __DIR__.'/Base.php'; + +class BoardTest extends Base +{ + public function testCreateProject() + { + $this->assertEquals(1, $this->app->createProject('A project')); + } + + public function testGetBoard() + { + $board = $this->app->getBoard(1); + $this->assertCount(1, $board); + $this->assertEquals('Default swimlane', $board[0]['name']); + + $this->assertCount(4, $board[0]['columns']); + $this->assertEquals('Ready', $board[0]['columns'][1]['title']); + } +} diff --git a/tests/integration/ColumnTest.php b/tests/integration/ColumnTest.php new file mode 100644 index 00000000..6d02afc0 --- /dev/null +++ b/tests/integration/ColumnTest.php @@ -0,0 +1,65 @@ +<?php + +require_once __DIR__.'/Base.php'; + +class ColumnTest extends Base +{ + public function testCreateProject() + { + $this->assertEquals(1, $this->app->createProject('A project')); + } + + public function testGetColumns() + { + $columns = $this->app->getColumns($this->getProjectId()); + $this->assertCount(4, $columns); + $this->assertEquals('Done', $columns[3]['title']); + } + + public function testUpdateColumn() + { + $this->assertTrue($this->app->updateColumn(4, 'Boo', 2)); + + $columns = $this->app->getColumns($this->getProjectId()); + $this->assertEquals('Boo', $columns[3]['title']); + $this->assertEquals(2, $columns[3]['task_limit']); + } + + public function testAddColumn() + { + $column_id = $this->app->addColumn($this->getProjectId(), 'New column'); + + $this->assertNotFalse($column_id); + $this->assertInternalType('int', $column_id); + $this->assertTrue($column_id > 0); + + $columns = $this->app->getColumns($this->getProjectId()); + $this->assertCount(5, $columns); + $this->assertEquals('New column', $columns[4]['title']); + } + + public function testRemoveColumn() + { + $this->assertTrue($this->app->removeColumn(5)); + + $columns = $this->app->getColumns($this->getProjectId()); + $this->assertCount(4, $columns); + } + + public function testChangeColumnPosition() + { + $this->assertTrue($this->app->changeColumnPosition($this->getProjectId(), 1, 3)); + + $columns = $this->app->getColumns($this->getProjectId()); + $this->assertCount(4, $columns); + + $this->assertEquals('Ready', $columns[0]['title']); + $this->assertEquals(1, $columns[0]['position']); + $this->assertEquals('Work in progress', $columns[1]['title']); + $this->assertEquals(2, $columns[1]['position']); + $this->assertEquals('Backlog', $columns[2]['title']); + $this->assertEquals(3, $columns[2]['position']); + $this->assertEquals('Boo', $columns[3]['title']); + $this->assertEquals(4, $columns[3]['position']); + } +} 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/integration/MeTest.php b/tests/integration/MeTest.php new file mode 100644 index 00000000..21f61756 --- /dev/null +++ b/tests/integration/MeTest.php @@ -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']); + } +} 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)); + } +} diff --git a/tests/integration/SwimlaneTest.php b/tests/integration/SwimlaneTest.php new file mode 100644 index 00000000..88747204 --- /dev/null +++ b/tests/integration/SwimlaneTest.php @@ -0,0 +1,103 @@ +<?php + +require_once __DIR__.'/Base.php'; + +class SwimlaneTest extends Base +{ + public function testCreateProject() + { + $this->assertEquals(1, $this->app->createProject('A project')); + } + + public function testGetDefaultSwimlane() + { + $swimlane = $this->app->getDefaultSwimlane(1); + $this->assertNotEmpty($swimlane); + $this->assertEquals('Default swimlane', $swimlane['default_swimlane']); + } + + public function testAddSwimlane() + { + $swimlane_id = $this->app->addSwimlane(1, 'Swimlane 1'); + $this->assertNotFalse($swimlane_id); + $this->assertInternalType('int', $swimlane_id); + + $swimlane = $this->app->getSwimlaneById($swimlane_id); + $this->assertNotEmpty($swimlane); + $this->assertInternalType('array', $swimlane); + $this->assertEquals('Swimlane 1', $swimlane['name']); + } + + public function testGetSwimlane() + { + $swimlane = $this->app->getSwimlane(1); + $this->assertInternalType('array', $swimlane); + $this->assertEquals('Swimlane 1', $swimlane['name']); + } + + public function testUpdateSwimlane() + { + $swimlane = $this->app->getSwimlaneByName(1, 'Swimlane 1'); + $this->assertInternalType('array', $swimlane); + $this->assertEquals(1, $swimlane['id']); + $this->assertEquals('Swimlane 1', $swimlane['name']); + + $this->assertTrue($this->app->updateSwimlane($swimlane['id'], 'Another swimlane')); + + $swimlane = $this->app->getSwimlaneById($swimlane['id']); + $this->assertEquals('Another swimlane', $swimlane['name']); + } + + public function testDisableSwimlane() + { + $this->assertTrue($this->app->disableSwimlane(1, 1)); + + $swimlane = $this->app->getSwimlaneById(1); + $this->assertEquals(0, $swimlane['is_active']); + } + + public function testEnableSwimlane() + { + $this->assertTrue($this->app->enableSwimlane(1, 1)); + + $swimlane = $this->app->getSwimlaneById(1); + $this->assertEquals(1, $swimlane['is_active']); + } + + public function testGetAllSwimlanes() + { + $this->assertNotFalse($this->app->addSwimlane(1, 'Swimlane A')); + + $swimlanes = $this->app->getAllSwimlanes(1); + $this->assertCount(2, $swimlanes); + $this->assertEquals('Another swimlane', $swimlanes[0]['name']); + $this->assertEquals('Swimlane A', $swimlanes[1]['name']); + } + + public function testGetActiveSwimlane() + { + $this->assertTrue($this->app->disableSwimlane(1, 1)); + + $swimlanes = $this->app->getActiveSwimlanes(1); + $this->assertCount(2, $swimlanes); + $this->assertEquals('Default swimlane', $swimlanes[0]['name']); + $this->assertEquals('Swimlane A', $swimlanes[1]['name']); + } + + public function testRemoveSwimlane() + { + $this->assertTrue($this->app->removeSwimlane(1, 2)); + } + + public function testChangePosition() + { + $this->assertNotFalse($this->app->addSwimlane(1, 'Swimlane 1')); + $this->assertNotFalse($this->app->addSwimlane(1, 'Swimlane 2')); + + $swimlanes = $this->app->getAllSwimlanes(1); + $this->assertCount(3, $swimlanes); + + $this->assertTrue($this->app->changeSwimlanePosition(1, 1, 3)); + $this->assertFalse($this->app->changeSwimlanePosition(1, 1, 6)); + } +} diff --git a/tests/integration/TaskTest.php b/tests/integration/TaskTest.php new file mode 100644 index 00000000..6d500da4 --- /dev/null +++ b/tests/integration/TaskTest.php @@ -0,0 +1,96 @@ +<?php + +require_once __DIR__.'/Base.php'; + +class TaskTest extends Base +{ + public function testChangeAssigneeToAssignableUser() + { + $project_id = $this->app->createProject('My project'); + $this->assertNotFalse($project_id); + + $user_id = $this->app->createUser('user0', 'password'); + $this->assertNotFalse($user_id); + + $this->assertTrue($this->app->addProjectUser($project_id, $user_id, 'project-member')); + + $task_id = $this->app->createTask(array('project_id' => $project_id, 'title' => 'My task')); + $this->assertNotFalse($task_id); + + $this->assertTrue($this->app->updateTask(array('id' => $task_id, 'project_id' => $project_id, 'owner_id' => $user_id))); + + $task = $this->app->getTask($task_id); + $this->assertEquals($user_id, $task['owner_id']); + } + + public function testChangeAssigneeToNotAssignableUser() + { + $project_id = $this->app->createProject('My project'); + $this->assertNotFalse($project_id); + + $task_id = $this->app->createTask(array('project_id' => $project_id, 'title' => 'My task')); + $this->assertNotFalse($task_id); + + $this->assertFalse($this->app->updateTask(array('id' => $task_id, 'project_id' => $project_id, 'owner_id' => 1))); + + $task = $this->app->getTask($task_id); + $this->assertEquals(0, $task['owner_id']); + } + + public function testChangeAssigneeToNobody() + { + $project_id = $this->app->createProject('My project'); + $this->assertNotFalse($project_id); + + $user_id = $this->app->createUser('user1', 'password'); + $this->assertNotFalse($user_id); + + $this->assertTrue($this->app->addProjectUser($project_id, $user_id, 'project-member')); + + $task_id = $this->app->createTask(array('project_id' => $project_id, 'title' => 'My task', 'owner_id' => $user_id)); + $this->assertNotFalse($task_id); + + $this->assertTrue($this->app->updateTask(array('id' => $task_id, 'project_id' => $project_id, 'owner_id' => 0))); + + $task = $this->app->getTask($task_id); + $this->assertEquals(0, $task['owner_id']); + } + + public function testMoveTaskToAnotherProject() + { + $project_id1 = $this->app->createProject('My project'); + $this->assertNotFalse($project_id1); + + $project_id2 = $this->app->createProject('My project'); + $this->assertNotFalse($project_id2); + + $task_id = $this->app->createTask(array('project_id' => $project_id1, 'title' => 'My task')); + $this->assertNotFalse($task_id); + + $this->assertTrue($this->app->moveTaskToProject($task_id, $project_id2)); + + $task = $this->app->getTask($task_id); + $this->assertEquals($project_id2, $task['project_id']); + } + + public function testMoveCopyToAnotherProject() + { + $project_id1 = $this->app->createProject('My project'); + $this->assertNotFalse($project_id1); + + $project_id2 = $this->app->createProject('My project'); + $this->assertNotFalse($project_id2); + + $task_id1 = $this->app->createTask(array('project_id' => $project_id1, 'title' => 'My task')); + $this->assertNotFalse($task_id1); + + $task_id2 = $this->app->duplicateTaskToProject($task_id1, $project_id2); + $this->assertNotFalse($task_id2); + + $task = $this->app->getTask($task_id1); + $this->assertEquals($project_id1, $task['project_id']); + + $task = $this->app->getTask($task_id2); + $this->assertEquals($project_id2, $task['project_id']); + } +} diff --git a/tests/integration/UserTest.php b/tests/integration/UserTest.php new file mode 100644 index 00000000..10da051c --- /dev/null +++ b/tests/integration/UserTest.php @@ -0,0 +1,18 @@ +<?php + +require_once __DIR__.'/Base.php'; + +class UserTest extends Base +{ + public function testDisableUser() + { + $this->assertEquals(2, $this->app->createUser(array('username' => 'someone', 'password' => 'test123'))); + $this->assertTrue($this->app->isActiveUser(2)); + + $this->assertTrue($this->app->disableUser(2)); + $this->assertFalse($this->app->isActiveUser(2)); + + $this->assertTrue($this->app->enableUser(2)); + $this->assertTrue($this->app->isActiveUser(2)); + } +} |