diff options
Diffstat (limited to 'tests')
182 files changed, 10963 insertions, 8485 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 7576f031..5fed0368 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(); @@ -180,190 +170,31 @@ class Api extends PHPUnit_Framework_TestCase $this->assertCount(0, $activities); } - public function testGetBoard() - { - $board = $this->client->getBoard(1); - $this->assertTrue(is_array($board)); - $this->assertEquals(1, count($board)); - $this->assertEquals('Default swimlane', $board[0]['name']); - $this->assertEquals(4, count($board[0]['columns'])); - } - - 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, 'Boo', 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() - { - $column_id = $this->client->addColumn(1, 'New column'); - - $this->assertNotFalse($column_id); - $this->assertInternalType('int', $column_id); - $this->assertTrue($column_id > 0); - - $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 testGetDefaultSwimlane() - { - $swimlane = $this->client->getDefaultSwimlane(1); - $this->assertNotEmpty($swimlane); - $this->assertEquals('Default swimlane', $swimlane['default_swimlane']); - } - - public function testAddSwimlane() - { - $swimlane_id = $this->client->addSwimlane(1, 'Swimlane 1'); - $this->assertNotFalse($swimlane_id); - $this->assertInternalType('int', $swimlane_id); - - $swimlane = $this->client->getSwimlaneById($swimlane_id); - $this->assertNotEmpty($swimlane); - $this->assertInternalType('array', $swimlane); - $this->assertEquals('Swimlane 1', $swimlane['name']); - } - - public function testGetSwimlane() - { - $swimlane = $this->client->getSwimlane(1); - $this->assertNotEmpty($swimlane); - $this->assertInternalType('array', $swimlane); - $this->assertEquals('Swimlane 1', $swimlane['name']); - } - - public function testUpdateSwimlane() - { - $swimlane = $this->client->getSwimlaneByName(1, 'Swimlane 1'); - $this->assertNotEmpty($swimlane); - $this->assertInternalType('array', $swimlane); - $this->assertEquals(1, $swimlane['id']); - $this->assertEquals('Swimlane 1', $swimlane['name']); - - $this->assertTrue($this->client->updateSwimlane($swimlane['id'], 'Another swimlane')); - - $swimlane = $this->client->getSwimlaneById($swimlane['id']); - $this->assertNotEmpty($swimlane); - $this->assertEquals('Another swimlane', $swimlane['name']); - } - - public function testDisableSwimlane() - { - $this->assertTrue($this->client->disableSwimlane(1, 1)); - - $swimlane = $this->client->getSwimlaneById(1); - $this->assertNotEmpty($swimlane); - $this->assertEquals(0, $swimlane['is_active']); - } - - public function testEnableSwimlane() - { - $this->assertTrue($this->client->enableSwimlane(1, 1)); - - $swimlane = $this->client->getSwimlaneById(1); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - } - - public function testGetAllSwimlanes() + public function testCreateTaskWithWrongMember() { - $this->assertNotFalse($this->client->addSwimlane(1, 'Swimlane A')); - - $swimlanes = $this->client->getAllSwimlanes(1); - $this->assertNotEmpty($swimlanes); - $this->assertCount(2, $swimlanes); - $this->assertEquals('Another swimlane', $swimlanes[0]['name']); - $this->assertEquals('Swimlane A', $swimlanes[1]['name']); - } + $task = array( + 'title' => 'Task #1', + 'color_id' => 'blue', + 'owner_id' => 1, + 'project_id' => 1, + 'column_id' => 2, + ); - public function testGetActiveSwimlane() - { - $this->assertTrue($this->client->disableSwimlane(1, 1)); + $task_id = $this->client->createTask($task); - $swimlanes = $this->client->getActiveSwimlanes(1); - $this->assertNotEmpty($swimlanes); - $this->assertCount(2, $swimlanes); - $this->assertEquals('Default swimlane', $swimlanes[0]['name']); - $this->assertEquals('Swimlane A', $swimlanes[1]['name']); + $this->assertFalse($task_id); } - public function testMoveSwimlaneUp() + public function testGetAllowedUsers() { - $this->assertTrue($this->client->enableSwimlane(1, 1)); - $this->assertTrue($this->client->moveSwimlaneUp(1, 1)); - - $swimlanes = $this->client->getActiveSwimlanes(1); - $this->assertNotEmpty($swimlanes); - $this->assertCount(3, $swimlanes); - $this->assertEquals('Default swimlane', $swimlanes[0]['name']); - $this->assertEquals('Another swimlane', $swimlanes[1]['name']); - $this->assertEquals('Swimlane A', $swimlanes[2]['name']); - - $this->assertTrue($this->client->moveSwimlaneUp(1, 2)); - - $swimlanes = $this->client->getActiveSwimlanes(1); - $this->assertNotEmpty($swimlanes); - $this->assertCount(3, $swimlanes); - $this->assertEquals('Default swimlane', $swimlanes[0]['name']); - $this->assertEquals('Swimlane A', $swimlanes[1]['name']); - $this->assertEquals('Another swimlane', $swimlanes[2]['name']); + $users = $this->client->getMembers(1); + $this->assertNotFalse($users); + $this->assertEquals(array(), $users); } - public function testMoveSwimlaneDown() + public function testAddMember() { - $this->assertTrue($this->client->moveSwimlaneDown(1, 2)); - - $swimlanes = $this->client->getActiveSwimlanes(1); - $this->assertNotEmpty($swimlanes); - $this->assertCount(3, $swimlanes); - $this->assertEquals('Default swimlane', $swimlanes[0]['name']); - $this->assertEquals('Another swimlane', $swimlanes[1]['name']); - $this->assertEquals('Swimlane A', $swimlanes[2]['name']); + $this->assertTrue($this->client->allowUser(1, 1)); } public function testCreateTask() @@ -447,18 +278,6 @@ class Api extends PHPUnit_Framework_TestCase $this->assertNotEquals($moved_timestamp, $task['date_moved']); } - public function testRemoveSwimlane() - { - $this->assertTrue($this->client->removeSwimlane(1, 2)); - - $task = $this->client->getTask($this->getTaskId()); - $this->assertNotFalse($task); - $this->assertTrue(is_array($task)); - $this->assertEquals(1, $task['position']); - $this->assertEquals(4, $task['column_id']); - $this->assertEquals(0, $task['swimlane_id']); - } - public function testUpdateTask() { $task = $this->client->getTask(1); @@ -504,6 +323,21 @@ class Api extends PHPUnit_Framework_TestCase $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 */ @@ -524,9 +358,27 @@ class Api extends PHPUnit_Framework_TestCase $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(); @@ -554,20 +406,13 @@ class Api extends PHPUnit_Framework_TestCase $this->assertEquals('titi@localhost', $user['email']); } - public function testGetAllowedUsers() - { - $users = $this->client->getMembers(1); - $this->assertNotFalse($users); - $this->assertEquals(array(), $users); - } - public function testAllowedUser() { $this->assertTrue($this->client->allowUser(1, 2)); $users = $this->client->getMembers(1); $this->assertNotFalse($users); - $this->assertEquals(array(2 => 'Titi'), $users); + $this->assertEquals(array(1 => 'admin', 2 => 'Titi'), $users); } public function testRevokeUser() @@ -576,7 +421,7 @@ class Api extends PHPUnit_Framework_TestCase $users = $this->client->getMembers(1); $this->assertNotFalse($users); - $this->assertEquals(array(), $users); + $this->assertEquals(array(1 => 'admin'), $users); } public function testCreateComment() @@ -836,7 +681,7 @@ class Api extends PHPUnit_Framework_TestCase $actions = $this->client->getAvailableActions(); $this->assertNotEmpty($actions); $this->assertInternalType('array', $actions); - $this->assertArrayHasKey('TaskLogMoveAnotherColumn', $actions); + $this->assertArrayHasKey('\Kanboard\Action\TaskCloseColumn', $actions); } public function testGetAvailableActionEvents() @@ -849,7 +694,7 @@ class Api extends PHPUnit_Framework_TestCase public function testGetCompatibleActionEvents() { - $events = $this->client->getCompatibleActionEvents('TaskClose'); + $events = $this->client->getCompatibleActionEvents('\Kanboard\Action\TaskCloseColumn'); $this->assertNotEmpty($events); $this->assertInternalType('array', $events); $this->assertArrayHasKey('task.move.column', $events); @@ -857,7 +702,7 @@ class Api extends PHPUnit_Framework_TestCase public function testCreateAction() { - $action_id = $this->client->createAction(1, 'task.move.column', 'TaskClose', array('column_id' => 1)); + $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); } 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/functionals/UserApiTest.php b/tests/integration/MeTest.php index 8a80c706..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')); @@ -163,6 +121,12 @@ class UserApi extends PHPUnit_Framework_TestCase $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); @@ -218,6 +182,11 @@ class UserApi extends PHPUnit_Framework_TestCase $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))); 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)); + } +} diff --git a/tests/units/Action/BaseActionTest.php b/tests/units/Action/BaseActionTest.php new file mode 100644 index 00000000..1d50c70e --- /dev/null +++ b/tests/units/Action/BaseActionTest.php @@ -0,0 +1,144 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\GenericEvent; + +class DummyAction extends Kanboard\Action\Base +{ + public function getDescription() + { + return 'Dummy Action'; + } + + public function getCompatibleEvents() + { + return array('my.event'); + } + + public function getActionRequiredParameters() + { + return array('p1' => 'Param 1'); + } + + public function getEventRequiredParameters() + { + return array('p1', 'p2'); + } + + public function doAction(array $data) + { + return true; + } + + public function hasRequiredCondition(array $data) + { + return $data['p1'] == $this->getParam('p1'); + } +} + +class BaseActionTest extends Base +{ + public function testGetName() + { + $dummyAction = new DummyAction($this->container); + $this->assertEquals('\\DummyAction', $dummyAction->getName()); + } + + public function testGetDescription() + { + $dummyAction = new DummyAction($this->container); + $this->assertEquals('Dummy Action', $dummyAction->getDescription()); + } + + public function testGetActionRequiredParameters() + { + $dummyAction = new DummyAction($this->container); + $this->assertEquals(array('p1' => 'Param 1'), $dummyAction->getActionRequiredParameters()); + } + + public function testGetEventRequiredParameters() + { + $dummyAction = new DummyAction($this->container); + $this->assertEquals(array('p1', 'p2'), $dummyAction->getEventRequiredParameters()); + } + + public function testGetCompatibleEvents() + { + $dummyAction = new DummyAction($this->container); + $this->assertEquals(array('my.event'), $dummyAction->getCompatibleEvents()); + } + + public function testHasRequiredCondition() + { + $dummyAction = new DummyAction($this->container); + $dummyAction->setParam('p1', 123); + $this->assertTrue($dummyAction->hasRequiredCondition(array('p1' => 123))); + $this->assertFalse($dummyAction->hasRequiredCondition(array('p1' => 456))); + } + + public function testProjectId() + { + $dummyAction = new DummyAction($this->container); + $this->assertInstanceOf('DummyAction', $dummyAction->setProjectId(123)); + $this->assertEquals(123, $dummyAction->getProjectId()); + } + + public function testParam() + { + $dummyAction = new DummyAction($this->container); + $this->assertInstanceOf('DummyAction', $dummyAction->setParam('p1', 123)); + $this->assertEquals(123, $dummyAction->getParam('p1')); + } + + public function testHasCompatibleEvents() + { + $dummyAction = new DummyAction($this->container); + $this->assertTrue($dummyAction->hasCompatibleEvent('my.event')); + $this->assertFalse($dummyAction->hasCompatibleEvent('foobar')); + } + + public function testHasRequiredProject() + { + $dummyAction = new DummyAction($this->container); + $dummyAction->setProjectId(1234); + + $this->assertTrue($dummyAction->hasRequiredProject(array('project_id' => 1234))); + $this->assertFalse($dummyAction->hasRequiredProject(array('project_id' => 1))); + $this->assertFalse($dummyAction->hasRequiredProject(array())); + } + + public function testHasRequiredParameters() + { + $dummyAction = new DummyAction($this->container); + $dummyAction->setProjectId(1234); + + $this->assertTrue($dummyAction->hasRequiredParameters(array('p1' => 12, 'p2' => 34))); + $this->assertFalse($dummyAction->hasRequiredParameters(array('p1' => 12))); + $this->assertFalse($dummyAction->hasRequiredParameters(array())); + } + + public function testAddEvent() + { + $dummyAction = new DummyAction($this->container); + $dummyAction->addEvent('foobar', 'FooBar'); + $dummyAction->addEvent('my.event', 'My Event Overrided'); + + $events = $dummyAction->getEvents(); + $this->assertcount(2, $events); + $this->assertEquals(array('my.event', 'foobar'), $events); + } + + public function testExecuteOnlyOnce() + { + $dummyAction = new DummyAction($this->container); + $dummyAction->setProjectId(1234); + $dummyAction->setParam('p1', 'something'); + $dummyAction->addEvent('foobar', 'FooBar'); + + $event = new GenericEvent(array('project_id' => 1234, 'p1' => 'something', 'p2' => 'abc')); + + $this->assertTrue($dummyAction->execute($event, 'foobar')); + $this->assertFalse($dummyAction->execute($event, 'foobar')); + } +} diff --git a/tests/units/Action/CommentCreationMoveTaskColumnTest.php b/tests/units/Action/CommentCreationMoveTaskColumnTest.php new file mode 100644 index 00000000..87ee86ea --- /dev/null +++ b/tests/units/Action/CommentCreationMoveTaskColumnTest.php @@ -0,0 +1,58 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\GenericEvent; +use Kanboard\Model\Task; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Comment; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectUserRole; +use Kanboard\Action\CommentCreationMoveTaskColumn; + +class CommentCreationMoveTaskColumnTest extends Base +{ + public function testSuccess() + { + $this->container['sessionStorage']->user = array('id' => 1); + + $projectModel = new Project($this->container); + $commentModel = new Comment($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2)); + + $action = new CommentCreationMoveTaskColumn($this->container); + $action->setProjectId(1); + $action->setParam('column_id', 2); + + $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + + $comment = $commentModel->getById(1); + $this->assertNotEmpty($comment); + $this->assertEquals(1, $comment['task_id']); + $this->assertEquals(1, $comment['user_id']); + $this->assertEquals('Moved to column Ready', $comment['comment']); + } + + public function testWithUserNotLogged() + { + $projectModel = new Project($this->container); + $commentModel = new Comment($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3)); + + $action = new CommentCreationMoveTaskColumn($this->container); + $action->setProjectId(1); + $action->setParam('column_id', 2); + + $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + } +} diff --git a/tests/units/Action/CommentCreationTest.php b/tests/units/Action/CommentCreationTest.php index 8a689309..8460a350 100644 --- a/tests/units/Action/CommentCreationTest.php +++ b/tests/units/Action/CommentCreationTest.php @@ -7,119 +7,88 @@ use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\Comment; use Kanboard\Model\Project; -use Kanboard\Integration\GithubWebhook; +use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\User; use Kanboard\Action\CommentCreation; +use Kanboard\Core\Security\Role; class CommentCreationTest extends Base { - public function testWithoutRequiredParams() + public function testSuccess() { - $action = new CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $c = new Comment($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'user_id' => 1, - ); - - // Our event should be executed - $this->assertFalse($action->execute(new GenericEvent($event))); - - $comment = $c->getById(1); - $this->assertEmpty($comment); - } + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $projectUserRoleModel = new ProjectUserRole($this->container); + $commentModel = new Comment($this->container); + $taskCreationModel = new TaskCreation($this->container); - public function testWithCommitMessage() - { - $action = new CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $c = new Comment($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'commit_comment' => 'plop', - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - $comment = $c->getById(1); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'comment' => 'test123', 'reference' => 'ref123', 'user_id' => 2)); + + $action = new CommentCreation($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); + + $this->assertTrue($action->execute($event, 'test.event')); + + $comment = $commentModel->getById(1); $this->assertNotEmpty($comment); $this->assertEquals(1, $comment['task_id']); - $this->assertEquals(0, $comment['user_id']); - $this->assertEquals('plop', $comment['comment']); + $this->assertEquals('test123', $comment['comment']); + $this->assertEquals('ref123', $comment['reference']); + $this->assertEquals(2, $comment['user_id']); } - public function testWithUser() + public function testWithUserNotAssignable() { - $action = new CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $c = new Comment($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'user_id' => 1, - 'comment' => 'youpi', - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - $comment = $c->getById(1); + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $projectUserRoleModel = new ProjectUserRole($this->container); + $commentModel = new Comment($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'comment' => 'test123', 'user_id' => 2)); + + $action = new CommentCreation($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); + + $this->assertTrue($action->execute($event, 'test.event')); + + $comment = $commentModel->getById(1); $this->assertNotEmpty($comment); $this->assertEquals(1, $comment['task_id']); - $this->assertEquals(1, $comment['user_id']); - $this->assertEquals('youpi', $comment['comment']); + $this->assertEquals('test123', $comment['comment']); + $this->assertEquals('', $comment['reference']); + $this->assertEquals(0, $comment['user_id']); } - public function testWithNoUser() + public function testWithNoComment() { - $action = new CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $c = new Comment($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'user_id' => 0, - 'comment' => 'youpi', - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - $comment = $c->getById(1); - $this->assertNotEmpty($comment); - $this->assertEquals(1, $comment['task_id']); - $this->assertEquals(0, $comment['user_id']); - $this->assertEquals('youpi', $comment['comment']); + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $projectUserRoleModel = new ProjectUserRole($this->container); + $commentModel = new Comment($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1)); + + $action = new CommentCreation($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); + + $this->assertFalse($action->execute($event, 'test.event')); } } diff --git a/tests/units/Action/TaskAssignCategoryColorTest.php b/tests/units/Action/TaskAssignCategoryColorTest.php new file mode 100644 index 00000000..bd8181e8 --- /dev/null +++ b/tests/units/Action/TaskAssignCategoryColorTest.php @@ -0,0 +1,60 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\GenericEvent; +use Kanboard\Model\Category; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Project; +use Kanboard\Model\Task; +use Kanboard\Action\TaskAssignCategoryColor; + +class TaskAssignCategoryColorTest extends Base +{ + public function testChangeCategory() + { + $categoryModel = new Category($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'color_id' => 'red')); + + $action = new TaskAssignCategoryColor($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); + $action->setParam('category_id', 1); + + $this->assertTrue($action->execute($event, Task::EVENT_CREATE_UPDATE)); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['category_id']); + } + + public function testWithWrongColor() + { + $categoryModel = new Category($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'color_id' => 'blue')); + + $action = new TaskAssignCategoryColor($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); + $action->setParam('category_id', 1); + + $this->assertFalse($action->execute($event, Task::EVENT_CREATE_UPDATE)); + } +} diff --git a/tests/units/Action/TaskAssignCategoryLabelTest.php b/tests/units/Action/TaskAssignCategoryLabelTest.php new file mode 100644 index 00000000..bf8bdb5b --- /dev/null +++ b/tests/units/Action/TaskAssignCategoryLabelTest.php @@ -0,0 +1,85 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\GenericEvent; +use Kanboard\Model\Category; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Project; +use Kanboard\Action\TaskAssignCategoryLabel; + +class TaskAssignCategoryLabelTest extends Base +{ + public function testChangeCategory() + { + $categoryModel = new Category($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'label' => 'foobar')); + + $action = new TaskAssignCategoryLabel($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); + $action->setParam('label', 'foobar'); + $action->setParam('category_id', 1); + + $this->assertTrue($action->execute($event, 'test.event')); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['category_id']); + } + + public function testWithWrongLabel() + { + $categoryModel = new Category($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'label' => 'something')); + + $action = new TaskAssignCategoryLabel($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); + $action->setParam('label', 'foobar'); + $action->setParam('category_id', 1); + + $this->assertFalse($action->execute($event, 'test.event')); + } + + public function testWithExistingCategory() + { + $categoryModel = new Category($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 1))); + + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'category_id' => 2))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'label' => 'foobar', 'category_id' => 2)); + + $action = new TaskAssignCategoryLabel($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); + $action->setParam('label', 'foobar'); + $action->setParam('category_id', 1); + + $this->assertFalse($action->execute($event, 'test.event')); + } +} diff --git a/tests/units/Action/TaskAssignCategoryLinkTest.php b/tests/units/Action/TaskAssignCategoryLinkTest.php new file mode 100644 index 00000000..f638e017 --- /dev/null +++ b/tests/units/Action/TaskAssignCategoryLinkTest.php @@ -0,0 +1,97 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\Task; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Project; +use Kanboard\Model\TaskLink; +use Kanboard\Model\Category; +use Kanboard\Event\TaskLinkEvent; +use Kanboard\Action\TaskAssignCategoryLink; + +class TaskAssignCategoryLinkTest extends Base +{ + public function testAssignCategory() + { + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $c = new Category($this->container); + + $action = new TaskAssignCategoryLink($this->container); + $action->setProjectId(1); + $action->setParam('category_id', 1); + $action->setParam('link_id', 2); + + $this->assertEquals(1, $p->create(array('name' => 'P1'))); + $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1))); + + $event = new TaskLinkEvent(array( + 'project_id' => 1, + 'task_id' => 1, + 'opposite_task_id' => 2, + 'link_id' => 2, + )); + + $this->assertTrue($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + + $task = $tf->getById(1); + $this->assertEquals(1, $task['category_id']); + } + + public function testWhenLinkDontMatch() + { + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $c = new Category($this->container); + + $action = new TaskAssignCategoryLink($this->container); + $action->setProjectId(1); + $action->setParam('category_id', 1); + $action->setParam('link_id', 1); + + $this->assertEquals(1, $p->create(array('name' => 'P1'))); + $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1))); + + $event = new TaskLinkEvent(array( + 'project_id' => 1, + 'task_id' => 1, + 'opposite_task_id' => 2, + 'link_id' => 2, + )); + + $this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + } + + public function testThatExistingCategoryWillNotChange() + { + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $p = new Project($this->container); + $c = new Category($this->container); + + $action = new TaskAssignCategoryLink($this->container); + $action->setProjectId(1); + $action->setParam('category_id', 2); + $action->setParam('link_id', 2); + + $this->assertEquals(1, $p->create(array('name' => 'P1'))); + $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1))); + $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'category_id' => 1))); + + $event = new TaskLinkEvent(array( + 'project_id' => 1, + 'task_id' => 1, + 'opposite_task_id' => 2, + 'link_id' => 2, + )); + + $this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + } +} diff --git a/tests/units/Action/TaskAssignColorCategoryTest.php b/tests/units/Action/TaskAssignColorCategoryTest.php index 1bd3493b..9f188645 100644 --- a/tests/units/Action/TaskAssignColorCategoryTest.php +++ b/tests/units/Action/TaskAssignColorCategoryTest.php @@ -2,80 +2,58 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; +use Kanboard\Event\GenericEvent; +use Kanboard\Model\Category; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; -use Kanboard\Model\Category; -use Kanboard\Event\GenericEvent; +use Kanboard\Model\Task; use Kanboard\Action\TaskAssignColorCategory; class TaskAssignColorCategoryTest extends Base { - public function testBadProject() + public function testChangeColor() { - $action = new TaskAssignColorCategory($this->container, 3, Task::EVENT_CREATE_UPDATE); + $categoryModel = new Category($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'category_id' => 1)); - public function testExecute() - { - $action = new TaskAssignColorCategory($this->container, 1, Task::EVENT_CREATE_UPDATE); + $action = new TaskAssignColorCategory($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); $action->setParam('category_id', 1); - $action->setParam('color_id', 'blue'); - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $this->assertTrue($action->execute($event, Task::EVENT_CREATE_UPDATE)); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $c->create(array('name' => 'c1', 'project_id' => 1))); - $this->assertEquals(2, $c->create(array('name' => 'c2', 'project_id' => 1))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green', 'category_id' => 2))); + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('red', $task['color_id']); + } - // We create an event but we don't do anything - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 1, - 'category_id' => 2, - 'position' => 2, - ); + public function testWithWrongCategory() + { + $categoryModel = new Category($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); - // Our event should NOT be executed - $this->assertFalse($action->execute(new GenericEvent($event))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - // Our task should be assigned to the ategory_id=1 and have the green color - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['category_id']); - $this->assertEquals('green', $task['color_id']); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'category_id' => 2)); - // We create an event to move the task - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 1, - 'position' => 5, - 'category_id' => 1, - ); - - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); + $action = new TaskAssignColorCategory($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); + $action->setParam('category_id', 1); - // Our task should have the blue color - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals('blue', $task['color_id']); + $this->assertFalse($action->execute($event, Task::EVENT_CREATE_UPDATE)); } } diff --git a/tests/units/Action/TaskAssignColorColumnTest.php b/tests/units/Action/TaskAssignColorColumnTest.php index c09dc96e..e5858b19 100644 --- a/tests/units/Action/TaskAssignColorColumnTest.php +++ b/tests/units/Action/TaskAssignColorColumnTest.php @@ -3,40 +3,53 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; +use Kanboard\Model\Task; use Kanboard\Action\TaskAssignColorColumn; class TaskAssignColorColumnTest extends Base { - public function testColorChange() + public function testChangeColumn() { - $action = new TaskAssignColorColumn($this->container, 1, Task::EVENT_MOVE_COLUMN); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2)); + + $action = new TaskAssignColorColumn($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); $action->setParam('column_id', 2); - $action->setParam('color_id', 'green'); - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); + $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'yellow'))); + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('red', $task['color_id']); + } + + public function testWithWrongCategory() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - 'color_id' => 'green', - ); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3)); + + $action = new TaskAssignColorColumn($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); + $action->setParam('column_id', 2); - // Our task should have color green - $task = $tf->getById(1); - $this->assertEquals('green', $task['color_id']); + $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Action/TaskAssignColorLinkTest.php b/tests/units/Action/TaskAssignColorLinkTest.php index 36a831dd..d89c8b06 100644 --- a/tests/units/Action/TaskAssignColorLinkTest.php +++ b/tests/units/Action/TaskAssignColorLinkTest.php @@ -2,47 +2,54 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Event\TaskLinkEvent; -use Kanboard\Model\Task; +use Kanboard\Event\GenericEvent; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; -use Kanboard\Model\TaskLink; use Kanboard\Model\Project; +use Kanboard\Model\TaskLink; use Kanboard\Action\TaskAssignColorLink; class TaskAssignColorLinkTest extends Base { - public function testExecute() + public function testChangeColor() { - $action = new TaskAssignColorLink($this->container, 1, TaskLink::EVENT_CREATE_UPDATE); - $action->setParam('link_id', 2); - $action->setParam('color_id', 'green'); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); - - // The color should be yellow - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals('yellow', $task['color_id']); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'link_id' => 2, - ); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - // Our event should be executed - $this->assertTrue($action->execute(new TaskLinkEvent($event))); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'link_id' => 1)); - // The color should be green - $task = $tf->getById(1); + $action = new TaskAssignColorLink($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); + $action->setParam('link_id', 1); + + $this->assertTrue($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); + + $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); - $this->assertEquals('green', $task['color_id']); + $this->assertEquals('red', $task['color_id']); + } + + public function testWithWrongLink() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'link_id' => 2)); + + $action = new TaskAssignColorLink($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); + $action->setParam('link_id', 1); + + $this->assertFalse($action->execute($event, TaskLink::EVENT_CREATE_UPDATE)); } } diff --git a/tests/units/Action/TaskAssignColorUserTest.php b/tests/units/Action/TaskAssignColorUserTest.php index ea2a8f38..e2656cc0 100644 --- a/tests/units/Action/TaskAssignColorUserTest.php +++ b/tests/units/Action/TaskAssignColorUserTest.php @@ -2,72 +2,54 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Task; +use Kanboard\Event\GenericEvent; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; -use Kanboard\Event\GenericEvent; +use Kanboard\Model\Task; use Kanboard\Action\TaskAssignColorUser; class TaskAssignColorUserTest extends Base { - public function testBadProject() + public function testChangeColor() { - $action = new TaskAssignColorUser($this->container, 3, Task::EVENT_CREATE); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'owner_id' => 1)); - public function testExecute() - { - $action = new TaskAssignColorUser($this->container, 1, Task::EVENT_ASSIGNEE_CHANGE); + $action = new TaskAssignColorUser($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); $action->setParam('user_id', 1); - $action->setParam('color_id', 'blue'); - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'color_id' => 'green'))); + $this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); - // We change the assignee - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'owner_id' => 5, - ); + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('red', $task['color_id']); + } - // Our event should NOT be executed - $this->assertFalse($action->execute(new GenericEvent($event))); + public function testWithWrongUser() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); - // Our task should be assigned to nobody and have the green color - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals('green', $task['color_id']); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - // We change the assignee - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'owner_id' => 1, - ); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'owner_id' => 2)); - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); + $action = new TaskAssignColorUser($this->container); + $action->setProjectId(1); + $action->setParam('color_id', 'red'); + $action->setParam('user_id', 1); - // Our task should be assigned to nobody and have the blue color - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['owner_id']); - $this->assertEquals('blue', $task['color_id']); + $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); } } diff --git a/tests/units/Action/TaskAssignCurrentUserColumnTest.php b/tests/units/Action/TaskAssignCurrentUserColumnTest.php new file mode 100644 index 00000000..41576ee4 --- /dev/null +++ b/tests/units/Action/TaskAssignCurrentUserColumnTest.php @@ -0,0 +1,75 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\GenericEvent; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Project; +use Kanboard\Model\Task; +use Kanboard\Action\TaskAssignCurrentUserColumn; + +class TaskAssignCurrentUserColumnTest extends Base +{ + public function testChangeUser() + { + $this->container['sessionStorage']->user = array('id' => 1); + + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2)); + + $action = new TaskAssignCurrentUserColumn($this->container); + $action->setProjectId(1); + $action->setParam('column_id', 2); + + $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['owner_id']); + } + + public function testWithWrongColumn() + { + $this->container['sessionStorage']->user = array('id' => 1); + + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3)); + + $action = new TaskAssignCurrentUserColumn($this->container); + $action->setProjectId(1); + $action->setParam('column_id', 2); + + $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + } + + public function testWithNoUserSession() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2)); + + $action = new TaskAssignCurrentUserColumn($this->container); + $action->setProjectId(1); + $action->setParam('column_id', 2); + + $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + } +} diff --git a/tests/units/Action/TaskAssignCurrentUserTest.php b/tests/units/Action/TaskAssignCurrentUserTest.php index f8946577..2fe84a5d 100644 --- a/tests/units/Action/TaskAssignCurrentUserTest.php +++ b/tests/units/Action/TaskAssignCurrentUserTest.php @@ -3,76 +3,51 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; -use Kanboard\Model\UserSession; +use Kanboard\Model\Task; use Kanboard\Action\TaskAssignCurrentUser; class TaskAssignCurrentUserTest extends Base { - public function testBadProject() + public function testChangeUser() { - $action = new TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE); - $action->setParam('column_id', 5); + $this->container['sessionStorage']->user = array('id' => 1); - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - public function testBadColumn() - { - $action = new TaskAssignCurrentUser($this->container, 3, Task::EVENT_CREATE); - $action->setParam('column_id', 5); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1)); - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 3, - ); + $action = new TaskAssignCurrentUser($this->container); + $action->setProjectId(1); - $this->assertFalse($action->execute(new GenericEvent($event))); + $this->assertTrue($action->execute($event, Task::EVENT_CREATE)); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['owner_id']); } - public function testExecute() + public function testWithNoUserSession() { - $action = new TaskAssignCurrentUser($this->container, 1, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 2); - $_SESSION = array( - 'user' => array('id' => 5) - ); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $us = new UserSession($this->container); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(5, $us->getId()); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1)); - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); + $action = new TaskAssignCurrentUser($this->container); + $action->setProjectId(1); - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); - - // Our task should be assigned to the user 5 (from the session) - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['id']); - $this->assertEquals(5, $task['owner_id']); + $this->assertFalse($action->execute($event, Task::EVENT_CREATE)); } } diff --git a/tests/units/Action/TaskAssignSpecificUserTest.php b/tests/units/Action/TaskAssignSpecificUserTest.php index a67335e8..67b2c397 100644 --- a/tests/units/Action/TaskAssignSpecificUserTest.php +++ b/tests/units/Action/TaskAssignSpecificUserTest.php @@ -3,69 +3,53 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; +use Kanboard\Model\Task; use Kanboard\Action\TaskAssignSpecificUser; class TaskAssignSpecificUserTest extends Base { - public function testBadProject() + public function testChangeUser() { - $action = new TaskAssignSpecificUser($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 0))); - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2)); - public function testBadColumn() - { - $action = new TaskAssignSpecificUser($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); + $action = new TaskAssignSpecificUser($this->container); + $action->setProjectId(1); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 3, - ); + $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); - $this->assertFalse($action->execute(new GenericEvent($event))); + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['owner_id']); } - public function testExecute() + public function testWithWrongColumn() { - $action = new TaskAssignSpecificUser($this->container, 1, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 2); - $action->setParam('user_id', 1); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3)); - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); + $action = new TaskAssignSpecificUser($this->container); + $action->setProjectId(1); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); - // Our task should be assigned to the user 1 - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['owner_id']); + $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Action/TaskAssignUserTest.php b/tests/units/Action/TaskAssignUserTest.php new file mode 100644 index 00000000..d1cb72b9 --- /dev/null +++ b/tests/units/Action/TaskAssignUserTest.php @@ -0,0 +1,62 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\GenericEvent; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\User; +use Kanboard\Model\Task; +use Kanboard\Action\TaskAssignUser; +use Kanboard\Core\Security\Role; + +class TaskAssignUserTest extends Base +{ + public function testChangeUser() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $projectUserRoleModel = new ProjectUserRole($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => 0))); + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'owner_id' => 2)); + + $action = new TaskAssignUser($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); + + $this->assertTrue($action->execute($event, 'test.event')); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(2, $task['owner_id']); + } + + public function testWithNotAssignableUser() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $projectUserRoleModel = new ProjectUserRole($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'owner_id' => 1)); + + $action = new TaskAssignUser($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); + + $this->assertFalse($action->execute($event, 'test.event')); + } +} diff --git a/tests/units/Action/TaskCloseColumnTest.php b/tests/units/Action/TaskCloseColumnTest.php new file mode 100644 index 00000000..ce41bb41 --- /dev/null +++ b/tests/units/Action/TaskCloseColumnTest.php @@ -0,0 +1,53 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\GenericEvent; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Project; +use Kanboard\Model\Task; +use Kanboard\Action\TaskCloseColumn; + +class TaskCloseColumnTest extends Base +{ + public function testClose() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2)); + + $action = new TaskCloseColumn($this->container); + $action->setProjectId(1); + $action->setParam('column_id', 2); + + $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['is_active']); + } + + public function testWithWrongColumn() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3)); + + $action = new TaskCloseColumn($this->container); + $action->setProjectId(1); + $action->setParam('column_id', 2); + + $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); + } +} diff --git a/tests/units/Action/TaskCloseNoActivityTest.php b/tests/units/Action/TaskCloseNoActivityTest.php new file mode 100644 index 00000000..b6e04c47 --- /dev/null +++ b/tests/units/Action/TaskCloseNoActivityTest.php @@ -0,0 +1,43 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\TaskListEvent; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Project; +use Kanboard\Model\Task; +use Kanboard\Action\TaskCloseNoActivity; + +class TaskCloseNoActivityTest extends Base +{ + public function testClose() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); + + $tasks = $taskFinderModel->getAll(1); + $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1)); + + $action = new TaskCloseNoActivity($this->container); + $action->setProjectId(1); + $action->setParam('duration', 2); + + $this->assertTrue($action->execute($event, Task::EVENT_DAILY_CRONJOB)); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['is_active']); + + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['is_active']); + } +} diff --git a/tests/units/Action/TaskCloseTest.php b/tests/units/Action/TaskCloseTest.php index b2d83194..536d79ca 100644 --- a/tests/units/Action/TaskCloseTest.php +++ b/tests/units/Action/TaskCloseTest.php @@ -3,107 +3,49 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; -use Kanboard\Integration\GithubWebhook; use Kanboard\Action\TaskClose; class TaskCloseTest extends Base { - public function testExecutable() + public function testClose() { - $action = new TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 5, - ); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertTrue($action->isExecutable($event)); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1)); - $action = new TaskClose($this->container, 3, GithubWebhook::EVENT_COMMIT); + $action = new TaskClose($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); - $event = array( - 'project_id' => 3, - 'task_id' => 3, - ); + $this->assertTrue($action->execute($event, 'test.event')); - $this->assertTrue($action->isExecutable($event)); - } - - public function testBadEvent() - { - $action = new TaskClose($this->container, 3, Task::EVENT_UPDATE); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 5, - ); - - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testBadProject() - { - $action = new TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); - - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testBadColumn() - { - $action = new TaskClose($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); - - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 3, - ); - - $this->assertFalse($action->execute(new GenericEvent($event))); + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['is_active']); } - public function testExecute() + public function testWithNoTaskId() { - $action = new TaskClose($this->container, 1, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 2); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); + $event = new GenericEvent(array('project_id' => 1)); - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); + $action = new TaskClose($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); - // Our task should be closed - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(0, $task['is_active']); + $this->assertFalse($action->execute($event, 'test.event')); } } diff --git a/tests/units/Action/TaskCreationTest.php b/tests/units/Action/TaskCreationTest.php new file mode 100644 index 00000000..57c2995d --- /dev/null +++ b/tests/units/Action/TaskCreationTest.php @@ -0,0 +1,49 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\GenericEvent; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Project; +use Kanboard\Action\TaskCreation as TaskCreationAction; + +class TaskCreationActionTest extends Base +{ + public function testSuccess() + { + $projectModel = new Project($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'title' => 'test123', 'reference' => 'ref123', 'description' => 'test')); + + $action = new TaskCreationAction($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); + + $this->assertTrue($action->execute($event, 'test.event')); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('test123', $task['title']); + $this->assertEquals('ref123', $task['reference']); + $this->assertEquals('test', $task['description']); + } + + public function testWithNoTitle() + { + $projectModel = new Project($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'reference' => 'ref123', 'description' => 'test')); + + $action = new TaskCreationAction($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); + + $this->assertFalse($action->execute($event, 'test.event')); + } +} diff --git a/tests/units/Action/TaskDuplicateAnotherProjectTest.php b/tests/units/Action/TaskDuplicateAnotherProjectTest.php index 50cbad01..d9491dd9 100644 --- a/tests/units/Action/TaskDuplicateAnotherProjectTest.php +++ b/tests/units/Action/TaskDuplicateAnotherProjectTest.php @@ -4,92 +4,53 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; +use Kanboard\Model\TaskCreation; use Kanboard\Model\Project; use Kanboard\Action\TaskDuplicateAnotherProject; class TaskDuplicateAnotherProjectTest extends Base { - public function testBadProject() + public function testSuccess() { - $action = new TaskDuplicateAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2)); - public function testBadColumn() - { - $action = new TaskDuplicateAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); + $action = new TaskDuplicateAnotherProject($this->container); + $action->setProjectId(1); + $action->setParam('project_id', 2); + $action->setParam('column_id', 2); - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 3, - ); + $this->assertTrue($action->execute($event, Task::EVENT_CLOSE)); - $this->assertFalse($action->execute(new GenericEvent($event))); + $task = $taskFinderModel->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals('test', $task['title']); + $this->assertEquals(2, $task['project_id']); } - public function testExecute() + public function testWithWrongColumn() { - $action = new TaskDuplicateAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'project 1'))); - $this->assertEquals(2, $p->create(array('name' => 'project 2'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Our event should NOT be executed because we define the same project - $action->setParam('column_id', 2); - $action->setParam('project_id', 1); - $this->assertFalse($action->execute(new GenericEvent($event))); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3)); - // Our task should be assigned to the project 1 - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['project_id']); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Our event should be executed because we define a different project - $action->setParam('column_id', 2); + $action = new TaskDuplicateAnotherProject($this->container); + $action->setProjectId(1); $action->setParam('project_id', 2); - $this->assertTrue($action->hasRequiredCondition($event)); - $this->assertTrue($action->execute(new GenericEvent($event))); - - // Our task should be assigned to the project 1 - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['project_id']); + $action->setParam('column_id', 2); - // We should have another task assigned to the project 2 - $task = $tf->getById(2); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['project_id']); + $this->assertFalse($action->execute($event, Task::EVENT_CLOSE)); } } diff --git a/tests/units/Action/TaskEmailNoActivityTest.php b/tests/units/Action/TaskEmailNoActivityTest.php new file mode 100644 index 00000000..af4baed5 --- /dev/null +++ b/tests/units/Action/TaskEmailNoActivityTest.php @@ -0,0 +1,103 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\TaskListEvent; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Project; +use Kanboard\Model\Task; +use Kanboard\Model\User; +use Kanboard\Action\TaskEmailNoActivity; + +class TaskEmailNoActivityTest extends Base +{ + public function testSendEmail() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'test', 'email' => 'chuck@norris', 'name' => 'Chuck Norris'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); + + $tasks = $taskFinderModel->getAll(1); + $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1)); + + $action = new TaskEmailNoActivity($this->container); + $action->setProjectId(1); + $action->setParam('user_id', 2); + $action->setParam('subject', 'Old tasks'); + $action->setParam('duration', 2); + + $this->container['emailClient'] + ->expects($this->once()) + ->method('send') + ->with('chuck@norris', 'Chuck Norris', 'Old tasks', $this->anything()); + + $this->assertTrue($action->execute($event, Task::EVENT_DAILY_CRONJOB)); + } + + public function testUserWithNoEmail() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'test', 'name' => 'Chuck Norris'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_modification' => strtotime('-10days'))); + + $tasks = $taskFinderModel->getAll(1); + $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1)); + + $action = new TaskEmailNoActivity($this->container); + $action->setProjectId(1); + $action->setParam('user_id', 2); + $action->setParam('subject', 'Old tasks'); + $action->setParam('duration', 2); + + $this->container['emailClient'] + ->expects($this->never()) + ->method('send'); + + $this->assertFalse($action->execute($event, Task::EVENT_DAILY_CRONJOB)); + } + + public function testTooRecent() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'test', 'email' => 'chuck@norris', 'name' => 'Chuck Norris'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $tasks = $taskFinderModel->getAll(1); + $event = new TaskListEvent(array('tasks' => $tasks, 'project_id' => 1)); + + $action = new TaskEmailNoActivity($this->container); + $action->setProjectId(1); + $action->setParam('user_id', 2); + $action->setParam('subject', 'Old tasks'); + $action->setParam('duration', 2); + + $this->container['emailClient'] + ->expects($this->never()) + ->method('send'); + + $this->assertFalse($action->execute($event, Task::EVENT_DAILY_CRONJOB)); + } +} diff --git a/tests/units/Action/TaskEmailTest.php b/tests/units/Action/TaskEmailTest.php index 404865f4..ef32a296 100644 --- a/tests/units/Action/TaskEmailTest.php +++ b/tests/units/Action/TaskEmailTest.php @@ -5,98 +5,30 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; use Kanboard\Model\User; use Kanboard\Action\TaskEmail; class TaskEmailTest extends Base { - public function testNoEmail() + public function testSuccess() { - $action = new TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 2); - $action->setParam('user_id', 1); - $action->setParam('subject', 'My email subject'); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $u = new User($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertTrue($userModel->update(array('id' => 1, 'email' => 'admin@localhost'))); - // Email should be not be sent - $this->container['emailClient']->expects($this->never())->method('send'); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2)); - // Our event should be executed - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testWrongColumn() - { - $action = new TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 2); - $action->setParam('user_id', 1); - $action->setParam('subject', 'My email subject'); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $u = new User($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 3, - ); - - // Email should be not be sent - $this->container['emailClient']->expects($this->never())->method('send'); - - // Our event should be executed - $this->assertFalse($action->execute(new GenericEvent($event))); - } - - public function testMoveColumn() - { - $action = new TaskEmail($this->container, 1, Task::EVENT_MOVE_COLUMN); + $action = new TaskEmail($this->container); + $action->setProjectId(1); $action->setParam('column_id', 2); $action->setParam('user_id', 1); $action->setParam('subject', 'My email subject'); - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $u = new User($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - $this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost'))); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Email should be sent $this->container['emailClient']->expects($this->once()) ->method('send') ->with( @@ -106,45 +38,24 @@ class TaskEmailTest extends Base $this->stringContains('test') ); - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); + $this->assertTrue($action->execute($event, Task::EVENT_CLOSE)); } - public function testTaskClose() + public function testWithWrongColumn() { - $action = new TaskEmail($this->container, 1, Task::EVENT_CLOSE); - $action->setParam('column_id', 2); - $action->setParam('user_id', 1); - $action->setParam('subject', 'My email subject'); - - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $u = new User($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); - $this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); - // We create an event - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3)); - // Email should be sent - $this->container['emailClient']->expects($this->once()) - ->method('send') - ->with( - $this->equalTo('admin@localhost'), - $this->equalTo('admin'), - $this->equalTo('My email subject'), - $this->stringContains('test') - ); + $action = new TaskEmail($this->container); + $action->setProjectId(1); + $action->setParam('column_id', 2); + $action->setParam('user_id', 1); + $action->setParam('subject', 'My email subject'); - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); + $this->assertFalse($action->execute($event, Task::EVENT_CLOSE)); } } diff --git a/tests/units/Action/TaskMoveAnotherProjectTest.php b/tests/units/Action/TaskMoveAnotherProjectTest.php index 93ee3b94..dfabe5f8 100644 --- a/tests/units/Action/TaskMoveAnotherProjectTest.php +++ b/tests/units/Action/TaskMoveAnotherProjectTest.php @@ -4,86 +4,54 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; +use Kanboard\Model\TaskCreation; use Kanboard\Model\Project; use Kanboard\Action\TaskMoveAnotherProject; class TaskMoveAnotherProjectTest extends Base { - public function testBadProject() + public function testSuccess() { - $action = new TaskMoveAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); - $event = array( - 'project_id' => 2, - 'task_id' => 3, - 'column_id' => 5, - ); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertFalse($action->isExecutable($event)); - $this->assertFalse($action->execute(new GenericEvent($event))); - } + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2)); - public function testBadColumn() - { - $action = new TaskMoveAnotherProject($this->container, 3, Task::EVENT_MOVE_COLUMN); - $action->setParam('column_id', 5); + $action = new TaskMoveAnotherProject($this->container); + $action->setProjectId(1); + $action->setParam('project_id', 2); + $action->setParam('column_id', 2); - $event = array( - 'project_id' => 3, - 'task_id' => 3, - 'column_id' => 3, - ); + $this->assertTrue($action->execute($event, Task::EVENT_CLOSE)); - $this->assertFalse($action->execute(new GenericEvent($event))); + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('test', $task['title']); + $this->assertEquals(2, $task['project_id']); + $this->assertEquals(5, $task['column_id']); } - public function testExecute() + public function testWithWrongColumn() { - $action = new TaskMoveAnotherProject($this->container, 1, Task::EVENT_MOVE_COLUMN); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'project 1'))); - $this->assertEquals(2, $p->create(array('name' => 'project 2'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3)); - // Our event should NOT be executed because we define the same project - $action->setParam('column_id', 2); - $action->setParam('project_id', 1); - $this->assertFalse($action->execute(new GenericEvent($event))); - - // Our task should be assigned to the project 1 - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['project_id']); - - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); - - // Our event should be executed because we define a different project - $action->setParam('column_id', 2); + $action = new TaskMoveAnotherProject($this->container); + $action->setProjectId(1); $action->setParam('project_id', 2); - $this->assertTrue($action->execute(new GenericEvent($event))); + $action->setParam('column_id', 2); - // Our task should be assigned to the project 2 - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(2, $task['project_id']); + $this->assertFalse($action->execute($event, Task::EVENT_CLOSE)); } } diff --git a/tests/units/Action/TaskMoveColumnAssignedTest.php b/tests/units/Action/TaskMoveColumnAssignedTest.php new file mode 100644 index 00000000..f0eec894 --- /dev/null +++ b/tests/units/Action/TaskMoveColumnAssignedTest.php @@ -0,0 +1,56 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\GenericEvent; +use Kanboard\Model\Task; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Project; +use Kanboard\Action\TaskMoveColumnAssigned; + +class TaskMoveColumnAssignedTest extends Base +{ + public function testSuccess() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 1)); + + $action = new TaskMoveColumnAssigned($this->container); + $action->setProjectId(1); + $action->setParam('src_column_id', 1); + $action->setParam('dest_column_id', 2); + + $this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('test', $task['title']); + $this->assertEquals(2, $task['column_id']); + } + + public function testWithWrongColumn() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3, 'owner_id' => 1)); + + $action = new TaskMoveColumnAssigned($this->container); + $action->setProjectId(1); + $action->setParam('src_column_id', 1); + $action->setParam('dest_column_id', 2); + + $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + } +} diff --git a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php index 03423776..1f0768c1 100644 --- a/tests/units/Action/TaskMoveColumnCategoryChangeTest.php +++ b/tests/units/Action/TaskMoveColumnCategoryChangeTest.php @@ -3,60 +3,84 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; +use Kanboard\Model\Category; use Kanboard\Model\Task; -use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; +use Kanboard\Model\TaskCreation; use Kanboard\Model\Project; -use Kanboard\Model\Category; -use Kanboard\Integration\GithubWebhook; use Kanboard\Action\TaskMoveColumnCategoryChange; class TaskMoveColumnCategoryChangeTest extends Base { - public function testExecute() + public function testSuccess() { - $action = new TaskMoveColumnCategoryChange($this->container, 1, Task::EVENT_UPDATE); - $action->setParam('dest_column_id', 3); - $action->setParam('category_id', 1); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(3, $action->getParam('dest_column_id')); - $this->assertEquals(1, $action->getParam('category_id')); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'category_id' => 1)); - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $c = new Category($this->container); + $action = new TaskMoveColumnCategoryChange($this->container); + $action->setProjectId(1); + $action->setParam('category_id', 1); + $action->setParam('dest_column_id', 2); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $c->create(array('name' => 'bug', 'project_id' => 1))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertTrue($action->execute($event, Task::EVENT_UPDATE)); - // No category should be assigned + column_id=1 - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEmpty($task['category_id']); - $this->assertEquals(1, $task['column_id']); - - // We create an event to move the task to the 2nd column - $event = array( - 'task_id' => 1, - 'column_id' => 1, - 'project_id' => 1, - 'category_id' => 1, - ); - - // Our event should be executed - $this->assertTrue($action->hasCompatibleEvent()); - $this->assertTrue($action->hasRequiredProject($event)); - $this->assertTrue($action->hasRequiredParameters($event)); - $this->assertTrue($action->hasRequiredCondition($event)); - $this->assertTrue($action->isExecutable($event)); - $this->assertTrue($action->execute(new GenericEvent($event))); - - // Our task should be moved to the other column - $task = $tf->getById(1); + $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); - $this->assertEquals(3, $task['column_id']); + $this->assertEquals('test', $task['title']); + $this->assertEquals(2, $task['column_id']); + } + + public function testWithWrongColumn() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2, 'category_id' => 1)); + + $action = new TaskMoveColumnCategoryChange($this->container); + $action->setProjectId(1); + $action->setParam('category_id', 1); + $action->setParam('dest_column_id', 2); + + $this->assertFalse($action->execute($event, Task::EVENT_UPDATE)); + } + + public function testWithWrongCategory() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 1))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'category_id' => 2)); + + $action = new TaskMoveColumnCategoryChange($this->container); + $action->setProjectId(1); + $action->setParam('category_id', 1); + $action->setParam('dest_column_id', 2); + + $this->assertFalse($action->execute($event, Task::EVENT_UPDATE)); } } diff --git a/tests/units/Action/TaskMoveColumnUnAssignedTest.php b/tests/units/Action/TaskMoveColumnUnAssignedTest.php new file mode 100644 index 00000000..0b54b781 --- /dev/null +++ b/tests/units/Action/TaskMoveColumnUnAssignedTest.php @@ -0,0 +1,74 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\GenericEvent; +use Kanboard\Model\Task; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Project; +use Kanboard\Action\TaskMoveColumnUnAssigned; + +class TaskMoveColumnUnAssignedTest extends Base +{ + public function testSuccess() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 0)); + + $action = new TaskMoveColumnUnAssigned($this->container); + $action->setProjectId(1); + $action->setParam('src_column_id', 1); + $action->setParam('dest_column_id', 2); + + $this->assertTrue($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals('test', $task['title']); + $this->assertEquals(2, $task['column_id']); + } + + public function testWithWrongColumn() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2, 'owner_id' => 0)); + + $action = new TaskMoveColumnUnAssigned($this->container); + $action->setProjectId(1); + $action->setParam('src_column_id', 1); + $action->setParam('dest_column_id', 2); + + $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + } + + public function testWithWrongUser() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 1, 'owner_id' => 1)); + + $action = new TaskMoveColumnUnAssigned($this->container); + $action->setProjectId(1); + $action->setParam('src_column_id', 1); + $action->setParam('dest_column_id', 2); + + $this->assertFalse($action->execute($event, Task::EVENT_ASSIGNEE_CHANGE)); + } +} diff --git a/tests/units/Action/TaskOpenTest.php b/tests/units/Action/TaskOpenTest.php new file mode 100644 index 00000000..01290a64 --- /dev/null +++ b/tests/units/Action/TaskOpenTest.php @@ -0,0 +1,51 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Event\GenericEvent; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskFinder; +use Kanboard\Model\Project; +use Kanboard\Action\TaskOpen; + +class TaskOpenTest extends Base +{ + public function testClose() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'is_active' => 0))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1)); + + $action = new TaskOpen($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); + + $this->assertTrue($action->execute($event, 'test.event')); + + $task = $taskFinderModel->getById(1); + $this->assertNotEmpty($task); + $this->assertEquals(1, $task['is_active']); + } + + public function testWithNoTaskId() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1)); + + $action = new TaskOpen($this->container); + $action->setProjectId(1); + $action->addEvent('test.event', 'Test Event'); + + $this->assertFalse($action->execute($event, 'test.event')); + } +} diff --git a/tests/units/Action/TaskUpdateStartDateTest.php b/tests/units/Action/TaskUpdateStartDateTest.php index 7d558e28..adf5bd9d 100644 --- a/tests/units/Action/TaskUpdateStartDateTest.php +++ b/tests/units/Action/TaskUpdateStartDateTest.php @@ -3,44 +3,50 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Event\GenericEvent; -use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; +use Kanboard\Model\Task; use Kanboard\Action\TaskUpdateStartDate; class TaskUpdateStartDateTest extends Base { - public function testExecute() + public function testClose() { - $action = new TaskUpdateStartDate($this->container, 1, Task::EVENT_MOVE_COLUMN); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskFinderModel = new TaskFinder($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2)); + + $action = new TaskUpdateStartDate($this->container); + $action->setProjectId(1); $action->setParam('column_id', 2); - // We create a task in the first column - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); + $this->assertTrue($action->execute($event, Task::EVENT_MOVE_COLUMN)); - // The start date must be empty - $task = $tf->getById(1); + $task = $taskFinderModel->getById(1); $this->assertNotEmpty($task); - $this->assertEmpty($task['date_started']); + $this->assertEquals(time(), $task['date_started'], 'Date started delta', 2); + } - // We create an event to move the task to the 2nd column - $event = array( - 'project_id' => 1, - 'task_id' => 1, - 'column_id' => 2, - ); + public function testWithWrongColumn() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); - // Our event should be executed - $this->assertTrue($action->execute(new GenericEvent($event))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); - // Our task should be updated - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(time(), $task['date_started'], '', 2); + $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 3)); + + $action = new TaskUpdateStartDate($this->container); + $action->setProjectId(1); + $action->setParam('column_id', 2); + + $this->assertFalse($action->execute($event, Task::EVENT_MOVE_COLUMN)); } } diff --git a/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php new file mode 100644 index 00000000..b8faec6c --- /dev/null +++ b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php @@ -0,0 +1,70 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Project; +use Kanboard\Model\Task; +use Kanboard\Analytic\AverageLeadCycleTimeAnalytic; + +class AverageLeadCycleTimeAnalyticTest extends Base +{ + public function testBuild() + { + $taskCreationModel = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $averageLeadCycleTimeAnalytic = new AverageLeadCycleTimeAnalytic($this->container); + $now = time(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test1'))); + + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(4, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + // LT=3600 CT=1800 + $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600, 'date_started' => $now + 1800)); + + // LT=1800 CT=900 + $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800, 'date_started' => $now + 900)); + + // LT=3600 CT=0 + $this->container['db']->table(Task::TABLE)->eq('id', 3)->update(array('date_completed' => $now + 3600)); + + // LT=2*3600 CT=0 + $this->container['db']->table(Task::TABLE)->eq('id', 4)->update(array('date_completed' => $now + 2 * 3600)); + + $stats = $averageLeadCycleTimeAnalytic->build(1); + + $this->assertEquals(4, $stats['count']); + $this->assertEquals(3600 + 1800 + 3600 + 2*3600, $stats['total_lead_time'], '', 5); + $this->assertEquals(1800 + 900, $stats['total_cycle_time'], '', 5); + $this->assertEquals((3600 + 1800 + 3600 + 2*3600) / 4, $stats['avg_lead_time'], '', 5); + $this->assertEquals((1800 + 900) / 4, $stats['avg_cycle_time'], '', 5); + } + + public function testBuildWithNoTasks() + { + $taskCreationModel = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $averageLeadCycleTimeAnalytic = new AverageLeadCycleTimeAnalytic($this->container); + $now = time(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test1'))); + + $stats = $averageLeadCycleTimeAnalytic->build(1); + + $expected = array( + 'count' => 0, + 'total_lead_time' => 0, + 'total_cycle_time' => 0, + 'avg_lead_time' => 0, + 'avg_cycle_time' => 0, + ); + + $this->assertEquals($expected, $stats); + } +} diff --git a/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php b/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php new file mode 100644 index 00000000..4e01bfa9 --- /dev/null +++ b/tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php @@ -0,0 +1,101 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Project; +use Kanboard\Model\Transition; +use Kanboard\Model\Task; +use Kanboard\Model\TaskFinder; +use Kanboard\Analytic\AverageTimeSpentColumnAnalytic; + +class AverageTimeSpentColumnAnalyticTest extends Base +{ + public function testAverageWithNoTransitions() + { + $taskCreationModel = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $averageLeadCycleTimeAnalytic = new AverageTimeSpentColumnAnalytic($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $now = time(); + + $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600)); + $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800)); + + $stats = $averageLeadCycleTimeAnalytic->build(1); + + $this->assertEquals(2, $stats[1]['count']); + $this->assertEquals(3600+1800, $stats[1]['time_spent'], '', 3); + $this->assertEquals((int) ((3600+1800)/2), $stats[1]['average'], '', 3); + $this->assertEquals('Backlog', $stats[1]['title']); + + $this->assertEquals(0, $stats[2]['count']); + $this->assertEquals(0, $stats[2]['time_spent'], '', 3); + $this->assertEquals(0, $stats[2]['average'], '', 3); + $this->assertEquals('Ready', $stats[2]['title']); + + $this->assertEquals(0, $stats[3]['count']); + $this->assertEquals(0, $stats[3]['time_spent'], '', 3); + $this->assertEquals(0, $stats[3]['average'], '', 3); + $this->assertEquals('Work in progress', $stats[3]['title']); + + $this->assertEquals(0, $stats[4]['count']); + $this->assertEquals(0, $stats[4]['time_spent'], '', 3); + $this->assertEquals(0, $stats[4]['average'], '', 3); + $this->assertEquals('Done', $stats[4]['title']); + } + + public function testAverageWithTransitions() + { + $transitionModel = new Transition($this->container); + $taskFinderModel = new TaskFinder($this->container); + $taskCreationModel = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $averageLeadCycleTimeAnalytic = new AverageTimeSpentColumnAnalytic($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $now = time(); + $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600)); + $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800)); + + foreach (array(1, 2) as $task_id) { + $task = $taskFinderModel->getById($task_id); + $task['task_id'] = $task['id']; + $task['date_moved'] = $now - 900; + $task['src_column_id'] = 3; + $task['dst_column_id'] = 1; + $this->assertTrue($transitionModel->save(1, $task)); + } + + $stats = $averageLeadCycleTimeAnalytic->build(1); + + $this->assertEquals(2, $stats[1]['count']); + $this->assertEquals(3600+1800, $stats[1]['time_spent'], '', 3); + $this->assertEquals((int) ((3600+1800)/2), $stats[1]['average'], '', 3); + $this->assertEquals('Backlog', $stats[1]['title']); + + $this->assertEquals(0, $stats[2]['count']); + $this->assertEquals(0, $stats[2]['time_spent'], '', 3); + $this->assertEquals(0, $stats[2]['average'], '', 3); + $this->assertEquals('Ready', $stats[2]['title']); + + $this->assertEquals(2, $stats[3]['count']); + $this->assertEquals(1800, $stats[3]['time_spent'], '', 3); + $this->assertEquals(900, $stats[3]['average'], '', 3); + $this->assertEquals('Work in progress', $stats[3]['title']); + + $this->assertEquals(0, $stats[4]['count']); + $this->assertEquals(0, $stats[4]['time_spent'], '', 3); + $this->assertEquals(0, $stats[4]['average'], '', 3); + $this->assertEquals('Done', $stats[4]['title']); + } +} diff --git a/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php b/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php new file mode 100644 index 00000000..2ca631b1 --- /dev/null +++ b/tests/units/Analytic/EstimatedTimeComparisonAnalyticTest.php @@ -0,0 +1,99 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Project; +use Kanboard\Analytic\EstimatedTimeComparisonAnalytic; + +class EstimatedTimeComparisonAnalyticTest extends Base +{ + public function testBuild() + { + $taskCreationModel = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $estimatedTimeComparisonAnalytic = new EstimatedTimeComparisonAnalytic($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test1'))); + + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 5.5))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.75))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.25, 'is_active' => 0))); + + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 8.25))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 0.25))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 0.5, 'is_active' => 0))); + + $expected = array( + 'open' => array( + 'time_spent' => 8.5, + 'time_estimated' => 7.25, + ), + 'closed' => array( + 'time_spent' => 0.5, + 'time_estimated' => 1.25, + ) + ); + + $this->assertEquals($expected, $estimatedTimeComparisonAnalytic->build(1)); + } + + public function testBuildWithNoClosedTask() + { + $taskCreationModel = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $estimatedTimeComparisonAnalytic = new EstimatedTimeComparisonAnalytic($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test1'))); + + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 5.5))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.75))); + + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 8.25))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 0.25))); + + $expected = array( + 'open' => array( + 'time_spent' => 8.5, + 'time_estimated' => 7.25, + ), + 'closed' => array( + 'time_spent' => 0, + 'time_estimated' => 0, + ) + ); + + $this->assertEquals($expected, $estimatedTimeComparisonAnalytic->build(1)); + } + + public function testBuildWithOnlyClosedTask() + { + $taskCreationModel = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $estimatedTimeComparisonAnalytic = new EstimatedTimeComparisonAnalytic($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test1'))); + + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 5.5, 'is_active' => 0))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_estimated' => 1.75, 'is_active' => 0))); + + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 8.25, 'is_active' => 0))); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'time_spent' => 0.25, 'is_active' => 0))); + + $expected = array( + 'closed' => array( + 'time_spent' => 8.5, + 'time_estimated' => 7.25, + ), + 'open' => array( + 'time_spent' => 0, + 'time_estimated' => 0, + ) + ); + + $this->assertEquals($expected, $estimatedTimeComparisonAnalytic->build(1)); + } +} diff --git a/tests/units/Analytic/TaskDistributionAnalyticTest.php b/tests/units/Analytic/TaskDistributionAnalyticTest.php new file mode 100644 index 00000000..531101ef --- /dev/null +++ b/tests/units/Analytic/TaskDistributionAnalyticTest.php @@ -0,0 +1,62 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Project; +use Kanboard\Analytic\TaskDistributionAnalytic; + +class TaskDistributionAnalyticTest extends Base +{ + public function testBuild() + { + $projectModel = new Project($this->container); + $taskDistributionModel = new TaskDistributionAnalytic($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test1'))); + + $this->createTasks(1, 20, 1); + $this->createTasks(2, 30, 1); + $this->createTasks(3, 40, 1); + $this->createTasks(4, 10, 1); + + $expected = array( + array( + 'column_title' => 'Backlog', + 'nb_tasks' => 20, + 'percentage' => 20.0, + ), + array( + 'column_title' => 'Ready', + 'nb_tasks' => 30, + 'percentage' => 30.0, + ), + array( + 'column_title' => 'Work in progress', + 'nb_tasks' => 40, + 'percentage' => 40.0, + ), + array( + 'column_title' => 'Done', + 'nb_tasks' => 10, + 'percentage' => 10.0, + ) + ); + + $this->assertEquals($expected, $taskDistributionModel->build(1)); + } + + private function createTasks($column_id, $nb_active, $nb_inactive) + { + $taskCreationModel = new TaskCreation($this->container); + + for ($i = 0; $i < $nb_active; $i++) { + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => $column_id, 'is_active' => 1))); + } + + for ($i = 0; $i < $nb_inactive; $i++) { + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => $column_id, 'is_active' => 0))); + } + } +} diff --git a/tests/units/Analytic/UserDistributionAnalyticTest.php b/tests/units/Analytic/UserDistributionAnalyticTest.php new file mode 100644 index 00000000..bdc136e1 --- /dev/null +++ b/tests/units/Analytic/UserDistributionAnalyticTest.php @@ -0,0 +1,83 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\User; +use Kanboard\Analytic\UserDistributionAnalytic; +use Kanboard\Core\Security\Role; + +class UserDistributionAnalyticTest extends Base +{ + public function testBuild() + { + $projectModel = new Project($this->container); + $projectUserRoleModel = new ProjectUserRole($this->container); + $userModel = new User($this->container); + $userDistributionModel = new UserDistributionAnalytic($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test1'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user4'))); + + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); + $this->assertTrue($projectUserRoleModel->addUser(1, 4, Role::PROJECT_MEMBER)); + $this->assertTrue($projectUserRoleModel->addUser(1, 5, Role::PROJECT_MEMBER)); + + $this->createTasks(0, 10, 1); + $this->createTasks(2, 30, 1); + $this->createTasks(3, 40, 1); + $this->createTasks(4, 10, 1); + $this->createTasks(5, 10, 1); + + $expected = array( + array( + 'user' => 'Unassigned', + 'nb_tasks' => 10, + 'percentage' => 10.0, + ), + array( + 'user' => 'user1', + 'nb_tasks' => 30, + 'percentage' => 30.0, + ), + array( + 'user' => 'user2', + 'nb_tasks' => 40, + 'percentage' => 40.0, + ), + array( + 'user' => 'user3', + 'nb_tasks' => 10, + 'percentage' => 10.0, + ), + array( + 'user' => 'user4', + 'nb_tasks' => 10, + 'percentage' => 10.0, + ) + ); + + $this->assertEquals($expected, $userDistributionModel->build(1)); + } + + private function createTasks($user_id, $nb_active, $nb_inactive) + { + $taskCreationModel = new TaskCreation($this->container); + + for ($i = 0; $i < $nb_active; $i++) { + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => $user_id, 'is_active' => 1))); + } + + for ($i = 0; $i < $nb_inactive; $i++) { + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'owner_id' => $user_id, 'is_active' => 0))); + } + } +} diff --git a/tests/units/Auth/DatabaseAuthTest.php b/tests/units/Auth/DatabaseAuthTest.php new file mode 100644 index 00000000..ac099a7e --- /dev/null +++ b/tests/units/Auth/DatabaseAuthTest.php @@ -0,0 +1,62 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Auth\DatabaseAuth; +use Kanboard\Model\User; + +class DatabaseAuthTest extends Base +{ + public function testGetName() + { + $provider = new DatabaseAuth($this->container); + $this->assertEquals('Database', $provider->getName()); + } + + public function testAuthenticate() + { + $provider = new DatabaseAuth($this->container); + + $provider->setUsername('admin'); + $provider->setPassword('admin'); + $this->assertTrue($provider->authenticate()); + + $provider->setUsername('admin'); + $provider->setPassword('test'); + $this->assertFalse($provider->authenticate()); + } + + public function testGetUser() + { + $provider = new DatabaseAuth($this->container); + $this->assertEquals(null, $provider->getUser()); + + $provider = new DatabaseAuth($this->container); + $provider->setUsername('admin'); + $provider->setPassword('admin'); + + $this->assertTrue($provider->authenticate()); + $this->assertInstanceOf('Kanboard\User\DatabaseUserProvider', $provider->getUser()); + } + + public function testIsvalidSession() + { + $userModel = new User($this->container); + $provider = new DatabaseAuth($this->container); + + $this->assertFalse($provider->isValidSession()); + + $this->assertEquals(2, $userModel->create(array('username' => 'foobar'))); + + $this->container['sessionStorage']->user = array('id' => 2); + $this->assertTrue($provider->isValidSession()); + + $this->container['sessionStorage']->user = array('id' => 3); + $this->assertFalse($provider->isValidSession()); + + $this->assertTrue($userModel->disable(2)); + + $this->container['sessionStorage']->user = array('id' => 2); + $this->assertFalse($provider->isValidSession()); + } +} diff --git a/tests/units/Auth/LdapTest.php b/tests/units/Auth/LdapTest.php deleted file mode 100644 index 19e7d7e2..00000000 --- a/tests/units/Auth/LdapTest.php +++ /dev/null @@ -1,697 +0,0 @@ -<?php - -namespace Kanboard\Auth; - -require_once __DIR__.'/../Base.php'; - -function ldap_connect($hostname, $port) -{ - return LdapTest::$functions->ldap_connect($hostname, $port); -} - -function ldap_set_option() -{ -} - -function ldap_bind($link_identifier, $bind_rdn, $bind_password) -{ - return LdapTest::$functions->ldap_bind($link_identifier, $bind_rdn, $bind_password); -} - -function ldap_search($link_identifier, $base_dn, $filter, array $attributes) -{ - return LdapTest::$functions->ldap_search($link_identifier, $base_dn, $filter, $attributes); -} - -function ldap_get_entries($link_identifier, $result_identifier) -{ - return LdapTest::$functions->ldap_get_entries($link_identifier, $result_identifier); -} - -class LdapTest extends \Base -{ - public static $functions; - private $ldap; - - public function setUp() - { - parent::setup(); - - self::$functions = $this - ->getMockBuilder('stdClass') - ->setMethods(array( - 'ldap_connect', - 'ldap_set_option', - 'ldap_bind', - 'ldap_search', - 'ldap_get_entries', - )) - ->getMock(); - } - - public function tearDown() - { - parent::tearDown(); - self::$functions = null; - } - - public function testGetAttributes() - { - $ldap = new Ldap($this->container); - $this->assertCount(3, $ldap->getProfileAttributes()); - $this->assertContains(LDAP_ACCOUNT_FULLNAME, $ldap->getProfileAttributes()); - $this->assertContains(LDAP_ACCOUNT_EMAIL, $ldap->getProfileAttributes()); - $this->assertContains(LDAP_ACCOUNT_MEMBEROF, $ldap->getProfileAttributes()); - } - - public function testConnectSuccess() - { - $ldap = $this - ->getMockBuilder('\Kanboard\Auth\Ldap') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('getLdapServer')) - ->getMock(); - - $ldap - ->expects($this->once()) - ->method('getLdapServer') - ->will($this->returnValue('my_ldap_server')); - - self::$functions - ->expects($this->once()) - ->method('ldap_connect') - ->with( - $this->equalTo('my_ldap_server'), - $this->equalTo($ldap->getLdapPort()) - ) - ->will($this->returnValue('my_ldap_resource')); - - $this->assertNotFalse($ldap->connect()); - } - - public function testConnectFailure() - { - $ldap = $this - ->getMockBuilder('\Kanboard\Auth\Ldap') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('getLdapServer')) - ->getMock(); - - $ldap - ->expects($this->once()) - ->method('getLdapServer') - ->will($this->returnValue('my_ldap_server')); - - self::$functions - ->expects($this->once()) - ->method('ldap_connect') - ->with( - $this->equalTo('my_ldap_server'), - $this->equalTo($ldap->getLdapPort()) - ) - ->will($this->returnValue(false)); - - $this->assertFalse($ldap->connect()); - } - - public function testBindAnonymous() - { - $ldap = $this - ->getMockBuilder('\Kanboard\Auth\Ldap') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('getLdapBindType')) - ->getMock(); - - $ldap - ->expects($this->any()) - ->method('getLdapBindType') - ->will($this->returnValue('anonymous')); - - self::$functions - ->expects($this->once()) - ->method('ldap_bind') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo(null), - $this->equalTo(null) - ) - ->will($this->returnValue(true)); - - $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password')); - } - - public function testBindUser() - { - $ldap = $this - ->getMockBuilder('\Kanboard\Auth\Ldap') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('getLdapUsername', 'getLdapBindType')) - ->getMock(); - - $ldap - ->expects($this->once()) - ->method('getLdapUsername') - ->will($this->returnValue('uid=my_user')); - - $ldap - ->expects($this->any()) - ->method('getLdapBindType') - ->will($this->returnValue('user')); - - self::$functions - ->expects($this->once()) - ->method('ldap_bind') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo('uid=my_user'), - $this->equalTo('my_password') - ) - ->will($this->returnValue(true)); - - $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password')); - } - - public function testBindProxy() - { - $ldap = $this - ->getMockBuilder('\Kanboard\Auth\Ldap') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('getLdapUsername', 'getLdapPassword', 'getLdapBindType')) - ->getMock(); - - $ldap - ->expects($this->once()) - ->method('getLdapUsername') - ->will($this->returnValue('someone')); - - $ldap - ->expects($this->once()) - ->method('getLdapPassword') - ->will($this->returnValue('something')); - - $ldap - ->expects($this->any()) - ->method('getLdapBindType') - ->will($this->returnValue('proxy')); - - self::$functions - ->expects($this->once()) - ->method('ldap_bind') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo('someone'), - $this->equalTo('something') - ) - ->will($this->returnValue(true)); - - $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password')); - } - - public function testSearchSuccess() - { - $entries = array( - 'count' => 1, - 0 => array( - 'count' => 2, - 'dn' => 'uid=my_user,ou=People,dc=kanboard,dc=local', - 'displayname' => array( - 'count' => 1, - 0 => 'My user', - ), - 'mail' => array( - 'count' => 2, - 0 => 'user1@localhost', - 1 => 'user2@localhost', - ), - 0 => 'displayname', - 1 => 'mail', - ) - ); - - $expected = array( - 'username' => 'my_user', - 'name' => 'My user', - 'email' => 'user1@localhost', - 'is_admin' => 0, - 'is_project_admin' => 0, - 'is_ldap_user' => 1, - ); - - $ldap = $this - ->getMockBuilder('\Kanboard\Auth\Ldap') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('getLdapUserPattern', 'getLdapBaseDn')) - ->getMock(); - - $ldap - ->expects($this->once()) - ->method('getLdapUserPattern') - ->will($this->returnValue('uid=my_user')); - - $ldap - ->expects($this->once()) - ->method('getLdapBaseDn') - ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); - - self::$functions - ->expects($this->at(0)) - ->method('ldap_search') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo('ou=People,dc=kanboard,dc=local'), - $this->equalTo('uid=my_user'), - $this->equalTo($ldap->getProfileAttributes()) - ) - ->will($this->returnValue('my_result_identifier')); - - self::$functions - ->expects($this->at(1)) - ->method('ldap_get_entries') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo('my_result_identifier') - ) - ->will($this->returnValue($entries)); - - self::$functions - ->expects($this->at(2)) - ->method('ldap_bind') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo('uid=my_user,ou=People,dc=kanboard,dc=local'), - $this->equalTo('my_password') - ) - ->will($this->returnValue(true)); - - $this->assertEquals($expected, $ldap->getProfile('my_ldap_connection', 'my_user', 'my_password')); - } - - public function testSearchWithBadPassword() - { - $entries = array( - 'count' => 1, - 0 => array( - 'count' => 2, - 'dn' => 'uid=my_user,ou=People,dc=kanboard,dc=local', - 'displayname' => array( - 'count' => 1, - 0 => 'My user', - ), - 'mail' => array( - 'count' => 2, - 0 => 'user1@localhost', - 1 => 'user2@localhost', - ), - 0 => 'displayname', - 1 => 'mail', - ) - ); - - $ldap = $this - ->getMockBuilder('\Kanboard\Auth\Ldap') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('getLdapUserPattern', 'getLdapBaseDn')) - ->getMock(); - - $ldap - ->expects($this->once()) - ->method('getLdapUserPattern') - ->will($this->returnValue('uid=my_user')); - - $ldap - ->expects($this->once()) - ->method('getLdapBaseDn') - ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); - - self::$functions - ->expects($this->at(0)) - ->method('ldap_search') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo('ou=People,dc=kanboard,dc=local'), - $this->equalTo('uid=my_user'), - $this->equalTo($ldap->getProfileAttributes()) - ) - ->will($this->returnValue('my_result_identifier')); - - self::$functions - ->expects($this->at(1)) - ->method('ldap_get_entries') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo('my_result_identifier') - ) - ->will($this->returnValue($entries)); - - self::$functions - ->expects($this->at(2)) - ->method('ldap_bind') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo('uid=my_user,ou=People,dc=kanboard,dc=local'), - $this->equalTo('my_password') - ) - ->will($this->returnValue(false)); - - $this->assertFalse($ldap->getProfile('my_ldap_connection', 'my_user', 'my_password')); - } - - public function testSearchWithUserNotFound() - { - $ldap = $this - ->getMockBuilder('\Kanboard\Auth\Ldap') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('getLdapUserPattern', 'getLdapBaseDn')) - ->getMock(); - - $ldap - ->expects($this->once()) - ->method('getLdapUserPattern') - ->will($this->returnValue('uid=my_user')); - - $ldap - ->expects($this->once()) - ->method('getLdapBaseDn') - ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); - - self::$functions - ->expects($this->at(0)) - ->method('ldap_search') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo('ou=People,dc=kanboard,dc=local'), - $this->equalTo('uid=my_user'), - $this->equalTo($ldap->getProfileAttributes()) - ) - ->will($this->returnValue('my_result_identifier')); - - self::$functions - ->expects($this->at(1)) - ->method('ldap_get_entries') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo('my_result_identifier') - ) - ->will($this->returnValue(array())); - - $this->assertFalse($ldap->getProfile('my_ldap_connection', 'my_user', 'my_password')); - } - - public function testSuccessfulAuthentication() - { - $this->container['userSession'] = $this - ->getMockBuilder('\Kanboard\Model\UserSession') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('refresh')) - ->getMock(); - - $this->container['user'] = $this - ->getMockBuilder('\Kanboard\Model\User') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('getByUsername')) - ->getMock(); - - $ldap = $this - ->getMockBuilder('\Kanboard\Auth\Ldap') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('findUser')) - ->getMock(); - - $ldap - ->expects($this->once()) - ->method('findUser') - ->with( - $this->equalTo('user'), - $this->equalTo('password') - ) - ->will($this->returnValue(array('username' => 'user', 'name' => 'My user', 'email' => 'user@here'))); - - $this->container['user'] - ->expects($this->once()) - ->method('getByUsername') - ->with( - $this->equalTo('user') - ) - ->will($this->returnValue(array('id' => 2, 'username' => 'user', 'is_ldap_user' => 1))); - - $this->container['userSession'] - ->expects($this->once()) - ->method('refresh'); - - $this->assertTrue($ldap->authenticate('user', 'password')); - } - - public function testAuthenticationWithExistingLocalUser() - { - $this->container['userSession'] = $this - ->getMockBuilder('\Kanboard\Model\UserSession') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('refresh')) - ->getMock(); - - $this->container['user'] = $this - ->getMockBuilder('\Kanboard\Model\User') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('getByUsername')) - ->getMock(); - - $ldap = $this - ->getMockBuilder('\Kanboard\Auth\Ldap') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('findUser')) - ->getMock(); - - $ldap - ->expects($this->once()) - ->method('findUser') - ->with( - $this->equalTo('user'), - $this->equalTo('password') - ) - ->will($this->returnValue(array('username' => 'user', 'name' => 'My user', 'email' => 'user@here'))); - - $this->container['user'] - ->expects($this->once()) - ->method('getByUsername') - ->with( - $this->equalTo('user') - ) - ->will($this->returnValue(array('id' => 2, 'username' => 'user', 'is_ldap_user' => 0))); - - $this->container['userSession'] - ->expects($this->never()) - ->method('refresh'); - - $this->assertFalse($ldap->authenticate('user', 'password')); - } - - public function testAuthenticationWithAutomaticAccountCreation() - { - $ldap_profile = array('username' => 'user', 'name' => 'My user', 'email' => 'user@here'); - - $this->container['userSession'] = $this - ->getMockBuilder('\Kanboard\Model\UserSession') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('refresh')) - ->getMock(); - - $this->container['user'] = $this - ->getMockBuilder('\Kanboard\Model\User') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('getByUsername', 'create')) - ->getMock(); - - $ldap = $this - ->getMockBuilder('\Kanboard\Auth\Ldap') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('findUser')) - ->getMock(); - - $ldap - ->expects($this->at(0)) - ->method('findUser') - ->with( - $this->equalTo('user'), - $this->equalTo('password') - ) - ->will($this->returnValue($ldap_profile)); - - $this->container['user'] - ->expects($this->at(0)) - ->method('getByUsername') - ->with( - $this->equalTo('user') - ) - ->will($this->returnValue(null)); - - $this->container['user'] - ->expects($this->at(1)) - ->method('create') - ->with( - $this->equalTo($ldap_profile) - ) - ->will($this->returnValue(true)); - - $this->container['user'] - ->expects($this->at(2)) - ->method('getByUsername') - ->with( - $this->equalTo('user') - ) - ->will($this->returnValue(array('id' => 2, 'username' => 'user', 'is_ldap_user' => 1))); - - $this->container['userSession'] - ->expects($this->once()) - ->method('refresh'); - - $this->assertTrue($ldap->authenticate('user', 'password')); - } - - public function testAuthenticationWithAutomaticAccountCreationFailed() - { - $ldap_profile = array('username' => 'user', 'name' => 'My user', 'email' => 'user@here'); - - $this->container['userSession'] = $this - ->getMockBuilder('\Kanboard\Model\UserSession') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('refresh')) - ->getMock(); - - $this->container['user'] = $this - ->getMockBuilder('\Kanboard\Model\User') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('getByUsername', 'create')) - ->getMock(); - - $ldap = $this - ->getMockBuilder('\Kanboard\Auth\Ldap') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('findUser')) - ->getMock(); - - $ldap - ->expects($this->at(0)) - ->method('findUser') - ->with( - $this->equalTo('user'), - $this->equalTo('password') - ) - ->will($this->returnValue($ldap_profile)); - - $this->container['user'] - ->expects($this->at(0)) - ->method('getByUsername') - ->with( - $this->equalTo('user') - ) - ->will($this->returnValue(null)); - - $this->container['user'] - ->expects($this->at(1)) - ->method('create') - ->with( - $this->equalTo($ldap_profile) - ) - ->will($this->returnValue(false)); - - $this->container['userSession'] - ->expects($this->never()) - ->method('refresh'); - - $this->assertFalse($ldap->authenticate('user', 'password')); - } - - public function testLookup() - { - $entries = array( - 'count' => 1, - 0 => array( - 'count' => 2, - 'dn' => 'uid=my_user,ou=People,dc=kanboard,dc=local', - 'displayname' => array( - 'count' => 1, - 0 => 'My LDAP user', - ), - 'mail' => array( - 'count' => 2, - 0 => 'user1@localhost', - 1 => 'user2@localhost', - ), - 'samaccountname' => array( - 'count' => 1, - 0 => 'my_ldap_user', - ), - 0 => 'displayname', - 1 => 'mail', - 2 => 'samaccountname', - ) - ); - - $expected = array( - 'username' => 'my_ldap_user', - 'name' => 'My LDAP user', - 'email' => 'user1@localhost', - 'is_admin' => 0, - 'is_project_admin' => 0, - 'is_ldap_user' => 1, - ); - - $ldap = $this - ->getMockBuilder('\Kanboard\Auth\Ldap') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('connect', 'getLdapUserPattern', 'getLdapBaseDn', 'getLdapAccountId')) - ->getMock(); - - $ldap - ->expects($this->once()) - ->method('connect') - ->will($this->returnValue('my_ldap_connection')); - - $ldap - ->expects($this->once()) - ->method('getLdapUserPattern') - ->will($this->returnValue('sAMAccountName=my_user')); - - $ldap - ->expects($this->any()) - ->method('getLdapAccountId') - ->will($this->returnValue('samaccountname')); - - $ldap - ->expects($this->once()) - ->method('getLdapBaseDn') - ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); - - self::$functions - ->expects($this->at(0)) - ->method('ldap_bind') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo(null), - $this->equalTo(null) - ) - ->will($this->returnValue(true)); - - self::$functions - ->expects($this->at(1)) - ->method('ldap_search') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo('ou=People,dc=kanboard,dc=local'), - $this->equalTo('(&(sAMAccountName=my_user)(mail=user@localhost))'), - $this->equalTo($ldap->getProfileAttributes()) - ) - ->will($this->returnValue('my_result_identifier')); - - self::$functions - ->expects($this->at(2)) - ->method('ldap_get_entries') - ->with( - $this->equalTo('my_ldap_connection'), - $this->equalTo('my_result_identifier') - ) - ->will($this->returnValue($entries)); - - $this->assertEquals($expected, $ldap->lookup('my_user', 'user@localhost')); - } -} diff --git a/tests/units/Auth/ReverseProxyTest.php b/tests/units/Auth/ReverseProxyTest.php deleted file mode 100644 index 6aaa5a67..00000000 --- a/tests/units/Auth/ReverseProxyTest.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Auth\ReverseProxy; -use Kanboard\Model\User; - -class ReverseProxyTest extends Base -{ - public function setUp() - { - parent::setup(); - $_SERVER = array(); - } - - public function testFailedAuthentication() - { - $auth = new ReverseProxy($this->container); - $this->assertFalse($auth->authenticate()); - } - - public function testSuccessfulAuthentication() - { - $_SERVER[REVERSE_PROXY_USER_HEADER] = 'my_user'; - - $a = new ReverseProxy($this->container); - $u = new User($this->container); - - $this->assertTrue($a->authenticate()); - - $user = $u->getByUsername('my_user'); - $this->assertNotEmpty($user); - $this->assertEquals(0, $user['is_admin']); - $this->assertEquals(1, $user['is_ldap_user']); - $this->assertEquals(1, $user['disable_login_form']); - } -} diff --git a/tests/units/Auth/TotpAuthTest.php b/tests/units/Auth/TotpAuthTest.php new file mode 100644 index 00000000..c8dcfb28 --- /dev/null +++ b/tests/units/Auth/TotpAuthTest.php @@ -0,0 +1,66 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Auth\TotpAuth; + +class TotpAuthTest extends Base +{ + public function testGetName() + { + $provider = new TotpAuth($this->container); + $this->assertEquals('Time-based One-time Password Algorithm', $provider->getName()); + } + + public function testGetSecret() + { + $provider = new TotpAuth($this->container); + $this->assertEmpty($provider->getSecret()); + + $provider->generateSecret(); + $secret = $provider->getSecret(); + + $this->assertNotEmpty($secret); + $this->assertEquals($secret, $provider->getSecret()); + $this->assertEquals($secret, $provider->getSecret()); + } + + public function testSetSecret() + { + $provider = new TotpAuth($this->container); + $provider->setSecret('mySecret'); + $this->assertEquals('mySecret', $provider->getSecret()); + } + + public function testGetUrl() + { + $provider = new TotpAuth($this->container); + $this->assertEmpty($provider->getQrCodeUrl('me')); + $this->assertEmpty($provider->getKeyUrl('me')); + + $provider->setSecret('mySecret'); + $this->assertEquals( + 'https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=M|0&chl=otpauth%3A%2F%2Ftotp%2Fme%3Fsecret%3DmySecret', + $provider->getQrCodeUrl('me') + ); + + $this->assertEquals('otpauth://totp/me?secret=mySecret', $provider->getKeyUrl('me')); + } + + public function testAuthentication() + { + $provider = new TotpAuth($this->container); + + $secret = $provider->generateSecret(); + $this->assertNotEmpty($secret); + + $provider->setCode('1234'); + $this->assertFalse($provider->authenticate()); + + if (!!`which oathtool`) { + $code = shell_exec('oathtool --totp -b '.$secret); + $provider->setCode(trim($code)); + $this->assertTrue($provider->authenticate()); + } + } +} diff --git a/tests/units/Base.php b/tests/units/Base.php index 8112c954..eb9fc68b 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -8,49 +8,9 @@ use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher; use Symfony\Component\Stopwatch\Stopwatch; use SimpleLogger\Logger; use SimpleLogger\File; - -class FakeHttpClient -{ - private $url = ''; - private $data = array(); - private $headers = array(); - - public function getUrl() - { - return $this->url; - } - - public function getData() - { - return $this->data; - } - - public function getHeaders() - { - return $this->headers; - } - - public function toPrettyJson() - { - return json_encode($this->data, JSON_PRETTY_PRINT); - } - - public function postJson($url, array $data, array $headers = array()) - { - $this->url = $url; - $this->data = $data; - $this->headers = $headers; - return true; - } - - public function postForm($url, array $data, array $headers = array()) - { - $this->url = $url; - $this->data = $data; - $this->headers = $headers; - return true; - } -} +use Kanboard\Core\Session\FlashMessage; +use Kanboard\Core\Session\SessionStorage; +use Kanboard\ServiceProvider\ActionProvider; abstract class Base extends PHPUnit_Framework_TestCase { @@ -73,8 +33,11 @@ abstract class Base extends PHPUnit_Framework_TestCase } $this->container = new Pimple\Container; + $this->container->register(new Kanboard\ServiceProvider\AuthenticationProvider); $this->container->register(new Kanboard\ServiceProvider\DatabaseProvider); $this->container->register(new Kanboard\ServiceProvider\ClassProvider); + $this->container->register(new Kanboard\ServiceProvider\NotificationProvider); + $this->container->register(new Kanboard\ServiceProvider\RouteProvider); $this->container['dispatcher'] = new TraceableEventDispatcher( new EventDispatcher, @@ -85,14 +48,37 @@ abstract class Base extends PHPUnit_Framework_TestCase $this->container['logger'] = new Logger; $this->container['logger']->setLogger(new File($this->isWindows() ? 'NUL' : '/dev/null')); - $this->container['httpClient'] = new FakeHttpClient; - $this->container['emailClient'] = $this->getMockBuilder('EmailClient')->setMethods(array('send'))->getMock(); + + $this->container['httpClient'] = $this + ->getMockBuilder('\Kanboard\Core\Http\Client') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('get', 'getJson', 'postJson', 'postForm')) + ->getMock(); + + $this->container['emailClient'] = $this + ->getMockBuilder('\Kanboard\Core\Mail\Client') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('send')) + ->getMock(); $this->container['userNotificationType'] = $this ->getMockBuilder('\Kanboard\Model\UserNotificationType') ->setConstructorArgs(array($this->container)) ->setMethods(array('getType', 'getSelectedTypes')) ->getMock(); + + $this->container['objectStorage'] = $this + ->getMockBuilder('\Kanboard\Core\ObjectStorage\FileStorage') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('put', 'moveFile', 'remove', 'moveUploadedFile')) + ->getMock(); + + $this->container['sessionStorage'] = new SessionStorage; + $this->container->register(new ActionProvider); + + $this->container['flash'] = function ($c) { + return new FlashMessage($c); + }; } public function tearDown() diff --git a/tests/units/Core/Action/ActionManagerTest.php b/tests/units/Core/Action/ActionManagerTest.php new file mode 100644 index 00000000..aae5bd2d --- /dev/null +++ b/tests/units/Core/Action/ActionManagerTest.php @@ -0,0 +1,196 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Action\ActionManager; +use Kanboard\Action\TaskAssignColorColumn; +use Kanboard\Action\TaskClose; +use Kanboard\Action\TaskCloseColumn; +use Kanboard\Action\TaskUpdateStartDate; +use Kanboard\Model\Action; +use Kanboard\Model\Task; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectUserRole; +use Kanboard\Core\Security\Role; + +class ActionManagerTest extends Base +{ + public function testRegister() + { + $actionManager = new ActionManager($this->container); + $actionTaskClose = new TaskClose($this->container); + + $actionManager->register($actionTaskClose); + $this->assertInstanceOf(get_class($actionTaskClose), $actionManager->getAction($actionTaskClose->getName())); + } + + public function testGetActionNotFound() + { + $this->setExpectedException('RuntimeException', 'Automatic Action Not Found: foobar'); + $actionManager = new ActionManager($this->container); + $actionManager->getAction('foobar'); + } + + public function testGetAvailableActions() + { + $actionManager = new ActionManager($this->container); + $actionTaskClose1 = new TaskCloseColumn($this->container); + $actionTaskClose2 = new TaskCloseColumn($this->container); + $actionTaskUpdateStartDate = new TaskUpdateStartDate($this->container); + + $actionManager + ->register($actionTaskClose1) + ->register($actionTaskClose2) + ->register($actionTaskUpdateStartDate); + + $actions = $actionManager->getAvailableActions(); + $this->assertCount(2, $actions); + $this->assertArrayHasKey($actionTaskClose1->getName(), $actions); + $this->assertArrayHasKey($actionTaskUpdateStartDate->getName(), $actions); + $this->assertNotEmpty($actions[$actionTaskClose1->getName()]); + $this->assertNotEmpty($actions[$actionTaskUpdateStartDate->getName()]); + } + + public function testGetAvailableParameters() + { + $actionManager = new ActionManager($this->container); + + $actionManager + ->register(new TaskCloseColumn($this->container)) + ->register(new TaskUpdateStartDate($this->container)); + + $params = $actionManager->getAvailableParameters(array( + array('action_name' => '\Kanboard\Action\TaskCloseColumn'), + array('action_name' => '\Kanboard\Action\TaskUpdateStartDate'), + )); + + $this->assertCount(2, $params); + $this->assertArrayHasKey('column_id', $params['\Kanboard\Action\TaskCloseColumn']); + $this->assertArrayHasKey('column_id', $params['\Kanboard\Action\TaskUpdateStartDate']); + $this->assertNotEmpty($params['\Kanboard\Action\TaskCloseColumn']['column_id']); + $this->assertNotEmpty($params['\Kanboard\Action\TaskUpdateStartDate']['column_id']); + } + + public function testGetCompatibleEvents() + { + $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container); + $actionManager = new ActionManager($this->container); + $actionManager->register($actionTaskAssignColorColumn); + + $events = $actionManager->getCompatibleEvents('\\'.get_class($actionTaskAssignColorColumn)); + $this->assertCount(2, $events); + $this->assertArrayHasKey(Task::EVENT_CREATE, $events); + $this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN, $events); + $this->assertNotEmpty($events[Task::EVENT_CREATE]); + $this->assertNotEmpty($events[Task::EVENT_MOVE_COLUMN]); + } + + public function testAttachEventsWithoutUserSession() + { + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); + $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container); + $actionManager = new ActionManager($this->container); + $actionManager->register($actionTaskAssignColorColumn); + + $actions = $actionManager->getAvailableActions(); + + $actionManager->attachEvents(); + $this->assertEmpty($this->container['dispatcher']->getListeners()); + + $this->assertEquals(1, $projectModel->create(array('name' =>'test'))); + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CREATE, + 'action_name' => key($actions), + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $actionManager->attachEvents(); + $listeners = $this->container['dispatcher']->getListeners(Task::EVENT_CREATE); + $this->assertCount(1, $listeners); + $this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]); + + $this->assertEquals(1, $listeners[0][0]->getProjectId()); + } + + public function testAttachEventsWithLoggedUser() + { + $this->container['sessionStorage']->user = array('id' => 1); + + $projectModel = new Project($this->container); + $projectUserRoleModel = new ProjectUserRole($this->container); + $actionModel = new Action($this->container); + $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container); + $actionManager = new ActionManager($this->container); + $actionManager->register($actionTaskAssignColorColumn); + + $actions = $actionManager->getAvailableActions(); + + $this->assertEquals(1, $projectModel->create(array('name' =>'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' =>'test2'))); + + $this->assertTrue($projectUserRoleModel->addUser(2, 1, Role::PROJECT_MEMBER)); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CREATE, + 'action_name' => key($actions), + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $this->assertEquals(2, $actionModel->create(array( + 'project_id' => 2, + 'event_name' => Task::EVENT_MOVE_COLUMN, + 'action_name' => key($actions), + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $actionManager->attachEvents(); + + $listeners = $this->container['dispatcher']->getListeners(Task::EVENT_MOVE_COLUMN); + $this->assertCount(1, $listeners); + $this->assertInstanceOf(get_class($actionTaskAssignColorColumn), $listeners[0][0]); + + $this->assertEquals(2, $listeners[0][0]->getProjectId()); + } + + public function testThatEachListenerAreDifferentInstance() + { + $projectModel = new Project($this->container); + $projectUserRoleModel = new ProjectUserRole($this->container); + $actionModel = new Action($this->container); + $actionTaskAssignColorColumn = new TaskAssignColorColumn($this->container); + $actionManager = new ActionManager($this->container); + $actionManager->register($actionTaskAssignColorColumn); + + $this->assertEquals(1, $projectModel->create(array('name' =>'test1'))); + $actions = $actionManager->getAvailableActions(); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_MOVE_COLUMN, + 'action_name' => key($actions), + 'params' => array('column_id' => 2, 'color_id' => 'green'), + ))); + + $this->assertEquals(2, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_MOVE_COLUMN, + 'action_name' => key($actions), + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $actionManager->attachEvents(); + + $listeners = $this->container['dispatcher']->getListeners(Task::EVENT_MOVE_COLUMN); + $this->assertCount(2, $listeners); + $this->assertFalse($listeners[0][0] === $listeners[1][0]); + + $this->assertEquals(2, $listeners[0][0]->getParam('column_id')); + $this->assertEquals('green', $listeners[0][0]->getParam('color_id')); + + $this->assertEquals(1, $listeners[1][0]->getParam('column_id')); + $this->assertEquals('red', $listeners[1][0]->getParam('color_id')); + } +} diff --git a/tests/units/Core/CsvTest.php b/tests/units/Core/CsvTest.php index 71542c20..da0be4a3 100644 --- a/tests/units/Core/CsvTest.php +++ b/tests/units/Core/CsvTest.php @@ -14,9 +14,43 @@ class CsvTest extends Base $this->assertEquals(1, Csv::getBooleanValue('TRUE')); $this->assertEquals(1, Csv::getBooleanValue('true')); $this->assertEquals(1, Csv::getBooleanValue('T')); + $this->assertEquals(1, Csv::getBooleanValue('Y')); + $this->assertEquals(1, Csv::getBooleanValue('y')); + $this->assertEquals(1, Csv::getBooleanValue('yes')); + $this->assertEquals(1, Csv::getBooleanValue('Yes')); $this->assertEquals(0, Csv::getBooleanValue('0')); $this->assertEquals(0, Csv::getBooleanValue('123')); $this->assertEquals(0, Csv::getBooleanValue('anything')); } + + public function testGetEnclosures() + { + $this->assertCount(3, Csv::getEnclosures()); + $this->assertCount(4, Csv::getDelimiters()); + } + + public function testReadWrite() + { + $filename = tempnam(sys_get_temp_dir(), 'UT'); + $rows = array( + array('Column A', 'Column B'), + array('value a', 'value b'), + ); + + $csv = new Csv; + $csv->write($filename, $rows); + $csv->setColumnMapping(array('A', 'B', 'C')); + $csv->read($filename, array($this, 'readRow')); + + unlink($filename); + + $this->expectOutputString('"Column A","Column B"'."\n".'"value a","value b"'."\n", $csv->output($rows)); + } + + public function readRow(array $row, $line) + { + $this->assertEquals(array('value a', 'value b', ''), $row); + $this->assertEquals(1, $line); + } } diff --git a/tests/units/Core/DateParserTest.php b/tests/units/Core/DateParserTest.php index 0d345784..dc3366b3 100644 --- a/tests/units/Core/DateParserTest.php +++ b/tests/units/Core/DateParserTest.php @@ -6,79 +6,167 @@ use Kanboard\Core\DateParser; class DateParserTest extends Base { + public function testGetTimeFormats() + { + $dateParser = new DateParser($this->container); + $this->assertCount(2, $dateParser->getTimeFormats()); + $this->assertContains('H:i', $dateParser->getTimeFormats()); + $this->assertContains('g:i a', $dateParser->getTimeFormats()); + } + + public function testGetDateFormats() + { + $dateParser = new DateParser($this->container); + $this->assertCount(4, $dateParser->getDateFormats()); + $this->assertCount(6, $dateParser->getDateFormats(true)); + $this->assertContains('d/m/Y', $dateParser->getDateFormats()); + $this->assertNotContains('Y-m-d', $dateParser->getDateFormats()); + $this->assertContains('Y-m-d', $dateParser->getDateFormats(true)); + } + + public function testGetDateTimeFormats() + { + $dateParser = new DateParser($this->container); + $this->assertCount(8, $dateParser->getDateTimeFormats()); + $this->assertCount(12, $dateParser->getDateTimeFormats(true)); + $this->assertContains('d/m/Y H:i', $dateParser->getDateTimeFormats()); + $this->assertNotContains('Y-m-d H:i', $dateParser->getDateTimeFormats()); + $this->assertContains('Y-m-d g:i a', $dateParser->getDateTimeFormats(true)); + } + + public function testGetAllDateFormats() + { + $dateParser = new DateParser($this->container); + $this->assertCount(12, $dateParser->getAllDateFormats()); + $this->assertCount(18, $dateParser->getAllDateFormats(true)); + $this->assertContains('d/m/Y', $dateParser->getAllDateFormats()); + $this->assertContains('d/m/Y H:i', $dateParser->getAllDateFormats()); + $this->assertNotContains('Y-m-d H:i', $dateParser->getAllDateFormats()); + $this->assertContains('Y-m-d g:i a', $dateParser->getAllDateFormats(true)); + $this->assertContains('Y-m-d', $dateParser->getAllDateFormats(true)); + } + + public function testGetAllAvailableFormats() + { + $dateParser = new DateParser($this->container); + + $formats = $dateParser->getAvailableFormats($dateParser->getDateFormats()); + $this->assertArrayHasKey('d/m/Y', $formats); + $this->assertContains(date('d/m/Y'), $formats); + + $formats = $dateParser->getAvailableFormats($dateParser->getDateTimeFormats()); + $this->assertArrayHasKey('d/m/Y H:i', $formats); + $this->assertContains(date('d/m/Y H:i'), $formats); + + $formats = $dateParser->getAvailableFormats($dateParser->getAllDateFormats()); + $this->assertArrayHasKey('d/m/Y', $formats); + $this->assertContains(date('d/m/Y'), $formats); + $this->assertArrayHasKey('d/m/Y H:i', $formats); + $this->assertContains(date('d/m/Y H:i'), $formats); + } + + public function testGetTimestamp() + { + $dateParser = new DateParser($this->container); + + $this->assertEquals(1393995600, $dateParser->getTimestamp(1393995600)); + $this->assertEquals('2014-03-05', date('Y-m-d', $dateParser->getTimestamp('2014-03-05'))); + $this->assertEquals('2014-03-05', date('Y-m-d', $dateParser->getTimestamp('2014_03_05'))); + $this->assertEquals('2014-03-05', date('Y-m-d', $dateParser->getTimestamp('03/05/2014'))); + $this->assertEquals('2014-03-25 17:18', date('Y-m-d H:i', $dateParser->getTimestamp('03/25/2014 5:18 pm'))); + $this->assertEquals('2014-03-25 05:18', date('Y-m-d H:i', $dateParser->getTimestamp('03/25/2014 5:18 am'))); + $this->assertEquals('2014-03-25 17:18', date('Y-m-d H:i', $dateParser->getTimestamp('03/25/2014 5:18pm'))); + $this->assertEquals('2014-03-25 23:14', date('Y-m-d H:i', $dateParser->getTimestamp('03/25/2014 23:14'))); + $this->assertEquals('2014-03-29 23:14', date('Y-m-d H:i', $dateParser->getTimestamp('2014_03_29 23:14'))); + $this->assertEquals('2014-03-29 23:14', date('Y-m-d H:i', $dateParser->getTimestamp('2014-03-29 23:14'))); + } + public function testDateRange() { - $d = new DateParser($this->container); + $dateParser = new DateParser($this->container); - $this->assertTrue($d->withinDateRange(new DateTime('2015-03-14 15:30:00'), new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 16:00:00'))); - $this->assertFalse($d->withinDateRange(new DateTime('2015-03-14 15:30:00'), new DateTime('2015-03-14 16:00:00'), new DateTime('2015-03-14 17:00:00'))); + $this->assertTrue($dateParser->withinDateRange(new DateTime('2015-03-14 15:30:00'), new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 16:00:00'))); + $this->assertFalse($dateParser->withinDateRange(new DateTime('2015-03-14 15:30:00'), new DateTime('2015-03-14 16:00:00'), new DateTime('2015-03-14 17:00:00'))); + } + + public function testGetHours() + { + $dateParser = new DateParser($this->container); + + $this->assertEquals(1, $dateParser->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 16:00:00'))); + $this->assertEquals(2.5, $dateParser->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 17:30:00'))); + $this->assertEquals(2.75, $dateParser->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 17:45:00'))); + $this->assertEquals(3, $dateParser->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 17:58:00'))); + $this->assertEquals(3, $dateParser->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 11:58:00'))); } public function testRoundSeconds() { - $d = new DateParser($this->container); - $this->assertEquals('16:30', date('H:i', $d->getRoundedSeconds(strtotime('16:28')))); - $this->assertEquals('16:00', date('H:i', $d->getRoundedSeconds(strtotime('16:02')))); - $this->assertEquals('16:15', date('H:i', $d->getRoundedSeconds(strtotime('16:14')))); - $this->assertEquals('17:00', date('H:i', $d->getRoundedSeconds(strtotime('16:58')))); + $dateParser = new DateParser($this->container); + $this->assertEquals('16:30', date('H:i', $dateParser->getRoundedSeconds(strtotime('16:28')))); + $this->assertEquals('16:00', date('H:i', $dateParser->getRoundedSeconds(strtotime('16:02')))); + $this->assertEquals('16:15', date('H:i', $dateParser->getRoundedSeconds(strtotime('16:14')))); + $this->assertEquals('17:00', date('H:i', $dateParser->getRoundedSeconds(strtotime('16:58')))); } - public function testGetHours() + public function testGetIsoDate() { - $d = new DateParser($this->container); + $dateParser = new DateParser($this->container); + + $this->assertEquals('2016-02-06', $dateParser->getIsoDate(1454786217)); + $this->assertEquals('2014-03-05', $dateParser->getIsoDate('2014-03-05')); + $this->assertEquals('2014-03-05', $dateParser->getIsoDate('2014_03_05')); + $this->assertEquals('2014-03-05', $dateParser->getIsoDate('03/05/2014')); + $this->assertEquals('2014-03-25', $dateParser->getIsoDate('03/25/2014 5:18 pm')); + $this->assertEquals('2014-03-25', $dateParser->getIsoDate('03/25/2014 5:18 am')); + $this->assertEquals('2014-03-25', $dateParser->getIsoDate('03/25/2014 5:18pm')); + $this->assertEquals('2014-03-25', $dateParser->getIsoDate('03/25/2014 23:14')); + $this->assertEquals('2014-03-29', $dateParser->getIsoDate('2014_03_29 23:14')); + $this->assertEquals('2014-03-29', $dateParser->getIsoDate('2014-03-29 23:14')); + } - $this->assertEquals(1, $d->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 16:00:00'))); - $this->assertEquals(2.5, $d->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 17:30:00'))); - $this->assertEquals(2.75, $d->getHours(new DateTime('2015-03-14 15:00:00'), new DateTime('2015-03-14 17:45:00'))); - $this->assertEquals(3, $d->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 17:58:00'))); - $this->assertEquals(3, $d->getHours(new DateTime('2015-03-14 14:57:00'), new DateTime('2015-03-14 11:58:00'))); + public function testGetTimestampFromIsoFormat() + { + $dateParser = new DateParser($this->container); + $this->assertEquals('2014-03-05 00:00', date('Y-m-d H:i', $dateParser->getTimestampFromIsoFormat('2014-03-05'))); + $this->assertEquals(date('Y-m-d 00:00', strtotime('+2 days')), date('Y-m-d H:i', $dateParser->getTimestampFromIsoFormat(strtotime('+2 days')))); } - public function testValidDate() + public function testRemoveTimeFromTimestamp() { - $d = new DateParser($this->container); - - $this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('2014-03-05', 'Y-m-d'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('2014_03_05', 'Y_m_d'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('05/03/2014', 'd/m/Y'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('03/05/2014', 'm/d/Y'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('3/5/2014', 'm/d/Y'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('5/3/2014', 'd/m/Y'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $d->getValidDate('5/3/14', 'd/m/y'))); - $this->assertEquals(0, $d->getValidDate('5/3/14', 'd/m/Y')); - $this->assertEquals(0, $d->getValidDate('5-3-2014', 'd/m/Y')); + $dateParser = new DateParser($this->container); + $this->assertEquals('2016-02-06 00:00', date('Y-m-d H:i', $dateParser->removeTimeFromTimestamp(1454786217))); } - public function testGetTimestamp() + public function testFormat() { - $d = new DateParser($this->container); - - $this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('2014-03-05'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('2014_03_05'))); - $this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('03/05/2014'))); - $this->assertEquals('2014-03-25 17:18', date('Y-m-d H:i', $d->getTimestamp('03/25/2014 5:18 pm'))); - $this->assertEquals('2014-03-25 05:18', date('Y-m-d H:i', $d->getTimestamp('03/25/2014 5:18 am'))); - $this->assertEquals('2014-03-25 05:18', date('Y-m-d H:i', $d->getTimestamp('03/25/2014 5:18am'))); - $this->assertEquals('2014-03-25 23:14', date('Y-m-d H:i', $d->getTimestamp('03/25/2014 23:14'))); - $this->assertEquals('2014-03-29 23:14', date('Y-m-d H:i', $d->getTimestamp('2014_03_29 23:14'))); - $this->assertEquals('2014-03-29 23:14', date('Y-m-d H:i', $d->getTimestamp('2014-03-29 23:14'))); + $dateParser = new DateParser($this->container); + $values['date'] = '1454787006'; + + $this->assertEquals(array('date' => '06/02/2016'), $dateParser->format($values, array('date'), 'd/m/Y')); + $this->assertEquals(array('date' => '02/06/2016 7:30 pm'), $dateParser->format($values, array('date'), 'm/d/Y g:i a')); } public function testConvert() { - $d = new DateParser($this->container); - + $dateParser = new DateParser($this->container); $values = array( 'date_due' => '2015-01-25', - 'date_started' => '2015_01_25', + 'date_started' => '2015-01-25 17:25', ); - $d->convert($values, array('date_due', 'date_started')); + $this->assertEquals( + array('date_due' => 1422144000, 'date_started' => 1422144000), + $dateParser->convert($values, array('date_due', 'date_started')) + ); - $this->assertEquals(mktime(0, 0, 0, 1, 25, 2015), $values['date_due']); - $this->assertEquals('2015-01-25', date('Y-m-d', $values['date_due'])); + $values = array( + 'date_started' => '2015-01-25 17:25', + ); - $this->assertEquals(mktime(0, 0, 0, 1, 25, 2015), $values['date_started']); - $this->assertEquals('2015-01-25', date('Y-m-d', $values['date_started'])); + $this->assertEquals( + array('date_started' => 1422206700), + $dateParser->convert($values, array('date_due', 'date_started'), true) + ); } } diff --git a/tests/units/Core/Event/EventManagerTest.php b/tests/units/Core/Event/EventManagerTest.php new file mode 100644 index 00000000..974fde62 --- /dev/null +++ b/tests/units/Core/Event/EventManagerTest.php @@ -0,0 +1,18 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Event\EventManager; + +class EventManagerTest extends Base +{ + public function testAddEvent() + { + $eventManager = new EventManager; + $eventManager->register('my.event', 'My Event'); + + $events = $eventManager->getAll(); + $this->assertArrayHasKey('my.event', $events); + $this->assertEquals('My Event', $events['my.event']); + } +} diff --git a/tests/units/Core/ExternalLink/ExternalLinkManagerTest.php b/tests/units/Core/ExternalLink/ExternalLinkManagerTest.php new file mode 100644 index 00000000..d284a80b --- /dev/null +++ b/tests/units/Core/ExternalLink/ExternalLinkManagerTest.php @@ -0,0 +1,120 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\ExternalLink\ExternalLinkManager; +use Kanboard\ExternalLink\WebLinkProvider; +use Kanboard\ExternalLink\AttachmentLinkProvider; + +class ExternalLinkManagerTest extends Base +{ + public function testRegister() + { + $externalLinkManager = new ExternalLinkManager($this->container); + $webLinkProvider = new WebLinkProvider($this->container); + $attachmentLinkProvider = new AttachmentLinkProvider($this->container); + + $externalLinkManager->register($webLinkProvider); + $externalLinkManager->register($attachmentLinkProvider); + + $this->assertInstanceOf(get_class($webLinkProvider), $externalLinkManager->getProvider($webLinkProvider->getType())); + $this->assertInstanceOf(get_class($attachmentLinkProvider), $externalLinkManager->getProvider($attachmentLinkProvider->getType())); + } + + public function testGetProviderNotFound() + { + $externalLinkManager = new ExternalLinkManager($this->container); + + $this->setExpectedException('\Kanboard\Core\ExternalLink\ExternalLinkProviderNotFound'); + $externalLinkManager->getProvider('not found'); + } + + public function testGetTypes() + { + $externalLinkManager = new ExternalLinkManager($this->container); + $webLinkProvider = new WebLinkProvider($this->container); + $attachmentLinkProvider = new AttachmentLinkProvider($this->container); + + $this->assertEquals(array(ExternalLinkManager::TYPE_AUTO => 'Auto'), $externalLinkManager->getTypes()); + + $externalLinkManager->register($webLinkProvider); + $externalLinkManager->register($attachmentLinkProvider); + + $this->assertEquals( + array(ExternalLinkManager::TYPE_AUTO => 'Auto', 'attachment' => 'Attachment', 'weblink' => 'Web Link'), + $externalLinkManager->getTypes() + ); + } + + public function testGetDependencyLabel() + { + $externalLinkManager = new ExternalLinkManager($this->container); + $webLinkProvider = new WebLinkProvider($this->container); + $attachmentLinkProvider = new AttachmentLinkProvider($this->container); + + $externalLinkManager->register($webLinkProvider); + $externalLinkManager->register($attachmentLinkProvider); + + $this->assertSame('Related', $externalLinkManager->getDependencyLabel($webLinkProvider->getType(), 'related')); + $this->assertSame('custom', $externalLinkManager->getDependencyLabel($webLinkProvider->getType(), 'custom')); + } + + public function testFindProviderNotFound() + { + $externalLinkManager = new ExternalLinkManager($this->container); + $webLinkProvider = new WebLinkProvider($this->container); + $attachmentLinkProvider = new AttachmentLinkProvider($this->container); + + $externalLinkManager->register($webLinkProvider); + $externalLinkManager->register($attachmentLinkProvider); + + $this->setExpectedException('\Kanboard\Core\ExternalLink\ExternalLinkProviderNotFound'); + $externalLinkManager->find(); + } + + public function testFindProvider() + { + $externalLinkManager = new ExternalLinkManager($this->container); + $webLinkProvider = new WebLinkProvider($this->container); + $attachmentLinkProvider = new AttachmentLinkProvider($this->container); + + $externalLinkManager->register($webLinkProvider); + $externalLinkManager->register($attachmentLinkProvider); + + $externalLinkManager->setUserInput(array('text' => 'https://google.com/', 'type' => ExternalLinkManager::TYPE_AUTO)); + $this->assertSame($webLinkProvider, $externalLinkManager->find()); + + $externalLinkManager->setUserInput(array('text' => 'https://google.com/file.pdf', 'type' => ExternalLinkManager::TYPE_AUTO)); + $this->assertSame($attachmentLinkProvider, $externalLinkManager->find()); + } + + public function testFindProviderWithSelectedType() + { + $externalLinkManager = new ExternalLinkManager($this->container); + $webLinkProvider = new WebLinkProvider($this->container); + $attachmentLinkProvider = new AttachmentLinkProvider($this->container); + + $externalLinkManager->register($webLinkProvider); + $externalLinkManager->register($attachmentLinkProvider); + + $externalLinkManager->setUserInput(array('text' => 'https://google.com/', 'type' => $webLinkProvider->getType())); + $this->assertSame($webLinkProvider, $externalLinkManager->find()); + + $externalLinkManager->setUserInput(array('text' => 'https://google.com/file.pdf', 'type' => $attachmentLinkProvider->getType())); + $this->assertSame($attachmentLinkProvider, $externalLinkManager->find()); + } + + public function testFindProviderWithSelectedTypeNotFound() + { + $externalLinkManager = new ExternalLinkManager($this->container); + $webLinkProvider = new WebLinkProvider($this->container); + $attachmentLinkProvider = new AttachmentLinkProvider($this->container); + + $externalLinkManager->register($webLinkProvider); + $externalLinkManager->register($attachmentLinkProvider); + + $this->setExpectedException('\Kanboard\Core\ExternalLink\ExternalLinkProviderNotFound'); + $externalLinkManager->setUserInput(array('text' => 'https://google.com/', 'type' => 'not found')); + $externalLinkManager->find(); + } +} diff --git a/tests/units/Core/Group/GroupManagerTest.php b/tests/units/Core/Group/GroupManagerTest.php new file mode 100644 index 00000000..faf5501f --- /dev/null +++ b/tests/units/Core/Group/GroupManagerTest.php @@ -0,0 +1,42 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Model\Group; +use Kanboard\Core\Group\GroupManager; +use Kanboard\Group\DatabaseBackendGroupProvider; + +class GroupManagerTest extends Base +{ + public function testFind() + { + $groupModel = new Group($this->container); + $groupManager = new GroupManager; + + $this->assertEquals(1, $groupModel->create('Group 1')); + $this->assertEquals(2, $groupModel->create('Group 2')); + + $this->assertEmpty($groupManager->find('group 1')); + + $groupManager->register(new DatabaseBackendGroupProvider($this->container)); + $groupManager->register(new DatabaseBackendGroupProvider($this->container)); + + $groups = $groupManager->find('group 1'); + $this->assertCount(1, $groups); + $this->assertInstanceOf('Kanboard\Group\DatabaseGroupProvider', $groups[0]); + $this->assertEquals('Group 1', $groups[0]->getName()); + $this->assertEquals('', $groups[0]->getExternalId()); + $this->assertEquals(1, $groups[0]->getInternalId()); + + $groups = $groupManager->find('grou'); + $this->assertCount(2, $groups); + $this->assertInstanceOf('Kanboard\Group\DatabaseGroupProvider', $groups[0]); + $this->assertInstanceOf('Kanboard\Group\DatabaseGroupProvider', $groups[1]); + $this->assertEquals('Group 1', $groups[0]->getName()); + $this->assertEquals('Group 2', $groups[1]->getName()); + $this->assertEquals('', $groups[0]->getExternalId()); + $this->assertEquals('', $groups[1]->getExternalId()); + $this->assertEquals(1, $groups[0]->getInternalId()); + $this->assertEquals(2, $groups[1]->getInternalId()); + } +} diff --git a/tests/units/Core/OAuth2Test.php b/tests/units/Core/Http/OAuth2Test.php index d5713608..c68ae116 100644 --- a/tests/units/Core/OAuth2Test.php +++ b/tests/units/Core/Http/OAuth2Test.php @@ -1,8 +1,8 @@ <?php -require_once __DIR__.'/../Base.php'; +require_once __DIR__.'/../../Base.php'; -use Kanboard\Core\OAuth2; +use Kanboard\Core\Http\OAuth2; class OAuth2Test extends Base { @@ -27,17 +27,27 @@ class OAuth2Test extends Base public function testAccessToken() { + $params = array( + 'code' => 'something', + 'client_id' => 'A', + 'client_secret' => 'B', + 'redirect_uri' => 'C', + 'grant_type' => 'authorization_code', + ); + + $response = json_encode(array( + 'token_type' => 'bearer', + 'access_token' => 'plop', + )); + + $this->container['httpClient'] + ->expects($this->once()) + ->method('postForm') + ->with('E', $params, array('Accept: application/json')) + ->will($this->returnValue($response)); + $oauth = new OAuth2($this->container); $oauth->createService('A', 'B', 'C', 'D', 'E', array('f', 'g')); $oauth->getAccessToken('something'); - - $data = $this->container['httpClient']->getData(); - $this->assertEquals('something', $data['code']); - $this->assertEquals('A', $data['client_id']); - $this->assertEquals('B', $data['client_secret']); - $this->assertEquals('C', $data['redirect_uri']); - $this->assertEquals('authorization_code', $data['grant_type']); - - $this->assertEquals('E', $this->container['httpClient']->getUrl()); } } diff --git a/tests/units/Core/Http/RememberMeCookieTest.php b/tests/units/Core/Http/RememberMeCookieTest.php new file mode 100644 index 00000000..ae5606ac --- /dev/null +++ b/tests/units/Core/Http/RememberMeCookieTest.php @@ -0,0 +1,108 @@ +<?php + +namespace Kanboard\Core\Http; + +require_once __DIR__.'/../../Base.php'; + +function setcookie($name, $value = "", $expire = 0, $path = "", $domain = "", $secure = false, $httponly = false) +{ + return RememberMeCookieTest::$functions->setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); +} + +class RememberMeCookieTest extends \Base +{ + public static $functions; + + public function setUp() + { + parent::setup(); + + self::$functions = $this + ->getMockBuilder('stdClass') + ->setMethods(array( + 'setcookie', + )) + ->getMock(); + } + + public function tearDown() + { + parent::tearDown(); + self::$functions = null; + } + + public function testEncode() + { + $cookie = new RememberMeCookie($this->container); + $this->assertEquals('a|b', $cookie->encode('a', 'b')); + } + + public function testDecode() + { + $cookie = new RememberMeCookie($this->container); + $this->assertEquals(array('token' => 'a', 'sequence' => 'b'), $cookie->decode('a|b')); + } + + public function testHasCookie() + { + $this->container['request'] = new Request($this->container, array(), array(), array(), array(), array()); + + $cookie = new RememberMeCookie($this->container); + $this->assertFalse($cookie->hasCookie()); + + $this->container['request'] = new Request($this->container, array(), array(), array(), array(), array(RememberMeCookie::COOKIE_NAME => 'miam')); + $this->assertTrue($cookie->hasCookie()); + } + + public function testWrite() + { + self::$functions + ->expects($this->once()) + ->method('setcookie') + ->with( + RememberMeCookie::COOKIE_NAME, + 'myToken|mySequence', + 1234, + '', + '', + false, + true + ) + ->will($this->returnValue(true)); + + $cookie = new RememberMeCookie($this->container); + $this->assertTrue($cookie->write('myToken', 'mySequence', 1234)); + } + + public function testRead() + { + $this->container['request'] = new Request($this->container, array(), array(), array(), array(), array()); + + $cookie = new RememberMeCookie($this->container); + $this->assertFalse($cookie->read()); + + $this->container['request'] = new Request($this->container, array(), array(), array(), array(), array(RememberMeCookie::COOKIE_NAME => 'T|S')); + + $this->assertEquals(array('token' => 'T', 'sequence' => 'S'), $cookie->read()); + } + + public function testRemove() + { + self::$functions + ->expects($this->once()) + ->method('setcookie') + ->with( + RememberMeCookie::COOKIE_NAME, + '', + time() - 3600, + '', + '', + false, + true + ) + ->will($this->returnValue(true)); + + $cookie = new RememberMeCookie($this->container); + $this->assertTrue($cookie->remove()); + } +} diff --git a/tests/units/Core/Http/RequestTest.php b/tests/units/Core/Http/RequestTest.php new file mode 100644 index 00000000..217698f9 --- /dev/null +++ b/tests/units/Core/Http/RequestTest.php @@ -0,0 +1,175 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Http\Request; + +class RequestTest extends Base +{ + public function testGetStringParam() + { + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertEquals('', $request->getStringParam('myvar')); + + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertEquals('default', $request->getStringParam('myvar', 'default')); + + $request = new Request($this->container, array(), array('myvar' => 'myvalue'), array(), array(), array()); + $this->assertEquals('myvalue', $request->getStringParam('myvar')); + } + + public function testGetIntegerParam() + { + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertEquals(0, $request->getIntegerParam('myvar')); + + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertEquals(5, $request->getIntegerParam('myvar', 5)); + + $request = new Request($this->container, array(), array('myvar' => 'myvalue'), array(), array(), array()); + $this->assertEquals(0, $request->getIntegerParam('myvar')); + + $request = new Request($this->container, array(), array('myvar' => '123'), array(), array(), array()); + $this->assertEquals(123, $request->getIntegerParam('myvar')); + } + + public function testGetValues() + { + $request = new Request($this->container, array(), array(), array('myvar' => 'myvalue'), array(), array()); + $this->assertEmpty($request->getValue('myvar')); + + $request = new Request($this->container, array(), array(), array('myvar' => 'myvalue', 'csrf_token' => $this->container['token']->getCSRFToken()), array(), array()); + $this->assertEquals('myvalue', $request->getValue('myvar')); + + $request = new Request($this->container, array(), array(), array('myvar' => 'myvalue', 'csrf_token' => $this->container['token']->getCSRFToken()), array(), array()); + $this->assertEquals(array('myvar' => 'myvalue'), $request->getValues()); + } + + public function testGetFileContent() + { + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertEmpty($request->getFileContent('myfile')); + + $filename = tempnam(sys_get_temp_dir(), 'UnitTest'); + file_put_contents($filename, 'something'); + + $request = new Request($this->container, array(), array(), array(), array('myfile' => array('tmp_name' => $filename)), array()); + $this->assertEquals('something', $request->getFileContent('myfile')); + + unlink($filename); + } + + public function testGetFilePath() + { + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertEmpty($request->getFilePath('myfile')); + + $request = new Request($this->container, array(), array(), array(), array('myfile' => array('tmp_name' => 'somewhere')), array()); + $this->assertEquals('somewhere', $request->getFilePath('myfile')); + } + + public function testIsPost() + { + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertFalse($request->isPost()); + + $request = new Request($this->container, array('REQUEST_METHOD' => 'POST'), array(), array(), array(), array()); + $this->assertTrue($request->isPost()); + } + + public function testIsAjax() + { + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertFalse($request->isAjax()); + + $request = new Request($this->container, array('HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'), array(), array(), array(), array()); + $this->assertTrue($request->isAjax()); + } + + public function testIsHTTPS() + { + $request = new Request($this->container, array(), array(), array(), array()); + $this->assertFalse($request->isHTTPS()); + + $request = new Request($this->container, array('HTTPS' => ''), array(), array(), array(), array()); + $this->assertFalse($request->isHTTPS()); + + $request = new Request($this->container, array('HTTPS' => 'off'), array(), array(), array(), array()); + $this->assertFalse($request->isHTTPS()); + + $request = new Request($this->container, array('HTTPS' => 'on'), array(), array(), array(), array()); + $this->assertTrue($request->isHTTPS()); + + $request = new Request($this->container, array('HTTPS' => '1'), array(), array(), array(), array()); + $this->assertTrue($request->isHTTPS()); + } + + public function testGetCookie() + { + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertEmpty($request->getCookie('mycookie')); + + $request = new Request($this->container, array(), array(), array(), array(), array('mycookie' => 'miam')); + $this->assertEquals('miam', $request->getCookie('mycookie')); + } + + public function testGetHeader() + { + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertEmpty($request->getHeader('X-Forwarded-For')); + + $request = new Request($this->container, array('HTTP_X_FORWARDED_FOR' => 'test'), array(), array(), array(), array()); + $this->assertEquals('test', $request->getHeader('X-Forwarded-For')); + } + + public function testGetRemoteUser() + { + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertEmpty($request->getRemoteUser()); + + $request = new Request($this->container, array(REVERSE_PROXY_USER_HEADER => 'test'), array(), array(), array(), array()); + $this->assertEquals('test', $request->getRemoteUser()); + } + + public function testGetQueryString() + { + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertEmpty($request->getQueryString()); + + $request = new Request($this->container, array('QUERY_STRING' => 'k=v'), array(), array(), array(), array()); + $this->assertEquals('k=v', $request->getQueryString()); + } + + public function testGetUri() + { + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertEmpty($request->getUri()); + + $request = new Request($this->container, array('REQUEST_URI' => '/blah'), array(), array(), array(), array()); + $this->assertEquals('/blah', $request->getUri()); + } + + public function testGetUserAgent() + { + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertEquals('Unknown', $request->getUserAgent()); + + $request = new Request($this->container, array('HTTP_USER_AGENT' => 'My browser'), array(), array(), array(), array()); + $this->assertEquals('My browser', $request->getUserAgent()); + } + + public function testGetIpAddress() + { + $request = new Request($this->container, array(), array(), array(), array(), array()); + $this->assertEquals('Unknown', $request->getIpAddress()); + + $request = new Request($this->container, array('HTTP_X_FORWARDED_FOR' => '192.168.0.1,127.0.0.1'), array(), array(), array(), array()); + $this->assertEquals('192.168.0.1', $request->getIpAddress()); + + $request = new Request($this->container, array('REMOTE_ADDR' => '192.168.0.1'), array(), array(), array(), array()); + $this->assertEquals('192.168.0.1', $request->getIpAddress()); + + $request = new Request($this->container, array('REMOTE_ADDR' => ''), array(), array(), array(), array()); + $this->assertEquals('Unknown', $request->getIpAddress()); + } +} diff --git a/tests/units/Core/Http/RouteTest.php b/tests/units/Core/Http/RouteTest.php new file mode 100644 index 00000000..5e44ad00 --- /dev/null +++ b/tests/units/Core/Http/RouteTest.php @@ -0,0 +1,79 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Http\Route; + +class RouteTest extends Base +{ + public function testFindParams() + { + $route = new Route($this->container); + $route->enable(); + + $this->assertEquals(array('p1' => true, 'p2' => true), $route->findParams(array('something', ':p1', ':p2'))); + $this->assertEquals(array('p1' => true), $route->findParams(array('something', ':p1', ''))); + $this->assertEquals(array('p1' => true), $route->findParams(array('something', ':p1', 'something else'))); + } + + public function testFindRoute() + { + $route = new Route($this->container); + $route->enable(); + + $route->addRoute('/mycontroller/myaction', 'mycontroller', 'myaction'); + $this->assertEquals( + array('controller' => 'mycontroller', 'action' => 'myaction', 'plugin' => ''), + $route->findRoute('/mycontroller/myaction') + ); + + $route->addRoute('/a/b/c', 'mycontroller', 'myaction', 'myplugin'); + $this->assertEquals( + array('controller' => 'mycontroller', 'action' => 'myaction', 'plugin' => 'myplugin'), + $route->findRoute('/a/b/c') + ); + + $this->assertEquals( + array('controller' => 'app', 'action' => 'index', 'plugin' => ''), + $route->findRoute('/notfound') + ); + + $route->addRoute('/a/b/:c', 'mycontroller', 'myaction', 'myplugin'); + $this->assertEquals( + array('controller' => 'mycontroller', 'action' => 'myaction', 'plugin' => 'myplugin'), + $route->findRoute('/a/b/myvalue') + ); + + $this->assertEquals('myvalue', $this->container['request']->getStringParam('c')); + + $route->addRoute('/a/:p1/b/:p2', 'mycontroller', 'myaction'); + $this->assertEquals( + array('controller' => 'mycontroller', 'action' => 'myaction', 'plugin' => ''), + $route->findRoute('/a/v1/b/v2') + ); + + $this->assertEquals('v1', $this->container['request']->getStringParam('p1')); + $this->assertEquals('v2', $this->container['request']->getStringParam('p2')); + } + + public function testFindUrl() + { + $route = new Route($this->container); + $route->enable(); + $route->addRoute('a/b', 'controller1', 'action1'); + $route->addRoute('a/:myvar1/b/:myvar2', 'controller2', 'action2'); + $route->addRoute('/something', 'controller1', 'action1', 'myplugin'); + $route->addRoute('/myplugin/myroute', 'controller1', 'action2', 'myplugin'); + $route->addRoute('/foo/:myvar', 'controller1', 'action3', 'myplugin'); + + $this->assertEquals('a/1/b/2', $route->findUrl('controller2', 'action2', array('myvar1' => 1, 'myvar2' => 2))); + $this->assertEquals('', $route->findUrl('controller2', 'action2', array('myvar1' => 1))); + $this->assertEquals('a/b', $route->findUrl('controller1', 'action1')); + $this->assertEquals('', $route->findUrl('controller1', 'action2')); + + $this->assertEquals('myplugin/myroute', $route->findUrl('controller1', 'action2', array(), 'myplugin')); + $this->assertEquals('something', $route->findUrl('controller1', 'action1', array(), 'myplugin')); + $this->assertEquals('foo/123', $route->findUrl('controller1', 'action3', array('myvar' => 123), 'myplugin')); + $this->assertEquals('foo/123', $route->findUrl('controller1', 'action3', array('myvar' => 123, 'plugin' => 'myplugin'))); + } +} diff --git a/tests/units/Core/Http/RouterTest.php b/tests/units/Core/Http/RouterTest.php new file mode 100644 index 00000000..0b200ab5 --- /dev/null +++ b/tests/units/Core/Http/RouterTest.php @@ -0,0 +1,203 @@ +<?php + +namespace Kanboard\Controller { + + class FakeController { + public function beforeAction() {} + public function myAction() {} + } +} + +namespace Kanboard\Plugin\Myplugin\Controller { + + class FakeController { + public function beforeAction() {} + public function myAction() {} + } +} + +namespace { + + require_once __DIR__.'/../../Base.php'; + + use Kanboard\Core\Helper; + use Kanboard\Core\Http\Route; + use Kanboard\Core\Http\Router; + use Kanboard\Core\Http\Request; + + class RouterTest extends Base + { + public function testSanitize() + { + $dispatcher = new Router($this->container); + + $this->assertEquals('PloP', $dispatcher->sanitize('PloP', 'default')); + $this->assertEquals('default', $dispatcher->sanitize('', 'default')); + $this->assertEquals('default', $dispatcher->sanitize('123-AB', 'default')); + $this->assertEquals('default', $dispatcher->sanitize('R&D', 'default')); + $this->assertEquals('Test123', $dispatcher->sanitize('Test123', 'default')); + $this->assertEquals('Test_123', $dispatcher->sanitize('Test_123', 'default')); + $this->assertEquals('userImport', $dispatcher->sanitize('userImport', 'default')); + } + + public function testGetPath() + { + $dispatcher = new Router($this->container); + + $this->container['helper'] = new Helper($this->container); + $this->container['request'] = new Request($this->container, array('PHP_SELF' => '/index.php', 'REQUEST_URI' => '/a/b/c', 'REQUEST_METHOD' => 'GET')); + $this->assertEquals('a/b/c', $dispatcher->getPath()); + + $this->container['helper'] = new Helper($this->container); + $this->container['request'] = new Request($this->container, array('PHP_SELF' => '/index.php', 'REQUEST_URI' => '/a/b/something?test=a', 'QUERY_STRING' => 'test=a', 'REQUEST_METHOD' => 'GET')); + $this->assertEquals('a/b/something', $dispatcher->getPath()); + + $this->container['helper'] = new Helper($this->container); + $this->container['request'] = new Request($this->container, array('PHP_SELF' => '/a/index.php', 'REQUEST_URI' => '/a/b/something?test=a', 'QUERY_STRING' => 'test=a', 'REQUEST_METHOD' => 'GET')); + $this->assertEquals('b/something', $dispatcher->getPath()); + } + + public function testDispatcherWithControllerNotFound() + { + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/kanboard/index.php', + 'REQUEST_URI' => '/kanboard/?controller=FakeControllerNotFound&action=myAction&myvar=value1', + 'QUERY_STRING' => 'controller=FakeControllerNotFound&action=myAction&myvar=value1', + 'REQUEST_METHOD' => 'GET' + ), + array( + 'controller' => 'FakeControllerNotFound', + 'action' => 'myAction', + 'myvar' => 'value1', + ) + ); + + $this->setExpectedException('RuntimeException', 'Controller not found'); + + $dispatcher = new Router($this->container); + $dispatcher->dispatch(); + } + + public function testDispatcherWithActionNotFound() + { + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/kanboard/index.php', + 'REQUEST_URI' => '/kanboard/?controller=FakeController&action=myActionNotFound&myvar=value1', + 'QUERY_STRING' => 'controller=FakeController&action=myActionNotFound&myvar=value1', + 'REQUEST_METHOD' => 'GET' + ), + array( + 'controller' => 'FakeController', + 'action' => 'myActionNotFound', + 'myvar' => 'value1', + ) + ); + + $this->setExpectedException('RuntimeException', 'Action not implemented'); + + $dispatcher = new Router($this->container); + $dispatcher->dispatch(); + } + + public function testDispatcherWithNoUrlRewrite() + { + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/kanboard/index.php', + 'REQUEST_URI' => '/kanboard/?controller=FakeController&action=myAction&myvar=value1', + 'QUERY_STRING' => 'controller=FakeController&action=myAction&myvar=value1', + 'REQUEST_METHOD' => 'GET' + ), + array( + 'controller' => 'FakeController', + 'action' => 'myAction', + 'myvar' => 'value1', + ) + ); + + $dispatcher = new Router($this->container); + $this->assertInstanceOf('\Kanboard\Controller\FakeController', $dispatcher->dispatch()); + $this->assertEquals('FakeController', $dispatcher->getController()); + $this->assertEquals('myAction', $dispatcher->getAction()); + $this->assertEquals('', $dispatcher->getPlugin()); + $this->assertEquals('value1', $this->container['request']->getStringParam('myvar')); + } + + public function testDispatcherWithNoUrlRewriteAndPlugin() + { + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/kanboard/index.php', + 'REQUEST_URI' => '/kanboard/?controller=FakeController&action=myAction&myvar=value1&plugin=myplugin', + 'QUERY_STRING' => 'controller=FakeController&action=myAction&myvar=value1&plugin=myplugin', + 'REQUEST_METHOD' => 'GET' + ), + array( + 'controller' => 'FakeController', + 'action' => 'myAction', + 'myvar' => 'value1', + 'plugin' => 'myplugin', + ) + ); + + $dispatcher = new Router($this->container); + $this->assertInstanceOf('\Kanboard\Plugin\Myplugin\Controller\FakeController', $dispatcher->dispatch()); + $this->assertEquals('FakeController', $dispatcher->getController()); + $this->assertEquals('myAction', $dispatcher->getAction()); + $this->assertEquals('Myplugin', $dispatcher->getPlugin()); + $this->assertEquals('value1', $this->container['request']->getStringParam('myvar')); + } + + public function testDispatcherWithUrlRewrite() + { + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/kanboard/index.php', + 'REQUEST_URI' => '/kanboard/my/route/123?myvar=value1', + 'QUERY_STRING' => 'myvar=value1', + 'REQUEST_METHOD' => 'GET' + ), + array( + 'myvar' => 'value1', + ) + ); + + $this->container['route'] = new Route($this->container); + $this->container['route']->enable(); + $dispatcher = new Router($this->container); + + $this->container['route']->addRoute('/my/route/:param', 'FakeController', 'myAction'); + + $this->assertInstanceOf('\Kanboard\Controller\FakeController', $dispatcher->dispatch()); + $this->assertEquals('FakeController', $dispatcher->getController()); + $this->assertEquals('myAction', $dispatcher->getAction()); + $this->assertEquals('', $dispatcher->getPlugin()); + $this->assertEquals('value1', $this->container['request']->getStringParam('myvar')); + $this->assertEquals('123', $this->container['request']->getStringParam('param')); + } + + public function testDispatcherWithUrlRewriteWithPlugin() + { + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/kanboard/index.php', + 'REQUEST_URI' => '/kanboard/my/plugin/route/123?myvar=value1', + 'QUERY_STRING' => 'myvar=value1', + 'REQUEST_METHOD' => 'GET' + ), + array( + 'myvar' => 'value1', + ) + ); + + $this->container['route'] = new Route($this->container); + $this->container['route']->enable(); + $dispatcher = new Router($this->container); + + $this->container['route']->addRoute('/my/plugin/route/:param', 'fakeController', 'myAction', 'Myplugin'); + + $this->assertInstanceOf('\Kanboard\Plugin\Myplugin\Controller\FakeController', $dispatcher->dispatch()); + $this->assertEquals('FakeController', $dispatcher->getController()); + $this->assertEquals('myAction', $dispatcher->getAction()); + $this->assertEquals('Myplugin', $dispatcher->getPlugin()); + $this->assertEquals('value1', $this->container['request']->getStringParam('myvar')); + $this->assertEquals('123', $this->container['request']->getStringParam('param')); + } + } +} diff --git a/tests/units/Core/Ldap/ClientTest.php b/tests/units/Core/Ldap/ClientTest.php new file mode 100644 index 00000000..d149500e --- /dev/null +++ b/tests/units/Core/Ldap/ClientTest.php @@ -0,0 +1,220 @@ +<?php + +namespace Kanboard\Core\Ldap; + +require_once __DIR__.'/../../Base.php'; + +function ldap_connect($hostname, $port) +{ + return ClientTest::$functions->ldap_connect($hostname, $port); +} + +function ldap_set_option() +{ +} + +function ldap_bind($link_identifier, $bind_rdn = null, $bind_password = null) +{ + return ClientTest::$functions->ldap_bind($link_identifier, $bind_rdn, $bind_password); +} + +function ldap_start_tls($link_identifier) +{ + return ClientTest::$functions->ldap_start_tls($link_identifier); +} + +class ClientTest extends \Base +{ + public static $functions; + private $ldap; + + public function setUp() + { + parent::setup(); + + self::$functions = $this + ->getMockBuilder('stdClass') + ->setMethods(array( + 'ldap_connect', + 'ldap_set_option', + 'ldap_bind', + 'ldap_start_tls', + )) + ->getMock(); + } + + public function tearDown() + { + parent::tearDown(); + self::$functions = null; + } + + public function testGetLdapServerNotConfigured() + { + $this->setExpectedException('\LogicException'); + $ldap = new Client; + $ldap->getLdapServer(); + } + + public function testConnectSuccess() + { + self::$functions + ->expects($this->once()) + ->method('ldap_connect') + ->with( + $this->equalTo('my_ldap_server'), + $this->equalTo(389) + ) + ->will($this->returnValue('my_ldap_resource')); + + $ldap = new Client; + $ldap->open('my_ldap_server'); + $this->assertEquals('my_ldap_resource', $ldap->getConnection()); + } + + public function testConnectFailure() + { + self::$functions + ->expects($this->once()) + ->method('ldap_connect') + ->with( + $this->equalTo('my_ldap_server'), + $this->equalTo(389) + ) + ->will($this->returnValue(false)); + + $this->setExpectedException('\Kanboard\Core\Ldap\ClientException'); + + $ldap = new Client; + $ldap->open('my_ldap_server'); + $this->assertNotEquals('my_ldap_resource', $ldap->getConnection()); + } + + public function testConnectSuccessWithTLS() + { + self::$functions + ->expects($this->once()) + ->method('ldap_connect') + ->with( + $this->equalTo('my_ldap_server'), + $this->equalTo(389) + ) + ->will($this->returnValue('my_ldap_resource')); + + self::$functions + ->expects($this->once()) + ->method('ldap_start_tls') + ->with( + $this->equalTo('my_ldap_resource') + ) + ->will($this->returnValue(true)); + + $ldap = new Client; + $ldap->open('my_ldap_server', 389, true); + $this->assertEquals('my_ldap_resource', $ldap->getConnection()); + } + + public function testConnectFailureWithTLS() + { + self::$functions + ->expects($this->once()) + ->method('ldap_connect') + ->with( + $this->equalTo('my_ldap_server'), + $this->equalTo(389) + ) + ->will($this->returnValue('my_ldap_resource')); + + self::$functions + ->expects($this->once()) + ->method('ldap_start_tls') + ->with( + $this->equalTo('my_ldap_resource') + ) + ->will($this->returnValue(false)); + + $this->setExpectedException('\Kanboard\Core\Ldap\ClientException'); + + $ldap = new Client; + $ldap->open('my_ldap_server', 389, true); + $this->assertNotEquals('my_ldap_resource', $ldap->getConnection()); + } + + public function testAnonymousAuthenticationSuccess() + { + self::$functions + ->expects($this->once()) + ->method('ldap_bind') + ->will($this->returnValue(true)); + + $ldap = new Client; + $this->assertTrue($ldap->useAnonymousAuthentication()); + } + + public function testAnonymousAuthenticationFailure() + { + self::$functions + ->expects($this->once()) + ->method('ldap_bind') + ->will($this->returnValue(false)); + + $this->setExpectedException('\Kanboard\Core\Ldap\ClientException'); + + $ldap = new Client; + $ldap->useAnonymousAuthentication(); + } + + public function testUserAuthenticationSuccess() + { + self::$functions + ->expects($this->once()) + ->method('ldap_connect') + ->with( + $this->equalTo('my_ldap_server'), + $this->equalTo(389) + ) + ->will($this->returnValue('my_ldap_resource')); + + self::$functions + ->expects($this->once()) + ->method('ldap_bind') + ->with( + $this->equalTo('my_ldap_resource'), + $this->equalTo('my_ldap_user'), + $this->equalTo('my_ldap_password') + ) + ->will($this->returnValue(true)); + + $ldap = new Client; + $ldap->open('my_ldap_server'); + $this->assertTrue($ldap->authenticate('my_ldap_user', 'my_ldap_password')); + } + + public function testUserAuthenticationFailure() + { + self::$functions + ->expects($this->once()) + ->method('ldap_connect') + ->with( + $this->equalTo('my_ldap_server'), + $this->equalTo(389) + ) + ->will($this->returnValue('my_ldap_resource')); + + self::$functions + ->expects($this->once()) + ->method('ldap_bind') + ->with( + $this->equalTo('my_ldap_resource'), + $this->equalTo('my_ldap_user'), + $this->equalTo('my_ldap_password') + ) + ->will($this->returnValue(false)); + + $this->setExpectedException('\Kanboard\Core\Ldap\ClientException'); + + $ldap = new Client; + $ldap->open('my_ldap_server'); + $ldap->authenticate('my_ldap_user', 'my_ldap_password'); + } +} diff --git a/tests/units/Core/Ldap/EntriesTest.php b/tests/units/Core/Ldap/EntriesTest.php new file mode 100644 index 00000000..65025b6e --- /dev/null +++ b/tests/units/Core/Ldap/EntriesTest.php @@ -0,0 +1,55 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Ldap\Entries; + +class EntriesTest extends Base +{ + private $entries = array( + 'count' => 2, + 0 => array( + 'cn' => array( + 'count' => 1, + 0 => 'Kanboard Other Group', + ), + 0 => 'cn', + 'count' => 1, + 'dn' => 'CN=Kanboard Other Group,CN=Users,DC=kanboard,DC=local', + ), + 1 => array( + 'cn' => array( + 'count' => 1, + 0 => 'Kanboard Users', + ), + 0 => 'cn', + 'count' => 1, + 'dn' => 'CN=Kanboard Users,CN=Users,DC=kanboard,DC=local', + ), + ); + + public function testGetAll() + { + $entries = new Entries(array()); + $this->assertEmpty($entries->getAll()); + + $entries = new Entries($this->entries); + $result = $entries->getAll(); + $this->assertCount(2, $result); + $this->assertInstanceOf('Kanboard\Core\Ldap\Entry', $result[0]); + $this->assertEquals('CN=Kanboard Users,CN=Users,DC=kanboard,DC=local', $result[1]->getDn()); + $this->assertEquals('Kanboard Users', $result[1]->getFirstValue('cn')); + } + + public function testGetFirst() + { + $entries = new Entries(array()); + $this->assertEquals('', $entries->getFirstEntry()->getDn()); + + $entries = new Entries($this->entries); + $result = $entries->getFirstEntry(); + $this->assertInstanceOf('Kanboard\Core\Ldap\Entry', $result); + $this->assertEquals('CN=Kanboard Other Group,CN=Users,DC=kanboard,DC=local', $result->getDn()); + $this->assertEquals('Kanboard Other Group', $result->getFirstValue('cn')); + } +} diff --git a/tests/units/Core/Ldap/EntryTest.php b/tests/units/Core/Ldap/EntryTest.php new file mode 100644 index 00000000..45585e77 --- /dev/null +++ b/tests/units/Core/Ldap/EntryTest.php @@ -0,0 +1,71 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Ldap\Entry; + +class EntryTest extends Base +{ + private $entry = array( + 'count' => 2, + 'dn' => 'uid=my_user,ou=People,dc=kanboard,dc=local', + 'displayname' => array( + 'count' => 1, + 0 => 'My LDAP user', + ), + 'broken' => array( + ), + 'mail' => array( + 'count' => 2, + 0 => 'user1@localhost', + 1 => 'user2@localhost', + ), + 'samaccountname' => array( + 'count' => 1, + 0 => 'my_ldap_user', + ), + 0 => 'displayname', + 1 => 'mail', + 2 => 'samaccountname', + ); + + public function testGetAll() + { + $expected = array( + 'user1@localhost', + 'user2@localhost', + ); + + $entry = new Entry($this->entry); + $this->assertEquals($expected, $entry->getAll('mail')); + $this->assertEmpty($entry->getAll('not found')); + $this->assertEmpty($entry->getAll('broken')); + } + + public function testGetFirst() + { + $entry = new Entry($this->entry); + $this->assertEquals('user1@localhost', $entry->getFirstValue('mail')); + $this->assertEquals('', $entry->getFirstValue('not found')); + $this->assertEquals('default', $entry->getFirstValue('not found', 'default')); + $this->assertEquals('default', $entry->getFirstValue('broken', 'default')); + } + + public function testGetDn() + { + $entry = new Entry($this->entry); + $this->assertEquals('uid=my_user,ou=People,dc=kanboard,dc=local', $entry->getDn()); + + $entry = new Entry(array()); + $this->assertEquals('', $entry->getDn()); + } + + public function testHasValue() + { + $entry = new Entry($this->entry); + $this->assertTrue($entry->hasValue('mail', 'user2@localhost')); + $this->assertFalse($entry->hasValue('mail', 'user3@localhost')); + $this->assertTrue($entry->hasValue('displayname', 'My LDAP user')); + $this->assertFalse($entry->hasValue('displayname', 'Something else')); + } +} diff --git a/tests/units/Core/Ldap/LdapGroupTest.php b/tests/units/Core/Ldap/LdapGroupTest.php new file mode 100644 index 00000000..3f538249 --- /dev/null +++ b/tests/units/Core/Ldap/LdapGroupTest.php @@ -0,0 +1,160 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Ldap\Group; +use Kanboard\Core\Ldap\Entries; +use Kanboard\Core\Security\Role; + +class LdapGroupTest extends Base +{ + private $query; + private $client; + private $group; + + public function setUp() + { + parent::setUp(); + + $this->client = $this + ->getMockBuilder('\Kanboard\Core\Ldap\Client') + ->setMethods(array( + 'getConnection', + )) + ->getMock(); + + $this->query = $this + ->getMockBuilder('\Kanboard\Core\Ldap\Query') + ->setConstructorArgs(array($this->client)) + ->setMethods(array( + 'execute', + 'hasResult', + 'getEntries', + )) + ->getMock(); + + $this->group = $this + ->getMockBuilder('\Kanboard\Core\Ldap\Group') + ->setConstructorArgs(array($this->query)) + ->setMethods(array( + 'getAttributeName', + 'getBasDn', + )) + ->getMock(); + } + + public function testGetGroups() + { + $entries = new Entries(array( + 'count' => 2, + 0 => array( + 'cn' => array( + 'count' => 1, + 0 => 'Kanboard Other Group', + ), + 0 => 'cn', + 'count' => 1, + 'dn' => 'CN=Kanboard Other Group,CN=Users,DC=kanboard,DC=local', + ), + 1 => array( + 'cn' => array( + 'count' => 1, + 0 => 'Kanboard Users', + ), + 0 => 'cn', + 'count' => 1, + 'dn' => 'CN=Kanboard Users,CN=Users,DC=kanboard,DC=local', + ), + )); + + $this->client + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + $this->query + ->expects($this->once()) + ->method('execute') + ->with( + $this->equalTo('CN=Users,DC=kanboard,DC=local'), + $this->equalTo('(&(objectClass=group)(sAMAccountName=Kanboard*))') + ); + + $this->query + ->expects($this->once()) + ->method('hasResult') + ->will($this->returnValue(true)); + + $this->query + ->expects($this->once()) + ->method('getEntries') + ->will($this->returnValue($entries)); + + $this->group + ->expects($this->any()) + ->method('getAttributeName') + ->will($this->returnValue('cn')); + + $this->group + ->expects($this->any()) + ->method('getBasDn') + ->will($this->returnValue('CN=Users,DC=kanboard,DC=local')); + + $groups = $this->group->find('(&(objectClass=group)(sAMAccountName=Kanboard*))'); + $this->assertCount(2, $groups); + $this->assertInstanceOf('Kanboard\Group\LdapGroupProvider', $groups[0]); + $this->assertInstanceOf('Kanboard\Group\LdapGroupProvider', $groups[1]); + $this->assertEquals('Kanboard Other Group', $groups[0]->getName()); + $this->assertEquals('Kanboard Users', $groups[1]->getName()); + $this->assertEquals('CN=Kanboard Other Group,CN=Users,DC=kanboard,DC=local', $groups[0]->getExternalId()); + $this->assertEquals('CN=Kanboard Users,CN=Users,DC=kanboard,DC=local', $groups[1]->getExternalId()); + } + + public function testGetGroupsWithNoResult() + { + $entries = new Entries(array()); + + $this->client + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + $this->query + ->expects($this->once()) + ->method('execute') + ->with( + $this->equalTo('CN=Users,DC=kanboard,DC=local'), + $this->equalTo('(&(objectClass=group)(sAMAccountName=Kanboard*))') + ); + + $this->query + ->expects($this->once()) + ->method('hasResult') + ->will($this->returnValue(false)); + + $this->query + ->expects($this->never()) + ->method('getEntries'); + + $this->group + ->expects($this->any()) + ->method('getAttributeName') + ->will($this->returnValue('cn')); + + $this->group + ->expects($this->any()) + ->method('getBasDn') + ->will($this->returnValue('CN=Users,DC=kanboard,DC=local')); + + $groups = $this->group->find('(&(objectClass=group)(sAMAccountName=Kanboard*))'); + $this->assertCount(0, $groups); + } + + public function testGetBaseDnNotConfigured() + { + $this->setExpectedException('\LogicException'); + + $group = new Group($this->query); + $group->getBasDn(); + } +} diff --git a/tests/units/Core/Ldap/LdapUserTest.php b/tests/units/Core/Ldap/LdapUserTest.php new file mode 100644 index 00000000..2b3db1e5 --- /dev/null +++ b/tests/units/Core/Ldap/LdapUserTest.php @@ -0,0 +1,379 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Ldap\User; +use Kanboard\Core\Ldap\Entries; +use Kanboard\Core\Security\Role; + +class LdapUserTest extends Base +{ + private $query; + private $client; + private $user; + + public function setUp() + { + parent::setUp(); + + $this->client = $this + ->getMockBuilder('\Kanboard\Core\Ldap\Client') + ->setMethods(array( + 'getConnection', + )) + ->getMock(); + + $this->query = $this + ->getMockBuilder('\Kanboard\Core\Ldap\Query') + ->setConstructorArgs(array($this->client)) + ->setMethods(array( + 'execute', + 'hasResult', + 'getEntries', + )) + ->getMock(); + + $this->user = $this + ->getMockBuilder('\Kanboard\Core\Ldap\User') + ->setConstructorArgs(array($this->query)) + ->setMethods(array( + 'getAttributeUsername', + 'getAttributeEmail', + 'getAttributeName', + 'getAttributeGroup', + 'getGroupAdminDn', + 'getGroupManagerDn', + 'getBasDn', + )) + ->getMock(); + } + + public function testGetUser() + { + $entries = new Entries(array( + 'count' => 1, + 0 => array( + 'count' => 2, + 'dn' => 'uid=my_ldap_user,ou=People,dc=kanboard,dc=local', + 'displayname' => array( + 'count' => 1, + 0 => 'My LDAP user', + ), + 'mail' => array( + 'count' => 2, + 0 => 'user1@localhost', + 1 => 'user2@localhost', + ), + 'samaccountname' => array( + 'count' => 1, + 0 => 'my_ldap_user', + ), + 0 => 'displayname', + 1 => 'mail', + 2 => 'samaccountname', + ) + )); + + $this->client + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + $this->query + ->expects($this->once()) + ->method('execute') + ->with( + $this->equalTo('ou=People,dc=kanboard,dc=local'), + $this->equalTo('(uid=my_ldap_user)') + ); + + $this->query + ->expects($this->once()) + ->method('hasResult') + ->will($this->returnValue(true)); + + $this->query + ->expects($this->once()) + ->method('getEntries') + ->will($this->returnValue($entries)); + + $this->user + ->expects($this->any()) + ->method('getAttributeUsername') + ->will($this->returnValue('samaccountname')); + + $this->user + ->expects($this->any()) + ->method('getAttributeName') + ->will($this->returnValue('displayname')); + + $this->user + ->expects($this->any()) + ->method('getAttributeEmail') + ->will($this->returnValue('mail')); + + $this->user + ->expects($this->any()) + ->method('getBasDn') + ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); + + $user = $this->user->find('(uid=my_ldap_user)'); + $this->assertInstanceOf('Kanboard\User\LdapUserProvider', $user); + $this->assertEquals('uid=my_ldap_user,ou=People,dc=kanboard,dc=local', $user->getDn()); + $this->assertEquals('my_ldap_user', $user->getUsername()); + $this->assertEquals('My LDAP user', $user->getName()); + $this->assertEquals('user1@localhost', $user->getEmail()); + $this->assertEquals(Role::APP_USER, $user->getRole()); + $this->assertEquals(array(), $user->getExternalGroupIds()); + $this->assertEquals(array('is_ldap_user' => 1), $user->getExtraAttributes()); + } + + public function testGetUserWithAdminRole() + { + $entries = new Entries(array( + 'count' => 1, + 0 => array( + 'count' => 2, + 'dn' => 'uid=my_ldap_user,ou=People,dc=kanboard,dc=local', + 'displayname' => array( + 'count' => 1, + 0 => 'My LDAP user', + ), + 'mail' => array( + 'count' => 2, + 0 => 'user1@localhost', + 1 => 'user2@localhost', + ), + 'samaccountname' => array( + 'count' => 1, + 0 => 'my_ldap_user', + ), + 'memberof' => array( + 'count' => 1, + 0 => 'CN=Kanboard-Admins,CN=Users,DC=kanboard,DC=local', + ), + 0 => 'displayname', + 1 => 'mail', + 2 => 'samaccountname', + 3 => 'memberof', + ) + )); + + $this->client + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + $this->query + ->expects($this->once()) + ->method('execute') + ->with( + $this->equalTo('ou=People,dc=kanboard,dc=local'), + $this->equalTo('(uid=my_ldap_user)') + ); + + $this->query + ->expects($this->once()) + ->method('hasResult') + ->will($this->returnValue(true)); + + $this->query + ->expects($this->once()) + ->method('getEntries') + ->will($this->returnValue($entries)); + + $this->user + ->expects($this->any()) + ->method('getAttributeUsername') + ->will($this->returnValue('samaccountname')); + + $this->user + ->expects($this->any()) + ->method('getAttributeName') + ->will($this->returnValue('displayname')); + + $this->user + ->expects($this->any()) + ->method('getAttributeEmail') + ->will($this->returnValue('mail')); + + $this->user + ->expects($this->any()) + ->method('getAttributeGroup') + ->will($this->returnValue('memberof')); + + $this->user + ->expects($this->any()) + ->method('getGroupAdminDn') + ->will($this->returnValue('CN=Kanboard-Admins,CN=Users,DC=kanboard,DC=local')); + + $this->user + ->expects($this->any()) + ->method('getBasDn') + ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); + + $user = $this->user->find('(uid=my_ldap_user)'); + $this->assertInstanceOf('Kanboard\User\LdapUserProvider', $user); + $this->assertEquals('uid=my_ldap_user,ou=People,dc=kanboard,dc=local', $user->getDn()); + $this->assertEquals('my_ldap_user', $user->getUsername()); + $this->assertEquals('My LDAP user', $user->getName()); + $this->assertEquals('user1@localhost', $user->getEmail()); + $this->assertEquals(Role::APP_ADMIN, $user->getRole()); + $this->assertEquals(array('CN=Kanboard-Admins,CN=Users,DC=kanboard,DC=local'), $user->getExternalGroupIds()); + $this->assertEquals(array('is_ldap_user' => 1), $user->getExtraAttributes()); + } + + public function testGetUserWithManagerRole() + { + $entries = new Entries(array( + 'count' => 1, + 0 => array( + 'count' => 2, + 'dn' => 'uid=my_ldap_user,ou=People,dc=kanboard,dc=local', + 'displayname' => array( + 'count' => 1, + 0 => 'My LDAP user', + ), + 'mail' => array( + 'count' => 2, + 0 => 'user1@localhost', + 1 => 'user2@localhost', + ), + 'samaccountname' => array( + 'count' => 1, + 0 => 'my_ldap_user', + ), + 'memberof' => array( + 'count' => 2, + 0 => 'CN=Kanboard-Users,CN=Users,DC=kanboard,DC=local', + 1 => 'CN=Kanboard-Managers,CN=Users,DC=kanboard,DC=local', + ), + 0 => 'displayname', + 1 => 'mail', + 2 => 'samaccountname', + 3 => 'memberof', + ) + )); + + $this->client + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + $this->query + ->expects($this->once()) + ->method('execute') + ->with( + $this->equalTo('ou=People,dc=kanboard,dc=local'), + $this->equalTo('(uid=my_ldap_user)') + ); + + $this->query + ->expects($this->once()) + ->method('hasResult') + ->will($this->returnValue(true)); + + $this->query + ->expects($this->once()) + ->method('getEntries') + ->will($this->returnValue($entries)); + + $this->user + ->expects($this->any()) + ->method('getAttributeUsername') + ->will($this->returnValue('samaccountname')); + + $this->user + ->expects($this->any()) + ->method('getAttributeName') + ->will($this->returnValue('displayname')); + + $this->user + ->expects($this->any()) + ->method('getAttributeEmail') + ->will($this->returnValue('mail')); + + $this->user + ->expects($this->any()) + ->method('getAttributeGroup') + ->will($this->returnValue('memberof')); + + $this->user + ->expects($this->any()) + ->method('getGroupManagerDn') + ->will($this->returnValue('CN=Kanboard-Managers,CN=Users,DC=kanboard,DC=local')); + + $this->user + ->expects($this->any()) + ->method('getBasDn') + ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); + + $user = $this->user->find('(uid=my_ldap_user)'); + $this->assertInstanceOf('Kanboard\User\LdapUserProvider', $user); + $this->assertEquals('uid=my_ldap_user,ou=People,dc=kanboard,dc=local', $user->getDn()); + $this->assertEquals('my_ldap_user', $user->getUsername()); + $this->assertEquals('My LDAP user', $user->getName()); + $this->assertEquals('user1@localhost', $user->getEmail()); + $this->assertEquals(Role::APP_MANAGER, $user->getRole()); + $this->assertEquals(array('CN=Kanboard-Users,CN=Users,DC=kanboard,DC=local', 'CN=Kanboard-Managers,CN=Users,DC=kanboard,DC=local'), $user->getExternalGroupIds()); + $this->assertEquals(array('is_ldap_user' => 1), $user->getExtraAttributes()); + } + + public function testGetUserNotFound() + { + $entries = new Entries(array()); + + $this->client + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + $this->query + ->expects($this->once()) + ->method('execute') + ->with( + $this->equalTo('ou=People,dc=kanboard,dc=local'), + $this->equalTo('(uid=my_ldap_user)') + ); + + $this->query + ->expects($this->once()) + ->method('hasResult') + ->will($this->returnValue(false)); + + $this->query + ->expects($this->never()) + ->method('getEntries'); + + $this->user + ->expects($this->any()) + ->method('getAttributeUsername') + ->will($this->returnValue('samaccountname')); + + $this->user + ->expects($this->any()) + ->method('getAttributeName') + ->will($this->returnValue('displayname')); + + $this->user + ->expects($this->any()) + ->method('getAttributeEmail') + ->will($this->returnValue('mail')); + + $this->user + ->expects($this->any()) + ->method('getBasDn') + ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); + + $user = $this->user->find('(uid=my_ldap_user)'); + $this->assertEquals(null, $user); + } + + public function testGetBaseDnNotConfigured() + { + $this->setExpectedException('\LogicException'); + + $user = new User($this->query); + $user->getBasDn(); + } +} diff --git a/tests/units/Core/Ldap/QueryTest.php b/tests/units/Core/Ldap/QueryTest.php new file mode 100644 index 00000000..b3987df0 --- /dev/null +++ b/tests/units/Core/Ldap/QueryTest.php @@ -0,0 +1,160 @@ +<?php + +namespace Kanboard\Core\Ldap; + +require_once __DIR__.'/../../Base.php'; + +function ldap_search($link_identifier, $base_dn, $filter, array $attributes) +{ + return QueryTest::$functions->ldap_search($link_identifier, $base_dn, $filter, $attributes); +} + +function ldap_get_entries($link_identifier, $result_identifier) +{ + return QueryTest::$functions->ldap_get_entries($link_identifier, $result_identifier); +} + +class QueryTest extends \Base +{ + public static $functions; + private $client; + + public function setUp() + { + parent::setup(); + + self::$functions = $this + ->getMockBuilder('stdClass') + ->setMethods(array( + 'ldap_search', + 'ldap_get_entries', + )) + ->getMock(); + + $this->client = $this + ->getMockBuilder('\Kanboard\Core\Ldap\Client') + ->setMethods(array( + 'getConnection', + )) + ->getMock(); + } + + public function tearDown() + { + parent::tearDown(); + self::$functions = null; + } + + public function testExecuteQuerySuccessfully() + { + $entries = array( + 'count' => 1, + 0 => array( + 'count' => 2, + 'dn' => 'uid=my_user,ou=People,dc=kanboard,dc=local', + 'displayname' => array( + 'count' => 1, + 0 => 'My user', + ), + 'mail' => array( + 'count' => 2, + 0 => 'user1@localhost', + 1 => 'user2@localhost', + ), + 0 => 'displayname', + 1 => 'mail', + ) + ); + + $this->client + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + self::$functions + ->expects($this->once()) + ->method('ldap_search') + ->with( + $this->equalTo('my_ldap_resource'), + $this->equalTo('ou=People,dc=kanboard,dc=local'), + $this->equalTo('uid=my_user'), + $this->equalTo(array('displayname')) + ) + ->will($this->returnValue('search_resource')); + + self::$functions + ->expects($this->once()) + ->method('ldap_get_entries') + ->with( + $this->equalTo('my_ldap_resource'), + $this->equalTo('search_resource') + ) + ->will($this->returnValue($entries)); + + $query = new Query($this->client); + $query->execute('ou=People,dc=kanboard,dc=local', 'uid=my_user', array('displayname')); + $this->assertTrue($query->hasResult()); + + $this->assertEquals('My user', $query->getEntries()->getFirstEntry()->getFirstValue('displayname')); + $this->assertEquals('user1@localhost', $query->getEntries()->getFirstEntry()->getFirstValue('mail')); + $this->assertEquals('', $query->getEntries()->getFirstEntry()->getFirstValue('not_found')); + + $this->assertEquals('uid=my_user,ou=People,dc=kanboard,dc=local', $query->getEntries()->getFirstEntry()->getDn()); + $this->assertEquals('', $query->getEntries()->getFirstEntry()->getFirstValue('missing')); + } + + public function testExecuteQueryNotFound() + { + $this->client + ->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + self::$functions + ->expects($this->once()) + ->method('ldap_search') + ->with( + $this->equalTo('my_ldap_resource'), + $this->equalTo('ou=People,dc=kanboard,dc=local'), + $this->equalTo('uid=my_user'), + $this->equalTo(array('displayname')) + ) + ->will($this->returnValue('search_resource')); + + self::$functions + ->expects($this->once()) + ->method('ldap_get_entries') + ->with( + $this->equalTo('my_ldap_resource'), + $this->equalTo('search_resource') + ) + ->will($this->returnValue(array())); + + $query = new Query($this->client); + $query->execute('ou=People,dc=kanboard,dc=local', 'uid=my_user', array('displayname')); + $this->assertFalse($query->hasResult()); + } + + public function testExecuteQueryFailed() + { + $this->client + ->expects($this->once()) + ->method('getConnection') + ->will($this->returnValue('my_ldap_resource')); + + self::$functions + ->expects($this->once()) + ->method('ldap_search') + ->with( + $this->equalTo('my_ldap_resource'), + $this->equalTo('ou=People,dc=kanboard,dc=local'), + $this->equalTo('uid=my_user'), + $this->equalTo(array('displayname')) + ) + ->will($this->returnValue(false)); + + $query = new Query($this->client); + $query->execute('ou=People,dc=kanboard,dc=local', 'uid=my_user', array('displayname')); + $this->assertFalse($query->hasResult()); + } +} diff --git a/tests/units/Core/LexerTest.php b/tests/units/Core/LexerTest.php index 9e14ff6b..55370aab 100644 --- a/tests/units/Core/LexerTest.php +++ b/tests/units/Core/LexerTest.php @@ -116,6 +116,31 @@ class LexerTest extends Base ); } + public function testLinkQuery() + { + $lexer = new Lexer; + + $this->assertEquals( + array(array('match' => 'link:', 'token' => 'T_LINK'), array('match' => 'is a milestone of', 'token' => 'T_STRING')), + $lexer->tokenize('link:"is a milestone of"') + ); + + $this->assertEquals( + array('T_LINK' => array('is a milestone of')), + $lexer->map($lexer->tokenize('link:"is a milestone of"')) + ); + + $this->assertEquals( + array('T_LINK' => array('is a milestone of', 'fixes')), + $lexer->map($lexer->tokenize('link:"is a milestone of" link:fixes')) + ); + + $this->assertEquals( + array(), + $lexer->map($lexer->tokenize('link: ')) + ); + } + public function testColumnQuery() { $lexer = new Lexer; diff --git a/tests/units/Core/RouterTest.php b/tests/units/Core/RouterTest.php deleted file mode 100644 index 753e1204..00000000 --- a/tests/units/Core/RouterTest.php +++ /dev/null @@ -1,81 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Core\Router; - -class RouterTest extends Base -{ - public function testSanitize() - { - $r = new Router($this->container); - - $this->assertEquals('PloP', $r->sanitize('PloP', 'default')); - $this->assertEquals('default', $r->sanitize('', 'default')); - $this->assertEquals('default', $r->sanitize('123-AB', 'default')); - $this->assertEquals('default', $r->sanitize('R&D', 'default')); - $this->assertEquals('Test123', $r->sanitize('Test123', 'default')); - $this->assertEquals('Test_123', $r->sanitize('Test_123', 'default')); - $this->assertEquals('userImport', $r->sanitize('userImport', 'default')); - } - - public function testPath() - { - $r = new Router($this->container); - - $this->assertEquals('a/b/c', $r->getPath('/a/b/c')); - $this->assertEquals('a/b/something', $r->getPath('/a/b/something?test=a', 'test=a')); - - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['PHP_SELF'] = '/a/index.php'; - - $this->assertEquals('b/c', $r->getPath('/a/b/c')); - $this->assertEquals('b/c', $r->getPath('/a/b/c?e=f', 'e=f')); - } - - public function testFindRouteWithEmptyTable() - { - $r = new Router($this->container); - $this->assertEquals(array('app', 'index'), $r->findRoute('')); - $this->assertEquals(array('app', 'index'), $r->findRoute('/')); - } - - public function testFindRouteWithoutPlaceholders() - { - $r = new Router($this->container); - $r->addRoute('a/b', 'controller', 'action'); - $this->assertEquals(array('app', 'index'), $r->findRoute('a/b/c')); - $this->assertEquals(array('controller', 'action'), $r->findRoute('a/b')); - } - - public function testFindRouteWithPlaceholders() - { - $r = new Router($this->container); - $r->addRoute('a/:myvar1/b/:myvar2', 'controller', 'action'); - $this->assertEquals(array('app', 'index'), $r->findRoute('a/123/b')); - $this->assertEquals(array('controller', 'action'), $r->findRoute('a/456/b/789')); - $this->assertEquals(array('myvar1' => 456, 'myvar2' => 789), $_GET); - } - - public function testFindMultipleRoutes() - { - $r = new Router($this->container); - $r->addRoute('a/b', 'controller1', 'action1'); - $r->addRoute('a/b', 'duplicate', 'duplicate'); - $r->addRoute('a', 'controller2', 'action2'); - $this->assertEquals(array('controller1', 'action1'), $r->findRoute('a/b')); - $this->assertEquals(array('controller2', 'action2'), $r->findRoute('a')); - } - - public function testFindUrl() - { - $r = new Router($this->container); - $r->addRoute('a/b', 'controller1', 'action1'); - $r->addRoute('a/:myvar1/b/:myvar2', 'controller2', 'action2', array('myvar1', 'myvar2')); - - $this->assertEquals('a/1/b/2', $r->findUrl('controller2', 'action2', array('myvar1' => 1, 'myvar2' => 2))); - $this->assertEquals('', $r->findUrl('controller2', 'action2', array('myvar1' => 1))); - $this->assertEquals('a/b', $r->findUrl('controller1', 'action1')); - $this->assertEquals('', $r->findUrl('controller1', 'action2')); - } -} diff --git a/tests/units/Core/Security/AccessMapTest.php b/tests/units/Core/Security/AccessMapTest.php new file mode 100644 index 00000000..ae8044c9 --- /dev/null +++ b/tests/units/Core/Security/AccessMapTest.php @@ -0,0 +1,53 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Security\AccessMap; + +class AccessMapTest extends Base +{ + public function testRoleHierarchy() + { + $acl = new AccessMap; + $acl->setRoleHierarchy('admin', array('manager', 'user')); + $acl->setRoleHierarchy('manager', array('user')); + + $this->assertEquals(array('admin'), $acl->getRoleHierarchy('admin')); + $this->assertEquals(array('manager', 'admin'), $acl->getRoleHierarchy('manager')); + $this->assertEquals(array('user', 'admin', 'manager'), $acl->getRoleHierarchy('user')); + } + + public function testGetHighestRole() + { + $acl = new AccessMap; + $acl->setRoleHierarchy('manager', array('member', 'viewer')); + $acl->setRoleHierarchy('member', array('viewer')); + + $this->assertEquals('manager', $acl->getHighestRole(array('viewer', 'manager', 'member'))); + $this->assertEquals('manager', $acl->getHighestRole(array('viewer', 'manager'))); + $this->assertEquals('manager', $acl->getHighestRole(array('manager', 'member'))); + $this->assertEquals('member', $acl->getHighestRole(array('viewer', 'member'))); + $this->assertEquals('member', $acl->getHighestRole(array('member'))); + $this->assertEquals('viewer', $acl->getHighestRole(array('viewer'))); + } + + public function testAddRulesAndGetRoles() + { + $acl = new AccessMap; + $acl->setDefaultRole('role3'); + $acl->setRoleHierarchy('role2', array('role1')); + + $acl->add('MyController', 'myAction1', 'role2'); + $acl->add('MyController', 'myAction2', 'role1'); + $acl->add('MyAdminController', '*', 'role2'); + $acl->add('SomethingElse', array('actionA', 'actionB'), 'role2'); + + $this->assertEquals(array('role2'), $acl->getRoles('mycontroller', 'MyAction1')); + $this->assertEquals(array('role1', 'role2'), $acl->getRoles('mycontroller', 'MyAction2')); + $this->assertEquals(array('role2'), $acl->getRoles('Myadmincontroller', 'MyAction')); + $this->assertEquals(array('role3'), $acl->getRoles('AnotherController', 'ActionNotFound')); + $this->assertEquals(array('role2'), $acl->getRoles('somethingelse', 'actiona')); + $this->assertEquals(array('role2'), $acl->getRoles('somethingelse', 'actionb')); + $this->assertEquals(array('role3'), $acl->getRoles('somethingelse', 'actionc')); + } +} diff --git a/tests/units/Core/Security/AuthenticationManagerTest.php b/tests/units/Core/Security/AuthenticationManagerTest.php new file mode 100644 index 00000000..c2369626 --- /dev/null +++ b/tests/units/Core/Security/AuthenticationManagerTest.php @@ -0,0 +1,150 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Http\Request; +use Kanboard\Core\Security\AuthenticationManager; +use Kanboard\Auth\DatabaseAuth; +use Kanboard\Auth\TotpAuth; +use Kanboard\Auth\ReverseProxyAuth; + +class AuthenticationManagerTest extends Base +{ + public function testRegister() + { + $authManager = new AuthenticationManager($this->container); + $authManager->register(new DatabaseAuth($this->container)); + $provider = $authManager->getProvider('Database'); + + $this->assertInstanceOf('Kanboard\Core\Security\AuthenticationProviderInterface', $provider); + } + + public function testGetProviderNotFound() + { + $authManager = new AuthenticationManager($this->container); + $this->setExpectedException('LogicException'); + $authManager->getProvider('Dababase'); + } + + public function testGetPostProviderNotFound() + { + $authManager = new AuthenticationManager($this->container); + $this->setExpectedException('LogicException'); + $authManager->getPostAuthenticationProvider(); + } + + public function testGetPostProvider() + { + $authManager = new AuthenticationManager($this->container); + $authManager->register(new TotpAuth($this->container)); + $provider = $authManager->getPostAuthenticationProvider(); + + $this->assertInstanceOf('Kanboard\Core\Security\PostAuthenticationProviderInterface', $provider); + } + + public function testCheckSessionWhenNobodyIsLogged() + { + $authManager = new AuthenticationManager($this->container); + $authManager->register(new DatabaseAuth($this->container)); + + $this->assertFalse($this->container['userSession']->isLogged()); + $this->assertTrue($authManager->checkCurrentSession()); + } + + public function testCheckSessionWhenSomeoneIsLogged() + { + $authManager = new AuthenticationManager($this->container); + $authManager->register(new DatabaseAuth($this->container)); + + $this->container['sessionStorage']->user = array('id' => 1); + + $this->assertTrue($this->container['userSession']->isLogged()); + $this->assertTrue($authManager->checkCurrentSession()); + } + + public function testCheckSessionWhenNotValid() + { + $authManager = new AuthenticationManager($this->container); + $authManager->register(new DatabaseAuth($this->container)); + + $this->container['sessionStorage']->user = array('id' => 2); + + $this->assertTrue($this->container['userSession']->isLogged()); + $this->assertFalse($authManager->checkCurrentSession()); + $this->assertFalse($this->container['userSession']->isLogged()); + } + + public function testPreAuthenticationSuccessful() + { + $this->container['request'] = new Request($this->container, array(REVERSE_PROXY_USER_HEADER => 'admin')); + $this->container['dispatcher']->addListener(AuthenticationManager::EVENT_SUCCESS, array($this, 'onSuccess')); + $this->container['dispatcher']->addListener(AuthenticationManager::EVENT_FAILURE, array($this, 'onFailure')); + + $authManager = new AuthenticationManager($this->container); + $authManager->register(new ReverseProxyAuth($this->container)); + + $this->assertTrue($authManager->preAuthentication()); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(AuthenticationManager::EVENT_SUCCESS.'.AuthenticationManagerTest::onSuccess', $called); + $this->assertArrayNotHasKey(AuthenticationManager::EVENT_FAILURE.'.AuthenticationManagerTest::onFailure', $called); + } + + public function testPreAuthenticationFailed() + { + $this->container['request'] = new Request($this->container, array(REVERSE_PROXY_USER_HEADER => '')); + $this->container['dispatcher']->addListener(AuthenticationManager::EVENT_SUCCESS, array($this, 'onSuccess')); + $this->container['dispatcher']->addListener(AuthenticationManager::EVENT_FAILURE, array($this, 'onFailure')); + + $authManager = new AuthenticationManager($this->container); + $authManager->register(new ReverseProxyAuth($this->container)); + + $this->assertFalse($authManager->preAuthentication()); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayNotHasKey(AuthenticationManager::EVENT_SUCCESS.'.AuthenticationManagerTest::onSuccess', $called); + $this->assertArrayNotHasKey(AuthenticationManager::EVENT_FAILURE.'.AuthenticationManagerTest::onFailure', $called); + } + + public function testPasswordAuthenticationSuccessful() + { + $this->container['dispatcher']->addListener(AuthenticationManager::EVENT_SUCCESS, array($this, 'onSuccess')); + $this->container['dispatcher']->addListener(AuthenticationManager::EVENT_FAILURE, array($this, 'onFailure')); + + $authManager = new AuthenticationManager($this->container); + $authManager->register(new DatabaseAuth($this->container)); + + $this->assertTrue($authManager->passwordAuthentication('admin', 'admin')); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(AuthenticationManager::EVENT_SUCCESS.'.AuthenticationManagerTest::onSuccess', $called); + $this->assertArrayNotHasKey(AuthenticationManager::EVENT_FAILURE.'.AuthenticationManagerTest::onFailure', $called); + } + + public function testPasswordAuthenticationFailed() + { + $this->container['dispatcher']->addListener(AuthenticationManager::EVENT_SUCCESS, array($this, 'onSuccess')); + $this->container['dispatcher']->addListener(AuthenticationManager::EVENT_FAILURE, array($this, 'onFailure')); + + $authManager = new AuthenticationManager($this->container); + $authManager->register(new DatabaseAuth($this->container)); + + $this->assertFalse($authManager->passwordAuthentication('admin', 'wrong password')); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayNotHasKey(AuthenticationManager::EVENT_SUCCESS.'.AuthenticationManagerTest::onSuccess', $called); + $this->assertArrayHasKey(AuthenticationManager::EVENT_FAILURE.'.AuthenticationManagerTest::onFailure', $called); + } + + public function onSuccess($event) + { + $this->assertInstanceOf('Kanboard\Event\AuthSuccessEvent', $event); + $this->assertTrue(in_array($event->getAuthType(), array('Database', 'ReverseProxy'))); + } + + public function onFailure($event) + { + $this->assertInstanceOf('Kanboard\Event\AuthFailureEvent', $event); + $this->assertEquals('admin', $event->getUsername()); + } +} diff --git a/tests/units/Core/Security/AuthorizationTest.php b/tests/units/Core/Security/AuthorizationTest.php new file mode 100644 index 00000000..70561ad8 --- /dev/null +++ b/tests/units/Core/Security/AuthorizationTest.php @@ -0,0 +1,39 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Security\Role; +use Kanboard\Core\Security\AccessMap; +use Kanboard\Core\Security\Authorization; + +class AuthorizationTest extends Base +{ + public function testIsAllowed() + { + $acl = new AccessMap; + $acl->setDefaultRole(Role::APP_USER); + $acl->setRoleHierarchy(Role::APP_ADMIN, array(Role::APP_MANAGER, Role::APP_USER)); + $acl->setRoleHierarchy(Role::APP_MANAGER, array(Role::APP_USER)); + + $acl->add('MyController', 'myAction1', Role::APP_MANAGER); + $acl->add('MyController', 'myAction2', Role::APP_ADMIN); + $acl->add('MyManagerController', '*', Role::APP_MANAGER); + + $authorization = new Authorization($acl); + + $this->assertTrue($authorization->isAllowed('myController', 'myAction1', Role::APP_ADMIN)); + $this->assertTrue($authorization->isAllowed('myController', 'myAction1', Role::APP_MANAGER)); + $this->assertFalse($authorization->isAllowed('myController', 'myAction1', Role::APP_USER)); + $this->assertFalse($authorization->isAllowed('myController', 'myAction1', 'something else')); + + $this->assertTrue($authorization->isAllowed('MyManagerController', 'myAction', Role::APP_ADMIN)); + $this->assertTrue($authorization->isAllowed('MyManagerController', 'myAction', Role::APP_MANAGER)); + $this->assertFalse($authorization->isAllowed('MyManagerController', 'myAction', Role::APP_USER)); + $this->assertFalse($authorization->isAllowed('MyManagerController', 'myAction', 'something else')); + + $this->assertTrue($authorization->isAllowed('MyUserController', 'myAction', Role::APP_ADMIN)); + $this->assertTrue($authorization->isAllowed('MyUserController', 'myAction', Role::APP_MANAGER)); + $this->assertTrue($authorization->isAllowed('MyUserController', 'myAction', Role::APP_USER)); + $this->assertFalse($authorization->isAllowed('MyUserController', 'myAction', 'something else')); + } +} diff --git a/tests/units/Core/Security/TokenTest.php b/tests/units/Core/Security/TokenTest.php new file mode 100644 index 00000000..dbb7bd1a --- /dev/null +++ b/tests/units/Core/Security/TokenTest.php @@ -0,0 +1,29 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Security\Token; + +class TokenTest extends Base +{ + public function testGenerateToken() + { + $t1 = Token::getToken(); + $t2 = Token::getToken(); + + $this->assertNotEmpty($t1); + $this->assertNotEmpty($t2); + + $this->assertNotEquals($t1, $t2); + } + + public function testCSRFTokens() + { + $token = new Token($this->container); + $t1 = $token->getCSRFToken(); + + $this->assertNotEmpty($t1); + $this->assertTrue($token->validateCSRFToken($t1)); + $this->assertFalse($token->validateCSRFToken($t1)); + } +} diff --git a/tests/units/Core/Session/FlashMessageTest.php b/tests/units/Core/Session/FlashMessageTest.php new file mode 100644 index 00000000..25361343 --- /dev/null +++ b/tests/units/Core/Session/FlashMessageTest.php @@ -0,0 +1,23 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Session\FlashMessage; + +class FlashMessageTest extends Base +{ + public function testMessage() + { + $flash = new FlashMessage($this->container); + + $flash->success('my message'); + $this->assertEquals('my message', $flash->getMessage('success')); + $this->assertEmpty($flash->getMessage('success')); + + $flash->failure('my error message'); + $this->assertEquals('my error message', $flash->getMessage('failure')); + $this->assertEmpty($flash->getMessage('failure')); + + $this->assertEmpty($flash->getMessage('not found')); + } +} diff --git a/tests/units/Core/Session/SessionStorageTest.php b/tests/units/Core/Session/SessionStorageTest.php new file mode 100644 index 00000000..dd0040d5 --- /dev/null +++ b/tests/units/Core/Session/SessionStorageTest.php @@ -0,0 +1,60 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Session\SessionStorage; + +class SessionStorageTest extends Base +{ + public function testNotPersistentStorage() + { + $storage = new SessionStorage(); + $storage->something = array('a' => 'b'); + $this->assertEquals(array('a' => 'b'), $storage->something); + $this->assertTrue(isset($storage->something)); + $this->assertFalse(isset($storage->something->x)); + $this->assertFalse(isset($storage->notFound)); + $this->assertFalse(isset($storage->notFound->x)); + $this->assertFalse(isset($storage->notFound['x'])); + } + + public function testPersistentStorage() + { + $session = array('d' => 'e'); + + $storage = new SessionStorage(); + $storage->setStorage($session); + $storage->something = array('a' => 'b'); + + $this->assertEquals(array('a' => 'b'), $storage->something); + $this->assertEquals('e', $storage->d); + + $storage->something['a'] = 'c'; + $this->assertEquals('c', $storage->something['a']); + + $storage = null; + $this->assertEquals(array('something' => array('a' => 'c'), 'd' => 'e'), $session); + } + + public function testFlush() + { + $session = array('d' => 'e'); + + $storage = new SessionStorage(); + $storage->setStorage($session); + $storage->something = array('a' => 'b'); + + $this->assertEquals(array('a' => 'b'), $storage->something); + $this->assertEquals('e', $storage->d); + + $storage->flush(); + + $this->assertFalse(isset($storage->d)); + $this->assertFalse(isset($storage->something)); + + $storage->foo = 'bar'; + + $storage = null; + $this->assertEquals(array('foo' => 'bar'), $session); + } +} diff --git a/tests/units/Core/User/GroupSyncTest.php b/tests/units/Core/User/GroupSyncTest.php new file mode 100644 index 00000000..e22b86d4 --- /dev/null +++ b/tests/units/Core/User/GroupSyncTest.php @@ -0,0 +1,30 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\User\GroupSync; +use Kanboard\Model\Group; +use Kanboard\Model\GroupMember; + +class GroupSyncTest extends Base +{ + public function testSynchronize() + { + $group = new Group($this->container); + $groupMember = new GroupMember($this->container); + $groupSync = new GroupSync($this->container); + + $this->assertEquals(1, $group->create('My Group 1', 'externalId1')); + $this->assertEquals(2, $group->create('My Group 2', 'externalId2')); + + $this->assertTrue($groupMember->addUser(1, 1)); + + $this->assertTrue($groupMember->isMember(1, 1)); + $this->assertFalse($groupMember->isMember(2, 1)); + + $groupSync->synchronize(1, array('externalId1', 'externalId2', 'externalId3')); + + $this->assertTrue($groupMember->isMember(1, 1)); + $this->assertTrue($groupMember->isMember(2, 1)); + } +} diff --git a/tests/units/Core/User/UserProfileTest.php b/tests/units/Core/User/UserProfileTest.php new file mode 100644 index 00000000..4886a945 --- /dev/null +++ b/tests/units/Core/User/UserProfileTest.php @@ -0,0 +1,63 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Security\Role; +use Kanboard\Core\User\UserProfile; +use Kanboard\User\LdapUserProvider; +use Kanboard\User\DatabaseUserProvider; + +class UserProfileTest extends Base +{ + public function testInitializeLocalUser() + { + $userProfile = new UserProfile($this->container); + $user = new DatabaseUserProvider(array('id' => 1)); + + $this->assertTrue($userProfile->initialize($user)); + $this->assertNotEmpty($this->container['sessionStorage']->user); + $this->assertEquals('admin', $this->container['sessionStorage']->user['username']); + } + + public function testInitializeLocalUserNotFound() + { + $userProfile = new UserProfile($this->container); + $user = new DatabaseUserProvider(array('id' => 2)); + + $this->assertFalse($userProfile->initialize($user)); + $this->assertFalse(isset($this->container['sessionStorage']->user)); + } + + public function testInitializeRemoteUser() + { + $userProfile = new UserProfile($this->container); + $user = new LdapUserProvider('ldapId', 'bob', 'Bob', '', Role::APP_MANAGER, array()); + + $this->assertTrue($userProfile->initialize($user)); + $this->assertNotEmpty($this->container['sessionStorage']->user); + $this->assertEquals(2, $this->container['sessionStorage']->user['id']); + $this->assertEquals('bob', $this->container['sessionStorage']->user['username']); + $this->assertEquals(Role::APP_MANAGER, $this->container['sessionStorage']->user['role']); + + $user = new LdapUserProvider('ldapId', 'bob', 'Bob', '', Role::APP_MANAGER, array()); + + $this->assertTrue($userProfile->initialize($user)); + $this->assertNotEmpty($this->container['sessionStorage']->user); + $this->assertEquals(2, $this->container['sessionStorage']->user['id']); + $this->assertEquals('bob', $this->container['sessionStorage']->user['username']); + } + + public function testAssignRemoteUser() + { + $userProfile = new UserProfile($this->container); + $user = new LdapUserProvider('ldapId', 'bob', 'Bob', '', Role::APP_MANAGER, array()); + + $this->assertTrue($userProfile->assign(1, $user)); + $this->assertNotEmpty($this->container['sessionStorage']->user); + $this->assertEquals(1, $this->container['sessionStorage']->user['id']); + $this->assertEquals('admin', $this->container['sessionStorage']->user['username']); + $this->assertEquals('Bob', $this->container['sessionStorage']->user['name']); + $this->assertEquals('', $this->container['sessionStorage']->user['email']); + $this->assertEquals(Role::APP_ADMIN, $this->container['sessionStorage']->user['role']); + } +} diff --git a/tests/units/Core/User/UserPropertyTest.php b/tests/units/Core/User/UserPropertyTest.php new file mode 100644 index 00000000..170eab4c --- /dev/null +++ b/tests/units/Core/User/UserPropertyTest.php @@ -0,0 +1,60 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Security\Role; +use Kanboard\Core\User\UserProperty; +use Kanboard\User\LdapUserProvider; + +class UserPropertyTest extends Base +{ + public function testGetProperties() + { + $user = new LdapUserProvider('ldapId', 'bob', 'Bob', '', Role::APP_USER, array()); + + $expected = array( + 'username' => 'bob', + 'name' => 'Bob', + 'role' => Role::APP_USER, + 'is_ldap_user' => 1, + ); + + $this->assertEquals($expected, UserProperty::getProperties($user)); + + $user = new LdapUserProvider('ldapId', 'bob', '', '', '', array()); + + $expected = array( + 'username' => 'bob', + 'is_ldap_user' => 1, + ); + + $this->assertEquals($expected, UserProperty::getProperties($user)); + } + + public function testFilterProperties() + { + $profile = array( + 'id' => 123, + 'username' => 'bob', + 'name' => null, + 'email' => '', + 'other_column' => 'myvalue', + 'role' => Role::APP_ADMIN, + ); + + $properties = array( + 'external_id' => '456', + 'username' => 'bobby', + 'name' => 'Bobby', + 'email' => 'admin@localhost', + 'role' => '', + ); + + $expected = array( + 'name' => 'Bobby', + 'email' => 'admin@localhost', + ); + + $this->assertEquals($expected, UserProperty::filterProperties($profile, $properties)); + } +} diff --git a/tests/units/Core/User/UserSessionTest.php b/tests/units/Core/User/UserSessionTest.php new file mode 100644 index 00000000..64413f98 --- /dev/null +++ b/tests/units/Core/User/UserSessionTest.php @@ -0,0 +1,144 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\User\UserSession; +use Kanboard\Core\Security\Role; + +class UserSessionTest extends Base +{ + public function testInitialize() + { + $us = new UserSession($this->container); + + $user = array( + 'id' => '123', + 'username' => 'john', + 'password' => 'something', + 'twofactor_secret' => 'something else', + 'is_admin' => '1', + 'is_project_admin' => '0', + 'is_ldap_user' => '0', + 'twofactor_activated' => '0', + 'role' => Role::APP_MANAGER, + ); + + $us->initialize($user); + + $session = $this->container['sessionStorage']->getAll(); + + $this->assertNotEmpty($session); + $this->assertEquals(123, $session['user']['id']); + $this->assertEquals('john', $session['user']['username']); + $this->assertEquals(Role::APP_MANAGER, $session['user']['role']); + $this->assertFalse($session['user']['is_ldap_user']); + $this->assertFalse($session['user']['twofactor_activated']); + $this->assertArrayNotHasKey('password', $session['user']); + $this->assertArrayNotHasKey('twofactor_secret', $session['user']); + $this->assertArrayNotHasKey('is_admin', $session['user']); + $this->assertArrayNotHasKey('is_project_admin', $session['user']); + + $this->assertEquals('john', $us->getUsername()); + } + + public function testGetId() + { + $us = new UserSession($this->container); + + $this->assertEquals(0, $us->getId()); + + $this->container['sessionStorage']->user = array('id' => 2); + $this->assertEquals(2, $us->getId()); + + $this->container['sessionStorage']->user = array('id' => '2'); + $this->assertEquals(2, $us->getId()); + } + + public function testIsLogged() + { + $us = new UserSession($this->container); + + $this->assertFalse($us->isLogged()); + + $this->container['sessionStorage']->user = array(); + $this->assertFalse($us->isLogged()); + + $this->container['sessionStorage']->user = array('id' => 1); + $this->assertTrue($us->isLogged()); + } + + public function testIsAdmin() + { + $us = new UserSession($this->container); + + $this->assertFalse($us->isAdmin()); + + $this->container['sessionStorage']->user = array('role' => Role::APP_ADMIN); + $this->assertTrue($us->isAdmin()); + + $this->container['sessionStorage']->user = array('role' => Role::APP_USER); + $this->assertFalse($us->isAdmin()); + + $this->container['sessionStorage']->user = array('role' => ''); + $this->assertFalse($us->isAdmin()); + } + + public function testCommentSorting() + { + $us = new UserSession($this->container); + $this->assertEquals('ASC', $us->getCommentSorting()); + + $us->setCommentSorting('DESC'); + $this->assertEquals('DESC', $us->getCommentSorting()); + } + + public function testBoardCollapseMode() + { + $us = new UserSession($this->container); + $this->assertFalse($us->isBoardCollapsed(2)); + + $us->setBoardDisplayMode(3, false); + $this->assertFalse($us->isBoardCollapsed(3)); + + $us->setBoardDisplayMode(3, true); + $this->assertTrue($us->isBoardCollapsed(3)); + } + + public function testFilters() + { + $us = new UserSession($this->container); + $this->assertEquals('status:open', $us->getFilters(1)); + + $us->setFilters(1, 'assignee:me'); + $this->assertEquals('assignee:me', $us->getFilters(1)); + + $this->assertEquals('status:open', $us->getFilters(2)); + + $us->setFilters(2, 'assignee:bob'); + $this->assertEquals('assignee:bob', $us->getFilters(2)); + } + + public function testPostAuthentication() + { + $us = new UserSession($this->container); + $this->assertFalse($us->isPostAuthenticationValidated()); + + $this->container['sessionStorage']->postAuthenticationValidated = false; + $this->assertFalse($us->isPostAuthenticationValidated()); + + $us->validatePostAuthentication(); + $this->assertTrue($us->isPostAuthenticationValidated()); + + $this->container['sessionStorage']->user = array(); + $this->assertFalse($us->hasPostAuthentication()); + + $this->container['sessionStorage']->user = array('twofactor_activated' => false); + $this->assertFalse($us->hasPostAuthentication()); + + $this->container['sessionStorage']->user = array('twofactor_activated' => true); + $this->assertTrue($us->hasPostAuthentication()); + + $us->disablePostAuthentication(); + $this->assertFalse($us->hasPostAuthentication()); + } +} diff --git a/tests/units/Core/User/UserSyncTest.php b/tests/units/Core/User/UserSyncTest.php new file mode 100644 index 00000000..e7ce42b2 --- /dev/null +++ b/tests/units/Core/User/UserSyncTest.php @@ -0,0 +1,55 @@ +<?php + +require_once __DIR__.'/../../Base.php'; + +use Kanboard\Core\Security\Role; +use Kanboard\Core\User\UserSync; +use Kanboard\User\LdapUserProvider; + +class UserSyncTest extends Base +{ + public function testSynchronizeNewUser() + { + $user = new LdapUserProvider('ldapId', 'bob', 'Bob', '', Role::APP_MANAGER, array()); + $userSync = new UserSync($this->container); + + $profile = array( + 'id' => 2, + 'username' => 'bob', + 'name' => 'Bob', + 'email' => '', + 'role' => Role::APP_MANAGER, + 'is_ldap_user' => 1, + ); + + $this->assertArraySubset($profile, $userSync->synchronize($user)); + } + + public function testSynchronizeExistingUser() + { + $userSync = new UserSync($this->container); + $user = new LdapUserProvider('ldapId', 'admin', 'Admin', 'email@localhost', Role::APP_MANAGER, array()); + + $profile = array( + 'id' => 1, + 'username' => 'admin', + 'name' => 'Admin', + 'email' => 'email@localhost', + 'role' => Role::APP_MANAGER, + ); + + $this->assertArraySubset($profile, $userSync->synchronize($user)); + + $user = new LdapUserProvider('ldapId', 'admin', '', '', Role::APP_ADMIN, array()); + + $profile = array( + 'id' => 1, + 'username' => 'admin', + 'name' => 'Admin', + 'email' => 'email@localhost', + 'role' => Role::APP_ADMIN, + ); + + $this->assertArraySubset($profile, $userSync->synchronize($user)); + } +} diff --git a/tests/units/ExternalLink/AttachmentLinkProviderTest.php b/tests/units/ExternalLink/AttachmentLinkProviderTest.php new file mode 100644 index 00000000..fe374664 --- /dev/null +++ b/tests/units/ExternalLink/AttachmentLinkProviderTest.php @@ -0,0 +1,64 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\ExternalLink\AttachmentLinkProvider; + +class AttachmentLinkProviderTest extends Base +{ + public function testGetName() + { + $attachmentLinkProvider = new AttachmentLinkProvider($this->container); + $this->assertEquals('Attachment', $attachmentLinkProvider->getName()); + } + + public function testGetType() + { + $attachmentLinkProvider = new AttachmentLinkProvider($this->container); + $this->assertEquals('attachment', $attachmentLinkProvider->getType()); + } + + public function testGetDependencies() + { + $attachmentLinkProvider = new AttachmentLinkProvider($this->container); + $this->assertEquals(array('related' => 'Related'), $attachmentLinkProvider->getDependencies()); + } + + public function testMatch() + { + $attachmentLinkProvider = new AttachmentLinkProvider($this->container); + + $attachmentLinkProvider->setUserTextInput('http://kanboard.net/FILE.DOC'); + $this->assertTrue($attachmentLinkProvider->match()); + + $attachmentLinkProvider->setUserTextInput('http://kanboard.net/folder/document.PDF'); + $this->assertTrue($attachmentLinkProvider->match()); + + $attachmentLinkProvider->setUserTextInput('http://kanboard.net/archive.zip'); + $this->assertTrue($attachmentLinkProvider->match()); + + $attachmentLinkProvider->setUserTextInput(' https://kanboard.net/folder/archive.tar '); + $this->assertTrue($attachmentLinkProvider->match()); + + $attachmentLinkProvider->setUserTextInput('http:// invalid url'); + $this->assertFalse($attachmentLinkProvider->match()); + + $attachmentLinkProvider->setUserTextInput(''); + $this->assertFalse($attachmentLinkProvider->match()); + + $attachmentLinkProvider->setUserTextInput('http://kanboard.net/folder/document.html'); + $this->assertFalse($attachmentLinkProvider->match()); + + $attachmentLinkProvider->setUserTextInput('http://kanboard.net/folder/DOC.HTML'); + $this->assertFalse($attachmentLinkProvider->match()); + + $attachmentLinkProvider->setUserTextInput('http://kanboard.net/folder/document.do'); + $this->assertFalse($attachmentLinkProvider->match()); + } + + public function testGetLink() + { + $attachmentLinkProvider = new AttachmentLinkProvider($this->container); + $this->assertInstanceOf('\Kanboard\ExternalLink\AttachmentLink', $attachmentLinkProvider->getLink()); + } +} diff --git a/tests/units/ExternalLink/AttachmentLinkTest.php b/tests/units/ExternalLink/AttachmentLinkTest.php new file mode 100644 index 00000000..0211869c --- /dev/null +++ b/tests/units/ExternalLink/AttachmentLinkTest.php @@ -0,0 +1,18 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\ExternalLink\AttachmentLink; + +class AttachmentLinkTest extends Base +{ + public function testGetTitleFromUrl() + { + $url = 'https://kanboard.net/folder/document.pdf'; + + $link = new AttachmentLink($this->container); + $link->setUrl($url); + $this->assertEquals($url, $link->getUrl()); + $this->assertEquals('document.pdf', $link->getTitle()); + } +} diff --git a/tests/units/ExternalLink/WebLinkProviderTest.php b/tests/units/ExternalLink/WebLinkProviderTest.php new file mode 100644 index 00000000..95110ed8 --- /dev/null +++ b/tests/units/ExternalLink/WebLinkProviderTest.php @@ -0,0 +1,52 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\ExternalLink\WebLinkProvider; + +class WebLinkProviderTest extends Base +{ + public function testGetName() + { + $webLinkProvider = new WebLinkProvider($this->container); + $this->assertEquals('Web Link', $webLinkProvider->getName()); + } + + public function testGetType() + { + $webLinkProvider = new WebLinkProvider($this->container); + $this->assertEquals('weblink', $webLinkProvider->getType()); + } + + public function testGetDependencies() + { + $webLinkProvider = new WebLinkProvider($this->container); + $this->assertEquals(array('related' => 'Related'), $webLinkProvider->getDependencies()); + } + + public function testMatch() + { + $webLinkProvider = new WebLinkProvider($this->container); + + $webLinkProvider->setUserTextInput('http://kanboard.net/'); + $this->assertTrue($webLinkProvider->match()); + + $webLinkProvider->setUserTextInput('http://kanboard.net/mypage'); + $this->assertTrue($webLinkProvider->match()); + + $webLinkProvider->setUserTextInput(' https://kanboard.net/ '); + $this->assertTrue($webLinkProvider->match()); + + $webLinkProvider->setUserTextInput('http:// invalid url'); + $this->assertFalse($webLinkProvider->match()); + + $webLinkProvider->setUserTextInput(''); + $this->assertFalse($webLinkProvider->match()); + } + + public function testGetLink() + { + $webLinkProvider = new WebLinkProvider($this->container); + $this->assertInstanceOf('\Kanboard\ExternalLink\WebLink', $webLinkProvider->getLink()); + } +} diff --git a/tests/units/ExternalLink/WebLinkTest.php b/tests/units/ExternalLink/WebLinkTest.php new file mode 100644 index 00000000..85487e15 --- /dev/null +++ b/tests/units/ExternalLink/WebLinkTest.php @@ -0,0 +1,45 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\ExternalLink\WebLink; + +class WebLinkTest extends Base +{ + public function testGetTitleFromHtml() + { + $url = 'http://kanboard.net/something'; + $title = 'My title'; + $html = '<!DOCTYPE html><html><head><title> '.$title.' </title></head><body>Test</body></html>'; + + $webLink = new WebLink($this->container); + $webLink->setUrl($url); + $this->assertEquals($url, $webLink->getUrl()); + + $this->container['httpClient'] + ->expects($this->once()) + ->method('get') + ->with($url) + ->will($this->returnValue($html)); + + $this->assertEquals($title, $webLink->getTitle()); + } + + public function testGetTitleFromUrl() + { + $url = 'http://kanboard.net/something'; + $html = '<!DOCTYPE html><html><head></head><body>Test</body></html>'; + + $webLink = new WebLink($this->container); + $webLink->setUrl($url); + $this->assertEquals($url, $webLink->getUrl()); + + $this->container['httpClient'] + ->expects($this->once()) + ->method('get') + ->with($url) + ->will($this->returnValue($html)); + + $this->assertEquals('kanboard.net/something', $webLink->getTitle()); + } +} diff --git a/tests/units/Group/LdapBackendGroupProviderTest.php b/tests/units/Group/LdapBackendGroupProviderTest.php new file mode 100644 index 00000000..67b5ef35 --- /dev/null +++ b/tests/units/Group/LdapBackendGroupProviderTest.php @@ -0,0 +1,16 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Group\LdapBackendGroupProvider; + +class LdapBackendGroupProviderTest extends Base +{ + public function testGetLdapGroupPattern() + { + $this->setExpectedException('LogicException', 'LDAP group filter empty, check the parameter LDAP_GROUP_FILTER'); + + $backend = new LdapBackendGroupProvider($this->container); + $backend->getLdapGroupPattern('test'); + } +} diff --git a/tests/units/Helper/AppHelperTest.php b/tests/units/Helper/AppHelperTest.php index cbd8b8ab..0639b7aa 100644 --- a/tests/units/Helper/AppHelperTest.php +++ b/tests/units/Helper/AppHelperTest.php @@ -2,7 +2,7 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Core\Session; +use Kanboard\Core\Session\FlashMessage; use Kanboard\Helper\App; use Kanboard\Model\Config; @@ -23,15 +23,15 @@ class AppHelperTest extends Base public function testFlashMessage() { $h = new App($this->container); - $s = new Session; + $f = new FlashMessage($this->container); $this->assertEmpty($h->flashMessage()); - $s->flash('test & test'); + + $f->success('test & test'); $this->assertEquals('<div class="alert alert-success alert-fade-out">test & test</div>', $h->flashMessage()); $this->assertEmpty($h->flashMessage()); - $this->assertEmpty($h->flashMessage()); - $s->flashError('test & test'); + $f->failure('test & test'); $this->assertEquals('<div class="alert alert-error">test & test</div>', $h->flashMessage()); $this->assertEmpty($h->flashMessage()); } diff --git a/tests/units/Helper/AssetHelperTest.php b/tests/units/Helper/AssetHelperTest.php index 7e1edb12..64fcd569 100644 --- a/tests/units/Helper/AssetHelperTest.php +++ b/tests/units/Helper/AssetHelperTest.php @@ -15,6 +15,7 @@ class AssetHelperTest extends Base $this->assertEmpty($h->customCss()); $this->assertTrue($c->save(array('application_stylesheet' => 'p { color: red }'))); + $this->container['memoryCache']->flush(); $this->assertEquals('<style>p { color: red }</style>', $h->customCss()); } diff --git a/tests/units/Helper/DatetimeHelperTest.php b/tests/units/Helper/DatetimeHelperTest.php index 8e9c461b..f27a2eb9 100644 --- a/tests/units/Helper/DatetimeHelperTest.php +++ b/tests/units/Helper/DatetimeHelperTest.php @@ -6,23 +6,45 @@ use Kanboard\Helper\Dt; class DatetimeHelperTest extends Base { + public function testGetTime() + { + $helper = new Dt($this->container); + $this->assertEquals('17:25', $helper->time(1422206700)); + } + + public function testGetDate() + { + $helper = new Dt($this->container); + $this->assertEquals('01/25/2015', $helper->date(1422206700)); + $this->assertEquals('01/25/2015', $helper->date('2015-01-25')); + $this->assertEquals('', $helper->date('0')); + $this->assertEquals('', $helper->date(0)); + $this->assertEquals('', $helper->date('')); + } + + public function testGetDatetime() + { + $helper = new Dt($this->container); + $this->assertEquals('01/25/2015 17:25', $helper->datetime(1422206700)); + } + public function testAge() { - $h = new Dt($this->container); - - $this->assertEquals('<15m', $h->age(0, 30)); - $this->assertEquals('<30m', $h->age(0, 1000)); - $this->assertEquals('<1h', $h->age(0, 3000)); - $this->assertEquals('~2h', $h->age(0, 2*3600)); - $this->assertEquals('1d', $h->age(0, 30*3600)); - $this->assertEquals('2d', $h->age(0, 65*3600)); + $helper = new Dt($this->container); + + $this->assertEquals('<15m', $helper->age(0, 30)); + $this->assertEquals('<30m', $helper->age(0, 1000)); + $this->assertEquals('<1h', $helper->age(0, 3000)); + $this->assertEquals('~2h', $helper->age(0, 2*3600)); + $this->assertEquals('1d', $helper->age(0, 30*3600)); + $this->assertEquals('2d', $helper->age(0, 65*3600)); } public function testGetDayHours() { - $h = new Dt($this->container); + $helper = new Dt($this->container); - $slots = $h->getDayHours(); + $slots = $helper->getDayHours(); $this->assertNotEmpty($slots); $this->assertCount(48, $slots); @@ -36,9 +58,9 @@ class DatetimeHelperTest extends Base public function testGetWeekDays() { - $h = new Dt($this->container); + $helper = new Dt($this->container); - $slots = $h->getWeekDays(); + $slots = $helper->getWeekDays(); $this->assertNotEmpty($slots); $this->assertCount(7, $slots); @@ -48,9 +70,9 @@ class DatetimeHelperTest extends Base public function testGetWeekDay() { - $h = new Dt($this->container); + $helper = new Dt($this->container); - $this->assertEquals('Monday', $h->getWeekDay(1)); - $this->assertEquals('Sunday', $h->getWeekDay(7)); + $this->assertEquals('Monday', $helper->getWeekDay(1)); + $this->assertEquals('Sunday', $helper->getWeekDay(7)); } } diff --git a/tests/units/Helper/FileHelperText.php b/tests/units/Helper/FileHelperText.php index a681c890..6a1b78a4 100644 --- a/tests/units/Helper/FileHelperText.php +++ b/tests/units/Helper/FileHelperText.php @@ -8,8 +8,29 @@ class FileHelperTest extends Base { public function testIcon() { - $h = new File($this->container); - $this->assertEquals('fa-file-image-o', $h->icon('test.png')); - $this->assertEquals('fa-file-o', $h->icon('test')); + $helper = new File($this->container); + $this->assertEquals('fa-file-image-o', $helper->icon('test.png')); + $this->assertEquals('fa-file-o', $helper->icon('test')); + } + + public function testGetMimeType() + { + $helper = new File($this->container); + + $this->assertEquals('image/jpeg', $helper->getImageMimeType('My File.JPG')); + $this->assertEquals('image/jpeg', $helper->getImageMimeType('My File.jpeg')); + $this->assertEquals('image/png', $helper->getImageMimeType('My File.PNG')); + $this->assertEquals('image/gif', $helper->getImageMimeType('My File.gif')); + $this->assertEquals('image/jpeg', $helper->getImageMimeType('My File.bmp')); + $this->assertEquals('image/jpeg', $helper->getImageMimeType('My File')); + } + + public function testGetPreviewType() + { + $helper = new File($this->container); + $this->assertEquals('text', $helper->getPreviewType('test.txt')); + $this->assertEquals('markdown', $helper->getPreviewType('test.markdown')); + $this->assertEquals('md', $helper->getPreviewType('test.md')); + $this->assertEquals(null, $helper->getPreviewType('test.doc')); } } diff --git a/tests/units/Helper/TaskHelperTest.php b/tests/units/Helper/TaskHelperTest.php new file mode 100644 index 00000000..726188e4 --- /dev/null +++ b/tests/units/Helper/TaskHelperTest.php @@ -0,0 +1,32 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Helper\Task; + +class TaskHelperTest extends Base +{ + public function testSelectPriority() + { + $helper = new Task($this->container); + $this->assertNotEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array())); + $this->assertEmpty($helper->selectPriority(array('priority_end' => '3', 'priority_start' => '3', 'priority_default' => '2'), array())); + } + + public function testFormatPriority() + { + $helper = new Task($this->container); + + $this->assertEquals( + '<span class="task-board-priority" title="Task priority">P2</span>', + $helper->formatPriority(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array('priority' => 2)) + ); + + $this->assertEquals( + '<span class="task-board-priority" title="Task priority">-P6</span>', + $helper->formatPriority(array('priority_end' => '3', 'priority_start' => '1', 'priority_default' => '2'), array('priority' => -6)) + ); + + $this->assertEmpty($helper->formatPriority(array('priority_end' => '3', 'priority_start' => '3', 'priority_default' => '2'), array())); + } +} diff --git a/tests/units/Helper/TextHelperTest.php b/tests/units/Helper/TextHelperTest.php index 30c537a9..a4bdfa91 100644 --- a/tests/units/Helper/TextHelperTest.php +++ b/tests/units/Helper/TextHelperTest.php @@ -6,7 +6,7 @@ use Kanboard\Helper\Text; class TextHelperTest extends Base { - public function testMarkdown() + public function testMarkdownTaskLink() { $h = new Text($this->container); @@ -31,6 +31,12 @@ class TextHelperTest extends Base ); } + public function testMarkdownUserLink() + { + $h = new Text($this->container); + $this->assertEquals('<p>Text <a href="?controller=user&action=profile&user_id=1" class="user-mention-link">@admin</a> @notfound</p>', $h->markdown('Text @admin @notfound')); + } + public function testFormatBytes() { $h = new Text($this->container); diff --git a/tests/units/Helper/UrlHelperTest.php b/tests/units/Helper/UrlHelperTest.php index cbacbc73..15e01237 100644 --- a/tests/units/Helper/UrlHelperTest.php +++ b/tests/units/Helper/UrlHelperTest.php @@ -4,14 +4,36 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Helper\Url; use Kanboard\Model\Config; +use Kanboard\Core\Http\Request; class UrlHelperTest extends Base { - public function testLink() + public function testPluginLink() { $h = new Url($this->container); $this->assertEquals( - '<a href="?controller=a&action=b&d=e" class="f" title="g" target="_blank">label</a>', + '<a href="?controller=a&action=b&d=e&plugin=something" class="f" title=\'g\' target="_blank">label</a>', + $h->link('label', 'a', 'b', array('d' => 'e', 'plugin' => 'something'), false, 'f', 'g', true) + ); + } + + public function testPluginLinkWithRouteDefined() + { + $this->container['route']->enable(); + $this->container['route']->addRoute('/myplugin/something/:d', 'a', 'b', 'something'); + + $h = new Url($this->container); + $this->assertEquals( + '<a href="myplugin/something/e" class="f" title=\'g\' target="_blank">label</a>', + $h->link('label', 'a', 'b', array('d' => 'e', 'plugin' => 'something'), false, 'f', 'g', true) + ); + } + + public function testAppLink() + { + $h = new Url($this->container); + $this->assertEquals( + '<a href="?controller=a&action=b&d=e" class="f" title=\'g\' target="_blank">label</a>', $h->link('label', 'a', 'b', array('d' => 'e'), false, 'f', 'g', true) ); } @@ -36,48 +58,66 @@ class UrlHelperTest extends Base public function testDir() { - $h = new Url($this->container); - $this->assertEquals('', $h->dir()); + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/kanboard/index.php', + 'REQUEST_METHOD' => 'GET' + ) + ); - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['PHP_SELF'] = '/plop/index.php'; $h = new Url($this->container); - $this->assertEquals('/plop/', $h->dir()); + $this->assertEquals('/kanboard/', $h->dir()); + + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/index.php', + 'REQUEST_METHOD' => 'GET' + ) + ); - $_SERVER['REQUEST_METHOD'] = 'GET'; - $_SERVER['PHP_SELF'] = ''; $h = new Url($this->container); $this->assertEquals('/', $h->dir()); } public function testServer() { - $h = new Url($this->container); + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/index.php', + 'REQUEST_METHOD' => 'GET', + 'SERVER_NAME' => 'localhost', + 'SERVER_PORT' => 80, + ) + ); + $h = new Url($this->container); $this->assertEquals('http://localhost/', $h->server()); - $_SERVER['PHP_SELF'] = '/'; - $_SERVER['SERVER_NAME'] = 'kb'; - $_SERVER['SERVER_PORT'] = 1234; + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/index.php', + 'REQUEST_METHOD' => 'GET', + 'SERVER_NAME' => 'kb', + 'SERVER_PORT' => 1234, + ) + ); + $h = new Url($this->container); $this->assertEquals('http://kb:1234/', $h->server()); } public function testBase() { - $h = new Url($this->container); - - $this->assertEquals('http://localhost/', $h->base()); - - $_SERVER['PHP_SELF'] = '/'; - $_SERVER['SERVER_NAME'] = 'kb'; - $_SERVER['SERVER_PORT'] = 1234; + $this->container['request'] = new Request($this->container, array( + 'PHP_SELF' => '/index.php', + 'REQUEST_METHOD' => 'GET', + 'SERVER_NAME' => 'kb', + 'SERVER_PORT' => 1234, + ) + ); $h = new Url($this->container); $this->assertEquals('http://kb:1234/', $h->base()); $c = new Config($this->container); $c->save(array('application_url' => 'https://mykanboard/')); + $this->container['memoryCache']->flush(); $h = new Url($this->container); $this->assertEquals('https://mykanboard/', $c->get('application_url')); diff --git a/tests/units/Helper/UserHelperTest.php b/tests/units/Helper/UserHelperTest.php index 4cc9fa65..f1099faa 100644 --- a/tests/units/Helper/UserHelperTest.php +++ b/tests/units/Helper/UserHelperTest.php @@ -4,179 +4,227 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Helper\User; use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; +use Kanboard\Model\ProjectUserRole; use Kanboard\Model\User as UserModel; -use Kanboard\Core\Session; +use Kanboard\Core\Security\Role; class UserHelperTest extends Base { public function testInitials() { - $h = new User($this->container); + $helper = new User($this->container); - $this->assertEquals('CN', $h->getInitials('chuck norris')); - $this->assertEquals('A', $h->getInitials('admin')); + $this->assertEquals('CN', $helper->getInitials('chuck norris')); + $this->assertEquals('A', $helper->getInitials('admin')); } - public function testIsProjectAdministrationAllowedForProjectAdmin() + public function testGetRoleName() { - $h = new User($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new UserModel($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project manager - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertFalse($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( + $helper = new User($this->container); + $this->assertEquals('Administrator', $helper->getRoleName(Role::APP_ADMIN)); + $this->assertEquals('Manager', $helper->getRoleName(Role::APP_MANAGER)); + $this->assertEquals('Project Viewer', $helper->getRoleName(Role::PROJECT_VIEWER)); + } + + public function testHasAccessForAdmins() + { + $helper = new User($this->container); + + $this->container['sessionStorage']->user = array( + 'id' => 2, + 'role' => Role::APP_ADMIN, + ); + + $this->assertTrue($helper->hasAccess('user', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreation', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreation', 'createPrivate')); + } + + public function testHasAccessForManagers() + { + $helper = new User($this->container); + + $this->container['sessionStorage']->user = array( + 'id' => 2, + 'role' => Role::APP_MANAGER, + ); + + $this->assertFalse($helper->hasAccess('user', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreation', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreation', 'createPrivate')); + } + + public function testHasAccessForUsers() + { + $helper = new User($this->container); + + $this->container['sessionStorage']->user = array( + 'id' => 2, + 'role' => Role::APP_USER, + ); + + $this->assertFalse($helper->hasAccess('user', 'create')); + $this->assertFalse($helper->hasAccess('ProjectCreation', 'create')); + $this->assertTrue($helper->hasAccess('ProjectCreation', 'createPrivate')); + } + + public function testHasProjectAccessForAdmins() + { + $helper = new User($this->container); + $project = new Project($this->container); + + $this->container['sessionStorage']->user = array( + 'id' => 2, + 'role' => Role::APP_ADMIN, + ); + + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + + $this->assertTrue($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); + } + + public function testHasProjectAccessForManagers() + { + $helper = new User($this->container); + $project = new Project($this->container); + + $this->container['sessionStorage']->user = array( 'id' => 2, - 'is_admin' => false, - 'is_project_admin' => true, + 'role' => Role::APP_MANAGER, ); - $this->assertTrue($h->isProjectAdministrationAllowed(1)); + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertFalse($helper->hasProjectAccess('board', 'show', 1)); } - public function testIsProjectAdministrationAllowedForProjectMember() + public function testHasProjectAccessForUsers() { - $h = new User($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new UserModel($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project member - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertFalse($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( + $helper = new User($this->container); + $project = new Project($this->container); + + $this->container['sessionStorage']->user = array( 'id' => 2, - 'is_admin' => false, - 'is_project_admin' => false, + 'role' => Role::APP_USER, ); - $this->assertFalse($h->isProjectAdministrationAllowed(1)); + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertFalse($helper->hasProjectAccess('board', 'show', 1)); } - public function testIsProjectAdministrationAllowedForProjectManager() + public function testHasProjectAccessForAppManagerAndProjectManagers() { - $h = new User($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new UserModel($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project member - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($pp->addManager(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertTrue($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( + $helper = new User($this->container); + $user = new UserModel($this->container); + $project = new Project($this->container); + $projectUserRole = new ProjectUserRole($this->container); + + $this->container['sessionStorage']->user = array( 'id' => 2, - 'is_admin' => false, - 'is_project_admin' => false, + 'role' => Role::APP_MANAGER, ); - $this->assertFalse($h->isProjectAdministrationAllowed(1)); + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $user->create(array('username' => 'user'))); + $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MANAGER)); + + $this->assertTrue($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('taskcreation', 'save', 1)); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 2)); } - public function testIsProjectManagementAllowedForProjectAdmin() + public function testHasProjectAccessForProjectManagers() { - $h = new User($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new UserModel($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project manager - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertFalse($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( + $helper = new User($this->container); + $user = new UserModel($this->container); + $project = new Project($this->container); + $projectUserRole = new ProjectUserRole($this->container); + + $this->container['sessionStorage']->user = array( 'id' => 2, - 'is_admin' => false, - 'is_project_admin' => true, + 'role' => Role::APP_USER, ); - $this->assertTrue($h->isProjectManagementAllowed(1)); + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $user->create(array('username' => 'user'))); + $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MANAGER)); + + $this->assertTrue($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('taskcreation', 'save', 1)); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 2)); } - public function testIsProjectManagementAllowedForProjectMember() + public function testHasProjectAccessForProjectMembers() { - $h = new User($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new UserModel($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project member - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertFalse($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( + $helper = new User($this->container); + $user = new UserModel($this->container); + $project = new Project($this->container); + $projectUserRole = new ProjectUserRole($this->container); + + $this->container['sessionStorage']->user = array( 'id' => 2, - 'is_admin' => false, - 'is_project_admin' => false, + 'role' => Role::APP_USER, ); - $this->assertFalse($h->isProjectManagementAllowed(1)); + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $user->create(array('username' => 'user'))); + $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MEMBER)); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('taskcreation', 'save', 1)); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 2)); } - public function testIsProjectManagementAllowedForProjectManager() + public function testHasProjectAccessForProjectViewers() { - $h = new User($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new UserModel($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project member - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($pp->addManager(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertTrue($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( + $helper = new User($this->container); + $user = new UserModel($this->container); + $project = new Project($this->container); + $projectUserRole = new ProjectUserRole($this->container); + + $this->container['sessionStorage']->user = array( 'id' => 2, - 'is_admin' => false, - 'is_project_admin' => false, + 'role' => Role::APP_USER, ); - $this->assertTrue($h->isProjectManagementAllowed(1)); + $this->assertEquals(1, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $project->create(array('name' => 'My project'))); + $this->assertEquals(2, $user->create(array('username' => 'user'))); + $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_VIEWER)); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 1)); + $this->assertTrue($helper->hasProjectAccess('board', 'show', 1)); + $this->assertTrue($helper->hasProjectAccess('task', 'show', 1)); + $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 1)); + + $this->assertFalse($helper->hasProjectAccess('ProjectEdit', 'edit', 2)); + $this->assertFalse($helper->hasProjectAccess('board', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('task', 'show', 2)); + $this->assertFalse($helper->hasProjectAccess('taskcreation', 'save', 2)); } } diff --git a/tests/units/Integration/BitbucketWebhookTest.php b/tests/units/Integration/BitbucketWebhookTest.php deleted file mode 100644 index 1a3b005b..00000000 --- a/tests/units/Integration/BitbucketWebhookTest.php +++ /dev/null @@ -1,398 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Integration\BitbucketWebhook; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; -use Kanboard\Model\User; - -class BitbucketWebhookTest extends Base -{ - public function testHandlePush() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_COMMIT, array($this, 'onCommit')); - - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $bw = new BitbucketWebhook($this->container); - $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_push.json'), true); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $bw->setProjectId(1); - - // No task - $this->assertFalse($bw->handlePush($payload)); - - // Create task with the wrong id - $this->assertEquals(1, $tc->create(array('title' => 'test1', 'project_id' => 1))); - $this->assertFalse($bw->handlePush($payload)); - - // Create task with the right id - $this->assertEquals(2, $tc->create(array('title' => 'test2', 'project_id' => 1))); - $this->assertTrue($bw->handlePush($payload)); - - $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(BitbucketWebhook::EVENT_COMMIT.'.BitbucketWebhookTest::onCommit', $called); - } - - public function testIssueOpened() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_OPENED, array($this, 'onIssueOpened')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $bw = new BitbucketWebhook($this->container); - $bw->setProjectId(1); - - $this->assertNotFalse($bw->parsePayload( - 'issue:created', - json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_opened.json'), true) - )); - } - - public function testCommentCreatedWithNoUser() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNoUser')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:comment_created', - json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_comment_created.json'), true) - )); - } - - public function testCommentCreatedWithNotMember() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNotMember')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:comment_created', - json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_comment_created.json'), true) - )); - } - - public function testCommentCreatedWithUser() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); - - $pp = new ProjectPermission($this->container); - $this->assertTrue($pp->addMember(1, 2)); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:comment_created', - json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_comment_created.json'), true) - )); - } - - public function testIssueClosed() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_CLOSED, array($this, 'onIssueClosed')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_closed.json'), true) - )); - } - - public function testIssueClosedWithNoTask() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_CLOSED, array($this, 'onIssueClosed')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 42, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_closed.json'), true) - )); - - $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); - } - - public function testIssueReopened() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_REOPENED, array($this, 'onIssueReopened')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_reopened.json'), true) - )); - } - - public function testIssueReopenedWithNoTask() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_REOPENED, array($this, 'onIssueReopened')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 42, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_reopened.json'), true) - )); - - $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); - } - - public function testIssueUnassigned() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueUnassigned')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_unassigned.json'), true) - )); - } - - public function testIssueAssigned() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueAssigned')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); - - $pp = new ProjectPermission($this->container); - $this->assertTrue($pp->addMember(1, 2)); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_assigned.json'), true) - )); - - $this->assertNotEmpty($this->container['dispatcher']->getCalledListeners()); - } - - public function testIssueAssignedWithNoPermission() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, function () {}); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_assigned.json'), true) - )); - - $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); - } - - public function testIssueAssignedWithNoUser() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, function () {}); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_assigned.json'), true) - )); - - $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); - } - - public function testIssueAssignedWithNoTask() - { - $this->container['dispatcher']->addListener(BitbucketWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, function () {}); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 43, 'project_id' => 1))); - - $g = new BitbucketWebhook($this->container); - $g->setProjectId(1); - - $this->assertFalse($g->parsePayload( - 'issue:updated', - json_decode(file_get_contents(__DIR__.'/../fixtures/bitbucket_issue_assigned.json'), true) - )); - - $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); - } - - public function onCommit($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(2, $data['task_id']); - $this->assertEquals('test2', $data['title']); - $this->assertEquals("Test another commit #2\n\n\n[Commit made by @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6)", $data['commit_comment']); - $this->assertEquals("Test another commit #2\n", $data['commit_message']); - $this->assertEquals('https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6', $data['commit_url']); - } - - public function onIssueOpened($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['reference']); - $this->assertEquals('My new issue', $data['title']); - $this->assertEquals("**test**\n\n[Bitbucket Issue](https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue)", $data['description']); - } - - public function onCommentCreatedWithNoUser($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(0, $data['user_id']); - $this->assertEquals(19176252, $data['reference']); - $this->assertEquals("1. step1\n2. step2\n\n[By @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252)", $data['comment']); - } - - public function onCommentCreatedWithNotMember($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(0, $data['user_id']); - $this->assertEquals(19176252, $data['reference']); - $this->assertEquals("1. step1\n2. step2\n\n[By @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252)", $data['comment']); - } - - public function onCommentCreatedWithUser($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(2, $data['user_id']); - $this->assertEquals(19176252, $data['reference']); - $this->assertEquals("1. step1\n2. step2\n\n[By @Frederic Guillot on Bitbucket](https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252)", $data['comment']); - } - - public function onIssueClosed($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(1, $data['reference']); - } - - public function onIssueReopened($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(1, $data['reference']); - } - - public function onIssueAssigned($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(1, $data['reference']); - $this->assertEquals(2, $data['owner_id']); - } - - public function onIssueUnassigned($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(1, $data['reference']); - $this->assertEquals(0, $data['owner_id']); - } -} diff --git a/tests/units/Integration/GithubWebhookTest.php b/tests/units/Integration/GithubWebhookTest.php deleted file mode 100644 index d64e783e..00000000 --- a/tests/units/Integration/GithubWebhookTest.php +++ /dev/null @@ -1,459 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Integration\GithubWebhook; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; -use Kanboard\Model\User; - -class GithubWebhookTest extends Base -{ - public function testIssueOpened() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_OPENED, array($this, 'onIssueOpened')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_opened.json'), true) - )); - } - - public function testIssueAssigned() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueAssigned')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); - - $pp = new ProjectPermission($this->container); - $this->assertTrue($pp->addMember(1, 2)); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true) - )); - } - - public function testIssueAssignedWithNoExistingTask() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true); - - $this->assertFalse($g->handleIssueAssigned($payload['issue'])); - } - - public function testIssueAssignedWithNoExistingUser() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true); - - $this->assertFalse($g->handleIssueAssigned($payload['issue'])); - } - - public function testIssueAssignedWithNoMember() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true); - - $this->assertFalse($g->handleIssueAssigned($payload['issue'])); - } - - public function testIssueAssignedWithMember() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); - - $pp = new ProjectPermission($this->container); - $this->assertTrue($pp->addMember(1, 2)); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_assigned.json'), true); - - $this->assertTrue($g->handleIssueAssigned($payload['issue'])); - } - - public function testIssueUnassigned() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_ASSIGNEE_CHANGE, array($this, 'onIssueUnassigned')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_unassigned.json'), true) - )); - } - - public function testIssueClosed() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_CLOSED, array($this, 'onIssueClosed')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_closed.json'), true) - )); - } - - public function testIssueClosedWithTaskNotFound() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_closed.json'), true); - - $this->assertFalse($g->handleIssueClosed($payload['issue'])); - } - - public function testIssueReopened() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_REOPENED, array($this, 'onIssueReopened')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_reopened.json'), true) - )); - } - - public function testIssueReopenedWithTaskNotFound() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_reopened.json'), true); - - $this->assertFalse($g->handleIssueReopened($payload['issue'])); - } - - public function testIssueLabeled() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_LABEL_CHANGE, array($this, 'onIssueLabeled')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_labeled.json'), true) - )); - } - - public function testIssueLabeledWithTaskNotFound() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_labeled.json'), true); - - $this->assertFalse($g->handleIssueLabeled($payload['issue'], $payload['label'])); - } - - public function testIssueUnLabeled() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_LABEL_CHANGE, array($this, 'onIssueUnlabeled')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issues', - json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_unlabeled.json'), true) - )); - } - - public function testIssueUnLabeledWithTaskNotFound() - { - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $payload = json_decode(file_get_contents(__DIR__.'/../fixtures/github_issue_unlabeled.json'), true); - - $this->assertFalse($g->handleIssueUnlabeled($payload['issue'], $payload['label'])); - } - - public function testCommentCreatedWithNoUser() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNoUser')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue_comment', - json_decode(file_get_contents(__DIR__.'/../fixtures/github_comment_created.json'), true) - )); - } - - public function testCommentCreatedWithNotMember() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNotMember')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue_comment', - json_decode(file_get_contents(__DIR__.'/../fixtures/github_comment_created.json'), true) - )); - } - - public function testCommentCreatedWithUser() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 3, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'fguillot'))); - - $pp = new ProjectPermission($this->container); - $this->assertTrue($pp->addMember(1, 2)); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'issue_comment', - json_decode(file_get_contents(__DIR__.'/../fixtures/github_comment_created.json'), true) - )); - } - - public function testPush() - { - $this->container['dispatcher']->addListener(GithubWebhook::EVENT_COMMIT, array($this, 'onPush')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'project_id' => 1))); - - $g = new GithubWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - 'push', - json_decode(file_get_contents(__DIR__.'/../fixtures/github_push.json'), true) - )); - } - - public function onIssueOpened($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(3, $data['reference']); - $this->assertEquals('Test Webhook', $data['title']); - $this->assertEquals("plop\n\n[Github Issue](https://github.com/kanboardapp/webhook/issues/3)", $data['description']); - } - - public function onIssueAssigned($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(3, $data['reference']); - $this->assertEquals(2, $data['owner_id']); - } - - public function onIssueUnassigned($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(3, $data['reference']); - $this->assertEquals(0, $data['owner_id']); - } - - public function onIssueClosed($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(3, $data['reference']); - } - - public function onIssueReopened($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(3, $data['reference']); - } - - public function onIssueLabeled($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(3, $data['reference']); - $this->assertEquals('bug', $data['label']); - } - - public function onIssueUnlabeled($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(3, $data['reference']); - $this->assertEquals('bug', $data['label']); - $this->assertEquals(0, $data['category_id']); - } - - public function onCommentCreatedWithNoUser($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(0, $data['user_id']); - $this->assertEquals(113834672, $data['reference']); - $this->assertEquals("test\n\n[By @fguillot on Github](https://github.com/kanboardapp/webhook/issues/3#issuecomment-113834672)", $data['comment']); - } - - public function onCommentCreatedWithNotMember($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(0, $data['user_id']); - $this->assertEquals(113834672, $data['reference']); - $this->assertEquals("test\n\n[By @fguillot on Github](https://github.com/kanboardapp/webhook/issues/3#issuecomment-113834672)", $data['comment']); - } - - public function onCommentCreatedWithUser($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(2, $data['user_id']); - $this->assertEquals(113834672, $data['reference']); - $this->assertEquals("test\n\n[By @fguillot on Github](https://github.com/kanboardapp/webhook/issues/3#issuecomment-113834672)", $data['comment']); - } - - public function onPush($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals('boo', $data['title']); - $this->assertEquals("Update README to fix #1\n\n[Commit made by @fguillot on Github](https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6)", $data['commit_comment']); - $this->assertEquals('Update README to fix #1', $data['commit_message']); - $this->assertEquals('https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6', $data['commit_url']); - } -} diff --git a/tests/units/Integration/GitlabWebhookTest.php b/tests/units/Integration/GitlabWebhookTest.php deleted file mode 100644 index 6d37819b..00000000 --- a/tests/units/Integration/GitlabWebhookTest.php +++ /dev/null @@ -1,221 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Integration\GitlabWebhook; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; -use Kanboard\Model\User; - -class GitlabWebhookTest extends Base -{ - public function testGetEventType() - { - $g = new GitlabWebhook($this->container); - - $this->assertEquals(GitlabWebhook::TYPE_PUSH, $g->getType(json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_push.json'), true))); - $this->assertEquals(GitlabWebhook::TYPE_ISSUE, $g->getType(json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_issue_opened.json'), true))); - $this->assertEquals(GitlabWebhook::TYPE_COMMENT, $g->getType(json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_comment_created.json'), true))); - $this->assertEquals('', $g->getType(array())); - } - - public function testHandleCommit() - { - $g = new GitlabWebhook($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $g->setProjectId(1); - - $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_COMMIT, array($this, 'onCommit')); - - $event = json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_push.json'), true); - - // No task - $this->assertFalse($g->handleCommit($event['commits'][0])); - - // Create task with the wrong id - $this->assertEquals(1, $tc->create(array('title' => 'test1', 'project_id' => 1))); - $this->assertFalse($g->handleCommit($event['commits'][0])); - - // Create task with the right id - $this->assertEquals(2, $tc->create(array('title' => 'test2', 'project_id' => 1))); - $this->assertTrue($g->handleCommit($event['commits'][0])); - - $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(GitlabWebhook::EVENT_COMMIT.'.GitlabWebhookTest::onCommit', $called); - } - - public function testHandleIssueOpened() - { - $g = new GitlabWebhook($this->container); - $g->setProjectId(1); - - $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_OPENED, array($this, 'onOpen')); - - $event = json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_issue_opened.json'), true); - $this->assertTrue($g->handleIssueOpened($event['object_attributes'])); - - $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(GitlabWebhook::EVENT_ISSUE_OPENED.'.GitlabWebhookTest::onOpen', $called); - } - - public function testHandleIssueClosed() - { - $g = new GitlabWebhook($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $g->setProjectId(1); - - $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_CLOSED, array($this, 'onClose')); - - $event = json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_issue_closed.json'), true); - - // Issue not there - $this->assertFalse($g->handleIssueClosed($event['object_attributes'])); - - $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertEmpty($called); - - // Create a task with the issue reference - $this->assertEquals(1, $tc->create(array('title' => 'A', 'project_id' => 1, 'reference' => 355691))); - $task = $tf->getByReference(1, 355691); - $this->assertNotEmpty($task); - - $task = $tf->getByReference(2, 355691); - $this->assertEmpty($task); - - $this->assertTrue($g->handleIssueClosed($event['object_attributes'])); - - $called = $this->container['dispatcher']->getCalledListeners(); - $this->assertArrayHasKey(GitlabWebhook::EVENT_ISSUE_CLOSED.'.GitlabWebhookTest::onClose', $called); - } - - public function testCommentCreatedWithNoUser() - { - $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNoUser')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 355691, 'project_id' => 1))); - - $g = new GitlabWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_comment_created.json'), true) - )); - } - - public function testCommentCreatedWithNotMember() - { - $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithNotMember')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 355691, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); - - $g = new GitlabWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_comment_created.json'), true) - )); - } - - public function testCommentCreatedWithUser() - { - $this->container['dispatcher']->addListener(GitlabWebhook::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser')); - - $p = new Project($this->container); - $this->assertEquals(1, $p->create(array('name' => 'foobar'))); - - $tc = new TaskCreation($this->container); - $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 355691, 'project_id' => 1))); - - $u = new User($this->container); - $this->assertEquals(2, $u->create(array('username' => 'minicoders'))); - - $pp = new ProjectPermission($this->container); - $this->assertTrue($pp->addMember(1, 2)); - - $g = new GitlabWebhook($this->container); - $g->setProjectId(1); - - $this->assertNotFalse($g->parsePayload( - json_decode(file_get_contents(__DIR__.'/../fixtures/gitlab_comment_created.json'), true) - )); - } - - public function onOpen($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(355691, $data['reference']); - $this->assertEquals('Bug', $data['title']); - $this->assertEquals("There is a bug somewhere.\r\n\r\nBye\n\n[Gitlab Issue](https://gitlab.com/minicoders/test-webhook/issues/1)", $data['description']); - } - - public function onClose($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(355691, $data['reference']); - } - - public function onCommit($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(2, $data['task_id']); - $this->assertEquals('test2', $data['title']); - $this->assertEquals("Fix bug #2\n\n[Commit made by @Fred on Gitlab](https://gitlab.com/minicoders/test-webhook/commit/48aafa75eef9ad253aa254b0c82c987a52ebea78)", $data['commit_comment']); - $this->assertEquals("Fix bug #2", $data['commit_message']); - $this->assertEquals('https://gitlab.com/minicoders/test-webhook/commit/48aafa75eef9ad253aa254b0c82c987a52ebea78', $data['commit_url']); - } - - public function onCommentCreatedWithNoUser($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(0, $data['user_id']); - $this->assertEquals(1642761, $data['reference']); - $this->assertEquals("Super comment!\n\n[By @minicoders on Gitlab](https://gitlab.com/minicoders/test-webhook/issues/1#note_1642761)", $data['comment']); - } - - public function onCommentCreatedWithNotMember($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(0, $data['user_id']); - $this->assertEquals(1642761, $data['reference']); - $this->assertEquals("Super comment!\n\n[By @minicoders on Gitlab](https://gitlab.com/minicoders/test-webhook/issues/1#note_1642761)", $data['comment']); - } - - public function onCommentCreatedWithUser($event) - { - $data = $event->getAll(); - $this->assertEquals(1, $data['project_id']); - $this->assertEquals(1, $data['task_id']); - $this->assertEquals(2, $data['user_id']); - $this->assertEquals(1642761, $data['reference']); - $this->assertEquals("Super comment!\n\n[By @minicoders on Gitlab](https://gitlab.com/minicoders/test-webhook/issues/1#note_1642761)", $data['comment']); - } -} diff --git a/tests/units/Model/AclTest.php b/tests/units/Model/AclTest.php deleted file mode 100644 index 28687a5c..00000000 --- a/tests/units/Model/AclTest.php +++ /dev/null @@ -1,308 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Core\Session; -use Kanboard\Model\Acl; -use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; -use Kanboard\Model\User; - -class AclTest extends Base -{ - public function testMatchAcl() - { - $acl_rules = array( - 'controller1' => array('action1', 'action3'), - 'controller3' => '*', - 'controller5' => '-', - 'controller6' => array(), - 'controllera' => '*', - ); - - $acl = new Acl($this->container); - $this->assertTrue($acl->matchAcl($acl_rules, 'controller1', 'aCtiOn1')); - $this->assertTrue($acl->matchAcl($acl_rules, 'controller1', 'action1')); - $this->assertTrue($acl->matchAcl($acl_rules, 'controller1', 'action3')); - $this->assertFalse($acl->matchAcl($acl_rules, 'controller1', 'action2')); - $this->assertFalse($acl->matchAcl($acl_rules, 'controller2', 'action2')); - $this->assertFalse($acl->matchAcl($acl_rules, 'controller2', 'action3')); - $this->assertTrue($acl->matchAcl($acl_rules, 'controller3', 'anything')); - $this->assertFalse($acl->matchAcl($acl_rules, 'controller4', 'anything')); - $this->assertFalse($acl->matchAcl($acl_rules, 'controller5', 'anything')); - $this->assertFalse($acl->matchAcl($acl_rules, 'controller6', 'anything')); - $this->assertTrue($acl->matchAcl($acl_rules, 'ControllerA', 'anything')); - $this->assertTrue($acl->matchAcl($acl_rules, 'controllera', 'anything')); - } - - public function testPublicActions() - { - $acl = new Acl($this->container); - $this->assertTrue($acl->isPublicAction('task', 'readonly')); - $this->assertTrue($acl->isPublicAction('board', 'readonly')); - $this->assertFalse($acl->isPublicAction('board', 'show')); - $this->assertTrue($acl->isPublicAction('feed', 'project')); - $this->assertTrue($acl->isPublicAction('feed', 'user')); - $this->assertTrue($acl->isPublicAction('ical', 'project')); - $this->assertTrue($acl->isPublicAction('ical', 'user')); - $this->assertTrue($acl->isPublicAction('oauth', 'github')); - $this->assertTrue($acl->isPublicAction('oauth', 'google')); - $this->assertTrue($acl->isPublicAction('auth', 'login')); - $this->assertTrue($acl->isPublicAction('auth', 'check')); - $this->assertTrue($acl->isPublicAction('auth', 'captcha')); - } - - public function testAdminActions() - { - $acl = new Acl($this->container); - $this->assertFalse($acl->isAdminAction('board', 'show')); - $this->assertFalse($acl->isAdminAction('task', 'show')); - $this->assertTrue($acl->isAdminAction('config', 'api')); - $this->assertTrue($acl->isAdminAction('config', 'anything')); - $this->assertTrue($acl->isAdminAction('config', 'anything')); - $this->assertTrue($acl->isAdminAction('user', 'save')); - } - - public function testProjectAdminActions() - { - $acl = new Acl($this->container); - $this->assertFalse($acl->isProjectAdminAction('config', 'save')); - $this->assertFalse($acl->isProjectAdminAction('user', 'index')); - $this->assertTrue($acl->isProjectAdminAction('project', 'remove')); - } - - public function testProjectManagerActions() - { - $acl = new Acl($this->container); - $this->assertFalse($acl->isProjectManagerAction('board', 'readonly')); - $this->assertFalse($acl->isProjectManagerAction('project', 'remove')); - $this->assertFalse($acl->isProjectManagerAction('project', 'show')); - $this->assertTrue($acl->isProjectManagerAction('project', 'disable')); - $this->assertTrue($acl->isProjectManagerAction('category', 'index')); - $this->assertTrue($acl->isProjectManagerAction('project', 'users')); - $this->assertFalse($acl->isProjectManagerAction('app', 'index')); - } - - public function testPageAccessNoSession() - { - $acl = new Acl($this->container); - $session = new Session; - $session = array(); - - $this->assertFalse($acl->isAllowed('board', 'readonly')); - $this->assertFalse($acl->isAllowed('task', 'show')); - $this->assertFalse($acl->isAllowed('config', 'application')); - $this->assertFalse($acl->isAllowed('project', 'users')); - $this->assertFalse($acl->isAllowed('task', 'remove')); - $this->assertTrue($acl->isAllowed('app', 'index')); - } - - public function testPageAccessEmptySession() - { - $acl = new Acl($this->container); - $session = new Session; - $session['user'] = array(); - - $this->assertFalse($acl->isAllowed('board', 'readonly')); - $this->assertFalse($acl->isAllowed('task', 'show')); - $this->assertFalse($acl->isAllowed('config', 'application')); - $this->assertFalse($acl->isAllowed('project', 'users')); - $this->assertFalse($acl->isAllowed('task', 'remove')); - $this->assertTrue($acl->isAllowed('app', 'index')); - } - - public function testPageAccessAdminUser() - { - $acl = new Acl($this->container); - $session = new Session; - - $session['user'] = array( - 'is_admin' => true, - ); - - $this->assertTrue($acl->isAllowed('board', 'readonly')); - $this->assertTrue($acl->isAllowed('task', 'readonly')); - $this->assertTrue($acl->isAllowed('webhook', 'github')); - $this->assertTrue($acl->isAllowed('task', 'show')); - $this->assertTrue($acl->isAllowed('task', 'update')); - $this->assertTrue($acl->isAllowed('config', 'application')); - $this->assertTrue($acl->isAllowed('project', 'show')); - $this->assertTrue($acl->isAllowed('project', 'users')); - $this->assertTrue($acl->isAllowed('project', 'remove')); - $this->assertTrue($acl->isAllowed('category', 'edit')); - $this->assertTrue($acl->isAllowed('task', 'remove')); - $this->assertTrue($acl->isAllowed('app', 'index')); - } - - public function testPageAccessProjectAdmin() - { - $acl = new Acl($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new User($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project manager - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertFalse($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( - 'id' => 2, - 'is_admin' => false, - 'is_project_admin' => true, - ); - - $this->assertTrue($acl->isAllowed('board', 'readonly', 1)); - $this->assertTrue($acl->isAllowed('task', 'readonly', 1)); - $this->assertTrue($acl->isAllowed('webhook', 'github', 1)); - $this->assertTrue($acl->isAllowed('task', 'show', 1)); - $this->assertFalse($acl->isAllowed('task', 'show', 2)); - $this->assertTrue($acl->isAllowed('task', 'update', 1)); - $this->assertTrue($acl->isAllowed('project', 'show', 1)); - $this->assertFalse($acl->isAllowed('config', 'application', 1)); - - $this->assertTrue($acl->isAllowed('project', 'users', 1)); - $this->assertFalse($acl->isAllowed('project', 'users', 2)); - - $this->assertTrue($acl->isAllowed('project', 'remove', 1)); - $this->assertFalse($acl->isAllowed('project', 'remove', 2)); - - $this->assertTrue($acl->isAllowed('category', 'edit', 1)); - $this->assertTrue($acl->isAllowed('task', 'remove', 1)); - $this->assertTrue($acl->isAllowed('app', 'index', 1)); - } - - public function testPageAccessProjectManager() - { - $acl = new Acl($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new User($this->container); - $session = new Session; - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as project manager - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'), 2, true)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertTrue($pp->isManager(1, 2)); - - // We fake a session for him - $session['user'] = array( - 'id' => 2, - 'is_admin' => false, - ); - - $this->assertTrue($acl->isAllowed('board', 'readonly', 1)); - $this->assertTrue($acl->isAllowed('task', 'readonly', 1)); - $this->assertTrue($acl->isAllowed('webhook', 'github', 1)); - $this->assertTrue($acl->isAllowed('task', 'show', 1)); - $this->assertFalse($acl->isAllowed('task', 'show', 2)); - $this->assertTrue($acl->isAllowed('task', 'update', 1)); - $this->assertTrue($acl->isAllowed('project', 'show', 1)); - $this->assertFalse($acl->isAllowed('config', 'application', 1)); - - $this->assertTrue($acl->isAllowed('project', 'users', 1)); - $this->assertFalse($acl->isAllowed('project', 'users', 2)); - - $this->assertFalse($acl->isAllowed('project', 'remove', 1)); - $this->assertFalse($acl->isAllowed('project', 'remove', 2)); - - $this->assertTrue($acl->isAllowed('category', 'edit', 1)); - $this->assertTrue($acl->isAllowed('task', 'remove', 1)); - $this->assertTrue($acl->isAllowed('app', 'index', 1)); - } - - public function testPageAccessMember() - { - $acl = new Acl($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new User($this->container); - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as member - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); - $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertFalse($pp->isManager(1, 2)); - - $session = new Session; - - $session['user'] = array( - 'id' => 2, - 'is_admin' => false, - ); - - $this->assertTrue($acl->isAllowed('board', 'readonly', 1)); - $this->assertTrue($acl->isAllowed('task', 'readonly', 1)); - $this->assertTrue($acl->isAllowed('webhook', 'github', 1)); - $this->assertFalse($acl->isAllowed('board', 'show', 2)); - $this->assertTrue($acl->isAllowed('board', 'show', 1)); - $this->assertFalse($acl->isAllowed('task', 'show', 2)); - $this->assertTrue($acl->isAllowed('task', 'show', 1)); - $this->assertTrue($acl->isAllowed('task', 'update', 1)); - $this->assertTrue($acl->isAllowed('project', 'show', 1)); - $this->assertFalse($acl->isAllowed('config', 'application', 1)); - $this->assertFalse($acl->isAllowed('project', 'users', 1)); - $this->assertTrue($acl->isAllowed('task', 'remove', 1)); - $this->assertFalse($acl->isAllowed('task', 'remove', 2)); - $this->assertTrue($acl->isAllowed('app', 'index', 1)); - } - - public function testPageAccessNotMember() - { - $acl = new Acl($this->container); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new User($this->container); - - // We create our user - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project and set our user as member - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); - $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); - $this->assertFalse($pp->isMember(1, 2)); - $this->assertFalse($pp->isManager(1, 2)); - - $session = new Session; - - $session['user'] = array( - 'id' => 2, - 'is_admin' => false, - ); - - $this->assertFalse($acl->isAllowed('board', 'show', 2)); - $this->assertFalse($acl->isAllowed('board', 'show', 1)); - $this->assertFalse($acl->isAllowed('task', 'show', 1)); - $this->assertFalse($acl->isAllowed('task', 'update', 1)); - $this->assertFalse($acl->isAllowed('project', 'show', 1)); - $this->assertFalse($acl->isAllowed('config', 'application', 1)); - $this->assertFalse($acl->isAllowed('project', 'users', 1)); - $this->assertFalse($acl->isAllowed('task', 'remove', 1)); - $this->assertTrue($acl->isAllowed('app', 'index', 1)); - } - - public function testExtend() - { - $acl = new Acl($this->container); - - $this->assertFalse($acl->isProjectManagerAction('plop', 'show')); - - $acl->extend('project_manager_acl', array('plop' => '*')); - - $this->assertTrue($acl->isProjectManagerAction('plop', 'show')); - $this->assertTrue($acl->isProjectManagerAction('swimlane', 'index')); - } -} diff --git a/tests/units/Model/ActionTest.php b/tests/units/Model/ActionTest.php index 30f6b22c..ed687846 100644 --- a/tests/units/Model/ActionTest.php +++ b/tests/units/Model/ActionTest.php @@ -4,387 +4,506 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Model\Action; use Kanboard\Model\Project; -use Kanboard\Model\Board; use Kanboard\Model\Task; -use Kanboard\Model\TaskPosition; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Category; use Kanboard\Model\User; -use Kanboard\Model\ProjectPermission; -use Kanboard\Integration\GithubWebhook; -use Kanboard\Integration\BitbucketWebhook; +use Kanboard\Model\Column; +use Kanboard\Model\Category; +use Kanboard\Model\ProjectUserRole; +use Kanboard\Core\Security\Role; class ActionTest extends Base { - public function testGetActions() + public function testCreate() { - $a = new Action($this->container); + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); - $actions = $a->getAvailableActions(); - $this->assertNotEmpty($actions); - $this->assertEquals('Add a comment log when moving the task between columns', current($actions)); - $this->assertEquals('TaskLogMoveAnotherColumn', key($actions)); + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); } - public function testExtendActions() + public function testRemove() { - $a = new Action($this->container); - $a->extendActions('MyClass', 'Description'); + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); - $actions = $a->getAvailableActions(); - $this->assertNotEmpty($actions); - $this->assertContains('Description', $actions); - $this->assertArrayHasKey('MyClass', $actions); + $this->assertNotEmpty($actionModel->getById(1)); + $this->assertTrue($actionModel->remove(1)); + $this->assertEmpty($actionModel->getById(1)); } - public function testGetEvents() + public function testGetById() { - $a = new Action($this->container); + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); - $events = $a->getAvailableEvents(); - $this->assertNotEmpty($events); - $this->assertEquals('Bitbucket commit received', current($events)); - $this->assertEquals(BitbucketWebhook::EVENT_COMMIT, key($events)); + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $action = $actionModel->getById(1); + $this->assertNotEmpty($action); + $this->assertEquals(1, $action['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $action['action_name']); + $this->assertEquals(Task::EVENT_CREATE, $action['event_name']); + $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $action['params']); } - public function testGetCompatibleEvents() + public function testGetAll() { - $a = new Action($this->container); - $events = $a->getCompatibleEvents('TaskAssignSpecificUser'); + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - $this->assertNotEmpty($events); - $this->assertCount(2, $events); - $this->assertArrayHasKey(Task::EVENT_CREATE_UPDATE, $events); - $this->assertArrayHasKey(Task::EVENT_MOVE_COLUMN, $events); + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $this->assertEquals(2, $actionModel->create(array( + 'project_id' => 2, + 'event_name' => Task::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 6, 'color_id' => 'blue'), + ))); + + $actions = $actionModel->getAll(); + $this->assertCount(2, $actions); + + $this->assertEquals(1, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); + + $this->assertEquals(2, $actions[1]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[1]['action_name']); + $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[1]['event_name']); + $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[1]['params']); } - public function testResolveDuplicatedParameters() + public function testGetAllByProject() { - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $a = new Action($this->container); - $c = new Category($this->container); - $u = new User($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'P1'))); - $this->assertEquals(2, $p->create(array('name' => 'P2'))); - - $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1))); - - $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 2))); - $this->assertEquals(3, $c->create(array('name' => 'C1', 'project_id' => 2))); - - $this->assertEquals(2, $u->create(array('username' => 'unittest1'))); - $this->assertEquals(3, $u->create(array('username' => 'unittest2'))); - - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->addMember(1, 3)); - $this->assertTrue($pp->addMember(2, 3)); - - // anything - $this->assertEquals('blah', $a->resolveParameters(array('name' => 'foobar', 'value' => 'blah'), 2)); - - // project_id - $this->assertEquals(2, $a->resolveParameters(array('name' => 'project_id', 'value' => 'blah'), 2)); - - // category_id - $this->assertEquals(3, $a->resolveParameters(array('name' => 'category_id', 'value' => 1), 2)); - $this->assertFalse($a->resolveParameters(array('name' => 'category_id', 'value' => 0), 2)); - $this->assertFalse($a->resolveParameters(array('name' => 'category_id', 'value' => 5), 2)); - - // column_id - $this->assertFalse($a->resolveParameters(array('name' => 'column_id', 'value' => 10), 2)); - $this->assertFalse($a->resolveParameters(array('name' => 'column_id', 'value' => 0), 2)); - $this->assertEquals(5, $a->resolveParameters(array('name' => 'column_id', 'value' => 1), 2)); - $this->assertEquals(6, $a->resolveParameters(array('name' => 'dest_column_id', 'value' => 2), 2)); - $this->assertEquals(7, $a->resolveParameters(array('name' => 'dst_column_id', 'value' => 3), 2)); - $this->assertEquals(8, $a->resolveParameters(array('name' => 'src_column_id', 'value' => 4), 2)); - - // user_id - $this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 10), 2)); - $this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 0), 2)); - $this->assertFalse($a->resolveParameters(array('name' => 'user_id', 'value' => 2), 2)); - $this->assertFalse($a->resolveParameters(array('name' => 'owner_id', 'value' => 2), 2)); - $this->assertEquals(3, $a->resolveParameters(array('name' => 'user_id', 'value' => 3), 2)); - $this->assertEquals(3, $a->resolveParameters(array('name' => 'owner_id', 'value' => 3), 2)); + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); + + $this->assertEquals(2, $actionModel->create(array( + 'project_id' => 2, + 'event_name' => Task::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 6, 'color_id' => 'blue'), + ))); + + $actions = $actionModel->getAllByProject(1); + $this->assertCount(1, $actions); + + $this->assertEquals(1, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); + + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']); } - public function testDuplicateSuccess() + public function testGetAllByUser() { - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $a = new Action($this->container); - $u = new User($this->container); + $projectModel = new Project($this->container); + $projectUserRoleModel = new ProjectUserRole($this->container); + $userModel = new User($this->container); + $actionModel = new Action($this->container); - $this->assertEquals(1, $p->create(array('name' => 'P1'))); - $this->assertEquals(2, $p->create(array('name' => 'P2'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + $this->assertEquals(3, $projectModel->create(array('name' => 'test4', 'is_active' => 0))); - $this->assertEquals(2, $u->create(array('username' => 'unittest1'))); - $this->assertEquals(3, $u->create(array('username' => 'unittest2'))); + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->addMember(1, 3)); - $this->assertTrue($pp->addMember(2, 3)); + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_VIEWER)); + $this->assertTrue($projectUserRoleModel->addUser(2, 3, Role::PROJECT_MANAGER)); + $this->assertTrue($projectUserRoleModel->addUser(3, 3, Role::PROJECT_MANAGER)); - $this->assertEquals(1, $a->create(array( + $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE_UPDATE, - 'action_name' => 'TaskAssignSpecificUser', - 'params' => array( - 'column_id' => 1, - 'user_id' => 3, - ) + 'event_name' => Task::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), ))); - $action = $a->getById(1); - $this->assertNotEmpty($action); - $this->assertNotEmpty($action['params']); - $this->assertEquals(1, $action['project_id']); + $this->assertEquals(2, $actionModel->create(array( + 'project_id' => 2, + 'event_name' => Task::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 6, 'color_id' => 'blue'), + ))); - $this->assertTrue($a->duplicate(1, 2)); + $this->assertEquals(3, $actionModel->create(array( + 'project_id' => 3, + 'event_name' => Task::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 10, 'color_id' => 'green'), + ))); - $action = $a->getById(2); - $this->assertNotEmpty($action); - $this->assertNotEmpty($action['params']); - $this->assertEquals(2, $action['project_id']); - $this->assertEquals(Task::EVENT_CREATE_UPDATE, $action['event_name']); - $this->assertEquals('TaskAssignSpecificUser', $action['action_name']); - $this->assertEquals('column_id', $action['params'][0]['name']); - $this->assertEquals(5, $action['params'][0]['value']); - $this->assertEquals('user_id', $action['params'][1]['name']); - $this->assertEquals(3, $action['params'][1]['value']); + $actions = $actionModel->getAllByUser(1); + $this->assertCount(0, $actions); + + $actions = $actionModel->getAllByUser(2); + $this->assertCount(1, $actions); + + $this->assertEquals(1, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 1, 'color_id' => 'red'), $actions[0]['params']); + + $actions = $actionModel->getAllByUser(3); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 6, 'color_id' => 'blue'), $actions[0]['params']); } - public function testDuplicateUnableToResolveParams() + public function testDuplicateWithColumnAndColorParameter() { - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $a = new Action($this->container); - $u = new User($this->container); + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); - $this->assertEquals(1, $p->create(array('name' => 'P1'))); - $this->assertEquals(2, $p->create(array('name' => 'P2'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - $this->assertEquals(2, $u->create(array('username' => 'unittest1'))); + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); - $this->assertTrue($pp->addMember(1, 2)); + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']); + } + + public function testDuplicateWithColumnsParameter() + { + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); - $this->assertEquals(1, $a->create(array( + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE_UPDATE, - 'action_name' => 'TaskAssignSpecificUser', - 'params' => array( - 'column_id' => 1, - 'user_id' => 2, - ) + 'event_name' => Task::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('src_column_id' => 1, 'dst_column_id' => 2, 'dest_column_id' => 3), ))); - $action = $a->getById(1); - $this->assertNotEmpty($action); - $this->assertNotEmpty($action['params']); - $this->assertEquals(1, $action['project_id']); - $this->assertEquals('user_id', $action['params'][1]['name']); - $this->assertEquals(2, $action['params'][1]['value']); + $this->assertTrue($actionModel->duplicate(1, 2)); - $this->assertTrue($a->duplicate(1, 2)); + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); - $action = $a->getById(2); - $this->assertEmpty($action); + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(array('src_column_id' => 5, 'dst_column_id' => 6, 'dest_column_id' => 7), $actions[0]['params']); } - public function testDuplicateMixedResults() + public function testDuplicateWithColumnParameterNotfound() { - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $a = new Action($this->container); - $u = new User($this->container); - $c = new Category($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'P1'))); - $this->assertEquals(2, $p->create(array('name' => 'P2'))); + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); + $columnModel = new Column($this->container); - $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1))); - $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 2))); - $this->assertEquals(3, $c->create(array('name' => 'C1', 'project_id' => 2))); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - $this->assertEquals(2, $u->create(array('username' => 'unittest1'))); + $this->assertTrue($columnModel->update(2, 'My unique column')); - $this->assertTrue($pp->addMember(1, 2)); + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CREATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 1, 'color_id' => 'red'), + ))); - $this->assertEquals(1, $a->create(array( + $this->assertEquals(2, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE_UPDATE, - 'action_name' => 'TaskAssignSpecificUser', - 'params' => array( - 'column_id' => 1, - 'user_id' => 2, - ) + 'event_name' => Task::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignColorColumn', + 'params' => array('column_id' => 2, 'color_id' => 'green'), ))); - $action = $a->getById(1); - $this->assertNotEmpty($action); - $this->assertNotEmpty($action['params']); + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorColumn', $actions[0]['action_name']); + $this->assertEquals(Task::EVENT_CREATE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 5, 'color_id' => 'red'), $actions[0]['params']); + } + + public function testDuplicateWithProjectParameter() + { + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); - $this->assertEquals(2, $a->create(array( + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + $this->assertEquals(3, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => Task::EVENT_CREATE_UPDATE, - 'action_name' => 'TaskAssignCategoryColor', - 'params' => array( - 'color_id' => 'blue', - 'category_id' => 1, - ) + 'event_name' => Task::EVENT_CLOSE, + 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject', + 'params' => array('column_id' => 1, 'project_id' => 3), ))); - $action = $a->getById(2); - $this->assertNotEmpty($action); - $this->assertNotEmpty($action['params']); - $this->assertEquals('category_id', $action['params'][1]['name']); - $this->assertEquals(1, $action['params'][1]['value']); + $this->assertTrue($actionModel->duplicate(1, 2)); - $actions = $a->getAllByProject(1); - $this->assertNotEmpty($actions); - $this->assertCount(2, $actions); + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); - $this->assertTrue($a->duplicate(1, 2)); + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskDuplicateAnotherProject', $actions[0]['action_name']); + $this->assertEquals(Task::EVENT_CLOSE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 5, 'project_id' => 3), $actions[0]['params']); + } - $actions = $a->getAllByProject(2); - $this->assertNotEmpty($actions); - $this->assertCount(1, $actions); + public function testDuplicateWithProjectParameterIdenticalToDestination() + { + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); - $actions = $a->getAll(); - $this->assertNotEmpty($actions); - $this->assertCount(3, $actions); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - $action = $a->getById($actions[2]['id']); - $this->assertNotEmpty($action); - $this->assertNotEmpty($action['params']); - $this->assertEquals('color_id', $action['params'][0]['name']); - $this->assertEquals('blue', $action['params'][0]['value']); - $this->assertEquals('category_id', $action['params'][1]['name']); - $this->assertEquals(3, $action['params'][1]['value']); + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_CLOSE, + 'action_name' => '\Kanboard\Action\TaskDuplicateAnotherProject', + 'params' => array('column_id' => 1, 'project_id' => 2), + ))); + + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(0, $actions); } - public function testSingleAction() + public function testDuplicateWithUserParameter() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $board = new Board($this->container); - $project = new Project($this->container); - $action = new Action($this->container); - - // We create a project - $this->assertEquals(1, $project->create(array('name' => 'unit_test'))); - - // We create a new action - $this->assertEquals(1, $action->create(array( + $projectUserRoleModel = new ProjectUserRole($this->container); + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_MEMBER)); + + $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, 'event_name' => Task::EVENT_MOVE_COLUMN, - 'action_name' => 'TaskClose', - 'params' => array( - 'column_id' => 4, - ) + 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', + 'params' => array('column_id' => 1, 'user_id' => 2), ))); - // We create a task - $this->assertEquals(1, $tc->create(array( - 'title' => 'unit_test', + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignSpecificUser', $actions[0]['action_name']); + $this->assertEquals(Task::EVENT_MOVE_COLUMN, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 5, 'user_id' => 2), $actions[0]['params']); + } + + public function testDuplicateWithUserParameterButNotAssignable() + { + $projectUserRoleModel = new ProjectUserRole($this->container); + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($projectUserRoleModel->addUser(2, 2, Role::PROJECT_VIEWER)); + + $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'owner_id' => 1, - 'color_id' => 'red', - 'column_id' => 1, + 'event_name' => Task::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', + 'params' => array('column_id' => 1, 'user_id' => 2), ))); - // We attach events - $action->attachEvents(); + $this->assertTrue($actionModel->duplicate(1, 2)); - // Our task should be open - $t1 = $tf->getById(1); - $this->assertEquals(1, $t1['is_active']); - $this->assertEquals(1, $t1['column_id']); + $actions = $actionModel->getAllByProject(2); + $this->assertCount(0, $actions); + } + + public function testDuplicateWithUserParameterButNotAvailable() + { + $projectUserRoleModel = new ProjectUserRole($this->container); + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); - // We move our task - $tp->movePosition(1, 1, 4, 1); + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); - // Our task should be closed - $t1 = $tf->getById(1); - $this->assertEquals(4, $t1['column_id']); - $this->assertEquals(0, $t1['is_active']); + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + + $this->assertTrue($projectUserRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + + $this->assertEquals(1, $actionModel->create(array( + 'project_id' => 1, + 'event_name' => Task::EVENT_MOVE_COLUMN, + 'action_name' => '\Kanboard\Action\TaskAssignSpecificUser', + 'params' => array('column_id' => 1, 'owner_id' => 2), + ))); + + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(0, $actions); } - public function testMultipleActions() + public function testDuplicateWithCategoryParameter() { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $tf = new TaskFinder($this->container); - $b = new Board($this->container); - $p = new Project($this->container); - $a = new Action($this->container); - $g = new GithubWebhook($this->container); - - // We create a project - $this->assertEquals(1, $p->create(array('name' => 'unit_test'))); - - // We create a new action - $this->assertEquals(1, $a->create(array( + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'c1', 'project_id' => 2))); + + $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => GithubWebhook::EVENT_ISSUE_OPENED, - 'action_name' => 'TaskCreation', - 'params' => array() + 'event_name' => Task::EVENT_CREATE_UPDATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', + 'params' => array('column_id' => 1, 'category_id' => 1), ))); - $this->assertEquals(2, $a->create(array( + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(1, $actions); + + $this->assertEquals(2, $actions[0]['project_id']); + $this->assertEquals('\Kanboard\Action\TaskAssignColorCategory', $actions[0]['action_name']); + $this->assertEquals(Task::EVENT_CREATE_UPDATE, $actions[0]['event_name']); + $this->assertEquals(array('column_id' => 5, 'category_id' => 2), $actions[0]['params']); + } + + public function testDuplicateWithCategoryParameterButDifferentName() + { + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + $this->assertEquals(2, $categoryModel->create(array('name' => 'c2', 'project_id' => 2))); + + $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, - 'event_name' => GithubWebhook::EVENT_ISSUE_LABEL_CHANGE, - 'action_name' => 'TaskAssignCategoryLabel', - 'params' => array( - 'label' => 'bug', - 'category_id' => 1, - ) + 'event_name' => Task::EVENT_CREATE_UPDATE, + 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', + 'params' => array('column_id' => 1, 'category_id' => 1), ))); - $this->assertEquals(3, $a->create(array( + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(0, $actions); + } + + public function testDuplicateWithCategoryParameterButNotFound() + { + $projectModel = new Project($this->container); + $actionModel = new Action($this->container); + $categoryModel = new Category($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test2'))); + + $this->assertEquals(1, $categoryModel->create(array('name' => 'c1', 'project_id' => 1))); + + $this->assertEquals(1, $actionModel->create(array( 'project_id' => 1, 'event_name' => Task::EVENT_CREATE_UPDATE, - 'action_name' => 'TaskAssignColorCategory', - 'params' => array( - 'color_id' => 'red', - 'category_id' => 1, - ) + 'action_name' => '\Kanboard\Action\TaskAssignColorCategory', + 'params' => array('column_id' => 1, 'category_id' => 1), ))); - // We attach events - $a->attachEvents(); - $g->setProjectId(1); - - // We create a Github issue - $issue = array( - 'number' => 123, - 'title' => 'Bugs everywhere', - 'body' => 'There is a bug!', - 'html_url' => 'http://localhost/', - ); - - $this->assertTrue($g->handleIssueOpened($issue)); - - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['is_active']); - $this->assertEquals(0, $task['category_id']); - $this->assertEquals('yellow', $task['color_id']); - - // We assign a label to our issue - $label = array( - 'name' => 'bug', - ); - - $this->assertTrue($g->handleIssueLabeled($issue, $label)); - - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals(1, $task['is_active']); - $this->assertEquals(1, $task['category_id']); - $this->assertEquals('red', $task['color_id']); + $this->assertTrue($actionModel->duplicate(1, 2)); + + $actions = $actionModel->getAllByProject(2); + $this->assertCount(0, $actions); } } diff --git a/tests/units/Model/AuthenticationTest.php b/tests/units/Model/AuthenticationTest.php deleted file mode 100644 index 6b48affe..00000000 --- a/tests/units/Model/AuthenticationTest.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Model\User; -use Kanboard\Model\Authentication; - -class AuthenticationTest extends Base -{ - public function testHasCaptcha() - { - $u = new User($this->container); - $a = new Authentication($this->container); - - $this->assertFalse($a->hasCaptcha('not_found')); - $this->assertFalse($a->hasCaptcha('admin')); - - $this->assertTrue($u->incrementFailedLogin('admin')); - $this->assertTrue($u->incrementFailedLogin('admin')); - $this->assertTrue($u->incrementFailedLogin('admin')); - - $this->assertFalse($a->hasCaptcha('not_found')); - $this->assertTrue($a->hasCaptcha('admin')); - } - - public function testHandleFailedLogin() - { - $u = new User($this->container); - $a = new Authentication($this->container); - - $this->assertFalse($u->isLocked('admin')); - - for ($i = 0; $i <= 6; $i++) { - $a->handleFailedLogin('admin'); - } - - $this->assertTrue($u->isLocked('admin')); - } -} diff --git a/tests/units/Model/BoardTest.php b/tests/units/Model/BoardTest.php index 125b9962..bb0778ce 100644 --- a/tests/units/Model/BoardTest.php +++ b/tests/units/Model/BoardTest.php @@ -4,6 +4,7 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Model\Project; use Kanboard\Model\Board; +use Kanboard\Model\Column; use Kanboard\Model\Config; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; @@ -15,12 +16,13 @@ class BoardTest extends Base { $p = new Project($this->container); $b = new Board($this->container); + $columnModel = new Column($this->container); $c = new Config($this->container); // Default columns $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); - $columns = $b->getColumnsList(1); + $columns = $columnModel->getList(1); $this->assertTrue(is_array($columns)); $this->assertEquals(4, count($columns)); @@ -33,10 +35,11 @@ class BoardTest extends Base $input = ' column #1 , column #2, '; $this->assertTrue($c->save(array('board_columns' => $input))); + $this->container['memoryCache']->flush(); $this->assertEquals($input, $c->get('board_columns')); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); - $columns = $b->getColumnsList(2); + $columns = $columnModel->getList(2); $this->assertTrue(is_array($columns)); $this->assertEquals(2, count($columns)); @@ -160,225 +163,4 @@ class BoardTest extends Base $this->assertEquals(1, $board[1]['columns'][3]['tasks'][0]['position']); $this->assertEquals(1, $board[1]['columns'][3]['tasks'][0]['swimlane_id']); } - - public function testGetColumn() - { - $p = new Project($this->container); - $b = new Board($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); - - $column = $b->getColumn(3); - $this->assertNotEmpty($column); - $this->assertEquals('Work in progress', $column['title']); - - $column = $b->getColumn(33); - $this->assertEmpty($column); - } - - public function testRemoveColumn() - { - $p = new Project($this->container); - $b = new Board($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); - $this->assertTrue($b->removeColumn(3)); - $this->assertFalse($b->removeColumn(322)); - - $columns = $b->getColumns(1); - $this->assertTrue(is_array($columns)); - $this->assertEquals(3, count($columns)); - } - - public function testUpdateColumn() - { - $p = new Project($this->container); - $b = new Board($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); - - $this->assertTrue($b->updateColumn(3, 'blah', 5)); - $this->assertTrue($b->updateColumn(2, 'boo')); - - $column = $b->getColumn(3); - $this->assertNotEmpty($column); - $this->assertEquals('blah', $column['title']); - $this->assertEquals(5, $column['task_limit']); - - $column = $b->getColumn(2); - $this->assertNotEmpty($column); - $this->assertEquals('boo', $column['title']); - $this->assertEquals(0, $column['task_limit']); - } - - public function testAddColumn() - { - $p = new Project($this->container); - $b = new Board($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); - $this->assertNotFalse($b->addColumn(1, 'another column')); - $this->assertNotFalse($b->addColumn(1, 'one more', 3, 'one more description')); - - $columns = $b->getColumns(1); - $this->assertTrue(is_array($columns)); - $this->assertEquals(6, count($columns)); - - $this->assertEquals('another column', $columns[4]['title']); - $this->assertEquals(0, $columns[4]['task_limit']); - $this->assertEquals(5, $columns[4]['position']); - - $this->assertEquals('one more', $columns[5]['title']); - $this->assertEquals(3, $columns[5]['task_limit']); - $this->assertEquals(6, $columns[5]['position']); - $this->assertEquals('one more description', $columns[5]['description']); - } - - public function testMoveColumns() - { - $p = new Project($this->container); - $b = new Board($this->container); - - // We create 2 projects - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); - $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); - - // We get the columns of the project 2 - $columns = $b->getColumns(2); - $columns_id = array_keys($b->getColumnsList(2)); - $this->assertNotEmpty($columns); - - // Initial order: 5, 6, 7, 8 - - // Move the column 1 down - $this->assertEquals(1, $columns[0]['position']); - $this->assertEquals($columns_id[0], $columns[0]['id']); - - $this->assertEquals(2, $columns[1]['position']); - $this->assertEquals($columns_id[1], $columns[1]['id']); - - $this->assertTrue($b->moveDown(2, $columns[0]['id'])); - $columns = $b->getColumns(2); // Sorted by position - - // New order: 6, 5, 7, 8 - - $this->assertEquals(1, $columns[0]['position']); - $this->assertEquals($columns_id[1], $columns[0]['id']); - - $this->assertEquals(2, $columns[1]['position']); - $this->assertEquals($columns_id[0], $columns[1]['id']); - - // Move the column 3 up - $this->assertTrue($b->moveUp(2, $columns[2]['id'])); - $columns = $b->getColumns(2); - - // New order: 6, 7, 5, 8 - - $this->assertEquals(1, $columns[0]['position']); - $this->assertEquals($columns_id[1], $columns[0]['id']); - - $this->assertEquals(2, $columns[1]['position']); - $this->assertEquals($columns_id[2], $columns[1]['id']); - - $this->assertEquals(3, $columns[2]['position']); - $this->assertEquals($columns_id[0], $columns[2]['id']); - - // Move column 1 up (must do nothing because it's the first column) - $this->assertFalse($b->moveUp(2, $columns[0]['id'])); - $columns = $b->getColumns(2); - - // Order: 6, 7, 5, 8 - - $this->assertEquals(1, $columns[0]['position']); - $this->assertEquals($columns_id[1], $columns[0]['id']); - - // Move column 4 down (must do nothing because it's the last column) - $this->assertFalse($b->moveDown(2, $columns[3]['id'])); - $columns = $b->getColumns(2); - - // Order: 6, 7, 5, 8 - - $this->assertEquals(4, $columns[3]['position']); - $this->assertEquals($columns_id[3], $columns[3]['id']); - } - - public function testMoveUpAndRemoveColumn() - { - $p = new Project($this->container); - $b = new Board($this->container); - - // We create a project - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); - - // We remove the second column - $this->assertTrue($b->removeColumn(2)); - - $columns = $b->getColumns(1); - $this->assertNotEmpty($columns); - $this->assertCount(3, $columns); - - $this->assertEquals(1, $columns[0]['position']); - $this->assertEquals(3, $columns[1]['position']); - $this->assertEquals(4, $columns[2]['position']); - - $this->assertEquals(1, $columns[0]['id']); - $this->assertEquals(3, $columns[1]['id']); - $this->assertEquals(4, $columns[2]['id']); - - // We move up the second column - $this->assertTrue($b->moveUp(1, $columns[1]['id'])); - - // Check the new positions - $columns = $b->getColumns(1); - $this->assertNotEmpty($columns); - $this->assertCount(3, $columns); - - $this->assertEquals(1, $columns[0]['position']); - $this->assertEquals(2, $columns[1]['position']); - $this->assertEquals(3, $columns[2]['position']); - - $this->assertEquals(3, $columns[0]['id']); - $this->assertEquals(1, $columns[1]['id']); - $this->assertEquals(4, $columns[2]['id']); - } - - public function testMoveDownAndRemoveColumn() - { - $p = new Project($this->container); - $b = new Board($this->container); - - // We create a project - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); - - // We remove the second column - $this->assertTrue($b->removeColumn(2)); - - $columns = $b->getColumns(1); - $this->assertNotEmpty($columns); - $this->assertCount(3, $columns); - - $this->assertEquals(1, $columns[0]['position']); - $this->assertEquals(3, $columns[1]['position']); - $this->assertEquals(4, $columns[2]['position']); - - $this->assertEquals(1, $columns[0]['id']); - $this->assertEquals(3, $columns[1]['id']); - $this->assertEquals(4, $columns[2]['id']); - - // We move up the second column - $this->assertTrue($b->moveDown(1, $columns[0]['id'])); - - // Check the new positions - $columns = $b->getColumns(1); - $this->assertNotEmpty($columns); - $this->assertCount(3, $columns); - - $this->assertEquals(1, $columns[0]['position']); - $this->assertEquals(2, $columns[1]['position']); - $this->assertEquals(3, $columns[2]['position']); - - $this->assertEquals(3, $columns[0]['id']); - $this->assertEquals(1, $columns[1]['id']); - $this->assertEquals(4, $columns[2]['id']); - } } diff --git a/tests/units/Model/ColumnTest.php b/tests/units/Model/ColumnTest.php new file mode 100644 index 00000000..e40f89c6 --- /dev/null +++ b/tests/units/Model/ColumnTest.php @@ -0,0 +1,236 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\Project; +use Kanboard\Model\Column; + +class ColumnTest extends Base +{ + public function testGetColumn() + { + $projectModel = new Project($this->container); + $columnModel = new Column($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + + $column = $columnModel->getById(3); + $this->assertNotEmpty($column); + $this->assertEquals('Work in progress', $column['title']); + + $column = $columnModel->getById(33); + $this->assertEmpty($column); + } + + public function testGetFirstColumnId() + { + $projectModel = new Project($this->container); + $columnModel = new Column($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertEquals(1, $columnModel->getFirstColumnId(1)); + } + + public function testGetLastColumnId() + { + $projectModel = new Project($this->container); + $columnModel = new Column($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertEquals(4, $columnModel->getLastColumnId(1)); + } + + public function testGetLastColumnPosition() + { + $projectModel = new Project($this->container); + $columnModel = new Column($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertEquals(4, $columnModel->getLastColumnPosition(1)); + } + + public function testGetColumnIdByTitle() + { + $projectModel = new Project($this->container); + $columnModel = new Column($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertEquals(2, $columnModel->getColumnIdByTitle(1, 'Ready')); + } + + public function testGetTitleByColumnId() + { + $projectModel = new Project($this->container); + $columnModel = new Column($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertEquals('Work in progress', $columnModel->getColumnTitleById(3)); + } + + public function testGetAll() + { + $projectModel = new Project($this->container); + $columnModel = new Column($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + + $columns = $columnModel->getAll(1); + $this->assertCount(4, $columns); + + $this->assertEquals(1, $columns[0]['id']); + $this->assertEquals(1, $columns[0]['position']); + $this->assertEquals('Backlog', $columns[0]['title']); + + $this->assertEquals(2, $columns[1]['id']); + $this->assertEquals(2, $columns[1]['position']); + $this->assertEquals('Ready', $columns[1]['title']); + + $this->assertEquals(3, $columns[2]['id']); + $this->assertEquals(3, $columns[2]['position']); + $this->assertEquals('Work in progress', $columns[2]['title']); + + $this->assertEquals(4, $columns[3]['id']); + $this->assertEquals(4, $columns[3]['position']); + $this->assertEquals('Done', $columns[3]['title']); + } + + public function testGetList() + { + $projectModel = new Project($this->container); + $columnModel = new Column($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + + $columns = $columnModel->getList(1); + $this->assertCount(4, $columns); + $this->assertEquals('Backlog', $columns[1]); + $this->assertEquals('Ready', $columns[2]); + $this->assertEquals('Work in progress', $columns[3]); + $this->assertEquals('Done', $columns[4]); + + $columns = $columnModel->getList(1, true); + $this->assertCount(5, $columns); + $this->assertEquals('All columns', $columns[-1]); + $this->assertEquals('Backlog', $columns[1]); + $this->assertEquals('Ready', $columns[2]); + $this->assertEquals('Work in progress', $columns[3]); + $this->assertEquals('Done', $columns[4]); + } + + public function testAddColumn() + { + $projectModel = new Project($this->container); + $columnModel = new Column($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertNotFalse($columnModel->create(1, 'another column')); + $this->assertNotFalse($columnModel->create(1, 'one more', 3, 'one more description')); + + $columns = $columnModel->getAll(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals(6, count($columns)); + + $this->assertEquals('another column', $columns[4]['title']); + $this->assertEquals(0, $columns[4]['task_limit']); + $this->assertEquals(5, $columns[4]['position']); + + $this->assertEquals('one more', $columns[5]['title']); + $this->assertEquals(3, $columns[5]['task_limit']); + $this->assertEquals(6, $columns[5]['position']); + $this->assertEquals('one more description', $columns[5]['description']); + } + + public function testUpdateColumn() + { + $projectModel = new Project($this->container); + $columnModel = new Column($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + + $this->assertTrue($columnModel->update(3, 'blah', 5)); + $this->assertTrue($columnModel->update(2, 'boo')); + + $column = $columnModel->getById(3); + $this->assertNotEmpty($column); + $this->assertEquals('blah', $column['title']); + $this->assertEquals(5, $column['task_limit']); + + $column = $columnModel->getById(2); + $this->assertNotEmpty($column); + $this->assertEquals('boo', $column['title']); + $this->assertEquals(0, $column['task_limit']); + } + + public function testRemoveColumn() + { + $projectModel = new Project($this->container); + $columnModel = new Column($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertTrue($columnModel->remove(3)); + $this->assertFalse($columnModel->remove(322)); + + $columns = $columnModel->getAll(1); + $this->assertTrue(is_array($columns)); + $this->assertEquals(3, count($columns)); + } + + public function testChangePosition() + { + $projectModel = new Project($this->container); + $columnModel = new Column($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + + $columns = $columnModel->getAll(1); + $this->assertEquals(1, $columns[0]['position']); + $this->assertEquals(1, $columns[0]['id']); + $this->assertEquals(2, $columns[1]['position']); + $this->assertEquals(2, $columns[1]['id']); + $this->assertEquals(3, $columns[2]['position']); + $this->assertEquals(3, $columns[2]['id']); + + $this->assertTrue($columnModel->changePosition(1, 3, 2)); + + $columns = $columnModel->getAll(1); + $this->assertEquals(1, $columns[0]['position']); + $this->assertEquals(1, $columns[0]['id']); + $this->assertEquals(2, $columns[1]['position']); + $this->assertEquals(3, $columns[1]['id']); + $this->assertEquals(3, $columns[2]['position']); + $this->assertEquals(2, $columns[2]['id']); + + $this->assertTrue($columnModel->changePosition(1, 2, 1)); + + $columns = $columnModel->getAll(1); + $this->assertEquals(1, $columns[0]['position']); + $this->assertEquals(2, $columns[0]['id']); + $this->assertEquals(2, $columns[1]['position']); + $this->assertEquals(1, $columns[1]['id']); + $this->assertEquals(3, $columns[2]['position']); + $this->assertEquals(3, $columns[2]['id']); + + $this->assertTrue($columnModel->changePosition(1, 2, 2)); + + $columns = $columnModel->getAll(1); + $this->assertEquals(1, $columns[0]['position']); + $this->assertEquals(1, $columns[0]['id']); + $this->assertEquals(2, $columns[1]['position']); + $this->assertEquals(2, $columns[1]['id']); + $this->assertEquals(3, $columns[2]['position']); + $this->assertEquals(3, $columns[2]['id']); + + $this->assertTrue($columnModel->changePosition(1, 4, 1)); + + $columns = $columnModel->getAll(1); + $this->assertEquals(1, $columns[0]['position']); + $this->assertEquals(4, $columns[0]['id']); + $this->assertEquals(2, $columns[1]['position']); + $this->assertEquals(1, $columns[1]['id']); + $this->assertEquals(3, $columns[2]['position']); + $this->assertEquals(2, $columns[2]['id']); + + $this->assertFalse($columnModel->changePosition(1, 2, 0)); + $this->assertFalse($columnModel->changePosition(1, 2, 5)); + } +} diff --git a/tests/units/Model/CommentTest.php b/tests/units/Model/CommentTest.php index 07c39fe3..ec4e7a56 100644 --- a/tests/units/Model/CommentTest.php +++ b/tests/units/Model/CommentTest.php @@ -90,53 +90,4 @@ class CommentTest extends Base $this->assertFalse($c->remove(1)); $this->assertFalse($c->remove(1111)); } - - public function testValidateCreation() - { - $c = new Comment($this->container); - - $result = $c->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla')); - $this->assertTrue($result[0]); - - $result = $c->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => '')); - $this->assertFalse($result[0]); - - $result = $c->validateCreation(array('user_id' => 1, 'task_id' => 'a', 'comment' => 'bla')); - $this->assertFalse($result[0]); - - $result = $c->validateCreation(array('user_id' => 'b', 'task_id' => 1, 'comment' => 'bla')); - $this->assertFalse($result[0]); - - $result = $c->validateCreation(array('user_id' => 1, 'comment' => 'bla')); - $this->assertFalse($result[0]); - - $result = $c->validateCreation(array('task_id' => 1, 'comment' => 'bla')); - $this->assertTrue($result[0]); - - $result = $c->validateCreation(array('comment' => 'bla')); - $this->assertFalse($result[0]); - - $result = $c->validateCreation(array()); - $this->assertFalse($result[0]); - } - - public function testValidateModification() - { - $c = new Comment($this->container); - - $result = $c->validateModification(array('id' => 1, 'comment' => 'bla')); - $this->assertTrue($result[0]); - - $result = $c->validateModification(array('id' => 1, 'comment' => '')); - $this->assertFalse($result[0]); - - $result = $c->validateModification(array('comment' => 'bla')); - $this->assertFalse($result[0]); - - $result = $c->validateModification(array('id' => 'b', 'comment' => 'bla')); - $this->assertFalse($result[0]); - - $result = $c->validateModification(array()); - $this->assertFalse($result[0]); - } } diff --git a/tests/units/Model/ConfigTest.php b/tests/units/Model/ConfigTest.php index 17617ceb..447c9238 100644 --- a/tests/units/Model/ConfigTest.php +++ b/tests/units/Model/ConfigTest.php @@ -3,10 +3,78 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Model\Config; -use Kanboard\Core\Session; +use Kanboard\Core\Session\SessionManager; class ConfigTest extends Base { + public function testGetTimezones() + { + $configModel = new Config($this->container); + $this->assertNotEmpty($configModel->getTimezones()); + $this->assertArrayHasKey('Europe/Paris', $configModel->getTimezones()); + $this->assertContains('Europe/Paris', $configModel->getTimezones()); + $this->assertArrayNotHasKey('', $configModel->getTimezones()); + + $this->assertArrayHasKey('', $configModel->getTimezones(true)); + $this->assertContains('Application default', $configModel->getTimezones(true)); + } + + public function testGetLanguages() + { + $configModel = new Config($this->container); + $this->assertNotEmpty($configModel->getLanguages()); + $this->assertArrayHasKey('fr_FR', $configModel->getLanguages()); + $this->assertContains('Français', $configModel->getLanguages()); + $this->assertArrayNotHasKey('', $configModel->getLanguages()); + + $this->assertArrayHasKey('', $configModel->getLanguages(true)); + $this->assertContains('Application default', $configModel->getLanguages(true)); + } + + public function testGetJsLanguage() + { + $configModel = new Config($this->container); + $this->assertEquals('en', $configModel->getJsLanguageCode()); + + $this->container['sessionStorage']->user = array('language' => 'fr_FR'); + $this->assertEquals('fr', $configModel->getJsLanguageCode()); + + $this->container['sessionStorage']->user = array('language' => 'xx_XX'); + $this->assertEquals('en', $configModel->getJsLanguageCode()); + } + + public function testGetCurrentLanguage() + { + $configModel = new Config($this->container); + $this->assertEquals('en_US', $configModel->getCurrentLanguage()); + + $this->container['sessionStorage']->user = array('language' => 'fr_FR'); + $this->assertEquals('fr_FR', $configModel->getCurrentLanguage()); + + $this->container['sessionStorage']->user = array('language' => 'xx_XX'); + $this->assertEquals('xx_XX', $configModel->getCurrentLanguage()); + } + + public function testGetCurrentTimezone() + { + $configModel = new Config($this->container); + $this->assertEquals('UTC', $configModel->getCurrentTimezone()); + + $this->container['sessionStorage']->user = array('timezone' => 'Europe/Paris'); + $this->assertEquals('Europe/Paris', $configModel->getCurrentTimezone()); + + $this->container['sessionStorage']->user = array('timezone' => 'Something'); + $this->assertEquals('Something', $configModel->getCurrentTimezone()); + } + + public function testRegenerateToken() + { + $configModel = new Config($this->container); + $token = $configModel->getOption('api_token'); + $this->assertTrue($configModel->regenerateToken('api_token')); + $this->assertNotEquals($token, $configModel->getOption('api_token')); + } + public function testCRUDOperations() { $c = new Config($this->container); @@ -37,62 +105,73 @@ class ConfigTest extends Base $c = new Config($this->container); $this->assertTrue($c->save(array('application_url' => 'http://localhost/'))); - $this->assertEquals('http://localhost/', $c->get('application_url')); + $this->assertEquals('http://localhost/', $c->getOption('application_url')); $this->assertTrue($c->save(array('application_url' => 'http://localhost'))); - $this->assertEquals('http://localhost/', $c->get('application_url')); + $this->assertEquals('http://localhost/', $c->getOption('application_url')); $this->assertTrue($c->save(array('application_url' => ''))); - $this->assertEquals('', $c->get('application_url')); + $this->assertEquals('', $c->getOption('application_url')); } public function testDefaultValues() { $c = new Config($this->container); - $this->assertEquals('en_US', $c->get('application_language')); - $this->assertEquals('UTC', $c->get('application_timezone')); - - $this->assertEmpty($c->get('webhook_url_task_modification')); - $this->assertEmpty($c->get('webhook_url_task_creation')); - $this->assertEmpty($c->get('board_columns')); - $this->assertEmpty($c->get('application_url')); - - $this->assertNotEmpty($c->get('webhook_token')); - $this->assertNotEmpty($c->get('api_token')); + $this->assertEquals(172800, $c->getOption('board_highlight_period')); + $this->assertEquals(60, $c->getOption('board_public_refresh_interval')); + $this->assertEquals(10, $c->getOption('board_private_refresh_interval')); + $this->assertEmpty($c->getOption('board_columns')); + + $this->assertEquals('yellow', $c->getOption('default_color')); + $this->assertEquals('en_US', $c->getOption('application_language')); + $this->assertEquals('UTC', $c->getOption('application_timezone')); + $this->assertEquals('m/d/Y', $c->getOption('application_date_format')); + $this->assertEmpty($c->getOption('application_url')); + $this->assertEmpty($c->getOption('application_stylesheet')); + $this->assertEquals('USD', $c->getOption('application_currency')); + + $this->assertEquals(0, $c->getOption('calendar_user_subtasks_time_tracking')); + $this->assertEquals('date_started', $c->getOption('calendar_user_tasks')); + $this->assertEquals('date_started', $c->getOption('calendar_user_tasks')); + + $this->assertEquals(0, $c->getOption('integration_gravatar')); + $this->assertEquals(1, $c->getOption('cfd_include_closed_tasks')); + $this->assertEquals(1, $c->getOption('password_reset')); + + $this->assertEquals(1, $c->getOption('subtask_time_tracking')); + $this->assertEquals(0, $c->getOption('subtask_restriction')); + $this->assertEmpty($c->getOption('project_categories')); + + $this->assertEmpty($c->getOption('webhook_url_task_modification')); + $this->assertEmpty($c->getOption('webhook_url_task_creation')); + $this->assertNotEmpty($c->getOption('webhook_token')); + $this->assertEmpty($c->getOption('webhook_url')); + + $this->assertNotEmpty($c->getOption('api_token')); } - public function testGet() + public function testGetOption() { $c = new Config($this->container); - $this->assertEquals('', $c->get('board_columns')); - $this->assertEquals('test', $c->get('board_columns', 'test')); - $this->assertEquals(0, $c->get('board_columns', 0)); + $this->assertEquals('', $c->getOption('board_columns')); + $this->assertEquals('test', $c->getOption('board_columns', 'test')); + $this->assertEquals(0, $c->getOption('board_columns', 0)); } - public function testGetWithSession() + public function testGetWithCaching() { - $this->container['session'] = new Session; $c = new Config($this->container); - session_id('test'); + $this->assertEquals('UTC', $c->get('application_timezone')); + $this->assertTrue($c->save(array('application_timezone' => 'Europe/Paris'))); - $this->assertTrue(Session::isOpen()); + $this->assertEquals('UTC', $c->get('application_timezone')); // cached value + $this->assertEquals('Europe/Paris', $c->getOption('application_timezone')); $this->assertEquals('', $c->get('board_columns')); $this->assertEquals('test', $c->get('board_columns', 'test')); - - $this->container['session']['config'] = array( - 'board_columns' => 'foo', - 'empty_value' => 0 - ); - - $this->assertEquals('foo', $c->get('board_columns')); - $this->assertEquals('foo', $c->get('board_columns', 'test')); $this->assertEquals('test', $c->get('empty_value', 'test')); - - session_id(''); - unset($this->container['session']); } } diff --git a/tests/units/Model/CurrencyTest.php b/tests/units/Model/CurrencyTest.php new file mode 100644 index 00000000..0bc71da6 --- /dev/null +++ b/tests/units/Model/CurrencyTest.php @@ -0,0 +1,53 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\Currency; + +class CurrencyTest extends Base +{ + public function testGetCurrencies() + { + $currencyModel = new Currency($this->container); + $currencies = $currencyModel->getCurrencies(); + $this->assertArrayHasKey('EUR', $currencies); + } + + public function testGetAll() + { + $currencyModel = new Currency($this->container); + $currencies = $currencyModel->getAll(); + $this->assertCount(0, $currencies); + + $this->assertNotFalse($currencyModel->create('USD', 9.9)); + $currencies = $currencyModel->getAll(); + $this->assertCount(1, $currencies); + $this->assertEquals('USD', $currencies[0]['currency']); + $this->assertEquals(9.9, $currencies[0]['rate']); + } + + public function testCreate() + { + $currencyModel = new Currency($this->container); + $this->assertNotFalse($currencyModel->create('EUR', 1.2)); + $this->assertNotFalse($currencyModel->create('EUR', 1.5)); + } + + public function testUpdate() + { + $currencyModel = new Currency($this->container); + $this->assertNotFalse($currencyModel->create('EUR', 1.1)); + $this->assertNotFalse($currencyModel->update('EUR', 2.2)); + } + + public function testGetPrice() + { + $currencyModel = new Currency($this->container); + + $this->assertEquals(123, $currencyModel->getPrice('USD', 123)); + + $this->assertNotFalse($currencyModel->create('EUR', 0.5)); + $this->assertEquals(50.0, $currencyModel->getPrice('EUR', 100)); + $this->assertEquals(50.0, $currencyModel->getPrice('EUR', 100)); // test with cached result + } +} diff --git a/tests/units/Model/CustomFilterTest.php b/tests/units/Model/CustomFilterTest.php index 190da899..a73bc401 100644 --- a/tests/units/Model/CustomFilterTest.php +++ b/tests/units/Model/CustomFilterTest.php @@ -52,34 +52,6 @@ class CustomFilterTest extends Base $this->assertEquals(1, $filter['is_shared']); } - public function testValidation() - { - $cf = new CustomFilter($this->container); - - // Validate creation - $r = $cf->validateCreation(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); - $this->assertTrue($r[0]); - - $r = $cf->validateCreation(array('filter' => str_repeat('a', 101), 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); - $this->assertFalse($r[0]); - - $r = $cf->validateCreation(array('name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); - $this->assertFalse($r[0]); - - // Validate modification - $r = $cf->validateModification(array('id' => 1, 'filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); - $this->assertTrue($r[0]); - - $r = $cf->validateModification(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); - $this->assertFalse($r[0]); - - $r = $cf->validateModification(array('id' => 1, 'filter' => str_repeat('a', 101), 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); - $this->assertFalse($r[0]); - - $r = $cf->validateModification(array('id' => 1, 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); - $this->assertFalse($r[0]); - } - public function testGetAll() { $u = new User($this->container); diff --git a/tests/units/Model/FileTest.php b/tests/units/Model/FileTest.php deleted file mode 100644 index 29f6ee93..00000000 --- a/tests/units/Model/FileTest.php +++ /dev/null @@ -1,263 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Model\Task; -use Kanboard\Model\File; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\Project; - -class FileTest extends Base -{ - public function setUp() - { - parent::setUp(); - - $this->container['objectStorage'] = $this - ->getMockBuilder('\Kanboard\Core\ObjectStorage\FileStorage') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('put', 'moveFile', 'remove')) - ->getMock(); - } - - public function testCreation() - { - $p = new Project($this->container); - $f = new File($this->container); - $tc = new TaskCreation($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - - $this->assertEquals(1, $f->create(1, 'test', '/tmp/foo', 10)); - - $file = $f->getById(1); - $this->assertNotEmpty($file); - $this->assertEquals('test', $file['name']); - $this->assertEquals('/tmp/foo', $file['path']); - $this->assertEquals(0, $file['is_image']); - $this->assertEquals(1, $file['task_id']); - $this->assertEquals(time(), $file['date'], '', 2); - $this->assertEquals(0, $file['user_id']); - $this->assertEquals(10, $file['size']); - - $this->assertEquals(2, $f->create(1, 'test2.png', '/tmp/foobar', 10)); - - $file = $f->getById(2); - $this->assertNotEmpty($file); - $this->assertEquals('test2.png', $file['name']); - $this->assertEquals('/tmp/foobar', $file['path']); - $this->assertEquals(1, $file['is_image']); - } - - public function testCreationFileNameTooLong() - { - $p = new Project($this->container); - $f = new File($this->container); - $tc = new TaskCreation($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - - $this->assertNotFalse($f->create(1, 'test', '/tmp/foo', 10)); - $this->assertNotFalse($f->create(1, str_repeat('a', 1000), '/tmp/foo', 10)); - - $files = $f->getAll(1); - $this->assertNotEmpty($files); - $this->assertCount(2, $files); - - $this->assertEquals(str_repeat('a', 255), $files[0]['name']); - $this->assertEquals('test', $files[1]['name']); - } - - public function testIsImage() - { - $f = new File($this->container); - - $this->assertTrue($f->isImage('test.png')); - $this->assertTrue($f->isImage('test.jpeg')); - $this->assertTrue($f->isImage('test.gif')); - $this->assertTrue($f->isImage('test.jpg')); - $this->assertTrue($f->isImage('test.JPG')); - - $this->assertFalse($f->isImage('test.bmp')); - $this->assertFalse($f->isImage('test')); - $this->assertFalse($f->isImage('test.pdf')); - } - - public function testGeneratePath() - { - $f = new File($this->container); - - $this->assertStringStartsWith('12'.DIRECTORY_SEPARATOR.'34'.DIRECTORY_SEPARATOR, $f->generatePath(12, 34, 'test.png')); - $this->assertNotEquals($f->generatePath(12, 34, 'test1.png'), $f->generatePath(12, 34, 'test2.png')); - } - - public function testUploadScreenshot() - { - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - - $data = base64_encode('image data'); - - $f = $this - ->getMockBuilder('\Kanboard\Model\File') - ->setConstructorArgs(array($this->container)) - ->setMethods(array('generateThumbnailFromData')) - ->getMock(); - - $this->container['objectStorage'] - ->expects($this->once()) - ->method('put') - ->with( - $this->stringContains('1'.DIRECTORY_SEPARATOR.'1'.DIRECTORY_SEPARATOR), - $this->equalTo(base64_decode($data)) - ) - ->will($this->returnValue(true)); - - $f->expects($this->once()) - ->method('generateThumbnailFromData'); - - $this->assertEquals(1, $f->uploadScreenshot(1, 1, $data)); - - $file = $f->getById(1); - $this->assertNotEmpty($file); - $this->assertStringStartsWith('Screenshot taken ', $file['name']); - $this->assertStringStartsWith('1'.DIRECTORY_SEPARATOR.'1'.DIRECTORY_SEPARATOR, $file['path']); - $this->assertEquals(1, $file['is_image']); - $this->assertEquals(1, $file['task_id']); - $this->assertEquals(time(), $file['date'], '', 2); - $this->assertEquals(0, $file['user_id']); - $this->assertEquals(10, $file['size']); - } - - public function testUploadFileContent() - { - $p = new Project($this->container); - $f = new File($this->container); - $tc = new TaskCreation($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - - $data = base64_encode('file data'); - - $this->container['objectStorage'] - ->expects($this->once()) - ->method('put') - ->with( - $this->stringContains('1'.DIRECTORY_SEPARATOR.'1'.DIRECTORY_SEPARATOR), - $this->equalTo(base64_decode($data)) - ) - ->will($this->returnValue(true)); - - $this->assertEquals(1, $f->uploadContent(1, 1, 'my file.pdf', $data)); - - $file = $f->getById(1); - $this->assertNotEmpty($file); - $this->assertEquals('my file.pdf', $file['name']); - $this->assertStringStartsWith('1'.DIRECTORY_SEPARATOR.'1'.DIRECTORY_SEPARATOR, $file['path']); - $this->assertEquals(0, $file['is_image']); - $this->assertEquals(1, $file['task_id']); - $this->assertEquals(time(), $file['date'], '', 2); - $this->assertEquals(0, $file['user_id']); - $this->assertEquals(9, $file['size']); - } - - public function testGetAll() - { - $p = new Project($this->container); - $f = new File($this->container); - $tc = new TaskCreation($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - - $this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo', 10)); - $this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo', 10)); - $this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo', 10)); - $this->assertEquals(4, $f->create(1, 'C.JPG', '/tmp/foo', 10)); - - $files = $f->getAll(1); - $this->assertNotEmpty($files); - $this->assertCount(4, $files); - $this->assertEquals('A.png', $files[0]['name']); - $this->assertEquals('B.pdf', $files[1]['name']); - $this->assertEquals('C.JPG', $files[2]['name']); - $this->assertEquals('D.doc', $files[3]['name']); - - $files = $f->getAllImages(1); - $this->assertNotEmpty($files); - $this->assertCount(2, $files); - $this->assertEquals('A.png', $files[0]['name']); - $this->assertEquals('C.JPG', $files[1]['name']); - - $files = $f->getAllDocuments(1); - $this->assertNotEmpty($files); - $this->assertCount(2, $files); - $this->assertEquals('B.pdf', $files[0]['name']); - $this->assertEquals('D.doc', $files[1]['name']); - } - - public function testRemove() - { - $p = new Project($this->container); - $f = new File($this->container); - $tc = new TaskCreation($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - - $this->assertEquals(1, $f->create(1, 'B.pdf', DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo1', 10)); - $this->assertEquals(2, $f->create(1, 'A.png', DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo2', 10)); - $this->assertEquals(3, $f->create(1, 'D.doc', DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo3', 10)); - - $this->container['objectStorage'] - ->expects($this->at(0)) - ->method('remove') - ->with( - $this->equalTo(DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo2') - ) - ->will($this->returnValue(true)); - - $this->container['objectStorage'] - ->expects($this->at(1)) - ->method('remove') - ->with( - $this->equalTo('thumbnails'.DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo2') - ) - ->will($this->returnValue(true)); - - $this->container['objectStorage'] - ->expects($this->at(2)) - ->method('remove') - ->with( - $this->equalTo(DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo1') - ) - ->will($this->returnValue(true)); - - $this->container['objectStorage'] - ->expects($this->at(3)) - ->method('remove') - ->with( - $this->equalTo(DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR.'foo3') - ) - ->will($this->returnValue(true)); - - $this->assertTrue($f->remove(2)); - - $files = $f->getAll(1); - $this->assertNotEmpty($files); - $this->assertCount(2, $files); - $this->assertEquals('B.pdf', $files[0]['name']); - $this->assertEquals('D.doc', $files[1]['name']); - - $this->assertTrue($f->removeAll(1)); - - $files = $f->getAll(1); - $this->assertEmpty($files); - } -} diff --git a/tests/units/Model/GroupMemberTest.php b/tests/units/Model/GroupMemberTest.php new file mode 100644 index 00000000..16f769e8 --- /dev/null +++ b/tests/units/Model/GroupMemberTest.php @@ -0,0 +1,76 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\Group; +use Kanboard\Model\User; +use Kanboard\Model\GroupMember; + +class GroupMemberTest extends Base +{ + public function testAddRemove() + { + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + + $this->assertEquals(1, $groupModel->create('Test')); + + $this->assertTrue($groupMemberModel->addUser(1, 1)); + $this->assertFalse($groupMemberModel->addUser(1, 1)); + + $users = $groupMemberModel->getMembers(1); + $this->assertCount(1, $users); + $this->assertEquals('admin', $users[0]['username']); + + $this->assertEmpty($groupMemberModel->getNotMembers(1)); + + $this->assertTrue($groupMemberModel->removeUser(1, 1)); + $this->assertFalse($groupMemberModel->removeUser(1, 1)); + + $this->assertEmpty($groupMemberModel->getMembers(1)); + } + + public function testMembers() + { + $userModel = new User($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + + $this->assertEquals(1, $groupModel->create('Group A')); + $this->assertEquals(2, $groupModel->create('Group B')); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user4'))); + + $this->assertTrue($groupMemberModel->addUser(1, 1)); + $this->assertTrue($groupMemberModel->addUser(1, 2)); + $this->assertTrue($groupMemberModel->addUser(1, 5)); + $this->assertTrue($groupMemberModel->addUser(2, 3)); + $this->assertTrue($groupMemberModel->addUser(2, 4)); + $this->assertTrue($groupMemberModel->addUser(2, 5)); + + $users = $groupMemberModel->getMembers(1); + $this->assertCount(3, $users); + $this->assertEquals('admin', $users[0]['username']); + $this->assertEquals('user1', $users[1]['username']); + $this->assertEquals('user4', $users[2]['username']); + + $users = $groupMemberModel->getNotMembers(1); + $this->assertCount(2, $users); + $this->assertEquals('user2', $users[0]['username']); + $this->assertEquals('user3', $users[1]['username']); + + $users = $groupMemberModel->getMembers(2); + $this->assertCount(3, $users); + $this->assertEquals('user2', $users[0]['username']); + $this->assertEquals('user3', $users[1]['username']); + $this->assertEquals('user4', $users[2]['username']); + + $users = $groupMemberModel->getNotMembers(2); + $this->assertCount(2, $users); + $this->assertEquals('admin', $users[0]['username']); + $this->assertEquals('user1', $users[1]['username']); + } +} diff --git a/tests/units/Model/GroupTest.php b/tests/units/Model/GroupTest.php new file mode 100644 index 00000000..36b47dc5 --- /dev/null +++ b/tests/units/Model/GroupTest.php @@ -0,0 +1,60 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\Group; + +class GroupTest extends Base +{ + public function testCreation() + { + $groupModel = new Group($this->container); + $this->assertEquals(1, $groupModel->create('Test')); + $this->assertFalse($groupModel->create('Test')); + } + + public function testGetById() + { + $groupModel = new Group($this->container); + $this->assertEquals(1, $groupModel->create('Test')); + + $group = $groupModel->getById(1); + $this->assertEquals('Test', $group['name']); + $this->assertEquals('', $group['external_id']); + + $this->assertEmpty($groupModel->getById(2)); + } + + public function testGetAll() + { + $groupModel = new Group($this->container); + $this->assertEquals(1, $groupModel->create('B')); + $this->assertEquals(2, $groupModel->create('A', 'uuid')); + + $groups = $groupModel->getAll(); + $this->assertCount(2, $groups); + $this->assertEquals('A', $groups[0]['name']); + $this->assertEquals('uuid', $groups[0]['external_id']); + $this->assertEquals('B', $groups[1]['name']); + $this->assertEquals('', $groups[1]['external_id']); + } + + public function testUpdate() + { + $groupModel = new Group($this->container); + $this->assertEquals(1, $groupModel->create('Test')); + $this->assertTrue($groupModel->update(array('id' => 1, 'name' => 'My group', 'external_id' => 'test'))); + + $group = $groupModel->getById(1); + $this->assertEquals('My group', $group['name']); + $this->assertEquals('test', $group['external_id']); + } + + public function testRemove() + { + $groupModel = new Group($this->container); + $this->assertEquals(1, $groupModel->create('Test')); + $this->assertTrue($groupModel->remove(1)); + $this->assertEmpty($groupModel->getById(1)); + } +} diff --git a/tests/units/Model/LastLoginTest.php b/tests/units/Model/LastLoginTest.php new file mode 100644 index 00000000..fc5ea1e5 --- /dev/null +++ b/tests/units/Model/LastLoginTest.php @@ -0,0 +1,43 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\LastLogin; + +class LastLoginTest extends Base +{ + public function testCreate() + { + $lastLoginModel = new LastLogin($this->container); + + $this->assertTrue($lastLoginModel->create('Test1', 1, '127.0.0.1', 'My browser')); + $this->assertTrue($lastLoginModel->create('Test2', 1, '127.0.0.1', str_repeat('Too long', 50))); + $this->assertTrue($lastLoginModel->create('Test3', 1, '2001:0db8:0000:0000:0000:ff00:0042:8329', 'My Ipv6 browser')); + + $connections = $lastLoginModel->getAll(1); + $this->assertCount(3, $connections); + + $this->assertEquals('Test3', $connections[0]['auth_type']); + $this->assertEquals('2001:0db8:0000:0000:0000:ff00:0042:8329', $connections[0]['ip']); + + $this->assertEquals('Test2', $connections[1]['auth_type']); + $this->assertEquals('127.0.0.1', $connections[1]['ip']); + + $this->assertEquals('Test1', $connections[2]['auth_type']); + $this->assertEquals('127.0.0.1', $connections[2]['ip']); + } + + public function testCleanup() + { + $lastLoginModel = new LastLogin($this->container); + + for ($i = 0; $i < $lastLoginModel::NB_LOGINS + 5; $i++) { + $this->assertTrue($lastLoginModel->create('Test' . $i, 1, '127.0.0.1', 'My browser')); + } + + $connections = $lastLoginModel->getAll(1); + $this->assertCount(10, $connections); + $this->assertEquals('Test14', $connections[0]['auth_type']); + $this->assertEquals('Test5', $connections[9]['auth_type']); + } +} diff --git a/tests/units/Model/LinkTest.php b/tests/units/Model/LinkTest.php index de9d843a..b102646d 100644 --- a/tests/units/Model/LinkTest.php +++ b/tests/units/Model/LinkTest.php @@ -124,50 +124,4 @@ class LinkTest extends Base $this->assertArrayNotHasKey(0, $links); $this->assertEquals('relates to', $links[1]); } - - public function testValidateCreation() - { - $l = new Link($this->container); - - $r = $l->validateCreation(array('label' => 'a')); - $this->assertTrue($r[0]); - - $r = $l->validateCreation(array('label' => 'a', 'opposite_label' => 'b')); - $this->assertTrue($r[0]); - - $r = $l->validateCreation(array('label' => 'relates to')); - $this->assertFalse($r[0]); - - $r = $l->validateCreation(array('label' => 'a', 'opposite_label' => 'a')); - $this->assertFalse($r[0]); - - $r = $l->validateCreation(array('label' => '')); - $this->assertFalse($r[0]); - } - - public function testValidateModification() - { - $l = new Link($this->container); - - $r = $l->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => 0)); - $this->assertTrue($r[0]); - - $r = $l->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => '1')); - $this->assertTrue($r[0]); - - $r = $l->validateModification(array('id' => 20, 'label' => 'relates to', 'opposite_id' => '1')); - $this->assertFalse($r[0]); - - $r = $l->validateModification(array('id' => 20, 'label' => '', 'opposite_id' => '1')); - $this->assertFalse($r[0]); - - $r = $l->validateModification(array('label' => '', 'opposite_id' => '1')); - $this->assertFalse($r[0]); - - $r = $l->validateModification(array('id' => 20, 'opposite_id' => '1')); - $this->assertFalse($r[0]); - - $r = $l->validateModification(array('label' => 'test')); - $this->assertFalse($r[0]); - } } diff --git a/tests/units/Model/NotificationTest.php b/tests/units/Model/NotificationTest.php index 7f9977ce..03ee5867 100644 --- a/tests/units/Model/NotificationTest.php +++ b/tests/units/Model/NotificationTest.php @@ -7,7 +7,7 @@ use Kanboard\Model\TaskCreation; use Kanboard\Model\Subtask; use Kanboard\Model\Comment; use Kanboard\Model\User; -use Kanboard\Model\File; +use Kanboard\Model\TaskFile; use Kanboard\Model\Task; use Kanboard\Model\Project; use Kanboard\Model\Notification; @@ -23,7 +23,7 @@ class NotificationTest extends Base $tc = new TaskCreation($this->container); $s = new Subtask($this->container); $c = new Comment($this->container); - $f = new File($this->container); + $f = new TaskFile($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); diff --git a/tests/units/Model/PasswordResetTest.php b/tests/units/Model/PasswordResetTest.php new file mode 100644 index 00000000..f88d24fb --- /dev/null +++ b/tests/units/Model/PasswordResetTest.php @@ -0,0 +1,85 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\User; +use Kanboard\Model\PasswordReset; + +class PasswordResetTest extends Base +{ + public function testCreate() + { + $userModel = new User($this->container); + $passwordResetModel = new PasswordReset($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); + + $this->assertFalse($passwordResetModel->create('user0')); + $this->assertFalse($passwordResetModel->create('user1')); + $this->assertNotFalse($passwordResetModel->create('user2')); + } + + public function testGetUserIdByToken() + { + $userModel = new User($this->container); + $passwordResetModel = new PasswordReset($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); + + $token = $passwordResetModel->create('user2'); + $this->assertEquals(2, $passwordResetModel->getUserIdByToken($token)); + } + + public function testGetUserIdByTokenWhenExpired() + { + $userModel = new User($this->container); + $passwordResetModel = new PasswordReset($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); + + $token = $passwordResetModel->create('user2', strtotime('-1 year')); + $this->assertFalse($passwordResetModel->getUserIdByToken($token)); + } + + public function testDisableTokens() + { + $userModel = new User($this->container); + $passwordResetModel = new PasswordReset($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); + + $token1 = $passwordResetModel->create('user2'); + $token2 = $passwordResetModel->create('user2'); + + $this->assertEquals(2, $passwordResetModel->getUserIdByToken($token1)); + $this->assertEquals(2, $passwordResetModel->getUserIdByToken($token2)); + + $this->assertTrue($passwordResetModel->disable(2)); + + $this->assertFalse($passwordResetModel->getUserIdByToken($token1)); + $this->assertFalse($passwordResetModel->getUserIdByToken($token2)); + } + + public function testGetAll() + { + $userModel = new User($this->container); + $passwordResetModel = new PasswordReset($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user2', 'email' => 'user1@localhost'))); + $this->assertNotFalse($passwordResetModel->create('user2')); + $this->assertNotFalse($passwordResetModel->create('user2')); + + $tokens = $passwordResetModel->getAll(1); + $this->assertCount(0, $tokens); + + $tokens = $passwordResetModel->getAll(2); + $this->assertCount(2, $tokens); + $this->assertNotEmpty($tokens[0]['token']); + $this->assertNotEmpty($tokens[0]['date_creation']); + $this->assertNotEmpty($tokens[0]['date_expiration']); + $this->assertEquals(2, $tokens[0]['user_id']); + $this->assertArrayHasKey('user_agent', $tokens[0]); + $this->assertArrayHasKey('ip', $tokens[0]); + } +} diff --git a/tests/units/Model/ProjectActivityTest.php b/tests/units/Model/ProjectActivityTest.php index 5a242cb2..04d3004d 100644 --- a/tests/units/Model/ProjectActivityTest.php +++ b/tests/units/Model/ProjectActivityTest.php @@ -9,7 +9,6 @@ use Kanboard\Model\ProjectActivity; use Kanboard\Model\Project; use Kanboard\Model\Subtask; use Kanboard\Model\Comment; -use Kanboard\Model\File; class ProjectActivityTest extends Base { @@ -87,9 +86,10 @@ class ProjectActivityTest extends Base $max = 15; $nb_events = 100; + $task = $tf->getbyId(1); for ($i = 0; $i < $nb_events; $i++) { - $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1)))); + $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $task))); } $this->assertEquals($nb_events, $this->container['db']->table('project_activities')->count()); @@ -98,20 +98,9 @@ class ProjectActivityTest extends Base $events = $e->getProject(1); $this->assertNotEmpty($events); - $this->assertTrue(is_array($events)); - $this->assertEquals($max, count($events)); + $this->assertCount($max, $events); $this->assertEquals(100, $events[0]['id']); $this->assertEquals(99, $events[1]['id']); $this->assertEquals(86, $events[14]['id']); - - // Cleanup during task creation - - $nb_events = ProjectActivity::MAX_EVENTS + 10; - - for ($i = 0; $i < $nb_events; $i++) { - $this->assertTrue($e->createEvent(1, 1, 1, Task::EVENT_CLOSE, array('task' => $tf->getbyId(1)))); - } - - $this->assertEquals(ProjectActivity::MAX_EVENTS, $this->container['db']->table('project_activities')->count()); } } diff --git a/tests/units/Model/ProjectDailyColumnStatsTest.php b/tests/units/Model/ProjectDailyColumnStatsTest.php index 4c801e02..5e8ec3e8 100644 --- a/tests/units/Model/ProjectDailyColumnStatsTest.php +++ b/tests/units/Model/ProjectDailyColumnStatsTest.php @@ -4,87 +4,262 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Model\Project; use Kanboard\Model\ProjectDailyColumnStats; +use Kanboard\Model\Config; use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskStatus; class ProjectDailyColumnStatsTest extends Base { + public function testUpdateTotalsWithScoreAtNull() + { + $projectModel = new Project($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $projectDailyColumnStats->updateTotals(1, '2016-01-16'); + + $task = $this->container['db']->table(Task::TABLE)->findOne(); + $this->assertNull($task['score']); + + $stats = $this->container['db']->table(ProjectDailyColumnStats::TABLE) + ->asc('day') + ->asc('column_id') + ->columns('day', 'project_id', 'column_id', 'total', 'score') + ->findAll(); + + $expected = array( + array( + 'day' => '2016-01-16', + 'project_id' => 1, + 'column_id' => 1, + 'total' => 1, + 'score' => 0, + ), + ); + + $this->assertEquals($expected, $stats); + } + public function testUpdateTotals() { - $p = new Project($this->container); - $pds = new ProjectDailyColumnStats($this->container); - $tc = new TaskCreation($this->container); - $ts = new TaskStatus($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertEquals(0, $pds->countDays(1, date('Y-m-d', strtotime('-2days')), date('Y-m-d'))); - - for ($i = 0; $i < 10; $i++) { - $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 1))); - } - - for ($i = 0; $i < 5; $i++) { - $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 4))); - } - - $pds->updateTotals(1, date('Y-m-d', strtotime('-2days'))); - - for ($i = 0; $i < 15; $i++) { - $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 3))); - } - - for ($i = 0; $i < 25; $i++) { - $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 2))); - } - - $pds->updateTotals(1, date('Y-m-d', strtotime('-1 day'))); - - $this->assertNotFalse($ts->close(1)); - $this->assertNotFalse($ts->close(2)); - - for ($i = 0; $i < 3; $i++) { - $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 3))); - } - - for ($i = 0; $i < 5; $i++) { - $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 2))); - } - - for ($i = 0; $i < 4; $i++) { - $this->assertNotFalse($tc->create(array('title' => 'Task #'.$i, 'project_id' => 1, 'column_id' => 4))); - } - - $pds->updateTotals(1, date('Y-m-d')); - - $this->assertEquals(3, $pds->countDays(1, date('Y-m-d', strtotime('-2days')), date('Y-m-d'))); - $metrics = $pds->getAggregatedMetrics(1, date('Y-m-d', strtotime('-2days')), date('Y-m-d')); - - $this->assertNotEmpty($metrics); - $this->assertEquals(4, count($metrics)); - $this->assertEquals(5, count($metrics[0])); - $this->assertEquals('Date', $metrics[0][0]); - $this->assertEquals('Backlog', $metrics[0][1]); - $this->assertEquals('Ready', $metrics[0][2]); - $this->assertEquals('Work in progress', $metrics[0][3]); - $this->assertEquals('Done', $metrics[0][4]); - - $this->assertEquals(date('Y-m-d', strtotime('-2days')), $metrics[1][0]); - $this->assertEquals(10, $metrics[1][1]); - $this->assertEquals(0, $metrics[1][2]); - $this->assertEquals(0, $metrics[1][3]); - $this->assertEquals(5, $metrics[1][4]); - - $this->assertEquals(date('Y-m-d', strtotime('-1day')), $metrics[2][0]); - $this->assertEquals(10, $metrics[2][1]); - $this->assertEquals(25, $metrics[2][2]); - $this->assertEquals(15, $metrics[2][3]); - $this->assertEquals(5, $metrics[2][4]); - - $this->assertEquals(date('Y-m-d'), $metrics[3][0]); - $this->assertEquals(10, $metrics[3][1]); - $this->assertEquals(30, $metrics[3][2]); - $this->assertEquals(18, $metrics[3][3]); - $this->assertEquals(9, $metrics[3][4]); + $projectModel = new Project($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + + $this->createTasks(1, 2, 1); + $this->createTasks(1, 3, 0); + + $this->createTasks(2, 5, 1); + $this->createTasks(2, 8, 1); + $this->createTasks(2, 0, 0); + $this->createTasks(2, 0, 0); + + $projectDailyColumnStats->updateTotals(1, '2016-01-16'); + + $this->createTasks(1, 9, 1); + $this->createTasks(1, 7, 0); + + $projectDailyColumnStats->updateTotals(1, '2016-01-16'); + + $this->createTasks(3, 0, 1); + + $projectDailyColumnStats->updateTotals(1, '2016-01-17'); + + $stats = $this->container['db']->table(ProjectDailyColumnStats::TABLE) + ->asc('day') + ->asc('column_id') + ->columns('day', 'project_id', 'column_id', 'total', 'score') + ->findAll(); + + $expected = array( + array( + 'day' => '2016-01-16', + 'project_id' => 1, + 'column_id' => 1, + 'total' => 4, + 'score' => 11, + ), + array( + 'day' => '2016-01-16', + 'project_id' => 1, + 'column_id' => 2, + 'total' => 4, + 'score' => 13, + ), + array( + 'day' => '2016-01-17', + 'project_id' => 1, + 'column_id' => 1, + 'total' => 4, + 'score' => 11, + ), + array( + 'day' => '2016-01-17', + 'project_id' => 1, + 'column_id' => 2, + 'total' => 4, + 'score' => 13, + ), + array( + 'day' => '2016-01-17', + 'project_id' => 1, + 'column_id' => 3, + 'total' => 1, + 'score' => 0, + ), + ); + + $this->assertEquals($expected, $stats); + } + + public function testUpdateTotalsWithOnlyOpenTasks() + { + $configModel = new Config($this->container); + $projectModel = new Project($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertTrue($configModel->save(array('cfd_include_closed_tasks' => 0))); + $this->container['memoryCache']->flush(); + + $this->createTasks(1, 2, 1); + $this->createTasks(1, 3, 0); + + $this->createTasks(2, 5, 1); + $this->createTasks(2, 8, 1); + $this->createTasks(2, 0, 0); + $this->createTasks(2, 0, 0); + + $projectDailyColumnStats->updateTotals(1, '2016-01-16'); + + $this->createTasks(1, 9, 1); + $this->createTasks(1, 7, 0); + + $projectDailyColumnStats->updateTotals(1, '2016-01-16'); + + $this->createTasks(3, 0, 1); + + $projectDailyColumnStats->updateTotals(1, '2016-01-17'); + + $stats = $this->container['db']->table(ProjectDailyColumnStats::TABLE) + ->asc('day') + ->asc('column_id') + ->columns('day', 'project_id', 'column_id', 'total', 'score') + ->findAll(); + + $expected = array( + array( + 'day' => '2016-01-16', + 'project_id' => 1, + 'column_id' => 1, + 'total' => 2, + 'score' => 11, + ), + array( + 'day' => '2016-01-16', + 'project_id' => 1, + 'column_id' => 2, + 'total' => 2, + 'score' => 13, + ), + array( + 'day' => '2016-01-17', + 'project_id' => 1, + 'column_id' => 1, + 'total' => 2, + 'score' => 11, + ), + array( + 'day' => '2016-01-17', + 'project_id' => 1, + 'column_id' => 2, + 'total' => 2, + 'score' => 13, + ), + array( + 'day' => '2016-01-17', + 'project_id' => 1, + 'column_id' => 3, + 'total' => 1, + 'score' => 0, + ), + ); + + $this->assertEquals($expected, $stats); + } + + public function testCountDays() + { + $projectModel = new Project($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + + $this->createTasks(1, 2, 1); + $projectDailyColumnStats->updateTotals(1, '2016-01-16'); + $this->assertEquals(1, $projectDailyColumnStats->countDays(1, '2016-01-16', '2016-01-17')); + + $projectDailyColumnStats->updateTotals(1, '2016-01-17'); + $this->assertEquals(2, $projectDailyColumnStats->countDays(1, '2016-01-16', '2016-01-17')); + } + + public function testGetAggregatedMetrics() + { + $projectModel = new Project($this->container); + $projectDailyColumnStats = new ProjectDailyColumnStats($this->container); + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + + $this->createTasks(1, 2, 1); + $this->createTasks(1, 3, 0); + + $this->createTasks(2, 5, 1); + $this->createTasks(2, 8, 1); + $this->createTasks(2, 0, 0); + $this->createTasks(2, 0, 0); + + $projectDailyColumnStats->updateTotals(1, '2016-01-16'); + + $this->createTasks(1, 9, 1); + $this->createTasks(1, 7, 0); + + $projectDailyColumnStats->updateTotals(1, '2016-01-16'); + + $this->createTasks(3, 0, 1); + + $projectDailyColumnStats->updateTotals(1, '2016-01-17'); + + $this->createTasks(2, 1, 1); + $this->createTasks(3, 1, 1); + $this->createTasks(3, 0, 1); + + $projectDailyColumnStats->updateTotals(1, '2016-01-18'); + + $expected = array( + array('Date', 'Backlog', 'Ready', 'Work in progress', 'Done'), + array('2016-01-16', 4, 4, 0, 0), + array('2016-01-17', 4, 4, 1, 0), + array('2016-01-18', 4, 5, 3, 0), + ); + + $this->assertEquals($expected, $projectDailyColumnStats->getAggregatedMetrics(1, '2016-01-16', '2016-01-18')); + + $expected = array( + array('Date', 'Backlog', 'Ready', 'Work in progress', 'Done'), + array('2016-01-16', 11, 13, 0, 0), + array('2016-01-17', 11, 13, 0, 0), + array('2016-01-18', 11, 14, 1, 0), + ); + + $this->assertEquals($expected, $projectDailyColumnStats->getAggregatedMetrics(1, '2016-01-16', '2016-01-18', 'score')); + } + + private function createTasks($column_id, $score, $is_active) + { + $taskCreationModel = new TaskCreation($this->container); + $this->assertNotFalse($taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'column_id' => $column_id, 'score' => $score, 'is_active' => $is_active))); } } diff --git a/tests/units/Model/ProjectDailyStatsTest.php b/tests/units/Model/ProjectDailyStatsTest.php new file mode 100644 index 00000000..9efdb199 --- /dev/null +++ b/tests/units/Model/ProjectDailyStatsTest.php @@ -0,0 +1,48 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\Project; +use Kanboard\Model\ProjectDailyStats; +use Kanboard\Model\Task; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskStatus; + +class ProjectDailyStatsTest extends Base +{ + public function testUpdateTotals() + { + $p = new Project($this->container); + $pds = new ProjectDailyStats($this->container); + $tc = new TaskCreation($this->container); + $ts = new TaskStatus($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + $this->assertEquals(2, $p->create(array('name' => 'UnitTest'))); + + $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'date_started' => strtotime('-1 day')))); + $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1))); + $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 2))); + + $pds->updateTotals(1, date('Y-m-d', strtotime('-1 day'))); + + $this->assertTrue($ts->close(1)); + $pds->updateTotals(1, date('Y-m-d')); + + $metrics = $pds->getRawMetrics(1, date('Y-m-d', strtotime('-1days')), date('Y-m-d')); + $expected = array( + array( + 'day' => date('Y-m-d', strtotime('-1days')), + 'avg_lead_time' => 0, + 'avg_cycle_time' => 43200, + ), + array( + 'day' => date('Y-m-d'), + 'avg_lead_time' => 0, + 'avg_cycle_time' => 43200, + ) + ); + + $this->assertEquals($expected, $metrics); + } +} diff --git a/tests/units/Model/ProjectDuplicationTest.php b/tests/units/Model/ProjectDuplicationTest.php index e3234dfe..ee5b4ce4 100644 --- a/tests/units/Model/ProjectDuplicationTest.php +++ b/tests/units/Model/ProjectDuplicationTest.php @@ -5,17 +5,28 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Model\Action; use Kanboard\Model\Project; use Kanboard\Model\Category; -use Kanboard\Model\ProjectPermission; +use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\ProjectGroupRole; use Kanboard\Model\ProjectDuplication; use Kanboard\Model\User; +use Kanboard\Model\Group; +use Kanboard\Model\GroupMember; use Kanboard\Model\Swimlane; use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; +use Kanboard\Core\Security\Role; class ProjectDuplicationTest extends Base { - public function testProjectName() + public function testGetSelections() + { + $projectDuplicationModel = new ProjectDuplication($this->container); + $this->assertCount(5, $projectDuplicationModel->getOptionalSelection()); + $this->assertCount(6, $projectDuplicationModel->getPossibleSelection()); + } + + public function testGetClonedProjectName() { $pd = new ProjectDuplication($this->container); @@ -28,54 +39,142 @@ class ProjectDuplicationTest extends Base $this->assertEquals(str_repeat('a', 42).' (Clone)', $pd->getClonedProjectName(str_repeat('a', 60))); } - public function testCopyProjectWithLongName() + public function testClonePublicProject() { $p = new Project($this->container); $pd = new ProjectDuplication($this->container); - $this->assertEquals(1, $p->create(array('name' => str_repeat('a', 50)))); + $this->assertEquals(1, $p->create(array('name' => 'Public'))); $this->assertEquals(2, $pd->duplicate(1)); $project = $p->getById(2); $this->assertNotEmpty($project); - $this->assertEquals(str_repeat('a', 42).' (Clone)', $project['name']); + $this->assertEquals('Public (Clone)', $project['name']); + $this->assertEquals(1, $project['is_active']); + $this->assertEquals(0, $project['is_private']); + $this->assertEquals(0, $project['is_public']); + $this->assertEquals(0, $project['owner_id']); + $this->assertEmpty($project['token']); } - public function testClonePublicProject() + public function testClonePrivateProject() { $p = new Project($this->container); $pd = new ProjectDuplication($this->container); + $pp = new ProjectUserRole($this->container); - $this->assertEquals(1, $p->create(array('name' => 'Public'))); + $this->assertEquals(1, $p->create(array('name' => 'Private', 'is_private' => 1), 1, true)); $this->assertEquals(2, $pd->duplicate(1)); $project = $p->getById(2); $this->assertNotEmpty($project); - $this->assertEquals('Public (Clone)', $project['name']); - $this->assertEquals(0, $project['is_private']); + $this->assertEquals('Private (Clone)', $project['name']); + $this->assertEquals(1, $project['is_active']); + $this->assertEquals(1, $project['is_private']); $this->assertEquals(0, $project['is_public']); + $this->assertEquals(0, $project['owner_id']); $this->assertEmpty($project['token']); + + $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 1)); } - public function testClonePrivateProject() + public function testCloneSharedProject() { $p = new Project($this->container); $pd = new ProjectDuplication($this->container); - $this->assertEquals(1, $p->create(array('name' => 'Private', 'is_private' => 1), 1, true)); + $this->assertEquals(1, $p->create(array('name' => 'Shared'))); + $this->assertTrue($p->update(array('id' => 1, 'is_public' => 1, 'token' => 'test'))); + + $project = $p->getById(1); + $this->assertEquals('test', $project['token']); + $this->assertEquals(1, $project['is_public']); + $this->assertEquals(2, $pd->duplicate(1)); $project = $p->getById(2); $this->assertNotEmpty($project); - $this->assertEquals('Private (Clone)', $project['name']); - $this->assertEquals(1, $project['is_private']); + $this->assertEquals('Shared (Clone)', $project['name']); + $this->assertEquals('', $project['token']); $this->assertEquals(0, $project['is_public']); - $this->assertEmpty($project['token']); + } - $pp = new ProjectPermission($this->container); + public function testCloneInactiveProject() + { + $p = new Project($this->container); + $pd = new ProjectDuplication($this->container); - $this->assertEquals(array(1 => 'admin'), $pp->getMembers(1)); - $this->assertEquals(array(1 => 'admin'), $pp->getMembers(2)); + $this->assertEquals(1, $p->create(array('name' => 'Inactive'))); + $this->assertTrue($p->update(array('id' => 1, 'is_active' => 0))); + + $project = $p->getById(1); + $this->assertEquals(0, $project['is_active']); + + $this->assertEquals(2, $pd->duplicate(1)); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('Inactive (Clone)', $project['name']); + $this->assertEquals(1, $project['is_active']); + } + + public function testCloneProjectWithOwner() + { + $p = new Project($this->container); + $pd = new ProjectDuplication($this->container); + $projectUserRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'Owner'))); + + $project = $p->getById(1); + $this->assertEquals(0, $project['owner_id']); + + $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1)); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('Owner (Clone)', $project['name']); + $this->assertEquals(1, $project['owner_id']); + + $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 1)); + } + + public function testCloneProjectWithDifferentName() + { + $p = new Project($this->container); + $pd = new ProjectDuplication($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'Owner'))); + + $project = $p->getById(1); + $this->assertEquals(0, $project['owner_id']); + + $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1, 'Foobar')); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('Foobar', $project['name']); + $this->assertEquals(1, $project['owner_id']); + } + + public function testCloneProjectAndForceItToBePrivate() + { + $p = new Project($this->container); + $pd = new ProjectDuplication($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'Owner'))); + + $project = $p->getById(1); + $this->assertEquals(0, $project['owner_id']); + $this->assertEquals(0, $project['is_private']); + + $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1, 'Foobar', true)); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('Foobar', $project['name']); + $this->assertEquals(1, $project['owner_id']); + $this->assertEquals(1, $project['is_private']); } public function testCloneProjectWithCategories() @@ -97,16 +196,9 @@ class ProjectDuplicationTest extends Base $this->assertEquals('P1 (Clone)', $project['name']); $categories = $c->getAll(2); - $this->assertNotempty($categories); - $this->assertEquals(3, count($categories)); - - $this->assertEquals(4, $categories[0]['id']); + $this->assertCount(3, $categories); $this->assertEquals('C1', $categories[0]['name']); - - $this->assertEquals(5, $categories[1]['id']); $this->assertEquals('C2', $categories[1]['name']); - - $this->assertEquals(6, $categories[2]['id']); $this->assertEquals('C3', $categories[2]['name']); } @@ -114,38 +206,119 @@ class ProjectDuplicationTest extends Base { $p = new Project($this->container); $c = new Category($this->container); - $pp = new ProjectPermission($this->container); + $pp = new ProjectUserRole($this->container); $u = new User($this->container); $pd = new ProjectDuplication($this->container); - $this->assertEquals(2, $u->create(array('username' => 'unittest1', 'password' => 'unittest'))); - $this->assertEquals(3, $u->create(array('username' => 'unittest2', 'password' => 'unittest'))); - $this->assertEquals(4, $u->create(array('username' => 'unittest3', 'password' => 'unittest'))); + $this->assertEquals(2, $u->create(array('username' => 'user1'))); + $this->assertEquals(3, $u->create(array('username' => 'user2'))); + $this->assertEquals(4, $u->create(array('username' => 'user3'))); $this->assertEquals(1, $p->create(array('name' => 'P1'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->addMember(1, 4)); - $this->assertTrue($pp->addManager(1, 3)); - $this->assertTrue($pp->isMember(1, 2)); - $this->assertTrue($pp->isMember(1, 3)); - $this->assertTrue($pp->isMember(1, 4)); - $this->assertFalse($pp->isManager(1, 2)); - $this->assertTrue($pp->isManager(1, 3)); - $this->assertFalse($pp->isManager(1, 4)); + + $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER)); + $this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER)); + $this->assertTrue($pp->addUser(1, 4, Role::PROJECT_VIEWER)); $this->assertEquals(2, $pd->duplicate(1)); + $this->assertCount(3, $pp->getUsers(2)); + $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 2)); + $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(2, 3)); + $this->assertEquals(Role::PROJECT_VIEWER, $pp->getUserRole(2, 4)); + } + + public function testCloneProjectWithUsersAndOverrideOwner() + { + $p = new Project($this->container); + $c = new Category($this->container); + $pp = new ProjectUserRole($this->container); + $u = new User($this->container); + $pd = new ProjectDuplication($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'user1'))); + $this->assertEquals(1, $p->create(array('name' => 'P1'), 2)); + + $project = $p->getById(1); + $this->assertEquals(2, $project['owner_id']); + + $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER)); + $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER)); + + $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 1)); + + $this->assertCount(2, $pp->getUsers(2)); + $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 2)); + $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 1)); + $project = $p->getById(2); - $this->assertNotEmpty($project); - $this->assertEquals('P1 (Clone)', $project['name']); + $this->assertEquals(1, $project['owner_id']); + } + + public function testCloneTeamProjectToPrivatProject() + { + $p = new Project($this->container); + $c = new Category($this->container); + $pp = new ProjectUserRole($this->container); + $u = new User($this->container); + $pd = new ProjectDuplication($this->container); + + $this->assertEquals(2, $u->create(array('username' => 'user1'))); + $this->assertEquals(3, $u->create(array('username' => 'user2'))); + $this->assertEquals(1, $p->create(array('name' => 'P1'), 2)); + + $project = $p->getById(1); + $this->assertEquals(2, $project['owner_id']); + $this->assertEquals(0, $project['is_private']); + + $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER)); + $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER)); - $this->assertEquals(3, count($pp->getMembers(2))); - $this->assertTrue($pp->isMember(2, 2)); - $this->assertTrue($pp->isMember(2, 3)); - $this->assertTrue($pp->isMember(2, 4)); - $this->assertFalse($pp->isManager(2, 2)); - $this->assertTrue($pp->isManager(2, 3)); - $this->assertFalse($pp->isManager(2, 4)); + $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 3, 'My private project', true)); + + $this->assertCount(1, $pp->getUsers(2)); + $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 3)); + + $project = $p->getById(2); + $this->assertEquals(3, $project['owner_id']); + $this->assertEquals(1, $project['is_private']); + } + + public function testCloneProjectWithGroups() + { + $p = new Project($this->container); + $c = new Category($this->container); + $pd = new ProjectDuplication($this->container); + $userModel = new User($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $projectGroupRoleModel = new ProjectGroupRole($this->container); + $projectUserRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'P1'))); + + $this->assertEquals(1, $groupModel->create('G1')); + $this->assertEquals(2, $groupModel->create('G2')); + $this->assertEquals(3, $groupModel->create('G3')); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user3'))); + + $this->assertTrue($groupMemberModel->addUser(1, 2)); + $this->assertTrue($groupMemberModel->addUser(2, 3)); + $this->assertTrue($groupMemberModel->addUser(3, 4)); + + $this->assertTrue($projectGroupRoleModel->addGroup(1, 1, Role::PROJECT_MANAGER)); + $this->assertTrue($projectGroupRoleModel->addGroup(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($projectGroupRoleModel->addGroup(1, 3, Role::PROJECT_VIEWER)); + + $this->assertEquals(2, $pd->duplicate(1)); + + $this->assertCount(3, $projectGroupRoleModel->getGroups(2)); + $this->assertEquals(Role::PROJECT_MANAGER, $projectUserRoleModel->getUserRole(2, 2)); + $this->assertEquals(Role::PROJECT_MEMBER, $projectUserRoleModel->getUserRole(2, 3)); + $this->assertEquals(Role::PROJECT_VIEWER, $projectUserRoleModel->getUserRole(2, 4)); } public function testCloneProjectWithActionTaskAssignCurrentUser() @@ -170,7 +343,7 @@ class ProjectDuplicationTest extends Base $this->assertNotEmpty($actions); $this->assertEquals('TaskAssignCurrentUser', $actions[0]['action_name']); $this->assertNotEmpty($actions[0]['params']); - $this->assertEquals(6, $actions[0]['params'][0]['value']); + $this->assertEquals(6, $actions[0]['params']['column_id']); } public function testCloneProjectWithActionTaskAssignColorCategory() @@ -200,11 +373,11 @@ class ProjectDuplicationTest extends Base $this->assertNotEmpty($actions); $this->assertEquals('TaskAssignColorCategory', $actions[0]['action_name']); $this->assertNotEmpty($actions[0]['params']); - $this->assertEquals('blue', $actions[0]['params'][0]['value']); - $this->assertEquals(5, $actions[0]['params'][1]['value']); + $this->assertEquals('blue', $actions[0]['params']['color_id']); + $this->assertEquals(5, $actions[0]['params']['category_id']); } - public function testCloneProjectWithSwimlanesAndTasks() + public function testCloneProjectWithSwimlanes() { $p = new Project($this->container); $pd = new ProjectDuplication($this->container); @@ -212,31 +385,22 @@ class ProjectDuplicationTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); - $this->assertEquals(1, $p->create(array('name' => 'P1'))); + $this->assertEquals(1, $p->create(array('name' => 'P1', 'default_swimlane' => 'New Default'))); // create initial swimlanes $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1'))); $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2'))); $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3'))); - $default_swimlane1 = $s->getDefault(1); - $default_swimlane1['default_swimlane'] = 'New Default'; + // create initial tasks + $this->assertEquals(1, $tc->create(array('title' => 'T0', 'project_id' => 1, 'swimlane_id' => 0))); + $this->assertEquals(2, $tc->create(array('title' => 'T1', 'project_id' => 1, 'swimlane_id' => 1))); + $this->assertEquals(3, $tc->create(array('title' => 'T2', 'project_id' => 1, 'swimlane_id' => 2))); + $this->assertEquals(4, $tc->create(array('title' => 'T3', 'project_id' => 1, 'swimlane_id' => 3))); - $this->assertTrue($s->updateDefault($default_swimlane1)); - - //create initial tasks - $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); - $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1))); - $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - - $this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'swimlane', 'task'))); - $project = $p->getByName('P1 (Clone)'); - $this->assertNotFalse($project); - $project_id = $project['id']; - - // Check if Swimlanes have been duplicated - $swimlanes = $s->getAll($project_id); + $this->assertEquals(2, $pd->duplicate(1, array('category', 'swimlane'))); + $swimlanes = $s->getAll(2); $this->assertCount(3, $swimlanes); $this->assertEquals(4, $swimlanes[0]['id']); $this->assertEquals('S1', $swimlanes[0]['name']); @@ -244,29 +408,15 @@ class ProjectDuplicationTest extends Base $this->assertEquals('S2', $swimlanes[1]['name']); $this->assertEquals(6, $swimlanes[2]['id']); $this->assertEquals('S3', $swimlanes[2]['name']); - $new_default = $s->getDefault($project_id); - $this->assertEquals('New Default', $new_default['default_swimlane']); - - // Check if Tasks have been duplicated - $tasks = $tf->getAll($project_id); + $swimlane = $s->getDefault(2); + $this->assertEquals('New Default', $swimlane['default_swimlane']); - $this->assertCount(3, $tasks); - // $this->assertEquals(4, $tasks[0]['id']); - $this->assertEquals('T1', $tasks[0]['title']); - // $this->assertEquals(5, $tasks[1]['id']); - $this->assertEquals('T2', $tasks[1]['title']); - // $this->assertEquals(6, $tasks[2]['id']); - $this->assertEquals('T3', $tasks[2]['title']); - - $p->remove($project_id); - - $this->assertFalse($p->exists($project_id)); - $this->assertCount(0, $s->getAll($project_id)); - $this->assertCount(0, $tf->getAll($project_id)); + // Check if tasks are NOT been duplicated + $this->assertCount(0, $tf->getAll(2)); } - public function testCloneProjectWithSwimlanes() + public function testCloneProjectWithTasks() { $p = new Project($this->container); $pd = new ProjectDuplication($this->container); @@ -276,43 +426,22 @@ class ProjectDuplicationTest extends Base $this->assertEquals(1, $p->create(array('name' => 'P1'))); - // create initial swimlanes - $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1'))); - $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2'))); - $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3'))); - - $default_swimlane1 = $s->getDefault(1); - $default_swimlane1['default_swimlane'] = 'New Default'; + // create initial tasks + $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1))); + $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2))); + $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3))); - $this->assertTrue($s->updateDefault($default_swimlane1)); - - //create initial tasks - $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); - $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1))); - $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - - $this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'swimlane'))); - $project = $p->getByName('P1 (Clone)'); - $this->assertNotFalse($project); - $project_id = $project['id']; - - $swimlanes = $s->getAll($project_id); - - $this->assertCount(3, $swimlanes); - $this->assertEquals(4, $swimlanes[0]['id']); - $this->assertEquals('S1', $swimlanes[0]['name']); - $this->assertEquals(5, $swimlanes[1]['id']); - $this->assertEquals('S2', $swimlanes[1]['name']); - $this->assertEquals(6, $swimlanes[2]['id']); - $this->assertEquals('S3', $swimlanes[2]['name']); - $new_default = $s->getDefault($project_id); - $this->assertEquals('New Default', $new_default['default_swimlane']); + $this->assertEquals(2, $pd->duplicate(1, array('category', 'action', 'task'))); - // Check if Tasks have NOT been duplicated - $this->assertCount(0, $tf->getAll($project_id)); + // Check if Tasks have been duplicated + $tasks = $tf->getAll(2); + $this->assertCount(3, $tasks); + $this->assertEquals('T1', $tasks[0]['title']); + $this->assertEquals('T2', $tasks[1]['title']); + $this->assertEquals('T3', $tasks[2]['title']); } - public function testCloneProjectWithTasks() + public function testCloneProjectWithSwimlanesAndTasks() { $p = new Project($this->container); $pd = new ProjectDuplication($this->container); @@ -320,40 +449,39 @@ class ProjectDuplicationTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); - $this->assertEquals(1, $p->create(array('name' => 'P1'))); + $this->assertEquals(1, $p->create(array('name' => 'P1', 'default_swimlane' => 'New Default'))); // create initial swimlanes $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1'))); $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2'))); $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'S3'))); - $default_swimlane1 = $s->getDefault(1); - $default_swimlane1['default_swimlane'] = 'New Default'; - - $this->assertTrue($s->updateDefault($default_swimlane1)); - - //create initial tasks + // create initial tasks $this->assertEquals(1, $tc->create(array('title' => 'T1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'T2', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 1))); $this->assertEquals(3, $tc->create(array('title' => 'T3', 'project_id' => 1, 'column_id' => 3, 'owner_id' => 1))); - $this->assertNotFalse($pd->duplicate(1, array('category', 'action', 'task'))); - $project = $p->getByName('P1 (Clone)'); - $this->assertNotFalse($project); - $project_id = $project['id']; + $this->assertEquals(2, $pd->duplicate(1, array('projectPermission', 'swimlane', 'task'))); + + // Check if Swimlanes have been duplicated + $swimlanes = $s->getAll(2); + $this->assertCount(3, $swimlanes); + $this->assertEquals(4, $swimlanes[0]['id']); + $this->assertEquals('S1', $swimlanes[0]['name']); + $this->assertEquals(5, $swimlanes[1]['id']); + $this->assertEquals('S2', $swimlanes[1]['name']); + $this->assertEquals(6, $swimlanes[2]['id']); + $this->assertEquals('S3', $swimlanes[2]['name']); - // Check if Swimlanes have NOT been duplicated - $this->assertCount(0, $s->getAll($project_id)); + $swimlane = $s->getDefault(2); + $this->assertEquals('New Default', $swimlane['default_swimlane']); // Check if Tasks have been duplicated - $tasks = $tf->getAll($project_id); + $tasks = $tf->getAll(2); $this->assertCount(3, $tasks); - //$this->assertEquals(4, $tasks[0]['id']); $this->assertEquals('T1', $tasks[0]['title']); - //$this->assertEquals(5, $tasks[1]['id']); $this->assertEquals('T2', $tasks[1]['title']); - //$this->assertEquals(6, $tasks[2]['id']); $this->assertEquals('T3', $tasks[2]['title']); } } diff --git a/tests/units/Model/ProjectFileTest.php b/tests/units/Model/ProjectFileTest.php new file mode 100644 index 00000000..d9b37fbe --- /dev/null +++ b/tests/units/Model/ProjectFileTest.php @@ -0,0 +1,311 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\ProjectFile; +use Kanboard\Model\Project; + +class ProjectFileTest extends Base +{ + public function testCreation() + { + $projectModel = new Project($this->container); + $fileModel = new ProjectFile($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); + + $file = $fileModel->getById(1); + $this->assertEquals('test', $file['name']); + $this->assertEquals('/tmp/foo', $file['path']); + $this->assertEquals(0, $file['is_image']); + $this->assertEquals(1, $file['project_id']); + $this->assertEquals(time(), $file['date'], '', 2); + $this->assertEquals(0, $file['user_id']); + $this->assertEquals(10, $file['size']); + + $this->assertEquals(2, $fileModel->create(1, 'test2.png', '/tmp/foobar', 10)); + + $file = $fileModel->getById(2); + $this->assertEquals('test2.png', $file['name']); + $this->assertEquals('/tmp/foobar', $file['path']); + $this->assertEquals(1, $file['is_image']); + } + + public function testCreationWithFileNameTooLong() + { + $projectModel = new Project($this->container); + $fileModel = new ProjectFile($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + + $this->assertNotFalse($fileModel->create(1, 'test', '/tmp/foo', 10)); + $this->assertNotFalse($fileModel->create(1, str_repeat('a', 1000), '/tmp/foo', 10)); + + $files = $fileModel->getAll(1); + $this->assertNotEmpty($files); + $this->assertCount(2, $files); + + $this->assertEquals(str_repeat('a', 255), $files[0]['name']); + $this->assertEquals('test', $files[1]['name']); + } + + public function testCreationWithSessionOpen() + { + $this->container['sessionStorage']->user = array('id' => 1); + + $projectModel = new Project($this->container); + $fileModel = new ProjectFile($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); + + $file = $fileModel->getById(1); + $this->assertEquals('test', $file['name']); + $this->assertEquals(1, $file['user_id']); + } + + public function testGetAll() + { + $projectModel = new Project($this->container); + $fileModel = new ProjectFile($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + + $this->assertEquals(1, $fileModel->create(1, 'B.pdf', '/tmp/foo', 10)); + $this->assertEquals(2, $fileModel->create(1, 'A.png', '/tmp/foo', 10)); + $this->assertEquals(3, $fileModel->create(1, 'D.doc', '/tmp/foo', 10)); + $this->assertEquals(4, $fileModel->create(1, 'C.JPG', '/tmp/foo', 10)); + + $fileModeliles = $fileModel->getAll(1); + $this->assertNotEmpty($fileModeliles); + $this->assertCount(4, $fileModeliles); + $this->assertEquals('A.png', $fileModeliles[0]['name']); + $this->assertEquals('B.pdf', $fileModeliles[1]['name']); + $this->assertEquals('C.JPG', $fileModeliles[2]['name']); + $this->assertEquals('D.doc', $fileModeliles[3]['name']); + + $fileModeliles = $fileModel->getAllImages(1); + $this->assertNotEmpty($fileModeliles); + $this->assertCount(2, $fileModeliles); + $this->assertEquals('A.png', $fileModeliles[0]['name']); + $this->assertEquals('C.JPG', $fileModeliles[1]['name']); + + $fileModeliles = $fileModel->getAllDocuments(1); + $this->assertNotEmpty($fileModeliles); + $this->assertCount(2, $fileModeliles); + $this->assertEquals('B.pdf', $fileModeliles[0]['name']); + $this->assertEquals('D.doc', $fileModeliles[1]['name']); + } + + public function testGetThumbnailPath() + { + $fileModel = new ProjectFile($this->container); + $this->assertEquals('thumbnails'.DIRECTORY_SEPARATOR.'test', $fileModel->getThumbnailPath('test')); + } + + public function testGeneratePath() + { + $fileModel = new ProjectFile($this->container); + + $this->assertStringStartsWith('projects'.DIRECTORY_SEPARATOR.'34'.DIRECTORY_SEPARATOR, $fileModel->generatePath(34, 'test.png')); + $this->assertNotEquals($fileModel->generatePath(34, 'test1.png'), $fileModel->generatePath(34, 'test2.png')); + } + + public function testUploadFiles() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\ProjectFile') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new Project($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + + $files = array( + 'name' => array( + 'file1.png', + 'file2.doc', + ), + 'tmp_name' => array( + '/tmp/phpYzdqkD', + '/tmp/phpeEwEWG', + ), + 'error' => array( + UPLOAD_ERR_OK, + UPLOAD_ERR_OK, + ), + 'size' => array( + 123, + 456, + ), + ); + + $fileModel + ->expects($this->once()) + ->method('generateThumbnailFromFile'); + + $this->container['objectStorage'] + ->expects($this->at(0)) + ->method('moveUploadedFile') + ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()); + + $this->container['objectStorage'] + ->expects($this->at(1)) + ->method('moveUploadedFile') + ->with($this->equalTo('/tmp/phpeEwEWG'), $this->anything()); + + $this->assertTrue($fileModel->uploadFiles(1, $files)); + + $files = $fileModel->getAll(1); + $this->assertCount(2, $files); + + $this->assertEquals(1, $files[0]['id']); + $this->assertEquals('file1.png', $files[0]['name']); + $this->assertEquals(1, $files[0]['is_image']); + $this->assertEquals(1, $files[0]['project_id']); + $this->assertEquals(0, $files[0]['user_id']); + $this->assertEquals(123, $files[0]['size']); + $this->assertEquals(time(), $files[0]['date'], '', 2); + + $this->assertEquals(2, $files[1]['id']); + $this->assertEquals('file2.doc', $files[1]['name']); + $this->assertEquals(0, $files[1]['is_image']); + $this->assertEquals(1, $files[1]['project_id']); + $this->assertEquals(0, $files[1]['user_id']); + $this->assertEquals(456, $files[1]['size']); + $this->assertEquals(time(), $files[1]['date'], '', 2); + } + + public function testUploadFilesWithEmptyFiles() + { + $fileModel = new ProjectFile($this->container); + $this->assertFalse($fileModel->uploadFiles(1, array())); + } + + public function testUploadFilesWithUploadError() + { + $files = array( + 'name' => array( + 'file1.png', + 'file2.doc', + ), + 'tmp_name' => array( + '', + '/tmp/phpeEwEWG', + ), + 'error' => array( + UPLOAD_ERR_CANT_WRITE, + UPLOAD_ERR_OK, + ), + 'size' => array( + 123, + 456, + ), + ); + + $fileModel = new ProjectFile($this->container); + $this->assertFalse($fileModel->uploadFiles(1, $files)); + } + + public function testUploadFilesWithObjectStorageError() + { + $files = array( + 'name' => array( + 'file1.csv', + 'file2.doc', + ), + 'tmp_name' => array( + '/tmp/phpYzdqkD', + '/tmp/phpeEwEWG', + ), + 'error' => array( + UPLOAD_ERR_OK, + UPLOAD_ERR_OK, + ), + 'size' => array( + 123, + 456, + ), + ); + + $this->container['objectStorage'] + ->expects($this->at(0)) + ->method('moveUploadedFile') + ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()) + ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); + + $fileModel = new ProjectFile($this->container); + $this->assertFalse($fileModel->uploadFiles(1, $files)); + } + + public function testUploadFileContent() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\ProjectFile') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new Project($this->container); + $data = 'test'; + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with($this->anything(), $this->equalTo($data)); + + $this->assertEquals(1, $fileModel->uploadContent(1, 'test.doc', base64_encode($data))); + + $files = $fileModel->getAll(1); + $this->assertCount(1, $files); + + $this->assertEquals(1, $files[0]['id']); + $this->assertEquals('test.doc', $files[0]['name']); + $this->assertEquals(0, $files[0]['is_image']); + $this->assertEquals(1, $files[0]['project_id']); + $this->assertEquals(0, $files[0]['user_id']); + $this->assertEquals(4, $files[0]['size']); + $this->assertEquals(time(), $files[0]['date'], '', 2); + } + + public function testUploadImageContent() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\ProjectFile') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new Project($this->container); + $data = 'test'; + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + + $fileModel + ->expects($this->once()) + ->method('generateThumbnailFromFile'); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with($this->anything(), $this->equalTo($data)); + + $this->assertEquals(1, $fileModel->uploadContent(1, 'test.png', base64_encode($data))); + + $files = $fileModel->getAll(1); + $this->assertCount(1, $files); + + $this->assertEquals(1, $files[0]['id']); + $this->assertEquals('test.png', $files[0]['name']); + $this->assertEquals(1, $files[0]['is_image']); + $this->assertEquals(1, $files[0]['project_id']); + $this->assertEquals(0, $files[0]['user_id']); + $this->assertEquals(4, $files[0]['size']); + $this->assertEquals(time(), $files[0]['date'], '', 2); + } +} diff --git a/tests/units/Model/ProjectGroupRoleTest.php b/tests/units/Model/ProjectGroupRoleTest.php new file mode 100644 index 00000000..e38e812a --- /dev/null +++ b/tests/units/Model/ProjectGroupRoleTest.php @@ -0,0 +1,401 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\Project; +use Kanboard\Model\User; +use Kanboard\Model\Group; +use Kanboard\Model\GroupMember; +use Kanboard\Model\ProjectGroupRole; +use Kanboard\Core\Security\Role; + +class ProjectGroupRoleTest extends Base +{ + public function testGetUserRole() + { + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $groupMemberModel = new GroupMember($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 1)); + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + + $this->assertEquals(Role::PROJECT_VIEWER, $groupRoleModel->getUserRole(1, 1)); + $this->assertEquals('', $groupRoleModel->getUserRole(1, 2)); + } + + public function testAddGroup() + { + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $groupModel->create('Test')); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertFalse($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + + $groups = $groupRoleModel->getGroups(1); + $this->assertCount(1, $groups); + $this->assertEquals(1, $groups[0]['id']); + $this->assertEquals('Test', $groups[0]['name']); + $this->assertEquals(Role::PROJECT_VIEWER, $groups[0]['role']); + } + + public function testRemoveGroup() + { + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $groupModel->create('Test')); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_MEMBER)); + $this->assertTrue($groupRoleModel->removeGroup(1, 1)); + $this->assertFalse($groupRoleModel->removeGroup(1, 1)); + + $this->assertEmpty($groupRoleModel->getGroups(1)); + } + + public function testChangeRole() + { + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $groupModel->create('Test')); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($groupRoleModel->changeGroupRole(1, 1, Role::PROJECT_MANAGER)); + + $groups = $groupRoleModel->getGroups(1); + $this->assertCount(1, $groups); + $this->assertEquals(1, $groups[0]['id']); + $this->assertEquals('Test', $groups[0]['name']); + $this->assertEquals(Role::PROJECT_MANAGER, $groups[0]['role']); + } + + public function testGetGroups() + { + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $groupModel->create('Group C')); + $this->assertEquals(2, $groupModel->create('Group B')); + $this->assertEquals(3, $groupModel->create('Group A')); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($groupRoleModel->addGroup(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); + + $groups = $groupRoleModel->getGroups(1); + $this->assertCount(3, $groups); + + $this->assertEquals(3, $groups[0]['id']); + $this->assertEquals('Group A', $groups[0]['name']); + $this->assertEquals(Role::PROJECT_MANAGER, $groups[0]['role']); + + $this->assertEquals(2, $groups[1]['id']); + $this->assertEquals('Group B', $groups[1]['name']); + $this->assertEquals(Role::PROJECT_MEMBER, $groups[1]['role']); + + $this->assertEquals(1, $groups[2]['id']); + $this->assertEquals('Group C', $groups[2]['name']); + $this->assertEquals(Role::PROJECT_VIEWER, $groups[2]['role']); + } + + public function testGetUsers() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1', 'name' => 'User #1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + + $this->assertEquals(1, $groupModel->create('Group A')); + $this->assertEquals(2, $groupModel->create('Group B')); + $this->assertEquals(3, $groupModel->create('Group C')); + + $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(2, 3)); + $this->assertTrue($groupMemberModel->addUser(3, 2)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($groupRoleModel->addGroup(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); + + $users = $groupRoleModel->getUsers(2); + $this->assertCount(0, $users); + + $users = $groupRoleModel->getUsers(1); + $this->assertCount(3, $users); + + $this->assertEquals(2, $users[0]['id']); + $this->assertEquals('user 1', $users[0]['username']); + $this->assertEquals('User #1', $users[0]['name']); + $this->assertEquals(Role::PROJECT_MANAGER, $users[0]['role']); + + $this->assertEquals(3, $users[1]['id']); + $this->assertEquals('user 2', $users[1]['username']); + $this->assertEquals('', $users[1]['name']); + $this->assertEquals(Role::PROJECT_MEMBER, $users[1]['role']); + + $this->assertEquals(4, $users[2]['id']); + $this->assertEquals('user 3', $users[2]['username']); + $this->assertEquals('', $users[2]['name']); + $this->assertEquals(Role::PROJECT_VIEWER, $users[2]['role']); + } + + public function testGetAssignableUsers() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1', 'name' => 'User #1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + + $this->assertEquals(1, $groupModel->create('Group A')); + $this->assertEquals(2, $groupModel->create('Group B')); + $this->assertEquals(3, $groupModel->create('Group C')); + + $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(2, 3)); + $this->assertTrue($groupMemberModel->addUser(3, 2)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($groupRoleModel->addGroup(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); + + $users = $groupRoleModel->getAssignableUsers(2); + $this->assertCount(0, $users); + + $users = $groupRoleModel->getAssignableUsers(1); + $this->assertCount(2, $users); + + $this->assertEquals(2, $users[0]['id']); + $this->assertEquals('user 1', $users[0]['username']); + $this->assertEquals('User #1', $users[0]['name']); + + $this->assertEquals(3, $users[1]['id']); + $this->assertEquals('user 2', $users[1]['username']); + $this->assertEquals('', $users[1]['name']); + } + + public function testGetAssignableUsersWithDisabledUsers() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1', 'name' => 'User #1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2', 'is_active' => 0))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + + $this->assertEquals(1, $groupModel->create('Group A')); + $this->assertEquals(2, $groupModel->create('Group B')); + $this->assertEquals(3, $groupModel->create('Group C')); + + $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(2, 3)); + $this->assertTrue($groupMemberModel->addUser(3, 2)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($groupRoleModel->addGroup(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); + + $users = $groupRoleModel->getAssignableUsers(2); + $this->assertCount(0, $users); + + $users = $groupRoleModel->getAssignableUsers(1); + $this->assertCount(1, $users); + + $this->assertEquals(2, $users[0]['id']); + $this->assertEquals('user 1', $users[0]['username']); + $this->assertEquals('User #1', $users[0]['name']); + } + + public function testGetProjectsByUser() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1', 'name' => 'User #1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + + $this->assertEquals(1, $groupModel->create('Group C')); + $this->assertEquals(2, $groupModel->create('Group B')); + $this->assertEquals(3, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(2, 5)); + $this->assertTrue($groupMemberModel->addUser(3, 3)); + $this->assertTrue($groupMemberModel->addUser(3, 2)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($groupRoleModel->addGroup(2, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); + + $projects = $groupRoleModel->getProjectsByUser(2); + $this->assertCount(1, $projects); + $this->assertEquals('Project 1', $projects[1]); + + $projects = $groupRoleModel->getProjectsByUser(3); + $this->assertCount(1, $projects); + $this->assertEquals('Project 1', $projects[1]); + + $projects = $groupRoleModel->getProjectsByUser(4); + $this->assertCount(1, $projects); + $this->assertEquals('Project 1', $projects[1]); + + $projects = $groupRoleModel->getProjectsByUser(5); + $this->assertCount(1, $projects); + $this->assertEquals('Project 2', $projects[2]); + } + + public function testGetActiveProjectsByUser() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_active' => 0))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1', 'name' => 'User #1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + + $this->assertEquals(1, $groupModel->create('Group C')); + $this->assertEquals(2, $groupModel->create('Group B')); + $this->assertEquals(3, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(2, 5)); + $this->assertTrue($groupMemberModel->addUser(3, 3)); + $this->assertTrue($groupMemberModel->addUser(3, 2)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($groupRoleModel->addGroup(2, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); + + $projects = $groupRoleModel->getProjectsByUser(2, array(Project::ACTIVE)); + $this->assertCount(0, $projects); + + $projects = $groupRoleModel->getProjectsByUser(3, array(Project::ACTIVE)); + $this->assertCount(0, $projects); + + $projects = $groupRoleModel->getProjectsByUser(4, array(Project::ACTIVE)); + $this->assertCount(0, $projects); + + $projects = $groupRoleModel->getProjectsByUser(5, array(Project::ACTIVE)); + $this->assertCount(1, $projects); + $this->assertEquals('Project 2', $projects[2]); + } + + public function testGetInactiveProjectsByUser() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_active' => 0))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1', 'name' => 'User #1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + + $this->assertEquals(1, $groupModel->create('Group C')); + $this->assertEquals(2, $groupModel->create('Group B')); + $this->assertEquals(3, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(2, 5)); + $this->assertTrue($groupMemberModel->addUser(3, 3)); + $this->assertTrue($groupMemberModel->addUser(3, 2)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($groupRoleModel->addGroup(2, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); + + $projects = $groupRoleModel->getProjectsByUser(2, array(Project::INACTIVE)); + $this->assertCount(1, $projects); + $this->assertEquals('Project 1', $projects[1]); + + $projects = $groupRoleModel->getProjectsByUser(3, array(Project::INACTIVE)); + $this->assertCount(1, $projects); + $this->assertEquals('Project 1', $projects[1]); + + $projects = $groupRoleModel->getProjectsByUser(4, array(Project::INACTIVE)); + $this->assertCount(1, $projects); + $this->assertEquals('Project 1', $projects[1]); + + $projects = $groupRoleModel->getProjectsByUser(5, array(Project::INACTIVE)); + $this->assertCount(0, $projects); + } + + public function testUserInMultipleGroupsShouldReturnHighestRole() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $groupMemberModel = new GroupMember($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(2, $userModel->create(array('username' => 'My user'))); + + $this->assertEquals(1, $groupModel->create('Group A')); + $this->assertEquals(2, $groupModel->create('Group B')); + + $this->assertTrue($groupMemberModel->addUser(1, 1)); + $this->assertTrue($groupMemberModel->addUser(2, 1)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_MEMBER)); + $this->assertTrue($groupRoleModel->addGroup(1, 2, Role::PROJECT_MANAGER)); + + $this->assertEquals(Role::PROJECT_MANAGER, $groupRoleModel->getUserRole(1, 1)); + } +} diff --git a/tests/units/Model/ProjectMetadataTest.php b/tests/units/Model/ProjectMetadataTest.php index 43d66b7b..5814987d 100644 --- a/tests/units/Model/ProjectMetadataTest.php +++ b/tests/units/Model/ProjectMetadataTest.php @@ -30,6 +30,11 @@ class ProjectMetadataTest extends Base $this->assertEquals(array('key1' => 'value2'), $pm->getAll(1)); $this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $pm->getAll(2)); + + $this->assertTrue($pm->remove(2, 'key1')); + $this->assertFalse($pm->remove(2, 'key1')); + + $this->assertEquals(array('key2' => 'value2'), $pm->getAll(2)); } public function testAutomaticRemove() diff --git a/tests/units/Model/ProjectPermissionTest.php b/tests/units/Model/ProjectPermissionTest.php index 1ee63a76..10fcdcc2 100644 --- a/tests/units/Model/ProjectPermissionTest.php +++ b/tests/units/Model/ProjectPermissionTest.php @@ -2,286 +2,317 @@ require_once __DIR__.'/../Base.php'; -use Kanboard\Model\Project; use Kanboard\Model\ProjectPermission; +use Kanboard\Model\Project; use Kanboard\Model\User; +use Kanboard\Model\Group; +use Kanboard\Model\GroupMember; +use Kanboard\Model\ProjectGroupRole; +use Kanboard\Model\ProjectUserRole; +use Kanboard\Core\Security\Role; class ProjectPermissionTest extends Base { - public function testAllowEverybody() + public function testFindByUsernames() { - $user = new User($this->container); - $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); - - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertFalse($pp->isEverybodyAllowed(1)); - $this->assertTrue($pp->isUserAllowed(1, 1)); - $this->assertFalse($pp->isUserAllowed(1, 2)); - $this->assertFalse($pp->isUserAllowed(1, 3)); - $this->assertEquals(array(), $pp->getMembers(1)); - $this->assertEquals(array('Unassigned'), $pp->getMemberList(1)); - - $this->assertEmpty($pp->getMemberProjects(1)); - $this->assertEmpty($pp->getMemberProjects(2)); - $this->assertEmpty($pp->getMemberProjects(3)); - - $this->assertEmpty($pp->getMemberProjectIds(1)); - $this->assertEmpty($pp->getMemberProjectIds(2)); - $this->assertEmpty($pp->getMemberProjectIds(3)); - - $this->assertEmpty($pp->getActiveMemberProjectIds(1)); - $this->assertEmpty($pp->getActiveMemberProjectIds(2)); - $this->assertEmpty($pp->getActiveMemberProjectIds(3)); - - $this->assertEmpty($pp->getActiveMemberProjects(1)); - $this->assertEmpty($pp->getActiveMemberProjects(2)); - $this->assertEmpty($pp->getActiveMemberProjects(3)); - - $this->assertTrue($p->update(array('id' => 1, 'is_everybody_allowed' => 1))); - $this->assertTrue($pp->isEverybodyAllowed(1)); - $this->assertTrue($pp->isUserAllowed(1, 1)); - $this->assertTrue($pp->isUserAllowed(1, 2)); - $this->assertTrue($pp->isUserAllowed(1, 3)); - $this->assertEquals(array('1' => 'admin', '2' => 'unittest#1', '3' => 'unittest#2'), $pp->getMembers(1)); - $this->assertEquals(array('Unassigned', '1' => 'admin', '2' => 'unittest#1', '3' => 'unittest#2'), $pp->getMemberList(1)); - - $this->assertNotEmpty($pp->getMemberProjects(1)); - $this->assertNotEmpty($pp->getMemberProjects(2)); - $this->assertNotEmpty($pp->getMemberProjects(3)); - - $this->assertNotEmpty($pp->getMemberProjectIds(1)); - $this->assertNotEmpty($pp->getMemberProjectIds(2)); - $this->assertNotEmpty($pp->getMemberProjectIds(3)); - - $this->assertNotEmpty($pp->getActiveMemberProjectIds(1)); - $this->assertNotEmpty($pp->getActiveMemberProjectIds(2)); - $this->assertNotEmpty($pp->getActiveMemberProjectIds(3)); - - $this->assertNotEmpty($pp->getActiveMemberProjects(1)); - $this->assertNotEmpty($pp->getActiveMemberProjects(2)); - $this->assertNotEmpty($pp->getActiveMemberProjects(3)); - - $this->assertTrue($p->disable(1)); - - $this->assertEmpty($pp->getActiveMemberProjectIds(1)); - $this->assertEmpty($pp->getActiveMemberProjectIds(2)); - $this->assertEmpty($pp->getActiveMemberProjectIds(3)); - - $this->assertEmpty($pp->getActiveMemberProjects(1)); - $this->assertEmpty($pp->getActiveMemberProjects(2)); - $this->assertEmpty($pp->getActiveMemberProjects(3)); - } + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermissionModel = new ProjectPermission($this->container); - public function testDisallowEverybody() - { - // We create a regular user - $user = new User($this->container); - $user->create(array('username' => 'unittest', 'password' => 'unittest')); + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user3'))); - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); + $this->assertEquals(1, $groupModel->create('Group A')); + $this->assertTrue($groupMemberModel->addUser(1, 2)); - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MANAGER)); - $this->assertEmpty($pp->getMembers(1)); // Nobody is specified for the given project - $this->assertTrue($pp->isUserAllowed(1, 1)); // Admin should be allowed - $this->assertFalse($pp->isUserAllowed(1, 2)); // Regular user should be denied + $this->assertEquals(array('user1', 'user2'), $projectPermissionModel->findUsernames(1, 'us')); + $this->assertEmpty($projectPermissionModel->findUsernames(1, 'a')); + $this->assertEmpty($projectPermissionModel->findUsernames(2, 'user')); } - public function testAllowUser() + public function testGetQueryByRole() { - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $user = new User($this->container); - - $this->assertNotFalse($user->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create a project - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - - $this->assertEmpty($pp->getMemberProjects(1)); - $this->assertEmpty($pp->getMemberProjects(2)); - - $this->assertEmpty($pp->getMemberProjectIds(1)); - $this->assertEmpty($pp->getMemberProjectIds(2)); - - $this->assertEmpty($pp->getActiveMemberProjectIds(1)); - $this->assertEmpty($pp->getActiveMemberProjectIds(2)); - - $this->assertEmpty($pp->getActiveMemberProjects(1)); - $this->assertEmpty($pp->getActiveMemberProjects(2)); - - // We allow the admin user - $this->assertTrue($pp->addMember(1, 1)); - $this->assertTrue($pp->addMember(1, 2)); - - // Non-existant project - $this->assertFalse($pp->addMember(50, 1)); - - // Non-existant user - $this->assertFalse($pp->addMember(1, 50)); - - // Both users should be allowed - $this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $pp->getMembers(1)); - $this->assertTrue($pp->isUserAllowed(1, 1)); - $this->assertTrue($pp->isUserAllowed(1, 2)); - - $this->assertNotEmpty($pp->getMemberProjects(1)); - $this->assertNotEmpty($pp->getMemberProjects(2)); - - $this->assertNotEmpty($pp->getMemberProjectIds(1)); - $this->assertNotEmpty($pp->getMemberProjectIds(2)); - - $this->assertNotEmpty($pp->getActiveMemberProjectIds(1)); - $this->assertNotEmpty($pp->getActiveMemberProjectIds(2)); - - $this->assertNotEmpty($pp->getActiveMemberProjects(1)); - $this->assertNotEmpty($pp->getActiveMemberProjects(2)); + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermission = new ProjectPermission($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + $this->assertEquals(3, $projectModel->create(array('name' => 'Project 3'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + + $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MANAGER)); + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MANAGER)); + $this->assertTrue($userRoleModel->addUser(1, 4, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 5, Role::PROJECT_MEMBER)); + + $this->assertTrue($userRoleModel->addUser(2, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(2, 3, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(2, 5, Role::PROJECT_MANAGER)); + + $this->assertTrue($userRoleModel->addUser(3, 4, Role::PROJECT_MANAGER)); + $this->assertTrue($userRoleModel->addUser(3, 5, Role::PROJECT_VIEWER)); + + $this->assertEmpty($projectPermission->getQueryByRole(array(), Role::PROJECT_MANAGER)->findAll()); + + $users = $projectPermission->getQueryByRole(array(1, 2), Role::PROJECT_MANAGER)->findAll(); + $this->assertCount(3, $users); + $this->assertEquals('user 1', $users[0]['username']); + $this->assertEquals('Project 1', $users[0]['project_name']); + $this->assertEquals('user 2', $users[1]['username']); + $this->assertEquals('Project 1', $users[1]['project_name']); + $this->assertEquals('user 4', $users[2]['username']); + $this->assertEquals('Project 2', $users[2]['project_name']); + + $users = $projectPermission->getQueryByRole(array(1), Role::PROJECT_MANAGER)->findAll(); + $this->assertCount(2, $users); + $this->assertEquals('user 1', $users[0]['username']); + $this->assertEquals('Project 1', $users[0]['project_name']); + $this->assertEquals('user 2', $users[1]['username']); + $this->assertEquals('Project 1', $users[1]['project_name']); + + $users = $projectPermission->getQueryByRole(array(1, 2, 3), Role::PROJECT_MEMBER)->findAll(); + $this->assertCount(4, $users); + $this->assertEquals('user 3', $users[0]['username']); + $this->assertEquals('Project 1', $users[0]['project_name']); + $this->assertEquals('user 4', $users[1]['username']); + $this->assertEquals('Project 1', $users[1]['project_name']); + $this->assertEquals('user 1', $users[2]['username']); + $this->assertEquals('Project 2', $users[2]['project_name']); + $this->assertEquals('user 2', $users[3]['username']); + $this->assertEquals('Project 2', $users[3]['project_name']); + + $users = $projectPermission->getQueryByRole(array(1, 2, 3), Role::PROJECT_VIEWER)->findAll(); + $this->assertCount(1, $users); + $this->assertEquals('user 4', $users[0]['username']); + $this->assertEquals('Project 3', $users[0]['project_name']); } - public function testRevokeUser() + public function testEverybodyAllowed() { - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $user = new User($this->container); - - $user->create(array('username' => 'unittest', 'password' => 'unittest')); - - // We create a project - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + $projectModel = new Project($this->container); + $projectPermission = new ProjectPermission($this->container); - // We revoke our admin user (not existing row) - $this->assertFalse($pp->revokeMember(1, 1)); + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2', 'is_everybody_allowed' => 1))); - // We should have nobody in the users list - $this->assertEmpty($pp->getMembers(1)); - - // Only admin is allowed - $this->assertTrue($pp->isUserAllowed(1, 1)); - $this->assertFalse($pp->isUserAllowed(1, 2)); - - // We allow only the regular user - $this->assertTrue($pp->addMember(1, 2)); - - // All users should be allowed (admin and regular) - $this->assertTrue($pp->isUserAllowed(1, 1)); - $this->assertTrue($pp->isUserAllowed(1, 2)); - - // However, we should have only our regular user in the list - $this->assertEquals(array('2' => 'unittest'), $pp->getMembers(1)); - - // We allow our admin, we should have both in the list - $this->assertTrue($pp->addMember(1, 1)); - $this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $pp->getMembers(1)); - $this->assertTrue($pp->isUserAllowed(1, 1)); - $this->assertTrue($pp->isUserAllowed(1, 2)); - - // We revoke the regular user - $this->assertTrue($pp->revokeMember(1, 2)); - - // Only admin should be allowed - $this->assertTrue($pp->isUserAllowed(1, 1)); - $this->assertFalse($pp->isUserAllowed(1, 2)); - - // We should have only admin in the list - $this->assertEquals(array('1' => 'admin'), $pp->getMembers(1)); - - // We revoke the admin user - $this->assertTrue($pp->revokeMember(1, 1)); - $this->assertEmpty($pp->getMembers(1)); - - // Only admin should be allowed again - $this->assertTrue($pp->isUserAllowed(1, 1)); - $this->assertFalse($pp->isUserAllowed(1, 2)); + $this->assertFalse($projectPermission->isEverybodyAllowed(1)); + $this->assertTrue($projectPermission->isEverybodyAllowed(2)); } - public function testManager() + public function testIsUserAllowed() { - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - $u = new User($this->container); - - $this->assertEquals(2, $u->create(array('username' => 'unittest', 'password' => 'unittest'))); - - $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); - $this->assertFalse($pp->isMember(1, 2)); - $this->assertFalse($pp->isManager(1, 2)); - - $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'), 1, true)); - $this->assertFalse($pp->isMember(2, 2)); - $this->assertFalse($pp->isManager(2, 2)); - - $this->assertEquals(3, $p->create(array('name' => 'UnitTest3'), 2, true)); - $this->assertTrue($pp->isMember(3, 2)); - $this->assertTrue($pp->isManager(3, 2)); - - $this->assertEquals(4, $p->create(array('name' => 'UnitTest4'))); - - $this->assertTrue($pp->addManager(4, 2)); - $this->assertTrue($pp->isMember(4, 2)); - $this->assertTrue($pp->isManager(4, 2)); - - $this->assertEquals(5, $p->create(array('name' => 'UnitTest5'))); - $this->assertTrue($pp->addMember(5, 2)); - $this->assertTrue($pp->changeRole(5, 2, 1)); - $this->assertTrue($pp->isMember(5, 2)); - $this->assertTrue($pp->isManager(5, 2)); - $this->assertTrue($pp->changeRole(5, 2, 0)); - $this->assertTrue($pp->isMember(5, 2)); - $this->assertFalse($pp->isManager(5, 2)); + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $groupMemberModel = new GroupMember($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermission = new ProjectPermission($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(1, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 2)); + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 4, Role::PROJECT_MANAGER)); + + $this->assertTrue($projectPermission->isUserAllowed(1, 2)); + $this->assertTrue($projectPermission->isUserAllowed(1, 3)); + $this->assertTrue($projectPermission->isUserAllowed(1, 4)); + $this->assertFalse($projectPermission->isUserAllowed(1, 5)); + + $this->assertFalse($projectPermission->isUserAllowed(2, 2)); + $this->assertFalse($projectPermission->isUserAllowed(2, 3)); + $this->assertFalse($projectPermission->isUserAllowed(2, 4)); + $this->assertFalse($projectPermission->isUserAllowed(2, 5)); } - public function testUsersList() + public function testIsAssignable() { - $p = new Project($this->container); - $pp = new ProjectPermission($this->container); - - $user = new User($this->container); - $this->assertNotFalse($user->create(array('username' => 'unittest', 'password' => 'unittest'))); - - // We create project - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - - // No restriction, we should have no body - $this->assertEquals( - array('Unassigned'), - $pp->getMemberList(1) - ); + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $groupMemberModel = new GroupMember($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermission = new ProjectPermission($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(1, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 2)); + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 4, Role::PROJECT_MANAGER)); + + $this->assertFalse($projectPermission->isAssignable(1, 2)); + $this->assertTrue($projectPermission->isAssignable(1, 3)); + $this->assertTrue($projectPermission->isAssignable(1, 4)); + $this->assertFalse($projectPermission->isAssignable(1, 5)); + + $this->assertFalse($projectPermission->isAssignable(2, 2)); + $this->assertFalse($projectPermission->isAssignable(2, 3)); + $this->assertFalse($projectPermission->isAssignable(2, 4)); + $this->assertFalse($projectPermission->isAssignable(2, 5)); + } - // We allow only the regular user - $this->assertTrue($pp->addMember(1, 2)); + public function testIsAssignableWhenUserIsDisabled() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $groupMemberModel = new GroupMember($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermission = new ProjectPermission($this->container); - $this->assertEquals( - array(0 => 'Unassigned', 2 => 'unittest'), - $pp->getMemberList(1) - ); + $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2', 'is_active' => 0))); - // We allow the admin user - $this->assertTrue($pp->addMember(1, 1)); + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); - $this->assertEquals( - array(0 => 'Unassigned', 1 => 'admin', 2 => 'unittest'), - $pp->getMemberList(1) - ); + $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); - // We revoke only the regular user - $this->assertTrue($pp->revokeMember(1, 2)); + $this->assertTrue($projectPermission->isAssignable(1, 2)); + $this->assertFalse($projectPermission->isAssignable(1, 3)); + } - $this->assertEquals( - array(0 => 'Unassigned', 1 => 'admin'), - $pp->getMemberList(1) - ); + public function testIsMember() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $groupMemberModel = new GroupMember($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermission = new ProjectPermission($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(1, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 2)); + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 4, Role::PROJECT_MANAGER)); + + $this->assertTrue($projectPermission->isMember(1, 2)); + $this->assertTrue($projectPermission->isMember(1, 3)); + $this->assertTrue($projectPermission->isMember(1, 4)); + $this->assertFalse($projectPermission->isMember(1, 5)); + + $this->assertFalse($projectPermission->isMember(2, 2)); + $this->assertFalse($projectPermission->isMember(2, 3)); + $this->assertFalse($projectPermission->isMember(2, 4)); + $this->assertFalse($projectPermission->isMember(2, 5)); + } - // We revoke only the admin user, we should have everybody - $this->assertTrue($pp->revokeMember(1, 1)); + public function testGetActiveProjectIds() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $groupMemberModel = new GroupMember($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermission = new ProjectPermission($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2', 'is_active' => 0))); + + $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(2, 2, Role::PROJECT_VIEWER)); + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_VIEWER)); + + $this->assertEmpty($projectPermission->getActiveProjectIds(1)); + $this->assertEquals(array(1), $projectPermission->getActiveProjectIds(2)); + $this->assertEquals(array(1), $projectPermission->getActiveProjectIds(3)); + } - $this->assertEquals( - array(0 => 'Unassigned'), - $pp->getMemberList(1) - ); + public function testDuplicate() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $projectPermission = new ProjectPermission($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1', 'name' => 'User #1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + $this->assertEquals(6, $userModel->create(array('username' => 'user 5', 'name' => 'User #5'))); + + $this->assertEquals(1, $groupModel->create('Group C')); + $this->assertEquals(2, $groupModel->create('Group B')); + $this->assertEquals(3, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(2, 5)); + $this->assertTrue($groupMemberModel->addUser(3, 3)); + $this->assertTrue($groupMemberModel->addUser(3, 2)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); + + $this->assertTrue($userRoleModel->addUser(1, 5, Role::PROJECT_MANAGER)); + $this->assertTrue($userRoleModel->addUser(1, 6, Role::PROJECT_MEMBER)); + + $this->assertTrue($projectPermission->duplicate(1, 2)); + + $this->assertCount(2, $userRoleModel->getUsers(2)); + $this->assertCount(3, $groupRoleModel->getUsers(2)); } } diff --git a/tests/units/Model/ProjectTest.php b/tests/units/Model/ProjectTest.php index f90c0dc1..5478fa40 100644 --- a/tests/units/Model/ProjectTest.php +++ b/tests/units/Model/ProjectTest.php @@ -5,12 +5,9 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Core\Translator; use Kanboard\Subscriber\ProjectModificationDateSubscriber; use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; use Kanboard\Model\User; use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; -use Kanboard\Model\Acl; -use Kanboard\Model\Board; use Kanboard\Model\Config; use Kanboard\Model\Category; @@ -44,6 +41,14 @@ class ProjectTest extends Base $this->assertEmpty($project['token']); } + public function testCreationWithDuplicateName() + { + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); + $this->assertEquals(2, $p->create(array('name' => 'UnitTest'))); + } + public function testCreationWithStartAndDate() { $p = new Project($this->container); @@ -79,6 +84,7 @@ class ProjectTest extends Base // Single category $this->assertTrue($c->save(array('project_categories' => 'Test1'))); + $this->container['memoryCache']->flush(); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); $project = $p->getById(2); @@ -92,6 +98,7 @@ class ProjectTest extends Base // Multiple categories badly formatted $this->assertTrue($c->save(array('project_categories' => 'ABC, , DEF 3, '))); + $this->container['memoryCache']->flush(); $this->assertEquals(3, $p->create(array('name' => 'UnitTest3'))); $project = $p->getById(3); @@ -105,6 +112,7 @@ class ProjectTest extends Base // No default categories $this->assertTrue($c->save(array('project_categories' => ' '))); + $this->container['memoryCache']->flush(); $this->assertEquals(4, $p->create(array('name' => 'UnitTest4'))); $project = $p->getById(4); @@ -270,30 +278,49 @@ class ProjectTest extends Base $project = $p->getByIdentifier(''); $this->assertFalse($project); + } - // Validation rules - $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'TEST1')); - $this->assertFalse($r[0]); + public function testThatProjectCreatorAreAlsoOwner() + { + $projectModel = new Project($this->container); + $userModel = new User($this->container); - $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test1')); - $this->assertFalse($r[0]); + $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'Me'))); + $this->assertEquals(1, $projectModel->create(array('name' => 'My project 1'), 2)); + $this->assertEquals(2, $projectModel->create(array('name' => 'My project 2'))); - $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1')); - $this->assertTrue($r[0]); + $project = $projectModel->getByIdWithOwner(1); + $this->assertNotEmpty($project); + $this->assertSame('My project 1', $project['name']); + $this->assertSame('Me', $project['owner_name']); + $this->assertSame('user1', $project['owner_username']); + $this->assertEquals(2, $project['owner_id']); - $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3')); - $this->assertTrue($r[0]); + $project = $projectModel->getByIdWithOwner(2); + $this->assertNotEmpty($project); + $this->assertSame('My project 2', $project['name']); + $this->assertEquals('', $project['owner_name']); + $this->assertEquals('', $project['owner_username']); + $this->assertEquals(0, $project['owner_id']); + } - $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => '')); - $this->assertTrue($r[0]); + public function testPriority() + { + $projectModel = new Project($this->container); + $this->assertEquals(1, $projectModel->create(array('name' => 'My project 2'))); - $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2')); - $this->assertFalse($r[0]); + $project = $projectModel->getById(1); + $this->assertNotEmpty($project); + $this->assertEquals(0, $project['priority_default']); + $this->assertEquals(0, $project['priority_start']); + $this->assertEquals(3, $project['priority_end']); - $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c')); - $this->assertFalse($r[0]); + $this->assertTrue($projectModel->update(array('id' => 1, 'priority_start' => 2, 'priority_end' => 5, 'priority_default' => 4))); - $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test 123')); - $this->assertFalse($r[0]); + $project = $projectModel->getById(1); + $this->assertNotEmpty($project); + $this->assertEquals(4, $project['priority_default']); + $this->assertEquals(2, $project['priority_start']); + $this->assertEquals(5, $project['priority_end']); } } diff --git a/tests/units/Model/ProjectUserRoleTest.php b/tests/units/Model/ProjectUserRoleTest.php new file mode 100644 index 00000000..06cd1b70 --- /dev/null +++ b/tests/units/Model/ProjectUserRoleTest.php @@ -0,0 +1,461 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\Project; +use Kanboard\Model\User; +use Kanboard\Model\Group; +use Kanboard\Model\GroupMember; +use Kanboard\Model\ProjectGroupRole; +use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\ProjectPermission; +use Kanboard\Core\Security\Role; + +class ProjectUserRoleTest extends Base +{ + public function testAddUser() + { + $projectModel = new Project($this->container); + $userRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + + $this->assertTrue($userRoleModel->addUser(1, 1, Role::PROJECT_VIEWER)); + $this->assertFalse($userRoleModel->addUser(1, 1, Role::PROJECT_VIEWER)); + + $users = $userRoleModel->getUsers(1); + $this->assertCount(1, $users); + $this->assertEquals(1, $users[0]['id']); + $this->assertEquals('admin', $users[0]['username']); + $this->assertEquals('', $users[0]['name']); + $this->assertEquals(Role::PROJECT_VIEWER, $users[0]['role']); + } + + public function testRemoveUser() + { + $projectModel = new Project($this->container); + $userRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + + $this->assertTrue($userRoleModel->addUser(1, 1, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->removeUser(1, 1)); + $this->assertFalse($userRoleModel->removeUser(1, 1)); + + $this->assertEmpty($userRoleModel->getUsers(1)); + } + + public function testChangeRole() + { + $projectModel = new Project($this->container); + $userRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + + $this->assertTrue($userRoleModel->addUser(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($userRoleModel->changeUserRole(1, 1, Role::PROJECT_MANAGER)); + + $users = $userRoleModel->getUsers(1); + $this->assertCount(1, $users); + $this->assertEquals(1, $users[0]['id']); + $this->assertEquals('admin', $users[0]['username']); + $this->assertEquals('', $users[0]['name']); + $this->assertEquals(Role::PROJECT_MANAGER, $users[0]['role']); + } + + public function testGetRole() + { + $projectModel = new Project($this->container); + $userRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEmpty($userRoleModel->getUserRole(1, 1)); + + $this->assertTrue($userRoleModel->addUser(1, 1, Role::PROJECT_VIEWER)); + $this->assertEquals(Role::PROJECT_VIEWER, $userRoleModel->getUserRole(1, 1)); + + $this->assertTrue($userRoleModel->changeUserRole(1, 1, Role::PROJECT_MEMBER)); + $this->assertEquals(Role::PROJECT_MEMBER, $userRoleModel->getUserRole(1, 1)); + + $this->assertTrue($userRoleModel->changeUserRole(1, 1, Role::PROJECT_MANAGER)); + $this->assertEquals(Role::PROJECT_MANAGER, $userRoleModel->getUserRole(1, 1)); + + $this->assertEquals('', $userRoleModel->getUserRole(1, 2)); + } + + public function testGetRoleWithGroups() + { + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $groupMemberModel = new GroupMember($this->container); + $userRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 1)); + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + + $this->assertEquals(Role::PROJECT_VIEWER, $userRoleModel->getUserRole(1, 1)); + $this->assertEquals('', $userRoleModel->getUserRole(1, 2)); + } + + public function testGetAssignableUsersWithDisabledUsers() + { + $projectModel = new Project($this->container); + $userModel = new User($this->container); + $userRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2'))); + + $this->assertTrue($userRoleModel->addUser(1, 1, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); + + $users = $userRoleModel->getAssignableUsers(1); + $this->assertCount(3, $users); + + $this->assertEquals('admin', $users[1]); + $this->assertEquals('User1', $users[2]); + $this->assertEquals('User2', $users[3]); + + $this->assertTrue($userModel->disable(2)); + + $users = $userRoleModel->getAssignableUsers(1); + $this->assertCount(2, $users); + + $this->assertEquals('admin', $users[1]); + $this->assertEquals('User2', $users[3]); + } + + public function testGetAssignableUsersWithoutGroups() + { + $projectModel = new Project($this->container); + $userModel = new User($this->container); + $userRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2'))); + + $this->assertTrue($userRoleModel->addUser(1, 1, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MANAGER)); + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_VIEWER)); + + $users = $userRoleModel->getAssignableUsers(1); + $this->assertCount(2, $users); + + $this->assertEquals('admin', $users[1]); + $this->assertEquals('User1', $users[2]); + } + + public function testGetAssignableUsersWithGroups() + { + $projectModel = new Project($this->container); + $userModel = new User($this->container); + $groupModel = new Group($this->container); + $userRoleModel = new ProjectUserRole($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $groupMemberModel = new GroupMember($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user3', 'name' => 'User3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user4', 'name' => 'User4'))); + + $this->assertTrue($userRoleModel->addUser(1, 1, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MANAGER)); + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_VIEWER)); + + $this->assertEquals(1, $groupModel->create('Group A')); + $this->assertEquals(2, $groupModel->create('Group B')); + + $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(2, 5)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($groupRoleModel->addGroup(1, 2, Role::PROJECT_MEMBER)); + + $users = $userRoleModel->getAssignableUsers(1); + $this->assertCount(3, $users); + + $this->assertEquals('admin', $users[1]); + $this->assertEquals('User1', $users[2]); + $this->assertEquals('User4', $users[5]); + } + + public function testGetAssignableUsersList() + { + $projectModel = new Project($this->container); + $userModel = new User($this->container); + $userRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Test2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2'))); + + $this->assertTrue($userRoleModel->addUser(2, 1, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 1, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(1, 2, Role::PROJECT_MANAGER)); + $this->assertTrue($userRoleModel->addUser(1, 3, Role::PROJECT_VIEWER)); + + $users = $userRoleModel->getAssignableUsersList(1); + $this->assertCount(3, $users); + + $this->assertEquals('Unassigned', $users[0]); + $this->assertEquals('admin', $users[1]); + $this->assertEquals('User1', $users[2]); + + $users = $userRoleModel->getAssignableUsersList(1, true, true, true); + $this->assertCount(4, $users); + + $this->assertEquals('Unassigned', $users[0]); + $this->assertEquals('Everybody', $users[-1]); + $this->assertEquals('admin', $users[1]); + $this->assertEquals('User1', $users[2]); + + $users = $userRoleModel->getAssignableUsersList(2, true, true, true); + $this->assertCount(1, $users); + + $this->assertEquals('admin', $users[1]); + } + + public function testGetAssignableUsersWithEverybodyAllowed() + { + $projectModel = new Project($this->container); + $userModel = new User($this->container); + $userRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test', 'is_everybody_allowed' => 1))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user3', 'name' => 'User3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user4', 'name' => 'User4'))); + + $users = $userRoleModel->getAssignableUsers(1); + $this->assertCount(5, $users); + + $this->assertEquals('admin', $users[1]); + $this->assertEquals('User1', $users[2]); + $this->assertEquals('User2', $users[3]); + $this->assertEquals('User3', $users[4]); + $this->assertEquals('User4', $users[5]); + } + + public function testGetAssignableUsersWithDisabledUsersAndEverybodyAllowed() + { + $projectModel = new Project($this->container); + $projectPermission = new ProjectPermission($this->container); + $userModel = new User($this->container); + $userRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User2'))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_everybody_allowed' => 1))); + + $this->assertTrue($projectPermission->isEverybodyAllowed(1)); + + $users = $userRoleModel->getAssignableUsers(1); + $this->assertCount(3, $users); + + $this->assertEquals('admin', $users[1]); + $this->assertEquals('User1', $users[2]); + $this->assertEquals('User2', $users[3]); + + $this->assertTrue($userModel->disable(2)); + + $users = $userRoleModel->getAssignableUsers(1); + $this->assertCount(2, $users); + + $this->assertEquals('admin', $users[1]); + $this->assertEquals('User2', $users[3]); + } + + public function testGetProjectsByUser() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $userRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1', 'name' => 'User #1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + $this->assertEquals(6, $userModel->create(array('username' => 'user 5', 'name' => 'User #5'))); + $this->assertEquals(7, $userModel->create(array('username' => 'user 6'))); + + $this->assertEquals(1, $groupModel->create('Group C')); + $this->assertEquals(2, $groupModel->create('Group B')); + $this->assertEquals(3, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(2, 5)); + $this->assertTrue($groupMemberModel->addUser(3, 3)); + $this->assertTrue($groupMemberModel->addUser(3, 2)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($groupRoleModel->addGroup(2, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); + + $this->assertTrue($userRoleModel->addUser(1, 6, Role::PROJECT_MANAGER)); + $this->assertTrue($userRoleModel->addUser(2, 6, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(2, 7, Role::PROJECT_MEMBER)); + + $projects = $userRoleModel->getProjectsByUser(2); + $this->assertCount(1, $projects); + $this->assertEquals('Project 1', $projects[1]); + + $projects = $userRoleModel->getProjectsByUser(3); + $this->assertCount(1, $projects); + $this->assertEquals('Project 1', $projects[1]); + + $projects = $userRoleModel->getProjectsByUser(4); + $this->assertCount(1, $projects); + $this->assertEquals('Project 1', $projects[1]); + + $projects = $userRoleModel->getProjectsByUser(5); + $this->assertCount(1, $projects); + $this->assertEquals('Project 2', $projects[2]); + + $projects = $userRoleModel->getProjectsByUser(6); + $this->assertCount(2, $projects); + $this->assertEquals('Project 1', $projects[1]); + $this->assertEquals('Project 2', $projects[2]); + + $projects = $userRoleModel->getProjectsByUser(7); + $this->assertCount(1, $projects); + $this->assertEquals('Project 2', $projects[2]); + } + + public function testGetActiveProjectsByUser() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $userRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_active' => 0))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1', 'name' => 'User #1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + $this->assertEquals(6, $userModel->create(array('username' => 'user 5', 'name' => 'User #5'))); + $this->assertEquals(7, $userModel->create(array('username' => 'user 6'))); + + $this->assertEquals(1, $groupModel->create('Group C')); + $this->assertEquals(2, $groupModel->create('Group B')); + $this->assertEquals(3, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(2, 5)); + $this->assertTrue($groupMemberModel->addUser(3, 3)); + $this->assertTrue($groupMemberModel->addUser(3, 2)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($groupRoleModel->addGroup(2, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); + + $this->assertTrue($userRoleModel->addUser(1, 6, Role::PROJECT_MANAGER)); + $this->assertTrue($userRoleModel->addUser(2, 6, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(2, 7, Role::PROJECT_MEMBER)); + + $projects = $userRoleModel->getProjectsByUser(2, array(Project::ACTIVE)); + $this->assertCount(0, $projects); + + $projects = $userRoleModel->getProjectsByUser(3, array(Project::ACTIVE)); + $this->assertCount(0, $projects); + + $projects = $userRoleModel->getProjectsByUser(4, array(Project::ACTIVE)); + $this->assertCount(0, $projects); + + $projects = $userRoleModel->getProjectsByUser(5, array(Project::ACTIVE)); + $this->assertCount(1, $projects); + $this->assertEquals('Project 2', $projects[2]); + + $projects = $userRoleModel->getProjectsByUser(6, array(Project::ACTIVE)); + $this->assertCount(1, $projects); + $this->assertEquals('Project 2', $projects[2]); + + $projects = $userRoleModel->getProjectsByUser(7, array(Project::ACTIVE)); + $this->assertCount(1, $projects); + $this->assertEquals('Project 2', $projects[2]); + } + + public function testGetInactiveProjectsByUser() + { + $userModel = new User($this->container); + $projectModel = new Project($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $groupRoleModel = new ProjectGroupRole($this->container); + $userRoleModel = new ProjectUserRole($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Project 1', 'is_active' => 0))); + $this->assertEquals(2, $projectModel->create(array('name' => 'Project 2'))); + + $this->assertEquals(2, $userModel->create(array('username' => 'user 1', 'name' => 'User #1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user 2'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user 3'))); + $this->assertEquals(5, $userModel->create(array('username' => 'user 4'))); + $this->assertEquals(6, $userModel->create(array('username' => 'user 5', 'name' => 'User #5'))); + $this->assertEquals(7, $userModel->create(array('username' => 'user 6'))); + + $this->assertEquals(1, $groupModel->create('Group C')); + $this->assertEquals(2, $groupModel->create('Group B')); + $this->assertEquals(3, $groupModel->create('Group A')); + + $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(2, 5)); + $this->assertTrue($groupMemberModel->addUser(3, 3)); + $this->assertTrue($groupMemberModel->addUser(3, 2)); + + $this->assertTrue($groupRoleModel->addGroup(1, 1, Role::PROJECT_VIEWER)); + $this->assertTrue($groupRoleModel->addGroup(2, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($groupRoleModel->addGroup(1, 3, Role::PROJECT_MANAGER)); + + $this->assertTrue($userRoleModel->addUser(1, 6, Role::PROJECT_MANAGER)); + $this->assertTrue($userRoleModel->addUser(2, 6, Role::PROJECT_MEMBER)); + $this->assertTrue($userRoleModel->addUser(2, 7, Role::PROJECT_MEMBER)); + + $projects = $userRoleModel->getProjectsByUser(2, array(Project::INACTIVE)); + $this->assertCount(1, $projects); + $this->assertEquals('Project 1', $projects[1]); + + $projects = $userRoleModel->getProjectsByUser(3, array(Project::INACTIVE)); + $this->assertCount(1, $projects); + $this->assertEquals('Project 1', $projects[1]); + + $projects = $userRoleModel->getProjectsByUser(4, array(Project::INACTIVE)); + $this->assertCount(1, $projects); + $this->assertEquals('Project 1', $projects[1]); + + $projects = $userRoleModel->getProjectsByUser(5, array(Project::INACTIVE)); + $this->assertCount(0, $projects); + + $projects = $userRoleModel->getProjectsByUser(6, array(Project::INACTIVE)); + $this->assertCount(1, $projects); + $this->assertEquals('Project 1', $projects[1]); + + $projects = $userRoleModel->getProjectsByUser(7, array(Project::INACTIVE)); + $this->assertCount(0, $projects); + } +} diff --git a/tests/units/Model/SubtaskTest.php b/tests/units/Model/SubtaskTest.php index 04b274cc..78945fd1 100644 --- a/tests/units/Model/SubtaskTest.php +++ b/tests/units/Model/SubtaskTest.php @@ -8,8 +8,7 @@ use Kanboard\Model\Subtask; use Kanboard\Model\Project; use Kanboard\Model\Category; use Kanboard\Model\User; -use Kanboard\Core\Session; -use Kanboard\Model\UserSession; +use Kanboard\Core\User\UserSession; class SubtaskTest extends Base { @@ -160,7 +159,7 @@ class SubtaskTest extends Base $this->assertEquals(0, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertTrue($s->toggleStatus(1)); + $this->assertEquals(Subtask::STATUS_INPROGRESS, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); @@ -168,7 +167,7 @@ class SubtaskTest extends Base $this->assertEquals(0, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertTrue($s->toggleStatus(1)); + $this->assertEquals(Subtask::STATUS_DONE, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); @@ -176,7 +175,7 @@ class SubtaskTest extends Base $this->assertEquals(0, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertTrue($s->toggleStatus(1)); + $this->assertEquals(Subtask::STATUS_TODO, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); @@ -190,7 +189,6 @@ class SubtaskTest extends Base $tc = new TaskCreation($this->container); $s = new Subtask($this->container); $p = new Project($this->container); - $ss = new Session; $us = new UserSession($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -205,9 +203,9 @@ class SubtaskTest extends Base $this->assertEquals(1, $subtask['task_id']); // Set the current logged user - $ss['user'] = array('id' => 1); + $this->container['sessionStorage']->user = array('id' => 1); - $this->assertTrue($s->toggleStatus(1)); + $this->assertEquals(Subtask::STATUS_INPROGRESS, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); @@ -215,7 +213,7 @@ class SubtaskTest extends Base $this->assertEquals(1, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertTrue($s->toggleStatus(1)); + $this->assertEquals(Subtask::STATUS_DONE, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); @@ -223,7 +221,7 @@ class SubtaskTest extends Base $this->assertEquals(1, $subtask['user_id']); $this->assertEquals(1, $subtask['task_id']); - $this->assertTrue($s->toggleStatus(1)); + $this->assertEquals(Subtask::STATUS_TODO, $s->toggleStatus(1)); $subtask = $s->getById(1); $this->assertNotEmpty($subtask); @@ -254,117 +252,6 @@ class SubtaskTest extends Base } } - public function testMoveUp() - { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); - - $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); - $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1))); - $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 1))); - - // Check positions - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - $this->assertEquals(1, $subtask['position']); - - $subtask = $s->getById(2); - $this->assertNotEmpty($subtask); - $this->assertEquals(2, $subtask['position']); - - $subtask = $s->getById(3); - $this->assertNotEmpty($subtask); - $this->assertEquals(3, $subtask['position']); - - // Move up - $this->assertTrue($s->moveUp(1, 2)); - - // Check positions - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - $this->assertEquals(2, $subtask['position']); - - $subtask = $s->getById(2); - $this->assertNotEmpty($subtask); - $this->assertEquals(1, $subtask['position']); - - $subtask = $s->getById(3); - $this->assertNotEmpty($subtask); - $this->assertEquals(3, $subtask['position']); - - // We can't move up #2 - $this->assertFalse($s->moveUp(1, 2)); - - // Test remove - $this->assertTrue($s->remove(1)); - $this->assertTrue($s->moveUp(1, 3)); - - // Check positions - $subtask = $s->getById(1); - $this->assertEmpty($subtask); - - $subtask = $s->getById(2); - $this->assertNotEmpty($subtask); - $this->assertEquals(2, $subtask['position']); - - $subtask = $s->getById(3); - $this->assertNotEmpty($subtask); - $this->assertEquals(1, $subtask['position']); - } - - public function testMoveDown() - { - $tc = new TaskCreation($this->container); - $s = new Subtask($this->container); - $p = new Project($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test1'))); - $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); - - $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); - $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1))); - $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 1))); - - // Move down #1 - $this->assertTrue($s->moveDown(1, 1)); - - // Check positions - $subtask = $s->getById(1); - $this->assertNotEmpty($subtask); - $this->assertEquals(2, $subtask['position']); - - $subtask = $s->getById(2); - $this->assertNotEmpty($subtask); - $this->assertEquals(1, $subtask['position']); - - $subtask = $s->getById(3); - $this->assertNotEmpty($subtask); - $this->assertEquals(3, $subtask['position']); - - // We can't move down #3 - $this->assertFalse($s->moveDown(1, 3)); - - // Test remove - $this->assertTrue($s->remove(1)); - $this->assertTrue($s->moveDown(1, 2)); - - // Check positions - $subtask = $s->getById(1); - $this->assertEmpty($subtask); - - $subtask = $s->getById(2); - $this->assertNotEmpty($subtask); - $this->assertEquals(2, $subtask['position']); - - $subtask = $s->getById(3); - $this->assertNotEmpty($subtask); - $this->assertEquals(1, $subtask['position']); - } - public function testDuplicate() { $tc = new TaskCreation($this->container); @@ -411,4 +298,69 @@ class SubtaskTest extends Base $this->assertEquals(1, $subtasks[0]['position']); $this->assertEquals(2, $subtasks[1]['position']); } + + public function testChangePosition() + { + $taskCreationModel = new TaskCreation($this->container); + $subtaskModel = new Subtask($this->container); + $projectModel = new Project($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1))); + + $this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #1', 'task_id' => 1))); + $this->assertEquals(2, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1))); + $this->assertEquals(3, $subtaskModel->create(array('title' => 'subtask #3', 'task_id' => 1))); + + $subtasks = $subtaskModel->getAll(1); + $this->assertEquals(1, $subtasks[0]['position']); + $this->assertEquals(1, $subtasks[0]['id']); + $this->assertEquals(2, $subtasks[1]['position']); + $this->assertEquals(2, $subtasks[1]['id']); + $this->assertEquals(3, $subtasks[2]['position']); + $this->assertEquals(3, $subtasks[2]['id']); + + $this->assertTrue($subtaskModel->changePosition(1, 3, 2)); + + $subtasks = $subtaskModel->getAll(1); + $this->assertEquals(1, $subtasks[0]['position']); + $this->assertEquals(1, $subtasks[0]['id']); + $this->assertEquals(2, $subtasks[1]['position']); + $this->assertEquals(3, $subtasks[1]['id']); + $this->assertEquals(3, $subtasks[2]['position']); + $this->assertEquals(2, $subtasks[2]['id']); + + $this->assertTrue($subtaskModel->changePosition(1, 2, 1)); + + $subtasks = $subtaskModel->getAll(1); + $this->assertEquals(1, $subtasks[0]['position']); + $this->assertEquals(2, $subtasks[0]['id']); + $this->assertEquals(2, $subtasks[1]['position']); + $this->assertEquals(1, $subtasks[1]['id']); + $this->assertEquals(3, $subtasks[2]['position']); + $this->assertEquals(3, $subtasks[2]['id']); + + $this->assertTrue($subtaskModel->changePosition(1, 2, 2)); + + $subtasks = $subtaskModel->getAll(1); + $this->assertEquals(1, $subtasks[0]['position']); + $this->assertEquals(1, $subtasks[0]['id']); + $this->assertEquals(2, $subtasks[1]['position']); + $this->assertEquals(2, $subtasks[1]['id']); + $this->assertEquals(3, $subtasks[2]['position']); + $this->assertEquals(3, $subtasks[2]['id']); + + $this->assertTrue($subtaskModel->changePosition(1, 1, 3)); + + $subtasks = $subtaskModel->getAll(1); + $this->assertEquals(1, $subtasks[0]['position']); + $this->assertEquals(2, $subtasks[0]['id']); + $this->assertEquals(2, $subtasks[1]['position']); + $this->assertEquals(3, $subtasks[1]['id']); + $this->assertEquals(3, $subtasks[2]['position']); + $this->assertEquals(1, $subtasks[2]['id']); + + $this->assertFalse($subtaskModel->changePosition(1, 2, 0)); + $this->assertFalse($subtaskModel->changePosition(1, 2, 4)); + } } diff --git a/tests/units/Model/SubtaskTimeTrackingTest.php b/tests/units/Model/SubtaskTimeTrackingTest.php index 309be64a..40461eea 100644 --- a/tests/units/Model/SubtaskTimeTrackingTest.php +++ b/tests/units/Model/SubtaskTimeTrackingTest.php @@ -9,7 +9,6 @@ use Kanboard\Model\SubtaskTimeTracking; use Kanboard\Model\Project; use Kanboard\Model\Category; use Kanboard\Model\User; -use Kanboard\Core\Session; class SubtaskTimeTrackingTest extends Base { @@ -38,9 +37,8 @@ class SubtaskTimeTrackingTest extends Base $s = new Subtask($this->container); $st = new SubtaskTimeTracking($this->container); $p = new Project($this->container); - $ss = new Session; - $ss['user'] = array('id' => 1); + $this->container['sessionStorage']->user = array('id' => 1); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1))); diff --git a/tests/units/Model/SwimlaneTest.php b/tests/units/Model/SwimlaneTest.php index 3d048abd..f8b496cf 100644 --- a/tests/units/Model/SwimlaneTest.php +++ b/tests/units/Model/SwimlaneTest.php @@ -86,7 +86,23 @@ class SwimlaneTest extends Base $this->assertEquals(0, $default['show_default_swimlane']); } - public function testDisable() + public function testDisableEnableDefaultSwimlane() + { + $projectModel = new Project($this->container); + $swimlaneModel = new Swimlane($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + + $this->assertTrue($swimlaneModel->disableDefault(1)); + $default = $swimlaneModel->getDefault(1); + $this->assertEquals(0, $default['show_default_swimlane']); + + $this->assertTrue($swimlaneModel->enableDefault(1)); + $default = $swimlaneModel->getDefault(1); + $this->assertEquals(1, $default['show_default_swimlane']); + } + + public function testDisableEnable() { $p = new Project($this->container); $s = new Swimlane($this->container); @@ -210,172 +226,6 @@ class SwimlaneTest extends Base $this->assertEquals(1, $swimlane['position']); } - public function testMoveUp() - { - $p = new Project($this->container); - $s = new Swimlane($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); - $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'Swimlane #2'))); - $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'Swimlane #3'))); - - $swimlane = $s->getById(1); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(1, $swimlane['position']); - - $swimlane = $s->getById(2); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(2, $swimlane['position']); - - $swimlane = $s->getById(3); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(3, $swimlane['position']); - - // Move the swimlane 3 up - $this->assertTrue($s->moveUp(1, 3)); - - $swimlane = $s->getById(1); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(1, $swimlane['position']); - - $swimlane = $s->getById(2); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(3, $swimlane['position']); - - $swimlane = $s->getById(3); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(2, $swimlane['position']); - - // First swimlane can be moved up - $this->assertFalse($s->moveUp(1, 1)); - - // Move with a disabled swimlane - $this->assertTrue($s->disable(1, 1)); - - $swimlane = $s->getById(1); - $this->assertNotEmpty($swimlane); - $this->assertEquals(0, $swimlane['is_active']); - $this->assertEquals(0, $swimlane['position']); - - $swimlane = $s->getById(2); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(2, $swimlane['position']); - - $swimlane = $s->getById(3); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(1, $swimlane['position']); - - // Move the 2nd swimlane up - $this->assertTrue($s->moveUp(1, 2)); - - $swimlane = $s->getById(1); - $this->assertNotEmpty($swimlane); - $this->assertEquals(0, $swimlane['is_active']); - $this->assertEquals(0, $swimlane['position']); - - $swimlane = $s->getById(2); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(1, $swimlane['position']); - - $swimlane = $s->getById(3); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(2, $swimlane['position']); - } - - public function testMoveDown() - { - $p = new Project($this->container); - $s = new Swimlane($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'UnitTest'))); - $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); - $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'Swimlane #2'))); - $this->assertEquals(3, $s->create(array('project_id' => 1, 'name' => 'Swimlane #3'))); - - $swimlane = $s->getById(1); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(1, $swimlane['position']); - - $swimlane = $s->getById(2); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(2, $swimlane['position']); - - $swimlane = $s->getById(3); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(3, $swimlane['position']); - - // Move the swimlane 1 down - $this->assertTrue($s->moveDown(1, 1)); - - $swimlane = $s->getById(1); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(2, $swimlane['position']); - - $swimlane = $s->getById(2); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(1, $swimlane['position']); - - $swimlane = $s->getById(3); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(3, $swimlane['position']); - - // Last swimlane can be moved down - $this->assertFalse($s->moveDown(1, 3)); - - // Move with a disabled swimlane - $this->assertTrue($s->disable(1, 3)); - - $swimlane = $s->getById(1); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(2, $swimlane['position']); - - $swimlane = $s->getById(2); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(1, $swimlane['position']); - - $swimlane = $s->getById(3); - $this->assertNotEmpty($swimlane); - $this->assertEquals(0, $swimlane['is_active']); - $this->assertEquals(0, $swimlane['position']); - - // Move the 2st swimlane down - $this->assertTrue($s->moveDown(1, 2)); - - $swimlane = $s->getById(1); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(1, $swimlane['position']); - - $swimlane = $s->getById(2); - $this->assertNotEmpty($swimlane); - $this->assertEquals(1, $swimlane['is_active']); - $this->assertEquals(2, $swimlane['position']); - - $swimlane = $s->getById(3); - $this->assertNotEmpty($swimlane); - $this->assertEquals(0, $swimlane['is_active']); - $this->assertEquals(0, $swimlane['position']); - } - public function testDuplicateSwimlane() { $p = new Project($this->container); @@ -406,4 +256,93 @@ class SwimlaneTest extends Base $new_default = $s->getDefault(2); $this->assertEquals('New Default', $new_default['default_swimlane']); } + + public function testChangePosition() + { + $projectModel = new Project($this->container); + $swimlaneModel = new Swimlane($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); + $this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #2'))); + $this->assertEquals(3, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #3'))); + $this->assertEquals(4, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #4'))); + + $swimlanes = $swimlaneModel->getAllByStatus(1); + $this->assertEquals(1, $swimlanes[0]['position']); + $this->assertEquals(1, $swimlanes[0]['id']); + $this->assertEquals(2, $swimlanes[1]['position']); + $this->assertEquals(2, $swimlanes[1]['id']); + $this->assertEquals(3, $swimlanes[2]['position']); + $this->assertEquals(3, $swimlanes[2]['id']); + + $this->assertTrue($swimlaneModel->changePosition(1, 3, 2)); + + $swimlanes = $swimlaneModel->getAllByStatus(1); + $this->assertEquals(1, $swimlanes[0]['position']); + $this->assertEquals(1, $swimlanes[0]['id']); + $this->assertEquals(2, $swimlanes[1]['position']); + $this->assertEquals(3, $swimlanes[1]['id']); + $this->assertEquals(3, $swimlanes[2]['position']); + $this->assertEquals(2, $swimlanes[2]['id']); + + $this->assertTrue($swimlaneModel->changePosition(1, 2, 1)); + + $swimlanes = $swimlaneModel->getAllByStatus(1); + $this->assertEquals(1, $swimlanes[0]['position']); + $this->assertEquals(2, $swimlanes[0]['id']); + $this->assertEquals(2, $swimlanes[1]['position']); + $this->assertEquals(1, $swimlanes[1]['id']); + $this->assertEquals(3, $swimlanes[2]['position']); + $this->assertEquals(3, $swimlanes[2]['id']); + + $this->assertTrue($swimlaneModel->changePosition(1, 2, 2)); + + $swimlanes = $swimlaneModel->getAllByStatus(1); + $this->assertEquals(1, $swimlanes[0]['position']); + $this->assertEquals(1, $swimlanes[0]['id']); + $this->assertEquals(2, $swimlanes[1]['position']); + $this->assertEquals(2, $swimlanes[1]['id']); + $this->assertEquals(3, $swimlanes[2]['position']); + $this->assertEquals(3, $swimlanes[2]['id']); + + $this->assertTrue($swimlaneModel->changePosition(1, 4, 1)); + + $swimlanes = $swimlaneModel->getAllByStatus(1); + $this->assertEquals(1, $swimlanes[0]['position']); + $this->assertEquals(4, $swimlanes[0]['id']); + $this->assertEquals(2, $swimlanes[1]['position']); + $this->assertEquals(1, $swimlanes[1]['id']); + $this->assertEquals(3, $swimlanes[2]['position']); + $this->assertEquals(2, $swimlanes[2]['id']); + + $this->assertFalse($swimlaneModel->changePosition(1, 2, 0)); + $this->assertFalse($swimlaneModel->changePosition(1, 2, 5)); + } + + public function testChangePositionWithInactiveSwimlane() + { + $projectModel = new Project($this->container); + $swimlaneModel = new Swimlane($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1'))); + $this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #2', 'is_active' => 0))); + $this->assertEquals(3, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #3', 'is_active' => 0))); + $this->assertEquals(4, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #4'))); + + $swimlanes = $swimlaneModel->getAllByStatus(1); + $this->assertEquals(1, $swimlanes[0]['position']); + $this->assertEquals(1, $swimlanes[0]['id']); + $this->assertEquals(2, $swimlanes[1]['position']); + $this->assertEquals(4, $swimlanes[1]['id']); + + $this->assertTrue($swimlaneModel->changePosition(1, 4, 1)); + + $swimlanes = $swimlaneModel->getAllByStatus(1); + $this->assertEquals(1, $swimlanes[0]['position']); + $this->assertEquals(4, $swimlanes[0]['id']); + $this->assertEquals(2, $swimlanes[1]['position']); + $this->assertEquals(1, $swimlanes[1]['id']); + } } diff --git a/tests/units/Model/TaskCreationTest.php b/tests/units/Model/TaskCreationTest.php index d76937b2..781a7147 100644 --- a/tests/units/Model/TaskCreationTest.php +++ b/tests/units/Model/TaskCreationTest.php @@ -8,7 +8,6 @@ use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\TaskStatus; use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; class TaskCreationTest extends Base { @@ -182,8 +181,7 @@ class TaskCreationTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); - $_SESSION = array(); - $_SESSION['user']['id'] = 1; + $this->container['sessionStorage']->user = array('id' => 1); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); @@ -194,8 +192,6 @@ class TaskCreationTest extends Base $this->assertEquals(1, $task['id']); $this->assertEquals(1, $task['creator_id']); - - $_SESSION = array(); } public function testColumnId() @@ -299,7 +295,7 @@ class TaskCreationTest extends Base $task = $tf->getById(2); $this->assertNotEmpty($task); $this->assertEquals(2, $task['id']); - $this->assertEquals($timestamp, $task['date_due']); + $this->assertEquals(date('Y-m-d 00:00', $timestamp), date('Y-m-d 00:00', $task['date_due'])); $task = $tf->getById(3); $this->assertEquals(3, $task['id']); @@ -406,6 +402,7 @@ class TaskCreationTest extends Base $this->assertEquals('yellow', $task['color_id']); $this->assertTrue($c->save(array('default_color' => 'orange'))); + $this->container['memoryCache']->flush(); $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test2'))); @@ -425,6 +422,6 @@ class TaskCreationTest extends Base $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertEquals('2050-01-10 12:30', date('Y-m-d H:i', $task['date_due'])); + $this->assertEquals('2050-01-10 00:00', date('Y-m-d H:i', $task['date_due'])); } } diff --git a/tests/units/Model/TaskDuplicationTest.php b/tests/units/Model/TaskDuplicationTest.php index 5273928c..8649c6b0 100644 --- a/tests/units/Model/TaskDuplicationTest.php +++ b/tests/units/Model/TaskDuplicationTest.php @@ -2,16 +2,18 @@ require_once __DIR__.'/../Base.php'; +use Kanboard\Core\DateParser; use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskDuplication; use Kanboard\Model\TaskFinder; use Kanboard\Model\TaskStatus; use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; +use Kanboard\Model\ProjectUserRole; use Kanboard\Model\Category; use Kanboard\Model\User; use Kanboard\Model\Swimlane; +use Kanboard\Core\Security\Role; class TaskDuplicationTest extends Base { @@ -31,8 +33,7 @@ class TaskDuplicationTest extends Base $this->assertEquals(1, $task['project_id']); $this->assertEquals(0, $task['creator_id']); - $_SESSION = array(); - $_SESSION['user']['id'] = 1; + $this->container['sessionStorage']->user = array('id' => 1); // We duplicate our task $this->assertEquals(2, $td->duplicate(1)); @@ -41,8 +42,6 @@ class TaskDuplicationTest extends Base $task = $tf->getById(2); $this->assertNotEmpty($task); $this->assertEquals(1, $task['creator_id']); - - $_SESSION = array(); } public function testDuplicateSameProject() @@ -130,7 +129,7 @@ class TaskDuplicationTest extends Base // Check the values of the duplicated task $task = $tf->getById(2); $this->assertNotEmpty($task); - $this->assertEquals(1, $task['owner_id']); + $this->assertEquals(0, $task['owner_id']); $this->assertEquals(0, $task['category_id']); $this->assertEquals(0, $task['swimlane_id']); $this->assertEquals(6, $task['column_id']); @@ -336,7 +335,7 @@ class TaskDuplicationTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); - $pp = new ProjectPermission($this->container); + $pp = new ProjectUserRole($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -360,10 +359,8 @@ class TaskDuplicationTest extends Base // We create a new user for our project $user = new User($this->container); $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->addMember(2, 2)); - $this->assertTrue($pp->isUserAllowed(1, 2)); - $this->assertTrue($pp->isUserAllowed(2, 2)); + $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER)); // We duplicate our task to the 2nd project $this->assertEquals(3, $td->duplicateToProject(1, 2)); @@ -394,7 +391,7 @@ class TaskDuplicationTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); - $pp = new ProjectPermission($this->container); + $pr = new ProjectUserRole($this->container); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -402,6 +399,7 @@ class TaskDuplicationTest extends Base // We create a task $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2))); + $this->assertTrue($pr->addUser(2, 1, Role::PROJECT_MEMBER)); // We duplicate our task to the 2nd project $this->assertEquals(2, $td->duplicateToProject(1, 2, null, null, null, 1)); @@ -428,7 +426,6 @@ class TaskDuplicationTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); - $pp = new ProjectPermission($this->container); $user = new User($this->container); // We create 2 projects @@ -449,7 +446,7 @@ class TaskDuplicationTest extends Base // Check the values of the moved task $task = $tf->getById(1); $this->assertNotEmpty($task); - $this->assertEquals(1, $task['owner_id']); + $this->assertEquals(0, $task['owner_id']); $this->assertEquals(0, $task['category_id']); $this->assertEquals(0, $task['swimlane_id']); $this->assertEquals(2, $task['project_id']); @@ -499,7 +496,7 @@ class TaskDuplicationTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); - $pp = new ProjectPermission($this->container); + $pp = new ProjectUserRole($this->container); $user = new User($this->container); // We create 2 projects @@ -508,10 +505,8 @@ class TaskDuplicationTest extends Base // We create a new user for our project $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->addMember(2, 2)); - $this->assertTrue($pp->isUserAllowed(1, 2)); - $this->assertTrue($pp->isUserAllowed(2, 2)); + $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER)); // We create a task $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 2))); @@ -534,7 +529,7 @@ class TaskDuplicationTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); - $pp = new ProjectPermission($this->container); + $pp = new ProjectUserRole($this->container); $user = new User($this->container); // We create 2 projects @@ -543,10 +538,8 @@ class TaskDuplicationTest extends Base // We create a new user for our project $this->assertNotFalse($user->create(array('username' => 'unittest#1', 'password' => 'unittest'))); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->addMember(2, 2)); - $this->assertTrue($pp->isUserAllowed(1, 2)); - $this->assertTrue($pp->isUserAllowed(2, 2)); + $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER)); // We create a task $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 3))); @@ -673,6 +666,7 @@ class TaskDuplicationTest extends Base $tf = new TaskFinder($this->container); $p = new Project($this->container); $c = new Category($this->container); + $dp = new DateParser($this->container); $this->assertEquals(1, $p->create(array('name' => 'test1'))); @@ -693,7 +687,7 @@ class TaskDuplicationTest extends Base $this->assertNotEmpty($task); $this->assertEquals(Task::RECURRING_STATUS_PROCESSED, $task['recurrence_status']); $this->assertEquals(2, $task['recurrence_child']); - $this->assertEquals(1436561776, $task['date_due'], '', 2); + $this->assertEquals(1436486400, $task['date_due'], '', 2); $task = $tf->getById(2); $this->assertNotEmpty($task); @@ -703,6 +697,6 @@ class TaskDuplicationTest extends Base $this->assertEquals(Task::RECURRING_BASEDATE_TRIGGERDATE, $task['recurrence_basedate']); $this->assertEquals(1, $task['recurrence_parent']); $this->assertEquals(2, $task['recurrence_factor']); - $this->assertEquals(strtotime('+2 days'), $task['date_due'], '', 2); + $this->assertEquals($dp->removeTimeFromTimestamp(strtotime('+2 days')), $task['date_due'], '', 2); } } diff --git a/tests/units/Model/TaskExportTest.php b/tests/units/Model/TaskExportTest.php index 40b3a5a2..b40b0771 100644 --- a/tests/units/Model/TaskExportTest.php +++ b/tests/units/Model/TaskExportTest.php @@ -51,7 +51,7 @@ class TaskExportTest extends Base $this->assertEquals($i, count($rows)); $this->assertEquals('Task Id', $rows[0][0]); $this->assertEquals(1, $rows[1][0]); - $this->assertEquals('Task #'.($i - 1), $rows[$i - 1][12]); + $this->assertEquals('Task #'.($i - 1), $rows[$i - 1][13]); $this->assertTrue(in_array($rows[$i - 1][4], array('Default swimlane', 'S1', 'S2'))); } } diff --git a/tests/units/Model/TaskExternalLinkTest.php b/tests/units/Model/TaskExternalLinkTest.php new file mode 100644 index 00000000..28ccab83 --- /dev/null +++ b/tests/units/Model/TaskExternalLinkTest.php @@ -0,0 +1,123 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Project; +use Kanboard\Model\TaskExternalLink; +use Kanboard\Core\ExternalLink\ExternalLinkManager; +use Kanboard\ExternalLink\WebLinkProvider; + +class TaskExternalLinkTest extends Base +{ + public function testCreate() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskExternalLinkModel = new TaskExternalLink($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'http://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related'))); + + $link = $taskExternalLinkModel->getById(1); + $this->assertNotEmpty($link); + $this->assertEquals('My website', $link['title']); + $this->assertEquals('http://kanboard.net/', $link['url']); + $this->assertEquals('related', $link['dependency']); + $this->assertEquals('weblink', $link['link_type']); + $this->assertEquals(0, $link['creator_id']); + $this->assertEquals(time(), $link['date_modification'], '', 2); + $this->assertEquals(time(), $link['date_creation'], '', 2); + } + + public function testCreateWithUserSession() + { + $this->container['sessionStorage']->user = array('id' => 1); + + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskExternalLinkModel = new TaskExternalLink($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'http://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related'))); + + $link = $taskExternalLinkModel->getById(1); + $this->assertNotEmpty($link); + $this->assertEquals('My website', $link['title']); + $this->assertEquals('http://kanboard.net/', $link['url']); + $this->assertEquals('related', $link['dependency']); + $this->assertEquals('weblink', $link['link_type']); + $this->assertEquals(1, $link['creator_id']); + $this->assertEquals(time(), $link['date_modification'], '', 2); + $this->assertEquals(time(), $link['date_creation'], '', 2); + } + + public function testModification() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskExternalLinkModel = new TaskExternalLink($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'http://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related'))); + + sleep(1); + + $this->assertTrue($taskExternalLinkModel->update(array('id' => 1, 'url' => 'https://kanboard.net/'))); + + $link = $taskExternalLinkModel->getById(1); + $this->assertNotEmpty($link); + $this->assertEquals('https://kanboard.net/', $link['url']); + $this->assertEquals(time(), $link['date_modification'], '', 2); + } + + public function testRemove() + { + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskExternalLinkModel = new TaskExternalLink($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'id' => '', 'url' => 'http://kanboard.net/', 'title' => 'My website', 'link_type' => 'weblink', 'dependency' => 'related'))); + + $this->assertTrue($taskExternalLinkModel->remove(1)); + $this->assertFalse($taskExternalLinkModel->remove(1)); + + $this->assertEmpty($taskExternalLinkModel->getById(1)); + } + + public function testGetAll() + { + $this->container['sessionStorage']->user = array('id' => 1); + $this->container['externalLinkManager'] = new ExternalLinkManager($this->container); + + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $taskExternalLinkModel = new TaskExternalLink($this->container); + $webLinkProvider = new WebLinkProvider($this->container); + + $this->container['externalLinkManager']->register($webLinkProvider); + + $this->assertEquals(1, $projectModel->create(array('name' => 'Test'))); + $this->assertEquals(1, $taskCreationModel->create(array('title' => 'Test', 'project_id' => 1))); + $this->assertEquals(1, $taskExternalLinkModel->create(array('task_id' => 1, 'url' => 'https://miniflux.net/', 'title' => 'MX', 'link_type' => 'weblink', 'dependency' => 'related'))); + $this->assertEquals(2, $taskExternalLinkModel->create(array('task_id' => 1, 'url' => 'http://kanboard.net/', 'title' => 'KB', 'link_type' => 'weblink', 'dependency' => 'related'))); + + $links = $taskExternalLinkModel->getAll(1); + $this->assertCount(2, $links); + $this->assertEquals('KB', $links[0]['title']); + $this->assertEquals('MX', $links[1]['title']); + $this->assertEquals('Web Link', $links[0]['type']); + $this->assertEquals('Web Link', $links[1]['type']); + $this->assertEquals('Related', $links[0]['dependency_label']); + $this->assertEquals('Related', $links[1]['dependency_label']); + $this->assertEquals('admin', $links[0]['creator_username']); + $this->assertEquals('admin', $links[1]['creator_username']); + $this->assertEquals('', $links[0]['creator_name']); + $this->assertEquals('', $links[1]['creator_name']); + } +} diff --git a/tests/units/Model/TaskFileTest.php b/tests/units/Model/TaskFileTest.php new file mode 100644 index 00000000..b7db96a9 --- /dev/null +++ b/tests/units/Model/TaskFileTest.php @@ -0,0 +1,446 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\Task; +use Kanboard\Model\TaskFile; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Project; + +class TaskFileTest extends Base +{ + public function testCreation() + { + $projectModel = new Project($this->container); + $fileModel = new TaskFile($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); + + $file = $fileModel->getById(1); + $this->assertEquals('test', $file['name']); + $this->assertEquals('/tmp/foo', $file['path']); + $this->assertEquals(0, $file['is_image']); + $this->assertEquals(1, $file['task_id']); + $this->assertEquals(time(), $file['date'], '', 2); + $this->assertEquals(0, $file['user_id']); + $this->assertEquals(10, $file['size']); + + $this->assertEquals(2, $fileModel->create(1, 'test2.png', '/tmp/foobar', 10)); + + $file = $fileModel->getById(2); + $this->assertEquals('test2.png', $file['name']); + $this->assertEquals('/tmp/foobar', $file['path']); + $this->assertEquals(1, $file['is_image']); + } + + public function testCreationWithFileNameTooLong() + { + $projectModel = new Project($this->container); + $fileModel = new TaskFile($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertNotFalse($fileModel->create(1, 'test', '/tmp/foo', 10)); + $this->assertNotFalse($fileModel->create(1, str_repeat('a', 1000), '/tmp/foo', 10)); + + $files = $fileModel->getAll(1); + $this->assertNotEmpty($files); + $this->assertCount(2, $files); + + $this->assertEquals(str_repeat('a', 255), $files[0]['name']); + $this->assertEquals('test', $files[1]['name']); + } + + public function testCreationWithSessionOpen() + { + $this->container['sessionStorage']->user = array('id' => 1); + + $projectModel = new Project($this->container); + $fileModel = new TaskFile($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', '/tmp/foo', 10)); + + $file = $fileModel->getById(1); + $this->assertEquals('test', $file['name']); + $this->assertEquals(1, $file['user_id']); + } + + public function testGetAll() + { + $projectModel = new Project($this->container); + $fileModel = new TaskFile($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->assertEquals(1, $fileModel->create(1, 'B.pdf', '/tmp/foo', 10)); + $this->assertEquals(2, $fileModel->create(1, 'A.png', '/tmp/foo', 10)); + $this->assertEquals(3, $fileModel->create(1, 'D.doc', '/tmp/foo', 10)); + $this->assertEquals(4, $fileModel->create(1, 'C.JPG', '/tmp/foo', 10)); + + $fileModeliles = $fileModel->getAll(1); + $this->assertNotEmpty($fileModeliles); + $this->assertCount(4, $fileModeliles); + $this->assertEquals('A.png', $fileModeliles[0]['name']); + $this->assertEquals('B.pdf', $fileModeliles[1]['name']); + $this->assertEquals('C.JPG', $fileModeliles[2]['name']); + $this->assertEquals('D.doc', $fileModeliles[3]['name']); + + $fileModeliles = $fileModel->getAllImages(1); + $this->assertNotEmpty($fileModeliles); + $this->assertCount(2, $fileModeliles); + $this->assertEquals('A.png', $fileModeliles[0]['name']); + $this->assertEquals('C.JPG', $fileModeliles[1]['name']); + + $fileModeliles = $fileModel->getAllDocuments(1); + $this->assertNotEmpty($fileModeliles); + $this->assertCount(2, $fileModeliles); + $this->assertEquals('B.pdf', $fileModeliles[0]['name']); + $this->assertEquals('D.doc', $fileModeliles[1]['name']); + } + + public function testIsImage() + { + $fileModel = new TaskFile($this->container); + + $this->assertTrue($fileModel->isImage('test.png')); + $this->assertTrue($fileModel->isImage('test.jpeg')); + $this->assertTrue($fileModel->isImage('test.gif')); + $this->assertTrue($fileModel->isImage('test.jpg')); + $this->assertTrue($fileModel->isImage('test.JPG')); + + $this->assertFalse($fileModel->isImage('test.bmp')); + $this->assertFalse($fileModel->isImage('test')); + $this->assertFalse($fileModel->isImage('test.pdf')); + } + + public function testGetThumbnailPath() + { + $fileModel = new TaskFile($this->container); + $this->assertEquals('thumbnails'.DIRECTORY_SEPARATOR.'test', $fileModel->getThumbnailPath('test')); + } + + public function testGeneratePath() + { + $fileModel = new TaskFile($this->container); + + $this->assertStringStartsWith('tasks'.DIRECTORY_SEPARATOR.'34'.DIRECTORY_SEPARATOR, $fileModel->generatePath(34, 'test.png')); + $this->assertNotEquals($fileModel->generatePath(34, 'test1.png'), $fileModel->generatePath(34, 'test2.png')); + } + + public function testUploadFiles() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\TaskFile') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $files = array( + 'name' => array( + 'file1.png', + 'file2.doc', + ), + 'tmp_name' => array( + '/tmp/phpYzdqkD', + '/tmp/phpeEwEWG', + ), + 'error' => array( + UPLOAD_ERR_OK, + UPLOAD_ERR_OK, + ), + 'size' => array( + 123, + 456, + ), + ); + + $fileModel + ->expects($this->once()) + ->method('generateThumbnailFromFile'); + + $this->container['objectStorage'] + ->expects($this->at(0)) + ->method('moveUploadedFile') + ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()); + + $this->container['objectStorage'] + ->expects($this->at(1)) + ->method('moveUploadedFile') + ->with($this->equalTo('/tmp/phpeEwEWG'), $this->anything()); + + $this->assertTrue($fileModel->uploadFiles(1, $files)); + + $files = $fileModel->getAll(1); + $this->assertCount(2, $files); + + $this->assertEquals(1, $files[0]['id']); + $this->assertEquals('file1.png', $files[0]['name']); + $this->assertEquals(1, $files[0]['is_image']); + $this->assertEquals(1, $files[0]['task_id']); + $this->assertEquals(0, $files[0]['user_id']); + $this->assertEquals(123, $files[0]['size']); + $this->assertEquals(time(), $files[0]['date'], '', 2); + + $this->assertEquals(2, $files[1]['id']); + $this->assertEquals('file2.doc', $files[1]['name']); + $this->assertEquals(0, $files[1]['is_image']); + $this->assertEquals(1, $files[1]['task_id']); + $this->assertEquals(0, $files[1]['user_id']); + $this->assertEquals(456, $files[1]['size']); + $this->assertEquals(time(), $files[1]['date'], '', 2); + } + + public function testUploadFilesWithEmptyFiles() + { + $fileModel = new TaskFile($this->container); + $this->assertFalse($fileModel->uploadFiles(1, array())); + } + + public function testUploadFilesWithUploadError() + { + $files = array( + 'name' => array( + 'file1.png', + 'file2.doc', + ), + 'tmp_name' => array( + '', + '/tmp/phpeEwEWG', + ), + 'error' => array( + UPLOAD_ERR_CANT_WRITE, + UPLOAD_ERR_OK, + ), + 'size' => array( + 123, + 456, + ), + ); + + $fileModel = new TaskFile($this->container); + $this->assertFalse($fileModel->uploadFiles(1, $files)); + } + + public function testUploadFilesWithObjectStorageError() + { + $files = array( + 'name' => array( + 'file1.csv', + 'file2.doc', + ), + 'tmp_name' => array( + '/tmp/phpYzdqkD', + '/tmp/phpeEwEWG', + ), + 'error' => array( + UPLOAD_ERR_OK, + UPLOAD_ERR_OK, + ), + 'size' => array( + 123, + 456, + ), + ); + + $this->container['objectStorage'] + ->expects($this->at(0)) + ->method('moveUploadedFile') + ->with($this->equalTo('/tmp/phpYzdqkD'), $this->anything()) + ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); + + $fileModel = new TaskFile($this->container); + $this->assertFalse($fileModel->uploadFiles(1, $files)); + } + + public function testUploadFileContent() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\TaskFile') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $data = 'test'; + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with($this->anything(), $this->equalTo($data)); + + $this->assertEquals(1, $fileModel->uploadContent(1, 'test.doc', base64_encode($data))); + + $files = $fileModel->getAll(1); + $this->assertCount(1, $files); + + $this->assertEquals(1, $files[0]['id']); + $this->assertEquals('test.doc', $files[0]['name']); + $this->assertEquals(0, $files[0]['is_image']); + $this->assertEquals(1, $files[0]['task_id']); + $this->assertEquals(0, $files[0]['user_id']); + $this->assertEquals(4, $files[0]['size']); + $this->assertEquals(time(), $files[0]['date'], '', 2); + } + + public function testUploadFileContentWithObjectStorageError() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\TaskFile') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $data = 'test'; + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with($this->anything(), $this->equalTo($data)) + ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); + + $this->assertFalse($fileModel->uploadContent(1, 'test.doc', base64_encode($data))); + } + + public function testUploadScreenshot() + { + $fileModel = $this + ->getMockBuilder('\Kanboard\Model\TaskFile') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromFile')) + ->getMock(); + + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $data = 'test'; + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + $fileModel + ->expects($this->once()) + ->method('generateThumbnailFromFile'); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with($this->anything(), $this->equalTo($data)); + + $this->assertEquals(1, $fileModel->uploadScreenshot(1, base64_encode($data))); + + $files = $fileModel->getAll(1); + $this->assertCount(1, $files); + + $this->assertEquals(1, $files[0]['id']); + $this->assertStringStartsWith('Screenshot taken ', $files[0]['name']); + $this->assertEquals(1, $files[0]['is_image']); + $this->assertEquals(1, $files[0]['task_id']); + $this->assertEquals(0, $files[0]['user_id']); + $this->assertEquals(4, $files[0]['size']); + $this->assertEquals(time(), $files[0]['date'], '', 2); + } + + public function testRemove() + { + $fileModel = new TaskFile($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', 'tmp/foo', 10)); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('remove') + ->with('tmp/foo'); + + $this->assertTrue($fileModel->remove(1)); + } + + public function testRemoveWithObjectStorageError() + { + $fileModel = new TaskFile($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', 'tmp/foo', 10)); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('remove') + ->with('tmp/foo') + ->will($this->throwException(new \Kanboard\Core\ObjectStorage\ObjectStorageException('test'))); + + $this->assertFalse($fileModel->remove(1)); + } + + public function testRemoveImage() + { + $fileModel = new TaskFile($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'image.gif', 'tmp/image.gif', 10)); + + $this->container['objectStorage'] + ->expects($this->at(0)) + ->method('remove') + ->with('tmp/image.gif'); + + $this->container['objectStorage'] + ->expects($this->at(1)) + ->method('remove') + ->with('thumbnails'.DIRECTORY_SEPARATOR.'tmp/image.gif'); + + $this->assertTrue($fileModel->remove(1)); + } + + public function testRemoveAll() + { + $fileModel = new TaskFile($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(1, $fileModel->create(1, 'test', 'tmp/foo', 10)); + $this->assertEquals(2, $fileModel->create(1, 'test', 'tmp/foo', 10)); + + $this->container['objectStorage'] + ->expects($this->exactly(2)) + ->method('remove') + ->with('tmp/foo'); + + $this->assertTrue($fileModel->removeAll(1)); + } +} diff --git a/tests/units/Model/TaskFilterTest.php b/tests/units/Model/TaskFilterTest.php index b668b7cc..daa193b2 100644 --- a/tests/units/Model/TaskFilterTest.php +++ b/tests/units/Model/TaskFilterTest.php @@ -6,6 +6,7 @@ use Kanboard\Model\Project; use Kanboard\Model\User; use Kanboard\Model\TaskFilter; use Kanboard\Model\TaskCreation; +use Kanboard\Model\TaskLink; use Kanboard\Core\DateParser; use Kanboard\Model\Category; use Kanboard\Model\Subtask; @@ -552,6 +553,65 @@ class TaskFilterTest extends Base $this->assertEquals('task3', $tasks[0]['title']); } + public function testSearchWithLink() + { + $p = new Project($this->container); + $u = new User($this->container); + $tc = new TaskCreation($this->container); + $tl = new TaskLink($this->container); + $tf = new TaskFilter($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Bob Ryan'))); + $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is awesome', 'color_id' => 'light_green'))); + $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'color_id' => 'blue'))); + $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work'))); + $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'I have a bad feeling about that'))); + $this->assertEquals(1, $tl->create(1, 2, 9)); // #1 is a milestone of #2 + $this->assertEquals(3, $tl->create(2, 1, 2)); // #2 blocks #1 + $this->assertEquals(5, $tl->create(3, 2, 2)); // #3 blocks #2 + + $tf->search('link:"is a milestone of"'); + $tasks = $tf->findAll(); + $this->assertNotEmpty($tasks); + $this->assertCount(1, $tasks); + $this->assertEquals('my task title is awesome', $tasks[0]['title']); + + $tf->search('link:"is a milestone of" amazing'); + $tasks = $tf->findAll(); + $this->assertEmpty($tasks); + + $tf->search('link:"unknown"'); + $tasks = $tf->findAll(); + $this->assertEmpty($tasks); + + $tf->search('link:unknown'); + $tasks = $tf->findAll(); + $this->assertEmpty($tasks); + + $tf->search('link:blocks amazing'); + $tasks = $tf->findAll(); + $this->assertNotEmpty($tasks); + $this->assertCount(1, $tasks); + $this->assertEquals('my task title is amazing', $tasks[0]['title']); + + $tf->search('link:"is a milestone of" link:blocks'); + $tasks = $tf->findAll(); + $this->assertNotEmpty($tasks); + $this->assertCount(3, $tasks); + $this->assertEquals('my task title is awesome', $tasks[0]['title']); + $this->assertEquals('my task title is amazing', $tasks[1]['title']); + $this->assertEquals('Bob at work', $tasks[2]['title']); + + $tf->search('link:"is a milestone of" link:blocks link:unknown'); + $tasks = $tf->findAll(); + $this->assertNotEmpty($tasks); + $this->assertCount(3, $tasks); + $this->assertEquals('my task title is awesome', $tasks[0]['title']); + $this->assertEquals('my task title is amazing', $tasks[1]['title']); + $this->assertEquals('Bob at work', $tasks[2]['title']); + } + public function testCopy() { $tf = new TaskFilter($this->container); diff --git a/tests/units/Model/TaskFinderTest.php b/tests/units/Model/TaskFinderTest.php index e22f14e1..b21a4ea3 100644 --- a/tests/units/Model/TaskFinderTest.php +++ b/tests/units/Model/TaskFinderTest.php @@ -6,7 +6,6 @@ use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; use Kanboard\Model\Category; use Kanboard\Model\User; diff --git a/tests/units/Model/TaskLinkTest.php b/tests/units/Model/TaskLinkTest.php index 4db42d99..192a4298 100644 --- a/tests/units/Model/TaskLinkTest.php +++ b/tests/units/Model/TaskLinkTest.php @@ -194,53 +194,4 @@ class TaskLinkTest extends Base $links = $tl->getAll(2); $this->assertEmpty($links); } - - public function testValidation() - { - $tl = new TaskLink($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); - $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); - - $links = $tl->getAll(1); - $this->assertEmpty($links); - - $links = $tl->getAll(2); - $this->assertEmpty($links); - - // Check creation - $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2)); - $this->assertTrue($r[0]); - - $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1)); - $this->assertFalse($r[0]); - - $r = $tl->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2)); - $this->assertFalse($r[0]); - - $r = $tl->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2)); - $this->assertFalse($r[0]); - - $r = $tl->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1)); - $this->assertFalse($r[0]); - - // Check modification - $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2)); - $this->assertTrue($r[0]); - - $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1)); - $this->assertFalse($r[0]); - - $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2)); - $this->assertFalse($r[0]); - - $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2)); - $this->assertFalse($r[0]); - - $r = $tl->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1)); - $this->assertFalse($r[0]); - } } diff --git a/tests/units/Model/TaskMetadataTest.php b/tests/units/Model/TaskMetadataTest.php index 9ce7d6be..2683c297 100644 --- a/tests/units/Model/TaskMetadataTest.php +++ b/tests/units/Model/TaskMetadataTest.php @@ -33,5 +33,10 @@ class TaskMetadataTest extends Base $this->assertEquals(array('key1' => 'value2'), $tm->getAll(1)); $this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $tm->getAll(2)); + + $this->assertTrue($tm->remove(2, 'key1')); + $this->assertFalse($tm->remove(2, 'key1')); + + $this->assertEquals(array('key2' => 'value2'), $tm->getAll(2)); } } diff --git a/tests/units/Model/TaskModificationTest.php b/tests/units/Model/TaskModificationTest.php index 49b51f9b..119201f0 100644 --- a/tests/units/Model/TaskModificationTest.php +++ b/tests/units/Model/TaskModificationTest.php @@ -8,7 +8,6 @@ use Kanboard\Model\TaskModification; use Kanboard\Model\TaskFinder; use Kanboard\Model\TaskStatus; use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; class TaskModificationTest extends Base { @@ -42,6 +41,24 @@ class TaskModificationTest extends Base $this->assertEquals(1, $event_data['owner_id']); } + public function testThatNoEventAreFiredWhenNoChanges() + { + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tm = new TaskModification($this->container); + $tf = new TaskFinder($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); + + $this->container['dispatcher']->addListener(Task::EVENT_CREATE_UPDATE, array($this, 'onCreateUpdate')); + $this->container['dispatcher']->addListener(Task::EVENT_UPDATE, array($this, 'onUpdate')); + + $this->assertTrue($tm->update(array('id' => 1, 'title' => 'test'))); + + $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); + } + public function testChangeTitle() { $p = new Project($this->container); diff --git a/tests/units/Model/TaskMovedDateSubscriberTest.php b/tests/units/Model/TaskMovedDateSubscriberTest.php deleted file mode 100644 index 0dd6e995..00000000 --- a/tests/units/Model/TaskMovedDateSubscriberTest.php +++ /dev/null @@ -1,77 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Model\TaskPosition; -use Kanboard\Model\TaskCreation; -use Kanboard\Model\TaskFinder; -use Kanboard\Model\Project; -use Kanboard\Model\Swimlane; -use Kanboard\Subscriber\TaskMovedDateSubscriber; -use Symfony\Component\EventDispatcher\EventDispatcher; - -class TaskMovedDateSubscriberTest extends Base -{ - public function testMoveTaskAnotherColumn() - { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - - $this->container['dispatcher'] = new EventDispatcher; - $this->container['dispatcher']->addSubscriber(new TaskMovedDateSubscriber($this->container)); - - $now = time(); - - $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); - - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals($now, $task['date_moved'], '', 1); - - sleep(1); - - $this->assertTrue($tp->movePosition(1, 1, 2, 1)); - - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertNotEquals($now, $task['date_moved']); - } - - public function testMoveTaskAnotherSwimlane() - { - $tp = new TaskPosition($this->container); - $tc = new TaskCreation($this->container); - $p = new Project($this->container); - $tf = new TaskFinder($this->container); - $s = new Swimlane($this->container); - - $this->container['dispatcher'] = new EventDispatcher; - $this->container['dispatcher']->addSubscriber(new TaskMovedDateSubscriber($this->container)); - - $now = time(); - - $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); - $this->assertEquals(1, $s->create(array('project_id' => 1, 'name' => 'S1'))); - $this->assertEquals(2, $s->create(array('project_id' => 1, 'name' => 'S2'))); - $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1))); - - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertEquals($now, $task['date_moved'], '', 1); - $this->assertEquals(1, $task['column_id']); - $this->assertEquals(0, $task['swimlane_id']); - - sleep(1); - - $this->assertTrue($tp->movePosition(1, 1, 2, 1, 2)); - - $task = $tf->getById(1); - $this->assertNotEmpty($task); - $this->assertNotEquals($now, $task['date_moved']); - $this->assertEquals(2, $task['column_id']); - $this->assertEquals(2, $task['swimlane_id']); - } -} diff --git a/tests/units/Model/TaskPermissionTest.php b/tests/units/Model/TaskPermissionTest.php index 52a36549..0b093bbb 100644 --- a/tests/units/Model/TaskPermissionTest.php +++ b/tests/units/Model/TaskPermissionTest.php @@ -9,7 +9,7 @@ use Kanboard\Model\TaskPermission; use Kanboard\Model\Project; use Kanboard\Model\Category; use Kanboard\Model\User; -use Kanboard\Model\UserSession; +use Kanboard\Core\User\UserSession; class TaskPermissionTest extends Base { @@ -33,7 +33,7 @@ class TaskPermissionTest extends Base // User #1 can remove everything $user = $u->getbyId(1); $this->assertNotEmpty($user); - $us->refresh($user); + $us->initialize($user); $task = $tf->getbyId(1); $this->assertNotEmpty($task); @@ -42,7 +42,7 @@ class TaskPermissionTest extends Base // User #2 can't remove the task #1 $user = $u->getbyId(2); $this->assertNotEmpty($user); - $us->refresh($user); + $us->initialize($user); $task = $tf->getbyId(1); $this->assertNotEmpty($task); @@ -51,7 +51,7 @@ class TaskPermissionTest extends Base // User #1 can remove everything $user = $u->getbyId(1); $this->assertNotEmpty($user); - $us->refresh($user); + $us->initialize($user); $task = $tf->getbyId(2); $this->assertNotEmpty($task); @@ -60,7 +60,7 @@ class TaskPermissionTest extends Base // User #2 can remove his own task $user = $u->getbyId(2); $this->assertNotEmpty($user); - $us->refresh($user); + $us->initialize($user); $task = $tf->getbyId(2); $this->assertNotEmpty($task); @@ -69,7 +69,7 @@ class TaskPermissionTest extends Base // User #1 can remove everything $user = $u->getbyId(1); $this->assertNotEmpty($user); - $us->refresh($user); + $us->initialize($user); $task = $tf->getbyId(3); $this->assertNotEmpty($task); @@ -78,7 +78,7 @@ class TaskPermissionTest extends Base // User #2 can't remove the task #3 $user = $u->getbyId(2); $this->assertNotEmpty($user); - $us->refresh($user); + $us->initialize($user); $task = $tf->getbyId(3); $this->assertNotEmpty($task); @@ -87,7 +87,7 @@ class TaskPermissionTest extends Base // User #1 can remove everything $user = $u->getbyId(1); $this->assertNotEmpty($user); - $us->refresh($user); + $us->initialize($user); $task = $tf->getbyId(4); $this->assertNotEmpty($task); @@ -96,7 +96,7 @@ class TaskPermissionTest extends Base // User #2 can't remove the task #4 $user = $u->getbyId(2); $this->assertNotEmpty($user); - $us->refresh($user); + $us->initialize($user); $task = $tf->getbyId(4); $this->assertNotEmpty($task); diff --git a/tests/units/Model/TaskPositionTest.php b/tests/units/Model/TaskPositionTest.php index 42612f44..28145a66 100644 --- a/tests/units/Model/TaskPositionTest.php +++ b/tests/units/Model/TaskPositionTest.php @@ -3,7 +3,7 @@ require_once __DIR__.'/../Base.php'; use Kanboard\Model\Task; -use Kanboard\Model\Board; +use Kanboard\Model\Column; use Kanboard\Model\TaskStatus; use Kanboard\Model\TaskPosition; use Kanboard\Model\TaskCreation; @@ -21,23 +21,23 @@ class TaskPositionTest extends Base $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); - $b = new Board($this->container); + $columnModel = new Column($this->container); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); - $this->assertEquals(0, $t->getProgress($tf->getById(1), $b->getColumnsList(1))); + $this->assertEquals(0, $t->getProgress($tf->getById(1), $columnModel->getList(1))); $this->assertTrue($tp->movePosition(1, 1, 2, 1)); - $this->assertEquals(25, $t->getProgress($tf->getById(1), $b->getColumnsList(1))); + $this->assertEquals(25, $t->getProgress($tf->getById(1), $columnModel->getList(1))); $this->assertTrue($tp->movePosition(1, 1, 3, 1)); - $this->assertEquals(50, $t->getProgress($tf->getById(1), $b->getColumnsList(1))); + $this->assertEquals(50, $t->getProgress($tf->getById(1), $columnModel->getList(1))); $this->assertTrue($tp->movePosition(1, 1, 4, 1)); - $this->assertEquals(75, $t->getProgress($tf->getById(1), $b->getColumnsList(1))); + $this->assertEquals(75, $t->getProgress($tf->getById(1), $columnModel->getList(1))); $this->assertTrue($ts->close(1)); - $this->assertEquals(100, $t->getProgress($tf->getById(1), $b->getColumnsList(1))); + $this->assertEquals(100, $t->getProgress($tf->getById(1), $columnModel->getList(1))); } public function testMoveTaskToWrongPosition() @@ -106,7 +106,7 @@ class TaskPositionTest extends Base $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1))); - // We move the task 2 to the column 3 + // We move the task 1 to the column 3 $this->assertTrue($tp->movePosition(1, 1, 3, 1)); // Check tasks position @@ -235,7 +235,7 @@ class TaskPositionTest extends Base $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'column_id' => 1))); $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1, 'column_id' => 1))); - // Move the last task to the bottom + // Move the first task to the bottom $this->assertTrue($tp->movePosition(1, 1, 1, 4)); // Check tasks position diff --git a/tests/units/Model/TaskStatusTest.php b/tests/units/Model/TaskStatusTest.php index de08ffb3..86f31d70 100644 --- a/tests/units/Model/TaskStatusTest.php +++ b/tests/units/Model/TaskStatusTest.php @@ -2,16 +2,51 @@ require_once __DIR__.'/../Base.php'; +use Kanboard\Model\Swimlane; use Kanboard\Model\Subtask; use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\TaskStatus; use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; class TaskStatusTest extends Base { + public function testCloseBySwimlaneAndColumn() + { + $tc = new TaskCreation($this->container); + $tf = new TaskFinder($this->container); + $ts = new TaskStatus($this->container); + $p = new Project($this->container); + $s = new Swimlane($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $s->create(array('name' => 'test', 'project_id' => 1))); + $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); + $this->assertEquals(2, $tc->create(array('title' => 'test', 'project_id' => 1))); + $this->assertEquals(3, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2))); + $this->assertEquals(4, $tc->create(array('title' => 'test', 'project_id' => 1, 'swimlane_id' => 1))); + + $this->assertEquals(2, $tf->countByColumnAndSwimlaneId(1, 1, 0)); + $this->assertEquals(1, $tf->countByColumnAndSwimlaneId(1, 1, 1)); + $this->assertEquals(1, $tf->countByColumnAndSwimlaneId(1, 2, 0)); + + $ts->closeTasksBySwimlaneAndColumn(0, 1); + $this->assertEquals(0, $tf->countByColumnAndSwimlaneId(1, 1, 0)); + $this->assertEquals(1, $tf->countByColumnAndSwimlaneId(1, 1, 1)); + $this->assertEquals(1, $tf->countByColumnAndSwimlaneId(1, 2, 0)); + + $ts->closeTasksBySwimlaneAndColumn(1, 1); + $this->assertEquals(0, $tf->countByColumnAndSwimlaneId(1, 1, 0)); + $this->assertEquals(0, $tf->countByColumnAndSwimlaneId(1, 1, 1)); + $this->assertEquals(1, $tf->countByColumnAndSwimlaneId(1, 2, 0)); + + $ts->closeTasksBySwimlaneAndColumn(0, 2); + $this->assertEquals(0, $tf->countByColumnAndSwimlaneId(1, 1, 0)); + $this->assertEquals(0, $tf->countByColumnAndSwimlaneId(1, 1, 1)); + $this->assertEquals(0, $tf->countByColumnAndSwimlaneId(1, 2, 0)); + } + public function testStatus() { $tc = new TaskCreation($this->container); diff --git a/tests/units/Model/TaskTest.php b/tests/units/Model/TaskTest.php index 192dc098..60e752e5 100644 --- a/tests/units/Model/TaskTest.php +++ b/tests/units/Model/TaskTest.php @@ -7,7 +7,6 @@ use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\TaskStatus; use Kanboard\Model\Project; -use Kanboard\Model\ProjectPermission; use Kanboard\Model\Category; use Kanboard\Model\User; diff --git a/tests/units/Model/UserLockingTest.php b/tests/units/Model/UserLockingTest.php new file mode 100644 index 00000000..c743f8eb --- /dev/null +++ b/tests/units/Model/UserLockingTest.php @@ -0,0 +1,43 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\UserLocking; + +class UserLockingTest extends Base +{ + public function testFailedLogin() + { + $u = new UserLocking($this->container); + + $this->assertEquals(0, $u->getFailedLogin('admin')); + $this->assertEquals(0, $u->getFailedLogin('not_found')); + + $this->assertTrue($u->incrementFailedLogin('admin')); + $this->assertTrue($u->incrementFailedLogin('admin')); + + $this->assertEquals(2, $u->getFailedLogin('admin')); + $this->assertTrue($u->resetFailedLogin('admin')); + $this->assertEquals(0, $u->getFailedLogin('admin')); + } + + public function testLocking() + { + $u = new UserLocking($this->container); + + $this->assertFalse($u->isLocked('admin')); + $this->assertFalse($u->isLocked('not_found')); + $this->assertTrue($u->lock('admin', 1)); + $this->assertTrue($u->isLocked('admin')); + } + + public function testCaptcha() + { + $u = new UserLocking($this->container); + $this->assertTrue($u->incrementFailedLogin('admin')); + $this->assertFalse($u->hasCaptcha('admin', 2)); + + $this->assertTrue($u->incrementFailedLogin('admin')); + $this->assertTrue($u->hasCaptcha('admin', 2)); + } +} diff --git a/tests/units/Model/UserMentionTest.php b/tests/units/Model/UserMentionTest.php new file mode 100644 index 00000000..d50c9285 --- /dev/null +++ b/tests/units/Model/UserMentionTest.php @@ -0,0 +1,114 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Core\Security\Role; +use Kanboard\Event\GenericEvent; +use Kanboard\Model\User; +use Kanboard\Model\Task; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Project; +use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\UserMention; + +class UserMentionTest extends Base +{ + public function testGetMentionedUsersWithNoMentions() + { + $userModel = new User($this->container); + $userMentionModel = new UserMention($this->container); + + $this->assertNotFalse($userModel->create(array('username' => 'user1'))); + $this->assertEmpty($userMentionModel->getMentionedUsers('test')); + } + + public function testGetMentionedUsersWithNotficationDisabled() + { + $userModel = new User($this->container); + $userMentionModel = new UserMention($this->container); + + $this->assertNotFalse($userModel->create(array('username' => 'user1'))); + $this->assertEmpty($userMentionModel->getMentionedUsers('test @user1')); + } + + public function testGetMentionedUsersWithNotficationEnabled() + { + $userModel = new User($this->container); + $userMentionModel = new UserMention($this->container); + + $this->assertNotFalse($userModel->create(array('username' => 'user1'))); + $this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1))); + + $users = $userMentionModel->getMentionedUsers('test @user2'); + $this->assertCount(1, $users); + $this->assertEquals('user2', $users[0]['username']); + $this->assertEquals('Foobar', $users[0]['name']); + $this->assertEquals('', $users[0]['email']); + $this->assertEquals('', $users[0]['language']); + } + + public function testGetMentionedUsersWithNotficationEnabledAndUserLoggedIn() + { + $this->container['sessionStorage']->user = array('id' => 3); + $userModel = new User($this->container); + $userMentionModel = new UserMention($this->container); + + $this->assertNotFalse($userModel->create(array('username' => 'user1'))); + $this->assertNotFalse($userModel->create(array('username' => 'user2', 'name' => 'Foobar', 'notifications_enabled' => 1))); + + $this->assertEmpty($userMentionModel->getMentionedUsers('test @user2')); + } + + public function testFireEventsWithMultipleMentions() + { + $projectUserRoleModel = new ProjectUserRole($this->container); + $projectModel = new Project($this->container); + $userModel = new User($this->container); + $userMentionModel = new UserMention($this->container); + $event = new GenericEvent(array('project_id' => 1)); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User 2', 'notifications_enabled' => 1))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); + + $this->container['dispatcher']->addListener(Task::EVENT_USER_MENTION, array($this, 'onUserMention')); + + $userMentionModel->fireEvents('test @user1 @user2', Task::EVENT_USER_MENTION, $event); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(Task::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); + } + + public function testFireEventsWithNoProjectId() + { + $projectUserRoleModel = new ProjectUserRole($this->container); + $projectModel = new Project($this->container); + $taskCreationModel = new TaskCreation($this->container); + $userModel = new User($this->container); + $userMentionModel = new UserMention($this->container); + $event = new GenericEvent(array('task_id' => 1)); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'name' => 'User 1', 'notifications_enabled' => 1))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'name' => 'User 2', 'notifications_enabled' => 1))); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + $this->assertTrue($projectUserRoleModel->addUser(1, 3, Role::PROJECT_MEMBER)); + + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'Task 1'))); + + $this->container['dispatcher']->addListener(Task::EVENT_USER_MENTION, array($this, 'onUserMention')); + + $userMentionModel->fireEvents('test @user1 @user2', Task::EVENT_USER_MENTION, $event); + + $called = $this->container['dispatcher']->getCalledListeners(); + $this->assertArrayHasKey(Task::EVENT_USER_MENTION.'.UserMentionTest::onUserMention', $called); + } + + public function onUserMention($event) + { + $this->assertInstanceOf('Kanboard\Event\GenericEvent', $event); + $this->assertEquals(array('id' => '3', 'username' => 'user2', 'name' => 'User 2', 'email' => null, 'language' => null), $event['mention']); + } +} diff --git a/tests/units/Model/UserMetadataTest.php b/tests/units/Model/UserMetadataTest.php index cc1fff12..457f1fb2 100644 --- a/tests/units/Model/UserMetadataTest.php +++ b/tests/units/Model/UserMetadataTest.php @@ -29,5 +29,10 @@ class UserMetadataTest extends Base $this->assertEquals(array('key1' => 'value2'), $m->getAll(1)); $this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $m->getAll(2)); + + $this->assertTrue($m->remove(2, 'key1')); + $this->assertFalse($m->remove(2, 'key1')); + + $this->assertEquals(array('key2' => 'value2'), $m->getAll(2)); } } diff --git a/tests/units/Model/UserNotificationTest.php b/tests/units/Model/UserNotificationTest.php index 729667de..e1928661 100644 --- a/tests/units/Model/UserNotificationTest.php +++ b/tests/units/Model/UserNotificationTest.php @@ -7,14 +7,18 @@ use Kanboard\Model\TaskCreation; use Kanboard\Model\Subtask; use Kanboard\Model\Comment; use Kanboard\Model\User; -use Kanboard\Model\File; +use Kanboard\Model\Group; +use Kanboard\Model\GroupMember; use Kanboard\Model\Project; -use Kanboard\Model\Task; use Kanboard\Model\ProjectPermission; +use Kanboard\Model\Task; +use Kanboard\Model\ProjectUserRole; +use Kanboard\Model\ProjectGroupRole; use Kanboard\Model\UserNotification; use Kanboard\Model\UserNotificationFilter; use Kanboard\Model\UserNotificationType; use Kanboard\Subscriber\UserNotificationSubscriber; +use Kanboard\Core\Security\Role; class UserNotificationTest extends Base { @@ -23,11 +27,11 @@ class UserNotificationTest extends Base $u = new User($this->container); $p = new Project($this->container); $n = new UserNotification($this->container); - $pp = new ProjectPermission($this->container); + $pp = new ProjectUserRole($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $u->create(array('username' => 'user1'))); - $this->assertTrue($pp->addMember(1, 2)); + $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); $this->assertEmpty($n->getUsersWithNotificationEnabled(1)); $n->enableNotification(2); @@ -96,12 +100,48 @@ class UserNotificationTest extends Base $this->assertEquals(array(1), $settings['notification_projects']); } + public function testGetGroupMembersWithNotificationEnabled() + { + $userModel = new User($this->container); + $groupModel = new Group($this->container); + $groupMemberModel = new GroupMember($this->container); + $projectModel = new Project($this->container); + $userNotificationModel = new UserNotification($this->container); + $projectGroupRole = new ProjectGroupRole($this->container); + $projectUserRole = new ProjectUserRole($this->container); + + $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); + $this->assertEquals(4, $userModel->create(array('username' => 'user3'))); + + $this->assertEquals(1, $groupModel->create('G1')); + $this->assertEquals(2, $groupModel->create('G2')); + + $this->assertTrue($groupMemberModel->addUser(1, 2)); + $this->assertTrue($groupMemberModel->addUser(1, 3)); + $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(2, 2)); + $this->assertTrue($groupMemberModel->addUser(2, 3)); + + $this->assertEquals(1, $projectModel->create(array('name' => 'P1'))); + + $this->assertTrue($projectGroupRole->addGroup(1, 1, Role::PROJECT_MEMBER)); + $this->assertTrue($projectGroupRole->addGroup(1, 2, Role::PROJECT_VIEWER)); + + $this->assertTrue($projectUserRole->addUser(1, 2, Role::PROJECT_MEMBER)); + + $users = $userNotificationModel->getUsersWithNotificationEnabled(1); + $this->assertCount(2, $users); + $this->assertEquals('user1', $users[0]['username']); + $this->assertEquals('user2', $users[1]['username']); + } + public function testGetProjectMembersWithNotifications() { $u = new User($this->container); $p = new Project($this->container); $n = new UserNotification($this->container); - $pp = new ProjectPermission($this->container); + $pp = new ProjectUserRole($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); @@ -118,16 +158,16 @@ class UserNotificationTest extends Base $this->assertNotFalse($u->create(array('username' => 'user4'))); // Nobody is member of any projects - $this->assertEmpty($pp->getMembers(1)); + $this->assertEmpty($pp->getUsers(1)); $this->assertEmpty($n->getUsersWithNotificationEnabled(1)); // We allow all users to be member of our projects - $this->assertTrue($pp->addMember(1, 1)); - $this->assertTrue($pp->addMember(1, 2)); - $this->assertTrue($pp->addMember(1, 3)); - $this->assertTrue($pp->addMember(1, 4)); + $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER)); + $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); + $this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER)); + $this->assertTrue($pp->addUser(1, 4, Role::PROJECT_MEMBER)); - $this->assertNotEmpty($pp->getMembers(1)); + $this->assertNotEmpty($pp->getUsers(1)); $users = $n->getUsersWithNotificationEnabled(1); $this->assertNotEmpty($users); diff --git a/tests/units/Model/UserSessionTest.php b/tests/units/Model/UserSessionTest.php deleted file mode 100644 index 66f6faa7..00000000 --- a/tests/units/Model/UserSessionTest.php +++ /dev/null @@ -1,32 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Kanboard\Core\Session; -use Kanboard\Model\UserSession; - -class UserSessionTest extends Base -{ - public function testIsAdmin() - { - $s = new Session; - $us = new UserSession($this->container); - - $this->assertFalse($us->isAdmin()); - - $s['user'] = array(); - $this->assertFalse($us->isAdmin()); - - $s['user'] = array('is_admin' => '1'); - $this->assertFalse($us->isAdmin()); - - $s['user'] = array('is_admin' => false); - $this->assertFalse($us->isAdmin()); - - $s['user'] = array('is_admin' => '2'); - $this->assertFalse($us->isAdmin()); - - $s['user'] = array('is_admin' => true); - $this->assertTrue($us->isAdmin()); - } -} diff --git a/tests/units/Model/UserTest.php b/tests/units/Model/UserTest.php index 90a80954..e411da0c 100644 --- a/tests/units/Model/UserTest.php +++ b/tests/units/Model/UserTest.php @@ -9,34 +9,10 @@ use Kanboard\Model\Task; use Kanboard\Model\TaskCreation; use Kanboard\Model\TaskFinder; use Kanboard\Model\Project; +use Kanboard\Core\Security\Role; class UserTest extends Base { - public function testFailedLogin() - { - $u = new User($this->container); - - $this->assertEquals(0, $u->getFailedLogin('admin')); - $this->assertEquals(0, $u->getFailedLogin('not_found')); - - $this->assertTrue($u->incrementFailedLogin('admin')); - $this->assertTrue($u->incrementFailedLogin('admin')); - - $this->assertEquals(2, $u->getFailedLogin('admin')); - $this->assertTrue($u->resetFailedLogin('admin')); - $this->assertEquals(0, $u->getFailedLogin('admin')); - } - - public function testLocking() - { - $u = new User($this->container); - - $this->assertFalse($u->isLocked('admin')); - $this->assertFalse($u->isLocked('not_found')); - $this->assertTrue($u->lock('admin', 1)); - $this->assertTrue($u->isLocked('admin')); - } - public function testGetByEmail() { $u = new User($this->container); @@ -47,33 +23,27 @@ class UserTest extends Base $this->assertEmpty($u->getByEmail('')); } - public function testGetByGitlabId() + public function testGetByExternalId() { $u = new User($this->container); $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'gitlab_id' => '1234'))); - $this->assertNotEmpty($u->getByGitlabId('1234')); - $this->assertEmpty($u->getByGitlabId('')); - } + $this->assertNotEmpty($u->getByExternalId('gitlab_id', '1234')); + $this->assertEmpty($u->getByExternalId('gitlab_id', '')); - public function testGetByGithubId() - { $u = new User($this->container); - $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'github_id' => 'plop'))); - $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'github_id' => ''))); + $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'github_id' => 'plop'))); + $this->assertNotFalse($u->create(array('username' => 'user3', 'password' => '123456', 'github_id' => ''))); - $this->assertNotEmpty($u->getByGithubId('plop')); - $this->assertEmpty($u->getByGithubId('')); - } + $this->assertNotEmpty($u->getByExternalId('github_id', 'plop')); + $this->assertEmpty($u->getByExternalId('github_id', '')); - public function testGetByGoogleId() - { $u = new User($this->container); - $this->assertNotFalse($u->create(array('username' => 'user1', 'password' => '123456', 'google_id' => '1234'))); - $this->assertNotFalse($u->create(array('username' => 'user2', 'password' => '123456', 'google_id' => ''))); + $this->assertNotFalse($u->create(array('username' => 'user4', 'password' => '123456', 'google_id' => '1234'))); + $this->assertNotFalse($u->create(array('username' => 'user5', 'password' => '123456', 'google_id' => ''))); - $this->assertNotEmpty($u->getByGoogleId('1234')); - $this->assertEmpty($u->getByGoogleId('')); + $this->assertNotEmpty($u->getByExternalId('google_id', '1234')); + $this->assertEmpty($u->getByExternalId('google_id', '')); } public function testGetByToken() @@ -126,13 +96,14 @@ class UserTest extends Base $this->assertEquals('you', $users[2]['username']); } - public function testGetList() + public function testGetActiveUsersList() { $u = new User($this->container); $this->assertEquals(2, $u->create(array('username' => 'you'))); $this->assertEquals(3, $u->create(array('username' => 'me', 'name' => 'Me too'))); + $this->assertEquals(4, $u->create(array('username' => 'foobar', 'is_active' => 0))); - $users = $u->getList(); + $users = $u->getActiveUsersList(); $expected = array( 1 => 'admin', @@ -142,7 +113,7 @@ class UserTest extends Base $this->assertEquals($expected, $users); - $users = $u->getList(true); + $users = $u->getActiveUsersList(true); $expected = array( User::EVERYBODY_ID => 'Everybody', @@ -197,7 +168,7 @@ class UserTest extends Base 'password' => '1234', 'confirmation' => '1234', 'name' => 'me', - 'is_admin' => '', + 'role' => Role::APP_ADMIN, ); $u->prepare($input); @@ -207,9 +178,6 @@ class UserTest extends Base $this->assertNotEquals('1234', $input['password']); $this->assertNotEmpty($input['password']); - $this->assertArrayHasKey('is_admin', $input); - $this->assertInternalType('integer', $input['is_admin']); - $input = array( 'username' => 'user1', 'password' => '1234', @@ -273,8 +241,8 @@ class UserTest extends Base $u = new User($this->container); $this->assertEquals(2, $u->create(array('username' => 'user #1', 'password' => '123456', 'name' => 'User'))); $this->assertEquals(3, $u->create(array('username' => 'user #2', 'is_ldap_user' => 1))); - $this->assertEquals(4, $u->create(array('username' => 'user #3', 'is_project_admin' => 1))); - $this->assertEquals(5, $u->create(array('username' => 'user #4', 'gitlab_id' => ''))); + $this->assertEquals(4, $u->create(array('username' => 'user #3', 'role' => Role::APP_MANAGER))); + $this->assertEquals(5, $u->create(array('username' => 'user #4', 'gitlab_id' => '', 'role' => Role::APP_ADMIN))); $this->assertEquals(6, $u->create(array('username' => 'user #5', 'gitlab_id' => '1234'))); $this->assertFalse($u->create(array('username' => 'user #1'))); @@ -283,7 +251,7 @@ class UserTest extends Base $this->assertTrue(is_array($user)); $this->assertEquals('admin', $user['username']); $this->assertEquals('', $user['name']); - $this->assertEquals(1, $user['is_admin']); + $this->assertEquals(Role::APP_ADMIN, $user['role']); $this->assertEquals(0, $user['is_ldap_user']); $user = $u->getById(2); @@ -291,7 +259,7 @@ class UserTest extends Base $this->assertTrue(is_array($user)); $this->assertEquals('user #1', $user['username']); $this->assertEquals('User', $user['name']); - $this->assertEquals(0, $user['is_admin']); + $this->assertEquals(Role::APP_USER, $user['role']); $this->assertEquals(0, $user['is_ldap_user']); $user = $u->getById(3); @@ -299,27 +267,28 @@ class UserTest extends Base $this->assertTrue(is_array($user)); $this->assertEquals('user #2', $user['username']); $this->assertEquals('', $user['name']); - $this->assertEquals(0, $user['is_admin']); + $this->assertEquals(Role::APP_USER, $user['role']); $this->assertEquals(1, $user['is_ldap_user']); $user = $u->getById(4); $this->assertNotFalse($user); $this->assertTrue(is_array($user)); $this->assertEquals('user #3', $user['username']); - $this->assertEquals(0, $user['is_admin']); - $this->assertEquals(1, $user['is_project_admin']); + $this->assertEquals(Role::APP_MANAGER, $user['role']); $user = $u->getById(5); $this->assertNotFalse($user); $this->assertTrue(is_array($user)); $this->assertEquals('user #4', $user['username']); $this->assertEquals('', $user['gitlab_id']); + $this->assertEquals(Role::APP_ADMIN, $user['role']); $user = $u->getById(6); $this->assertNotFalse($user); $this->assertTrue(is_array($user)); $this->assertEquals('user #5', $user['username']); $this->assertEquals('1234', $user['gitlab_id']); + $this->assertEquals(Role::APP_USER, $user['role']); } public function testUpdate() @@ -336,7 +305,7 @@ class UserTest extends Base $this->assertTrue(is_array($user)); $this->assertEquals('biloute', $user['username']); $this->assertEquals('Toto', $user['name']); - $this->assertEquals(0, $user['is_admin']); + $this->assertEquals(Role::APP_USER, $user['role']); $this->assertEquals(0, $user['is_ldap_user']); $user = $u->getById(3); @@ -423,4 +392,24 @@ class UserTest extends Base $this->assertEquals('toto', $user['username']); $this->assertEmpty($user['token']); } + + public function testEnableDisable() + { + $userModel = new User($this->container); + $this->assertEquals(2, $userModel->create(array('username' => 'toto'))); + + $this->assertTrue($userModel->isActive(2)); + $user = $userModel->getById(2); + $this->assertEquals(1, $user['is_active']); + + $this->assertTrue($userModel->disable(2)); + $user = $userModel->getById(2); + $this->assertEquals(0, $user['is_active']); + $this->assertFalse($userModel->isActive(2)); + + $this->assertTrue($userModel->enable(2)); + $user = $userModel->getById(2); + $this->assertEquals(1, $user['is_active']); + $this->assertTrue($userModel->isActive(2)); + } } diff --git a/tests/units/Model/UserUnreadNotificationTest.php b/tests/units/Model/UserUnreadNotificationTest.php index bf274d95..62889bf0 100644 --- a/tests/units/Model/UserUnreadNotificationTest.php +++ b/tests/units/Model/UserUnreadNotificationTest.php @@ -7,7 +7,6 @@ use Kanboard\Model\TaskCreation; use Kanboard\Model\Subtask; use Kanboard\Model\Comment; use Kanboard\Model\User; -use Kanboard\Model\File; use Kanboard\Model\Task; use Kanboard\Model\Project; use Kanboard\Model\UserUnreadNotification; diff --git a/tests/units/Notification/MailTest.php b/tests/units/Notification/MailTest.php index 3aa1a39c..7dc6aaef 100644 --- a/tests/units/Notification/MailTest.php +++ b/tests/units/Notification/MailTest.php @@ -7,10 +7,9 @@ use Kanboard\Model\TaskCreation; use Kanboard\Model\Subtask; use Kanboard\Model\Comment; use Kanboard\Model\User; -use Kanboard\Model\File; +use Kanboard\Model\TaskFile; use Kanboard\Model\Project; use Kanboard\Model\Task; -use Kanboard\Model\ProjectPermission; use Kanboard\Notification\Mail; use Kanboard\Subscriber\NotificationSubscriber; @@ -24,7 +23,7 @@ class MailTest extends Base $tc = new TaskCreation($this->container); $s = new Subtask($this->container); $c = new Comment($this->container); - $f = new File($this->container); + $f = new TaskFile($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); diff --git a/tests/units/Notification/WebhookTest.php b/tests/units/Notification/WebhookTest.php index b55cd6e2..7215baeb 100644 --- a/tests/units/Notification/WebhookTest.php +++ b/tests/units/Notification/WebhookTest.php @@ -21,92 +21,12 @@ class WebhookTest extends Base $c->save(array('webhook_url' => 'http://localhost/?task-creation')); - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - - $this->assertStringStartsWith('http://localhost/?task-creation&token=', $this->container['httpClient']->getUrl()); - - $event = $this->container['httpClient']->getData(); - $this->assertNotEmpty($event); - $this->assertArrayHasKey('event_name', $event); - $this->assertArrayHasKey('event_data', $event); - $this->assertEquals('task.create', $event['event_name']); - $this->assertNotEmpty($event['event_data']); - - $this->assertArrayHasKey('project_id', $event['event_data']['task']); - $this->assertArrayHasKey('id', $event['event_data']['task']); - $this->assertArrayHasKey('title', $event['event_data']['task']); - $this->assertArrayHasKey('column_id', $event['event_data']['task']); - $this->assertArrayHasKey('color_id', $event['event_data']['task']); - $this->assertArrayHasKey('swimlane_id', $event['event_data']['task']); - $this->assertArrayHasKey('date_creation', $event['event_data']['task']); - $this->assertArrayHasKey('date_modification', $event['event_data']['task']); - $this->assertArrayHasKey('date_moved', $event['event_data']['task']); - $this->assertArrayHasKey('position', $event['event_data']['task']); - } - - public function testTaskModification() - { - $c = new Config($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $tm = new TaskModification($this->container); - $this->container['dispatcher']->addSubscriber(new NotificationSubscriber($this->container)); - - $c->save(array('webhook_url' => 'http://localhost/modif/')); - - $this->assertEquals(1, $p->create(array('name' => 'test'))); - $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertTrue($tm->update(array('id' => 1, 'title' => 'test update'))); - - $this->assertStringStartsWith('http://localhost/modif/?token=', $this->container['httpClient']->getUrl()); - - $event = $this->container['httpClient']->getData(); - $this->assertNotEmpty($event); - $this->assertArrayHasKey('event_name', $event); - $this->assertArrayHasKey('event_data', $event); - $this->assertEquals('task.update', $event['event_name']); - $this->assertNotEmpty($event['event_data']); - - $this->assertArrayHasKey('project_id', $event['event_data']['task']); - $this->assertArrayHasKey('id', $event['event_data']['task']); - $this->assertArrayHasKey('title', $event['event_data']['task']); - $this->assertArrayHasKey('column_id', $event['event_data']['task']); - $this->assertArrayHasKey('color_id', $event['event_data']['task']); - $this->assertArrayHasKey('swimlane_id', $event['event_data']['task']); - $this->assertArrayHasKey('date_creation', $event['event_data']['task']); - $this->assertArrayHasKey('date_modification', $event['event_data']['task']); - $this->assertArrayHasKey('date_moved', $event['event_data']['task']); - $this->assertArrayHasKey('position', $event['event_data']['task']); - } - - public function testCommentCreation() - { - $c = new Config($this->container); - $p = new Project($this->container); - $tc = new TaskCreation($this->container); - $cm = new Comment($this->container); - $this->container['dispatcher']->addSubscriber(new NotificationSubscriber($this->container)); - - $c->save(array('webhook_url' => 'http://localhost/comment')); + $this->container['httpClient'] + ->expects($this->once()) + ->method('postJson') + ->with($this->stringContains('http://localhost/?task-creation&token='), $this->anything()); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $cm->create(array('task_id' => 1, 'comment' => 'test comment', 'user_id' => 1))); - - $this->assertStringStartsWith('http://localhost/comment?token=', $this->container['httpClient']->getUrl()); - - $event = $this->container['httpClient']->getData(); - $this->assertNotEmpty($event); - $this->assertArrayHasKey('event_name', $event); - $this->assertArrayHasKey('event_data', $event); - $this->assertEquals('comment.create', $event['event_name']); - $this->assertNotEmpty($event['event_data']); - - $this->assertArrayHasKey('task_id', $event['event_data']['comment']); - $this->assertArrayHasKey('user_id', $event['event_data']['comment']); - $this->assertArrayHasKey('comment', $event['event_data']['comment']); - $this->assertArrayHasKey('id', $event['event_data']['comment']); - $this->assertEquals('test comment', $event['event_data']['comment']['comment']); } } diff --git a/tests/units/User/DatabaseUserProviderTest.php b/tests/units/User/DatabaseUserProviderTest.php new file mode 100644 index 00000000..96c03667 --- /dev/null +++ b/tests/units/User/DatabaseUserProviderTest.php @@ -0,0 +1,14 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\User\DatabaseUserProvider; + +class DatabaseUserProviderTest extends Base +{ + public function testGetInternalId() + { + $provider = new DatabaseUserProvider(array('id' => 123)); + $this->assertEquals(123, $provider->getInternalId()); + } +} diff --git a/tests/units/Validator/CommentValidatorTest.php b/tests/units/Validator/CommentValidatorTest.php new file mode 100644 index 00000000..378fe924 --- /dev/null +++ b/tests/units/Validator/CommentValidatorTest.php @@ -0,0 +1,57 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Validator\CommentValidator; + +class CommentValidatorTest extends Base +{ + public function testValidateCreation() + { + $validator = new CommentValidator($this->container); + + $result = $validator->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => 'bla')); + $this->assertTrue($result[0]); + + $result = $validator->validateCreation(array('user_id' => 1, 'task_id' => 1, 'comment' => '')); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array('user_id' => 1, 'task_id' => 'a', 'comment' => 'bla')); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array('user_id' => 'b', 'task_id' => 1, 'comment' => 'bla')); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array('user_id' => 1, 'comment' => 'bla')); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array('task_id' => 1, 'comment' => 'bla')); + $this->assertTrue($result[0]); + + $result = $validator->validateCreation(array('comment' => 'bla')); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array()); + $this->assertFalse($result[0]); + } + + public function testValidateModification() + { + $validator = new CommentValidator($this->container); + + $result = $validator->validateModification(array('id' => 1, 'comment' => 'bla')); + $this->assertTrue($result[0]); + + $result = $validator->validateModification(array('id' => 1, 'comment' => '')); + $this->assertFalse($result[0]); + + $result = $validator->validateModification(array('comment' => 'bla')); + $this->assertFalse($result[0]); + + $result = $validator->validateModification(array('id' => 'b', 'comment' => 'bla')); + $this->assertFalse($result[0]); + + $result = $validator->validateModification(array()); + $this->assertFalse($result[0]); + } +} diff --git a/tests/units/Validator/CurrencyValidatorTest.php b/tests/units/Validator/CurrencyValidatorTest.php new file mode 100644 index 00000000..39c06d44 --- /dev/null +++ b/tests/units/Validator/CurrencyValidatorTest.php @@ -0,0 +1,27 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Validator\CurrencyValidator; + +class CurrencyValidatorTest extends Base +{ + public function testValidation() + { + $validator = new CurrencyValidator($this->container); + $result = $validator->validateCreation(array()); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array('currency' => 'EUR')); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array('rate' => 1.9)); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 'foobar')); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array('currency' => 'EUR', 'rate' => 1.25)); + $this->assertTrue($result[0]); + } +} diff --git a/tests/units/Validator/CustomFilterValidatorTest.php b/tests/units/Validator/CustomFilterValidatorTest.php new file mode 100644 index 00000000..3b70e42c --- /dev/null +++ b/tests/units/Validator/CustomFilterValidatorTest.php @@ -0,0 +1,40 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Validator\CustomFilterValidator; + +class CustomFilterValidatorTest extends Base +{ + public function testValidateCreation() + { + $validator = new CustomFilterValidator($this->container); + + // Validate creation + $r = $validator->validateCreation(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertTrue($r[0]); + + $r = $validator->validateCreation(array('filter' => str_repeat('a', 101), 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertFalse($r[0]); + + $r = $validator->validateCreation(array('name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertFalse($r[0]); + } + + public function testValidateModification() + { + $validator = new CustomFilterValidator($this->container); + + $r = $validator->validateModification(array('id' => 1, 'filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertTrue($r[0]); + + $r = $validator->validateModification(array('filter' => 'test', 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertFalse($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'filter' => str_repeat('a', 101), 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertFalse($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'user_id' => 1, 'project_id' => 1, 'is_shared' => 0)); + $this->assertFalse($r[0]); + } +} diff --git a/tests/units/Validator/ExternalLinkValidatorTest.php b/tests/units/Validator/ExternalLinkValidatorTest.php new file mode 100644 index 00000000..b41b779a --- /dev/null +++ b/tests/units/Validator/ExternalLinkValidatorTest.php @@ -0,0 +1,63 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Validator\ExternalLinkValidator; + +class ExternalLinkValidatorTest extends Base +{ + public function testValidateCreation() + { + $validator = new ExternalLinkValidator($this->container); + + $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related')); + $this->assertTrue($result[0]); + + $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 'abc', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related')); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink')); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'dependency' => 'related')); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array('url' => 'http://somewhere', 'task_id' => 1, 'link_type' => 'weblink', 'dependency' => 'related')); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array('url' => 'http://somewhere', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related')); + $this->assertFalse($result[0]); + + $result = $validator->validateCreation(array('task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related')); + $this->assertFalse($result[0]); + } + + public function testValidateModification() + { + $validator = new ExternalLinkValidator($this->container); + + $result = $validator->validateModification(array('id' => 1, 'url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related')); + $this->assertTrue($result[0]); + + $result = $validator->validateModification(array('id' => 1, 'url' => 'http://somewhere', 'task_id' => 'abc', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related')); + $this->assertFalse($result[0]); + + $result = $validator->validateModification(array('id' => 1, 'url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink')); + $this->assertFalse($result[0]); + + $result = $validator->validateModification(array('id' => 1, 'url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'dependency' => 'related')); + $this->assertFalse($result[0]); + + $result = $validator->validateModification(array('id' => 1, 'url' => 'http://somewhere', 'task_id' => 1, 'link_type' => 'weblink', 'dependency' => 'related')); + $this->assertFalse($result[0]); + + $result = $validator->validateModification(array('id' => 1, 'url' => 'http://somewhere', 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related')); + $this->assertFalse($result[0]); + + $result = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related')); + $this->assertFalse($result[0]); + + $result = $validator->validateModification(array('url' => 'http://somewhere', 'task_id' => 1, 'title' => 'Title', 'link_type' => 'weblink', 'dependency' => 'related')); + $this->assertFalse($result[0]); + } +} diff --git a/tests/units/Validator/GroupValidatorTest.php b/tests/units/Validator/GroupValidatorTest.php new file mode 100644 index 00000000..879f99ce --- /dev/null +++ b/tests/units/Validator/GroupValidatorTest.php @@ -0,0 +1,30 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Validator\GroupValidator; + +class GroupValidatorTest extends Base +{ + public function testValidateCreation() + { + $validator = new GroupValidator($this->container); + + $result = $validator->validateCreation(array('name' => 'Test')); + $this->assertTrue($result[0]); + + $result = $validator->validateCreation(array('name' => '')); + $this->assertFalse($result[0]); + } + + public function testValidateModification() + { + $validator = new GroupValidator($this->container); + + $result = $validator->validateModification(array('name' => 'Test', 'id' => 1)); + $this->assertTrue($result[0]); + + $result = $validator->validateModification(array('name' => 'Test')); + $this->assertFalse($result[0]); + } +} diff --git a/tests/units/Validator/LinkValidatorTest.php b/tests/units/Validator/LinkValidatorTest.php new file mode 100644 index 00000000..8b7b182c --- /dev/null +++ b/tests/units/Validator/LinkValidatorTest.php @@ -0,0 +1,54 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Validator\LinkValidator; + +class LinkValidatorTest extends Base +{ + public function testValidateCreation() + { + $validator = new LinkValidator($this->container); + + $r = $validator->validateCreation(array('label' => 'a')); + $this->assertTrue($r[0]); + + $r = $validator->validateCreation(array('label' => 'a', 'opposite_label' => 'b')); + $this->assertTrue($r[0]); + + $r = $validator->validateCreation(array('label' => 'relates to')); + $this->assertFalse($r[0]); + + $r = $validator->validateCreation(array('label' => 'a', 'opposite_label' => 'a')); + $this->assertFalse($r[0]); + + $r = $validator->validateCreation(array('label' => '')); + $this->assertFalse($r[0]); + } + + public function testValidateModification() + { + $validator = new LinkValidator($this->container); + + $r = $validator->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => 0)); + $this->assertTrue($r[0]); + + $r = $validator->validateModification(array('id' => 20, 'label' => 'a', 'opposite_id' => '1')); + $this->assertTrue($r[0]); + + $r = $validator->validateModification(array('id' => 20, 'label' => 'relates to', 'opposite_id' => '1')); + $this->assertFalse($r[0]); + + $r = $validator->validateModification(array('id' => 20, 'label' => '', 'opposite_id' => '1')); + $this->assertFalse($r[0]); + + $r = $validator->validateModification(array('label' => '', 'opposite_id' => '1')); + $this->assertFalse($r[0]); + + $r = $validator->validateModification(array('id' => 20, 'opposite_id' => '1')); + $this->assertFalse($r[0]); + + $r = $validator->validateModification(array('label' => 'test')); + $this->assertFalse($r[0]); + } +} diff --git a/tests/units/Validator/PasswordResetValidatorTest.php b/tests/units/Validator/PasswordResetValidatorTest.php new file mode 100644 index 00000000..4af6c75e --- /dev/null +++ b/tests/units/Validator/PasswordResetValidatorTest.php @@ -0,0 +1,64 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Model\User; +use Kanboard\Validator\PasswordResetValidator; + +class PasswordResetValidatorTest extends Base +{ + public function testValidateModification() + { + $validator = new PasswordResetValidator($this->container); + list($valid, ) = $validator->validateModification(array('password' => 'test123', 'confirmation' => 'test123')); + $this->assertTrue($valid); + } + + public function testValidateModificationWithWrongPasswords() + { + $validator = new PasswordResetValidator($this->container); + list($valid, ) = $validator->validateModification(array('password' => 'test123', 'confirmation' => 'test456')); + $this->assertFalse($valid); + } + + public function testValidateModificationWithPasswordTooShort() + { + $validator = new PasswordResetValidator($this->container); + list($valid, ) = $validator->validateModification(array('password' => 'test', 'confirmation' => 'test')); + $this->assertFalse($valid); + } + + public function testValidateCreation() + { + $this->container['sessionStorage']->captcha = 'test'; + + $validator = new PasswordResetValidator($this->container); + list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test')); + $this->assertTrue($valid); + } + + public function testValidateCreationWithNoUsername() + { + $this->container['sessionStorage']->captcha = 'test'; + + $validator = new PasswordResetValidator($this->container); + list($valid,) = $validator->validateCreation(array('captcha' => 'test')); + $this->assertFalse($valid); + } + + public function testValidateCreationWithWrongCaptcha() + { + $this->container['sessionStorage']->captcha = 'test123'; + + $validator = new PasswordResetValidator($this->container); + list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test')); + $this->assertFalse($valid); + } + + public function testValidateCreationWithMissingCaptcha() + { + $validator = new PasswordResetValidator($this->container); + list($valid,) = $validator->validateCreation(array('username' => 'foobar', 'captcha' => 'test')); + $this->assertFalse($valid); + } +} diff --git a/tests/units/Validator/ProjectValidatorTest.php b/tests/units/Validator/ProjectValidatorTest.php new file mode 100644 index 00000000..a73e8247 --- /dev/null +++ b/tests/units/Validator/ProjectValidatorTest.php @@ -0,0 +1,67 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Validator\ProjectValidator; +use Kanboard\Model\Project; + +class ProjectValidatorTest extends Base +{ + public function testValidateCreation() + { + $validator = new ProjectValidator($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); + $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); + + $project = $p->getById(1); + $this->assertNotEmpty($project); + $this->assertEquals('TEST1', $project['identifier']); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('', $project['identifier']); + + $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'TEST1')); + $this->assertFalse($r[0]); + + $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test1')); + $this->assertFalse($r[0]); + + $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c')); + $this->assertFalse($r[0]); + + $r = $validator->validateCreation(array('name' => 'test', 'identifier' => 'test 123')); + $this->assertFalse($r[0]); + } + + public function testValidateModification() + { + $validator = new ProjectValidator($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1'))); + $this->assertEquals(2, $p->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2'))); + + $project = $p->getById(1); + $this->assertNotEmpty($project); + $this->assertEquals('TEST1', $project['identifier']); + + $project = $p->getById(2); + $this->assertNotEmpty($project); + $this->assertEquals('TEST2', $project['identifier']); + + $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1')); + $this->assertTrue($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3')); + $this->assertTrue($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => '')); + $this->assertTrue($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2')); + $this->assertFalse($r[0]); + } +} diff --git a/tests/units/Validator/TaskLinkValidatorTest.php b/tests/units/Validator/TaskLinkValidatorTest.php new file mode 100644 index 00000000..5ac4588e --- /dev/null +++ b/tests/units/Validator/TaskLinkValidatorTest.php @@ -0,0 +1,72 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Validator\TaskLinkValidator; +use Kanboard\Model\TaskLink; +use Kanboard\Model\TaskCreation; +use Kanboard\Model\Project; + +class TaskLinkValidatorTest extends Base +{ + public function testValidateCreation() + { + $validator = new TaskLinkValidator($this->container); + $tl = new TaskLink($this->container); + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); + $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); + + $links = $tl->getAll(1); + $this->assertEmpty($links); + + $links = $tl->getAll(2); + $this->assertEmpty($links); + + // Check creation + $r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2)); + $this->assertTrue($r[0]); + + $r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1)); + $this->assertFalse($r[0]); + + $r = $validator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2)); + $this->assertFalse($r[0]); + + $r = $validator->validateCreation(array('task_id' => 1, 'opposite_task_id' => 2)); + $this->assertFalse($r[0]); + + $r = $validator->validateCreation(array('task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1)); + $this->assertFalse($r[0]); + } + + public function testValidateModification() + { + $validator = new TaskLinkValidator($this->container); + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'A'))); + $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'B'))); + + // Check modification + $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 2)); + $this->assertTrue($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1)); + $this->assertFalse($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2)); + $this->assertFalse($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'opposite_task_id' => 2)); + $this->assertFalse($r[0]); + + $r = $validator->validateModification(array('id' => 1, 'task_id' => 1, 'link_id' => 1, 'opposite_task_id' => 1)); + $this->assertFalse($r[0]); + } +} diff --git a/tests/units/Validator/UserValidatorTest.php b/tests/units/Validator/UserValidatorTest.php new file mode 100644 index 00000000..6d904ade --- /dev/null +++ b/tests/units/Validator/UserValidatorTest.php @@ -0,0 +1,41 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Validator\UserValidator; +use Kanboard\Core\Security\Role; + +class UserValidatorTest extends Base +{ + public function testValidatePasswordModification() + { + $validator = new UserValidator($this->container); + + $this->container['sessionStorage']->user = array( + 'id' => 1, + 'role' => Role::APP_ADMIN, + 'username' => 'admin', + ); + + $result = $validator->validatePasswordModification(array()); + $this->assertFalse($result[0]); + + $result = $validator->validatePasswordModification(array('id' => 1)); + $this->assertFalse($result[0]); + + $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456')); + $this->assertFalse($result[0]); + + $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => 'wrong')); + $this->assertFalse($result[0]); + + $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456')); + $this->assertFalse($result[0]); + + $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'wrong')); + $this->assertFalse($result[0]); + + $result = $validator->validatePasswordModification(array('id' => 1, 'password' => '123456', 'confirmation' => '123456', 'current_password' => 'admin')); + $this->assertTrue($result[0]); + } +} diff --git a/tests/units/fixtures/bitbucket_comment_created.json b/tests/units/fixtures/bitbucket_comment_created.json deleted file mode 100644 index 66a09bb8..00000000 --- a/tests/units/fixtures/bitbucket_comment_created.json +++ /dev/null @@ -1,147 +0,0 @@ -{ - "actor": { - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "display_name": "Frederic Guillot", - "type": "user", - "links": { - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - } - }, - "repository": { - "full_name": "minicoders/test-webhook", - "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}", - "type": "repository", - "links": { - "avatar": { - "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook" - } - }, - "owner": { - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "display_name": "Frederic Guillot", - "type": "user", - "links": { - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - } - }, - "name": "test-webhook" - }, - "comment": { - "content": { - "html": "<ol>\n<li>step1</li>\n<li>step2</li>\n</ol>", - "raw": "1. step1\n2. step2", - "markup": "markdown" - }, - "created_on": "2015-06-21T02:51:40.532529+00:00", - "links": { - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/issue/1#comment-19176252" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments/19176252" - } - }, - "id": 19176252, - "user": { - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "display_name": "Frederic Guillot", - "type": "user", - "links": { - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - } - }, - "updated_on": null - }, - "issue": { - "updated_on": "2015-06-21T02:51:40.536516+00:00", - "votes": 0, - "assignee": null, - "links": { - "vote": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/vote" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1" - }, - "watch": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/watch" - }, - "comments": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments" - }, - "attachments": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/attachments" - } - }, - "priority": "major", - "kind": "bug", - "watches": 1, - "edited_on": null, - "state": "new", - "content": { - "html": "<p><strong>test</strong></p>", - "raw": "**test**", - "markup": "markdown" - }, - "component": null, - "milestone": null, - "version": null, - "id": 1, - "created_on": "2015-06-21T02:17:40.990654+00:00", - "type": "issue", - "reporter": { - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "display_name": "Frederic Guillot", - "type": "user", - "links": { - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - } - }, - "title": "My new issue" - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/bitbucket_issue_assigned.json b/tests/units/fixtures/bitbucket_issue_assigned.json deleted file mode 100644 index 0324afb2..00000000 --- a/tests/units/fixtures/bitbucket_issue_assigned.json +++ /dev/null @@ -1,209 +0,0 @@ -{ - "repository": { - "name": "test-webhook", - "type": "repository", - "full_name": "minicoders/test-webhook", - "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}", - "links": { - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook" - }, - "avatar": { - "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook" - } - }, - "owner": { - "display_name": "Frederic Guillot", - "type": "user", - "links": { - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - } - }, - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - } - }, - "changes": { - "responsible": { - "new": { - "is_system": false, - "name": "Frederic Guillot", - "username": "minicoders", - "id": 1290132, - "billing_external_uuid": null - }, - "old": null - }, - "assignee": { - "new": { - "display_name": "Frederic Guillot", - "type": "user", - "links": { - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - } - }, - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - }, - "old": null - } - }, - "actor": { - "display_name": "Frederic Guillot", - "type": "user", - "links": { - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - } - }, - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - }, - "issue": { - "repository": { - "links": { - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook" - }, - "avatar": { - "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook" - } - }, - "type": "repository", - "full_name": "minicoders/test-webhook", - "name": "test-webhook", - "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}" - }, - "edited_on": null, - "component": null, - "updated_on": "2015-06-21T15:21:28.023525+00:00", - "reporter": { - "display_name": "Frederic Guillot", - "type": "user", - "links": { - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - } - }, - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - }, - "state": "open", - "content": { - "raw": "**test**", - "markup": "markdown", - "html": "<p><strong>test</strong></p>" - }, - "kind": "bug", - "links": { - "attachments": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/attachments" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue" - }, - "watch": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/watch" - }, - "vote": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/vote" - }, - "comments": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1" - } - }, - "created_on": "2015-06-21T02:17:40.990654+00:00", - "watches": 1, - "milestone": null, - "version": null, - "assignee": { - "display_name": "Frederic Guillot", - "type": "user", - "links": { - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - } - }, - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - }, - "title": "My new issue", - "priority": "major", - "id": 1, - "votes": 0, - "type": "issue" - }, - "comment": { - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments/19181255" - } - }, - "updated_on": null, - "content": { - "raw": null, - "markup": "markdown", - "html": "" - }, - "id": 19181255, - "created_on": "2015-06-21T15:21:28.043980+00:00", - "user": { - "display_name": "Frederic Guillot", - "type": "user", - "links": { - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - } - }, - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - } - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/bitbucket_issue_closed.json b/tests/units/fixtures/bitbucket_issue_closed.json deleted file mode 100644 index 473b5167..00000000 --- a/tests/units/fixtures/bitbucket_issue_closed.json +++ /dev/null @@ -1,183 +0,0 @@ -{ - "actor": { - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "type": "user", - "display_name": "Frederic Guillot", - "links": { - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - } - }, - "changes": { - "status": { - "old": "new", - "new": "closed" - } - }, - "repository": { - "full_name": "minicoders/test-webhook", - "type": "repository", - "links": { - "avatar": { - "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook" - } - }, - "owner": { - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "type": "user", - "display_name": "Frederic Guillot", - "links": { - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - } - }, - "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}", - "name": "test-webhook" - }, - "comment": { - "content": { - "html": "", - "raw": null, - "markup": "markdown" - }, - "created_on": "2015-06-21T02:54:40.263014+00:00", - "updated_on": null, - "id": 19176265, - "user": { - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "type": "user", - "display_name": "Frederic Guillot", - "links": { - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - } - }, - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments/19176265" - } - } - }, - "issue": { - "state": "closed", - "votes": 0, - "assignee": { - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "type": "user", - "display_name": "Frederic Guillot", - "links": { - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - } - }, - "links": { - "vote": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/vote" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1" - }, - "watch": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/watch" - }, - "comments": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments" - }, - "attachments": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/attachments" - } - }, - "priority": "major", - "version": null, - "watches": 1, - "edited_on": null, - "reporter": { - "username": "minicoders", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "type": "user", - "display_name": "Frederic Guillot", - "links": { - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - } - }, - "content": { - "html": "<p><strong>test</strong></p>", - "raw": "**test**", - "markup": "markdown" - }, - "component": null, - "created_on": "2015-06-21T02:17:40.990654+00:00", - "updated_on": "2015-06-21T02:54:40.249466+00:00", - "kind": "bug", - "id": 1, - "milestone": null, - "type": "issue", - "repository": { - "full_name": "minicoders/test-webhook", - "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}", - "type": "repository", - "name": "test-webhook", - "links": { - "avatar": { - "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook" - } - } - }, - "title": "My new issue" - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/bitbucket_issue_opened.json b/tests/units/fixtures/bitbucket_issue_opened.json deleted file mode 100644 index 7891c230..00000000 --- a/tests/units/fixtures/bitbucket_issue_opened.json +++ /dev/null @@ -1,112 +0,0 @@ -{ - "issue": { - "type": "issue", - "links": { - "attachments": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/attachments" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue" - }, - "comments": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments" - }, - "vote": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/vote" - }, - "watch": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/watch" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1" - } - }, - "component": null, - "updated_on": "2015-06-21T02:17:40.990654+00:00", - "reporter": { - "links": { - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - } - }, - "username": "minicoders", - "type": "user", - "display_name": "Frederic Guillot", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - }, - "watches": 1, - "kind": "bug", - "edited_on": null, - "created_on": "2015-06-21T02:17:40.990654+00:00", - "milestone": null, - "version": null, - "state": "new", - "assignee": null, - "content": { - "raw": "**test**", - "markup": "markdown", - "html": "<p><strong>test</strong></p>" - }, - "priority": "major", - "id": 1, - "votes": 0, - "title": "My new issue" - }, - "repository": { - "links": { - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook" - }, - "avatar": { - "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook" - } - }, - "type": "repository", - "full_name": "minicoders/test-webhook", - "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}", - "name": "test-webhook", - "owner": { - "links": { - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - } - }, - "username": "minicoders", - "type": "user", - "display_name": "Frederic Guillot", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - } - }, - "actor": { - "links": { - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - } - }, - "username": "minicoders", - "type": "user", - "display_name": "Frederic Guillot", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/bitbucket_issue_reopened.json b/tests/units/fixtures/bitbucket_issue_reopened.json deleted file mode 100644 index bb950916..00000000 --- a/tests/units/fixtures/bitbucket_issue_reopened.json +++ /dev/null @@ -1,183 +0,0 @@ -{ - "issue": { - "edited_on": null, - "watches": 1, - "created_on": "2015-06-21T02:17:40.990654+00:00", - "reporter": { - "username": "minicoders", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - } - }, - "display_name": "Frederic Guillot", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "type": "user" - }, - "content": { - "markup": "markdown", - "raw": "**test**", - "html": "<p><strong>test</strong></p>" - }, - "id": 1, - "milestone": null, - "repository": { - "full_name": "minicoders/test-webhook", - "type": "repository", - "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook" - }, - "avatar": { - "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/" - } - }, - "name": "test-webhook" - }, - "component": null, - "version": null, - "votes": 0, - "priority": "major", - "type": "issue", - "state": "open", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1" - }, - "comments": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue" - }, - "watch": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/watch" - }, - "attachments": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/attachments" - }, - "vote": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/vote" - } - }, - "kind": "bug", - "updated_on": "2015-06-21T14:56:49.739063+00:00", - "assignee": { - "username": "minicoders", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - } - }, - "display_name": "Frederic Guillot", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "type": "user" - }, - "title": "My new issue" - }, - "comment": { - "id": 19181022, - "created_on": "2015-06-21T14:56:49.749362+00:00", - "content": { - "markup": "markdown", - "raw": null, - "html": "" - }, - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments/19181022" - } - }, - "user": { - "username": "minicoders", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - } - }, - "display_name": "Frederic Guillot", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "type": "user" - }, - "updated_on": null - }, - "repository": { - "name": "test-webhook", - "owner": { - "username": "minicoders", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - } - }, - "display_name": "Frederic Guillot", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "type": "user" - }, - "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}", - "type": "repository", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook" - }, - "avatar": { - "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/" - } - }, - "full_name": "minicoders/test-webhook" - }, - "changes": { - "status": { - "new": "open", - "old": "closed" - } - }, - "actor": { - "username": "minicoders", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - } - }, - "display_name": "Frederic Guillot", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "type": "user" - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/bitbucket_issue_unassigned.json b/tests/units/fixtures/bitbucket_issue_unassigned.json deleted file mode 100644 index 3cbab2ea..00000000 --- a/tests/units/fixtures/bitbucket_issue_unassigned.json +++ /dev/null @@ -1,193 +0,0 @@ -{ - "comment": { - "updated_on": null, - "content": { - "html": "", - "markup": "markdown", - "raw": null - }, - "created_on": "2015-06-21T15:07:45.787623+00:00", - "user": { - "display_name": "Frederic Guillot", - "username": "minicoders", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - }, - "type": "user", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - }, - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments/19181143" - } - }, - "id": 19181143 - }, - "issue": { - "state": "open", - "content": { - "html": "<p><strong>test</strong></p>", - "markup": "markdown", - "raw": "**test**" - }, - "milestone": null, - "type": "issue", - "version": null, - "title": "My new issue", - "assignee": null, - "kind": "bug", - "component": null, - "priority": "major", - "reporter": { - "display_name": "Frederic Guillot", - "username": "minicoders", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - }, - "type": "user", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - }, - "created_on": "2015-06-21T02:17:40.990654+00:00", - "edited_on": null, - "updated_on": "2015-06-21T15:07:45.775705+00:00", - "id": 1, - "votes": 0, - "repository": { - "full_name": "minicoders/test-webhook", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook" - }, - "avatar": { - "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook" - } - }, - "type": "repository", - "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}", - "name": "test-webhook" - }, - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1" - }, - "watch": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/watch" - }, - "vote": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/vote" - }, - "comments": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/comments" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/issue/1/my-new-issue" - }, - "attachments": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/issues/1/attachments" - } - }, - "watches": 1 - }, - "actor": { - "display_name": "Frederic Guillot", - "username": "minicoders", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - }, - "type": "user", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - }, - "repository": { - "full_name": "minicoders/test-webhook", - "owner": { - "display_name": "Frederic Guillot", - "username": "minicoders", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - }, - "type": "user", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - }, - "type": "repository", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook" - }, - "avatar": { - "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook" - } - }, - "name": "test-webhook", - "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}" - }, - "changes": { - "responsible": { - "old": { - "is_system": false, - "username": "minicoders", - "name": "Frederic Guillot", - "billing_external_uuid": null, - "id": 1290132 - }, - "new": null - }, - "assignee": { - "old": { - "display_name": "Frederic Guillot", - "username": "minicoders", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - } - }, - "type": "user", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}" - }, - "new": null - } - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/bitbucket_push.json b/tests/units/fixtures/bitbucket_push.json deleted file mode 100644 index f480b074..00000000 --- a/tests/units/fixtures/bitbucket_push.json +++ /dev/null @@ -1,182 +0,0 @@ -{ - "push": { - "changes": [ - { - "forced": false, - "old": { - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/refs/branches/master" - }, - "commits": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commits/master" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/branch/master" - } - }, - "name": "master", - "target": { - "date": "2015-06-21T00:50:37+00:00", - "hash": "b6b46580eb9b20a06396f5f697ea1a55cf170e69", - "message": "test edited online with Bitbucket for task #5", - "type": "commit", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commit/b6b46580eb9b20a06396f5f697ea1a55cf170e69" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/commits/b6b46580eb9b20a06396f5f697ea1a55cf170e69" - } - }, - "parents": [ - { - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commit/7251db4b505cbfca3f845ebcff0ec0ddc4003ed8" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/commits/7251db4b505cbfca3f845ebcff0ec0ddc4003ed8" - } - }, - "type": "commit", - "hash": "7251db4b505cbfca3f845ebcff0ec0ddc4003ed8" - } - ], - "author": { - "raw": "Frederic Guillot <bob>", - "user": { - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - } - }, - "type": "user", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "username": "minicoders", - "display_name": "Frederic Guillot" - } - } - }, - "type": "branch" - }, - "created": false, - "links": { - "diff": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/diff/824059cce7667d3f8d8780cc707391be821e0ea6..b6b46580eb9b20a06396f5f697ea1a55cf170e69" - }, - "commits": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commits?include=824059cce7667d3f8d8780cc707391be821e0ea6exclude=b6b46580eb9b20a06396f5f697ea1a55cf170e69" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/branches/compare/824059cce7667d3f8d8780cc707391be821e0ea6..b6b46580eb9b20a06396f5f697ea1a55cf170e69" - } - }, - "new": { - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/refs/branches/master" - }, - "commits": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commits/master" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/branch/master" - } - }, - "name": "master", - "target": { - "date": "2015-06-21T03:15:08+00:00", - "hash": "824059cce7667d3f8d8780cc707391be821e0ea6", - "message": "Test another commit #2\n", - "type": "commit", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commit/824059cce7667d3f8d8780cc707391be821e0ea6" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/commits/824059cce7667d3f8d8780cc707391be821e0ea6" - } - }, - "parents": [ - { - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook/commit/24aa9d82bbb6f9a60f743fe538deb0a44622fc98" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook/commits/24aa9d82bbb6f9a60f743fe538deb0a44622fc98" - } - }, - "type": "commit", - "hash": "24aa9d82bbb6f9a60f743fe538deb0a44622fc98" - } - ], - "author": { - "raw": "Frederic Guillot <bob@localhost>" - } - }, - "type": "branch" - }, - "closed": false - } - ] - }, - "repository": { - "name": "test-webhook", - "owner": { - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - } - }, - "type": "user", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "username": "minicoders", - "display_name": "Frederic Guillot" - }, - "uuid": "{590fd9c4-0812-425e-8d72-ab08b4fd5735}", - "type": "repository", - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/repositories/minicoders/test-webhook" - }, - "html": { - "href": "https://bitbucket.org/minicoders/test-webhook" - }, - "avatar": { - "href": "https://bitbucket.org/minicoders/test-webhook/avatar/16/" - } - }, - "full_name": "minicoders/test-webhook" - }, - "actor": { - "links": { - "self": { - "href": "https://bitbucket.org/api/2.0/users/minicoders" - }, - "html": { - "href": "https://bitbucket.org/minicoders" - }, - "avatar": { - "href": "https://bitbucket.org/account/minicoders/avatar/32/" - } - }, - "type": "user", - "uuid": "{fc59b45a-f68b-4fc1-ad1f-a17d4f17cd2c}", - "username": "minicoders", - "display_name": "Frederic Guillot" - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/github_comment_created.json b/tests/units/fixtures/github_comment_created.json deleted file mode 100644 index bb601c7c..00000000 --- a/tests/units/fixtures/github_comment_created.json +++ /dev/null @@ -1,187 +0,0 @@ -{ - "action": "created", - "issue": { - "url": "https://api.github.com/repos/kanboardapp/webhook/issues/3", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/labels{/name}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/comments", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/events", - "html_url": "https://github.com/kanboardapp/webhook/issues/3", - "id": 89823399, - "number": 3, - "title": "test with ngrok", - "user": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - }, - "labels": [], - "state": "open", - "locked": false, - "assignee": null, - "milestone": null, - "comments": 1, - "created_at": "2015-06-20T21:58:20Z", - "updated_at": "2015-06-20T22:45:51Z", - "closed_at": null, - "body": "plop" - }, - "comment": { - "url": "https://api.github.com/repos/kanboardapp/webhook/issues/comments/113834672", - "html_url": "https://github.com/kanboardapp/webhook/issues/3#issuecomment-113834672", - "issue_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3", - "id": 113834672, - "user": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - }, - "created_at": "2015-06-20T22:45:51Z", - "updated_at": "2015-06-20T22:45:51Z", - "body": "test" - }, - "repository": { - "id": 25744941, - "name": "webhook", - "full_name": "kanboardapp/webhook", - "owner": { - "login": "kanboardapp", - "id": 8738076, - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/kanboardapp", - "html_url": "https://github.com/kanboardapp", - "followers_url": "https://api.github.com/users/kanboardapp/followers", - "following_url": "https://api.github.com/users/kanboardapp/following{/other_user}", - "gists_url": "https://api.github.com/users/kanboardapp/gists{/gist_id}", - "starred_url": "https://api.github.com/users/kanboardapp/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/kanboardapp/subscriptions", - "organizations_url": "https://api.github.com/users/kanboardapp/orgs", - "repos_url": "https://api.github.com/users/kanboardapp/repos", - "events_url": "https://api.github.com/users/kanboardapp/events{/privacy}", - "received_events_url": "https://api.github.com/users/kanboardapp/received_events", - "type": "Organization", - "site_admin": false - }, - "private": false, - "html_url": "https://github.com/kanboardapp/webhook", - "description": "", - "fork": false, - "url": "https://api.github.com/repos/kanboardapp/webhook", - "forks_url": "https://api.github.com/repos/kanboardapp/webhook/forks", - "keys_url": "https://api.github.com/repos/kanboardapp/webhook/keys{/key_id}", - "collaborators_url": "https://api.github.com/repos/kanboardapp/webhook/collaborators{/collaborator}", - "teams_url": "https://api.github.com/repos/kanboardapp/webhook/teams", - "hooks_url": "https://api.github.com/repos/kanboardapp/webhook/hooks", - "issue_events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/events{/number}", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/events", - "assignees_url": "https://api.github.com/repos/kanboardapp/webhook/assignees{/user}", - "branches_url": "https://api.github.com/repos/kanboardapp/webhook/branches{/branch}", - "tags_url": "https://api.github.com/repos/kanboardapp/webhook/tags", - "blobs_url": "https://api.github.com/repos/kanboardapp/webhook/git/blobs{/sha}", - "git_tags_url": "https://api.github.com/repos/kanboardapp/webhook/git/tags{/sha}", - "git_refs_url": "https://api.github.com/repos/kanboardapp/webhook/git/refs{/sha}", - "trees_url": "https://api.github.com/repos/kanboardapp/webhook/git/trees{/sha}", - "statuses_url": "https://api.github.com/repos/kanboardapp/webhook/statuses/{sha}", - "languages_url": "https://api.github.com/repos/kanboardapp/webhook/languages", - "stargazers_url": "https://api.github.com/repos/kanboardapp/webhook/stargazers", - "contributors_url": "https://api.github.com/repos/kanboardapp/webhook/contributors", - "subscribers_url": "https://api.github.com/repos/kanboardapp/webhook/subscribers", - "subscription_url": "https://api.github.com/repos/kanboardapp/webhook/subscription", - "commits_url": "https://api.github.com/repos/kanboardapp/webhook/commits{/sha}", - "git_commits_url": "https://api.github.com/repos/kanboardapp/webhook/git/commits{/sha}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/comments{/number}", - "issue_comment_url": "https://api.github.com/repos/kanboardapp/webhook/issues/comments{/number}", - "contents_url": "https://api.github.com/repos/kanboardapp/webhook/contents/{+path}", - "compare_url": "https://api.github.com/repos/kanboardapp/webhook/compare/{base}...{head}", - "merges_url": "https://api.github.com/repos/kanboardapp/webhook/merges", - "archive_url": "https://api.github.com/repos/kanboardapp/webhook/{archive_format}{/ref}", - "downloads_url": "https://api.github.com/repos/kanboardapp/webhook/downloads", - "issues_url": "https://api.github.com/repos/kanboardapp/webhook/issues{/number}", - "pulls_url": "https://api.github.com/repos/kanboardapp/webhook/pulls{/number}", - "milestones_url": "https://api.github.com/repos/kanboardapp/webhook/milestones{/number}", - "notifications_url": "https://api.github.com/repos/kanboardapp/webhook/notifications{?since,all,participating}", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/labels{/name}", - "releases_url": "https://api.github.com/repos/kanboardapp/webhook/releases{/id}", - "created_at": "2014-10-25T20:10:38Z", - "updated_at": "2014-10-25T20:10:38Z", - "pushed_at": "2014-10-25T22:02:01Z", - "git_url": "git://github.com/kanboardapp/webhook.git", - "ssh_url": "git@github.com:kanboardapp/webhook.git", - "clone_url": "https://github.com/kanboardapp/webhook.git", - "svn_url": "https://github.com/kanboardapp/webhook", - "homepage": null, - "size": 124, - "stargazers_count": 0, - "watchers_count": 0, - "language": null, - "has_issues": true, - "has_downloads": true, - "has_wiki": true, - "has_pages": false, - "forks_count": 0, - "mirror_url": null, - "open_issues_count": 3, - "forks": 0, - "open_issues": 3, - "watchers": 0, - "default_branch": "master" - }, - "organization": { - "login": "kanboardapp", - "id": 8738076, - "url": "https://api.github.com/orgs/kanboardapp", - "repos_url": "https://api.github.com/orgs/kanboardapp/repos", - "events_url": "https://api.github.com/orgs/kanboardapp/events", - "members_url": "https://api.github.com/orgs/kanboardapp/members{/member}", - "public_members_url": "https://api.github.com/orgs/kanboardapp/public_members{/member}", - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "description": null - }, - "sender": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/github_issue_assigned.json b/tests/units/fixtures/github_issue_assigned.json deleted file mode 100644 index 9125e976..00000000 --- a/tests/units/fixtures/github_issue_assigned.json +++ /dev/null @@ -1,196 +0,0 @@ -{ - "action": "assigned", - "issue": { - "url": "https://api.github.com/repos/kanboardapp/webhook/issues/3", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/labels{/name}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/comments", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/events", - "html_url": "https://github.com/kanboardapp/webhook/issues/3", - "id": 89823399, - "number": 3, - "title": "test with ngrok", - "user": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - }, - "labels": [], - "state": "open", - "locked": false, - "assignee": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - }, - "milestone": null, - "comments": 0, - "created_at": "2015-06-20T21:58:20Z", - "updated_at": "2015-06-20T22:12:15Z", - "closed_at": null, - "body": "plop" - }, - "assignee": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - }, - "repository": { - "id": 25744941, - "name": "webhook", - "full_name": "kanboardapp/webhook", - "owner": { - "login": "kanboardapp", - "id": 8738076, - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/kanboardapp", - "html_url": "https://github.com/kanboardapp", - "followers_url": "https://api.github.com/users/kanboardapp/followers", - "following_url": "https://api.github.com/users/kanboardapp/following{/other_user}", - "gists_url": "https://api.github.com/users/kanboardapp/gists{/gist_id}", - "starred_url": "https://api.github.com/users/kanboardapp/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/kanboardapp/subscriptions", - "organizations_url": "https://api.github.com/users/kanboardapp/orgs", - "repos_url": "https://api.github.com/users/kanboardapp/repos", - "events_url": "https://api.github.com/users/kanboardapp/events{/privacy}", - "received_events_url": "https://api.github.com/users/kanboardapp/received_events", - "type": "Organization", - "site_admin": false - }, - "private": false, - "html_url": "https://github.com/kanboardapp/webhook", - "description": "", - "fork": false, - "url": "https://api.github.com/repos/kanboardapp/webhook", - "forks_url": "https://api.github.com/repos/kanboardapp/webhook/forks", - "keys_url": "https://api.github.com/repos/kanboardapp/webhook/keys{/key_id}", - "collaborators_url": "https://api.github.com/repos/kanboardapp/webhook/collaborators{/collaborator}", - "teams_url": "https://api.github.com/repos/kanboardapp/webhook/teams", - "hooks_url": "https://api.github.com/repos/kanboardapp/webhook/hooks", - "issue_events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/events{/number}", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/events", - "assignees_url": "https://api.github.com/repos/kanboardapp/webhook/assignees{/user}", - "branches_url": "https://api.github.com/repos/kanboardapp/webhook/branches{/branch}", - "tags_url": "https://api.github.com/repos/kanboardapp/webhook/tags", - "blobs_url": "https://api.github.com/repos/kanboardapp/webhook/git/blobs{/sha}", - "git_tags_url": "https://api.github.com/repos/kanboardapp/webhook/git/tags{/sha}", - "git_refs_url": "https://api.github.com/repos/kanboardapp/webhook/git/refs{/sha}", - "trees_url": "https://api.github.com/repos/kanboardapp/webhook/git/trees{/sha}", - "statuses_url": "https://api.github.com/repos/kanboardapp/webhook/statuses/{sha}", - "languages_url": "https://api.github.com/repos/kanboardapp/webhook/languages", - "stargazers_url": "https://api.github.com/repos/kanboardapp/webhook/stargazers", - "contributors_url": "https://api.github.com/repos/kanboardapp/webhook/contributors", - "subscribers_url": "https://api.github.com/repos/kanboardapp/webhook/subscribers", - "subscription_url": "https://api.github.com/repos/kanboardapp/webhook/subscription", - "commits_url": "https://api.github.com/repos/kanboardapp/webhook/commits{/sha}", - "git_commits_url": "https://api.github.com/repos/kanboardapp/webhook/git/commits{/sha}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/comments{/number}", - "issue_comment_url": "https://api.github.com/repos/kanboardapp/webhook/issues/comments{/number}", - "contents_url": "https://api.github.com/repos/kanboardapp/webhook/contents/{+path}", - "compare_url": "https://api.github.com/repos/kanboardapp/webhook/compare/{base}...{head}", - "merges_url": "https://api.github.com/repos/kanboardapp/webhook/merges", - "archive_url": "https://api.github.com/repos/kanboardapp/webhook/{archive_format}{/ref}", - "downloads_url": "https://api.github.com/repos/kanboardapp/webhook/downloads", - "issues_url": "https://api.github.com/repos/kanboardapp/webhook/issues{/number}", - "pulls_url": "https://api.github.com/repos/kanboardapp/webhook/pulls{/number}", - "milestones_url": "https://api.github.com/repos/kanboardapp/webhook/milestones{/number}", - "notifications_url": "https://api.github.com/repos/kanboardapp/webhook/notifications{?since,all,participating}", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/labels{/name}", - "releases_url": "https://api.github.com/repos/kanboardapp/webhook/releases{/id}", - "created_at": "2014-10-25T20:10:38Z", - "updated_at": "2014-10-25T20:10:38Z", - "pushed_at": "2014-10-25T22:02:01Z", - "git_url": "git://github.com/kanboardapp/webhook.git", - "ssh_url": "git@github.com:kanboardapp/webhook.git", - "clone_url": "https://github.com/kanboardapp/webhook.git", - "svn_url": "https://github.com/kanboardapp/webhook", - "homepage": null, - "size": 124, - "stargazers_count": 0, - "watchers_count": 0, - "language": null, - "has_issues": true, - "has_downloads": true, - "has_wiki": true, - "has_pages": false, - "forks_count": 0, - "mirror_url": null, - "open_issues_count": 3, - "forks": 0, - "open_issues": 3, - "watchers": 0, - "default_branch": "master" - }, - "organization": { - "login": "kanboardapp", - "id": 8738076, - "url": "https://api.github.com/orgs/kanboardapp", - "repos_url": "https://api.github.com/orgs/kanboardapp/repos", - "events_url": "https://api.github.com/orgs/kanboardapp/events", - "members_url": "https://api.github.com/orgs/kanboardapp/members{/member}", - "public_members_url": "https://api.github.com/orgs/kanboardapp/public_members{/member}", - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "description": null - }, - "sender": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/github_issue_closed.json b/tests/units/fixtures/github_issue_closed.json deleted file mode 100644 index 5d2393eb..00000000 --- a/tests/units/fixtures/github_issue_closed.json +++ /dev/null @@ -1,159 +0,0 @@ -{ - "action": "closed", - "issue": { - "url": "https://api.github.com/repos/kanboardapp/webhook/issues/3", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/labels{/name}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/comments", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/events", - "html_url": "https://github.com/kanboardapp/webhook/issues/3", - "id": 89823399, - "number": 3, - "title": "test with ngrok", - "user": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - }, - "labels": [], - "state": "closed", - "locked": false, - "assignee": null, - "milestone": null, - "comments": 0, - "created_at": "2015-06-20T21:58:20Z", - "updated_at": "2015-06-20T22:28:32Z", - "closed_at": "2015-06-20T22:28:32Z", - "body": "plop" - }, - "repository": { - "id": 25744941, - "name": "webhook", - "full_name": "kanboardapp/webhook", - "owner": { - "login": "kanboardapp", - "id": 8738076, - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/kanboardapp", - "html_url": "https://github.com/kanboardapp", - "followers_url": "https://api.github.com/users/kanboardapp/followers", - "following_url": "https://api.github.com/users/kanboardapp/following{/other_user}", - "gists_url": "https://api.github.com/users/kanboardapp/gists{/gist_id}", - "starred_url": "https://api.github.com/users/kanboardapp/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/kanboardapp/subscriptions", - "organizations_url": "https://api.github.com/users/kanboardapp/orgs", - "repos_url": "https://api.github.com/users/kanboardapp/repos", - "events_url": "https://api.github.com/users/kanboardapp/events{/privacy}", - "received_events_url": "https://api.github.com/users/kanboardapp/received_events", - "type": "Organization", - "site_admin": false - }, - "private": false, - "html_url": "https://github.com/kanboardapp/webhook", - "description": "", - "fork": false, - "url": "https://api.github.com/repos/kanboardapp/webhook", - "forks_url": "https://api.github.com/repos/kanboardapp/webhook/forks", - "keys_url": "https://api.github.com/repos/kanboardapp/webhook/keys{/key_id}", - "collaborators_url": "https://api.github.com/repos/kanboardapp/webhook/collaborators{/collaborator}", - "teams_url": "https://api.github.com/repos/kanboardapp/webhook/teams", - "hooks_url": "https://api.github.com/repos/kanboardapp/webhook/hooks", - "issue_events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/events{/number}", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/events", - "assignees_url": "https://api.github.com/repos/kanboardapp/webhook/assignees{/user}", - "branches_url": "https://api.github.com/repos/kanboardapp/webhook/branches{/branch}", - "tags_url": "https://api.github.com/repos/kanboardapp/webhook/tags", - "blobs_url": "https://api.github.com/repos/kanboardapp/webhook/git/blobs{/sha}", - "git_tags_url": "https://api.github.com/repos/kanboardapp/webhook/git/tags{/sha}", - "git_refs_url": "https://api.github.com/repos/kanboardapp/webhook/git/refs{/sha}", - "trees_url": "https://api.github.com/repos/kanboardapp/webhook/git/trees{/sha}", - "statuses_url": "https://api.github.com/repos/kanboardapp/webhook/statuses/{sha}", - "languages_url": "https://api.github.com/repos/kanboardapp/webhook/languages", - "stargazers_url": "https://api.github.com/repos/kanboardapp/webhook/stargazers", - "contributors_url": "https://api.github.com/repos/kanboardapp/webhook/contributors", - "subscribers_url": "https://api.github.com/repos/kanboardapp/webhook/subscribers", - "subscription_url": "https://api.github.com/repos/kanboardapp/webhook/subscription", - "commits_url": "https://api.github.com/repos/kanboardapp/webhook/commits{/sha}", - "git_commits_url": "https://api.github.com/repos/kanboardapp/webhook/git/commits{/sha}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/comments{/number}", - "issue_comment_url": "https://api.github.com/repos/kanboardapp/webhook/issues/comments{/number}", - "contents_url": "https://api.github.com/repos/kanboardapp/webhook/contents/{+path}", - "compare_url": "https://api.github.com/repos/kanboardapp/webhook/compare/{base}...{head}", - "merges_url": "https://api.github.com/repos/kanboardapp/webhook/merges", - "archive_url": "https://api.github.com/repos/kanboardapp/webhook/{archive_format}{/ref}", - "downloads_url": "https://api.github.com/repos/kanboardapp/webhook/downloads", - "issues_url": "https://api.github.com/repos/kanboardapp/webhook/issues{/number}", - "pulls_url": "https://api.github.com/repos/kanboardapp/webhook/pulls{/number}", - "milestones_url": "https://api.github.com/repos/kanboardapp/webhook/milestones{/number}", - "notifications_url": "https://api.github.com/repos/kanboardapp/webhook/notifications{?since,all,participating}", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/labels{/name}", - "releases_url": "https://api.github.com/repos/kanboardapp/webhook/releases{/id}", - "created_at": "2014-10-25T20:10:38Z", - "updated_at": "2014-10-25T20:10:38Z", - "pushed_at": "2014-10-25T22:02:01Z", - "git_url": "git://github.com/kanboardapp/webhook.git", - "ssh_url": "git@github.com:kanboardapp/webhook.git", - "clone_url": "https://github.com/kanboardapp/webhook.git", - "svn_url": "https://github.com/kanboardapp/webhook", - "homepage": null, - "size": 124, - "stargazers_count": 0, - "watchers_count": 0, - "language": null, - "has_issues": true, - "has_downloads": true, - "has_wiki": true, - "has_pages": false, - "forks_count": 0, - "mirror_url": null, - "open_issues_count": 2, - "forks": 0, - "open_issues": 2, - "watchers": 0, - "default_branch": "master" - }, - "organization": { - "login": "kanboardapp", - "id": 8738076, - "url": "https://api.github.com/orgs/kanboardapp", - "repos_url": "https://api.github.com/orgs/kanboardapp/repos", - "events_url": "https://api.github.com/orgs/kanboardapp/events", - "members_url": "https://api.github.com/orgs/kanboardapp/members{/member}", - "public_members_url": "https://api.github.com/orgs/kanboardapp/public_members{/member}", - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "description": null - }, - "sender": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/github_issue_labeled.json b/tests/units/fixtures/github_issue_labeled.json deleted file mode 100644 index 4576b04f..00000000 --- a/tests/units/fixtures/github_issue_labeled.json +++ /dev/null @@ -1,170 +0,0 @@ -{ - "action": "labeled", - "issue": { - "url": "https://api.github.com/repos/kanboardapp/webhook/issues/3", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/labels{/name}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/comments", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/events", - "html_url": "https://github.com/kanboardapp/webhook/issues/3", - "id": 89823399, - "number": 3, - "title": "test with ngrok", - "user": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - }, - "labels": [ - { - "url": "https://api.github.com/repos/kanboardapp/webhook/labels/bug", - "name": "bug", - "color": "fc2929" - } - ], - "state": "open", - "locked": false, - "assignee": null, - "milestone": null, - "comments": 0, - "created_at": "2015-06-20T21:58:20Z", - "updated_at": "2015-06-20T22:37:49Z", - "closed_at": null, - "body": "plop" - }, - "label": { - "url": "https://api.github.com/repos/kanboardapp/webhook/labels/bug", - "name": "bug", - "color": "fc2929" - }, - "repository": { - "id": 25744941, - "name": "webhook", - "full_name": "kanboardapp/webhook", - "owner": { - "login": "kanboardapp", - "id": 8738076, - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/kanboardapp", - "html_url": "https://github.com/kanboardapp", - "followers_url": "https://api.github.com/users/kanboardapp/followers", - "following_url": "https://api.github.com/users/kanboardapp/following{/other_user}", - "gists_url": "https://api.github.com/users/kanboardapp/gists{/gist_id}", - "starred_url": "https://api.github.com/users/kanboardapp/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/kanboardapp/subscriptions", - "organizations_url": "https://api.github.com/users/kanboardapp/orgs", - "repos_url": "https://api.github.com/users/kanboardapp/repos", - "events_url": "https://api.github.com/users/kanboardapp/events{/privacy}", - "received_events_url": "https://api.github.com/users/kanboardapp/received_events", - "type": "Organization", - "site_admin": false - }, - "private": false, - "html_url": "https://github.com/kanboardapp/webhook", - "description": "", - "fork": false, - "url": "https://api.github.com/repos/kanboardapp/webhook", - "forks_url": "https://api.github.com/repos/kanboardapp/webhook/forks", - "keys_url": "https://api.github.com/repos/kanboardapp/webhook/keys{/key_id}", - "collaborators_url": "https://api.github.com/repos/kanboardapp/webhook/collaborators{/collaborator}", - "teams_url": "https://api.github.com/repos/kanboardapp/webhook/teams", - "hooks_url": "https://api.github.com/repos/kanboardapp/webhook/hooks", - "issue_events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/events{/number}", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/events", - "assignees_url": "https://api.github.com/repos/kanboardapp/webhook/assignees{/user}", - "branches_url": "https://api.github.com/repos/kanboardapp/webhook/branches{/branch}", - "tags_url": "https://api.github.com/repos/kanboardapp/webhook/tags", - "blobs_url": "https://api.github.com/repos/kanboardapp/webhook/git/blobs{/sha}", - "git_tags_url": "https://api.github.com/repos/kanboardapp/webhook/git/tags{/sha}", - "git_refs_url": "https://api.github.com/repos/kanboardapp/webhook/git/refs{/sha}", - "trees_url": "https://api.github.com/repos/kanboardapp/webhook/git/trees{/sha}", - "statuses_url": "https://api.github.com/repos/kanboardapp/webhook/statuses/{sha}", - "languages_url": "https://api.github.com/repos/kanboardapp/webhook/languages", - "stargazers_url": "https://api.github.com/repos/kanboardapp/webhook/stargazers", - "contributors_url": "https://api.github.com/repos/kanboardapp/webhook/contributors", - "subscribers_url": "https://api.github.com/repos/kanboardapp/webhook/subscribers", - "subscription_url": "https://api.github.com/repos/kanboardapp/webhook/subscription", - "commits_url": "https://api.github.com/repos/kanboardapp/webhook/commits{/sha}", - "git_commits_url": "https://api.github.com/repos/kanboardapp/webhook/git/commits{/sha}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/comments{/number}", - "issue_comment_url": "https://api.github.com/repos/kanboardapp/webhook/issues/comments{/number}", - "contents_url": "https://api.github.com/repos/kanboardapp/webhook/contents/{+path}", - "compare_url": "https://api.github.com/repos/kanboardapp/webhook/compare/{base}...{head}", - "merges_url": "https://api.github.com/repos/kanboardapp/webhook/merges", - "archive_url": "https://api.github.com/repos/kanboardapp/webhook/{archive_format}{/ref}", - "downloads_url": "https://api.github.com/repos/kanboardapp/webhook/downloads", - "issues_url": "https://api.github.com/repos/kanboardapp/webhook/issues{/number}", - "pulls_url": "https://api.github.com/repos/kanboardapp/webhook/pulls{/number}", - "milestones_url": "https://api.github.com/repos/kanboardapp/webhook/milestones{/number}", - "notifications_url": "https://api.github.com/repos/kanboardapp/webhook/notifications{?since,all,participating}", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/labels{/name}", - "releases_url": "https://api.github.com/repos/kanboardapp/webhook/releases{/id}", - "created_at": "2014-10-25T20:10:38Z", - "updated_at": "2014-10-25T20:10:38Z", - "pushed_at": "2014-10-25T22:02:01Z", - "git_url": "git://github.com/kanboardapp/webhook.git", - "ssh_url": "git@github.com:kanboardapp/webhook.git", - "clone_url": "https://github.com/kanboardapp/webhook.git", - "svn_url": "https://github.com/kanboardapp/webhook", - "homepage": null, - "size": 124, - "stargazers_count": 0, - "watchers_count": 0, - "language": null, - "has_issues": true, - "has_downloads": true, - "has_wiki": true, - "has_pages": false, - "forks_count": 0, - "mirror_url": null, - "open_issues_count": 3, - "forks": 0, - "open_issues": 3, - "watchers": 0, - "default_branch": "master" - }, - "organization": { - "login": "kanboardapp", - "id": 8738076, - "url": "https://api.github.com/orgs/kanboardapp", - "repos_url": "https://api.github.com/orgs/kanboardapp/repos", - "events_url": "https://api.github.com/orgs/kanboardapp/events", - "members_url": "https://api.github.com/orgs/kanboardapp/members{/member}", - "public_members_url": "https://api.github.com/orgs/kanboardapp/public_members{/member}", - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "description": null - }, - "sender": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/github_issue_opened.json b/tests/units/fixtures/github_issue_opened.json deleted file mode 100644 index 13f8d930..00000000 --- a/tests/units/fixtures/github_issue_opened.json +++ /dev/null @@ -1,159 +0,0 @@ -{ - "action": "opened", - "issue": { - "url": "https://api.github.com/repos/kanboardapp/webhook/issues/3", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/labels{/name}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/comments", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/events", - "html_url": "https://github.com/kanboardapp/webhook/issues/3", - "id": 89823399, - "number": 3, - "title": "Test Webhook", - "user": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - }, - "labels": [], - "state": "open", - "locked": false, - "assignee": null, - "milestone": null, - "comments": 0, - "created_at": "2015-06-20T21:58:20Z", - "updated_at": "2015-06-20T21:58:20Z", - "closed_at": null, - "body": "plop" - }, - "repository": { - "id": 25744941, - "name": "webhook", - "full_name": "kanboardapp/webhook", - "owner": { - "login": "kanboardapp", - "id": 8738076, - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/kanboardapp", - "html_url": "https://github.com/kanboardapp", - "followers_url": "https://api.github.com/users/kanboardapp/followers", - "following_url": "https://api.github.com/users/kanboardapp/following{/other_user}", - "gists_url": "https://api.github.com/users/kanboardapp/gists{/gist_id}", - "starred_url": "https://api.github.com/users/kanboardapp/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/kanboardapp/subscriptions", - "organizations_url": "https://api.github.com/users/kanboardapp/orgs", - "repos_url": "https://api.github.com/users/kanboardapp/repos", - "events_url": "https://api.github.com/users/kanboardapp/events{/privacy}", - "received_events_url": "https://api.github.com/users/kanboardapp/received_events", - "type": "Organization", - "site_admin": false - }, - "private": false, - "html_url": "https://github.com/kanboardapp/webhook", - "description": "", - "fork": false, - "url": "https://api.github.com/repos/kanboardapp/webhook", - "forks_url": "https://api.github.com/repos/kanboardapp/webhook/forks", - "keys_url": "https://api.github.com/repos/kanboardapp/webhook/keys{/key_id}", - "collaborators_url": "https://api.github.com/repos/kanboardapp/webhook/collaborators{/collaborator}", - "teams_url": "https://api.github.com/repos/kanboardapp/webhook/teams", - "hooks_url": "https://api.github.com/repos/kanboardapp/webhook/hooks", - "issue_events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/events{/number}", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/events", - "assignees_url": "https://api.github.com/repos/kanboardapp/webhook/assignees{/user}", - "branches_url": "https://api.github.com/repos/kanboardapp/webhook/branches{/branch}", - "tags_url": "https://api.github.com/repos/kanboardapp/webhook/tags", - "blobs_url": "https://api.github.com/repos/kanboardapp/webhook/git/blobs{/sha}", - "git_tags_url": "https://api.github.com/repos/kanboardapp/webhook/git/tags{/sha}", - "git_refs_url": "https://api.github.com/repos/kanboardapp/webhook/git/refs{/sha}", - "trees_url": "https://api.github.com/repos/kanboardapp/webhook/git/trees{/sha}", - "statuses_url": "https://api.github.com/repos/kanboardapp/webhook/statuses/{sha}", - "languages_url": "https://api.github.com/repos/kanboardapp/webhook/languages", - "stargazers_url": "https://api.github.com/repos/kanboardapp/webhook/stargazers", - "contributors_url": "https://api.github.com/repos/kanboardapp/webhook/contributors", - "subscribers_url": "https://api.github.com/repos/kanboardapp/webhook/subscribers", - "subscription_url": "https://api.github.com/repos/kanboardapp/webhook/subscription", - "commits_url": "https://api.github.com/repos/kanboardapp/webhook/commits{/sha}", - "git_commits_url": "https://api.github.com/repos/kanboardapp/webhook/git/commits{/sha}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/comments{/number}", - "issue_comment_url": "https://api.github.com/repos/kanboardapp/webhook/issues/comments{/number}", - "contents_url": "https://api.github.com/repos/kanboardapp/webhook/contents/{+path}", - "compare_url": "https://api.github.com/repos/kanboardapp/webhook/compare/{base}...{head}", - "merges_url": "https://api.github.com/repos/kanboardapp/webhook/merges", - "archive_url": "https://api.github.com/repos/kanboardapp/webhook/{archive_format}{/ref}", - "downloads_url": "https://api.github.com/repos/kanboardapp/webhook/downloads", - "issues_url": "https://api.github.com/repos/kanboardapp/webhook/issues{/number}", - "pulls_url": "https://api.github.com/repos/kanboardapp/webhook/pulls{/number}", - "milestones_url": "https://api.github.com/repos/kanboardapp/webhook/milestones{/number}", - "notifications_url": "https://api.github.com/repos/kanboardapp/webhook/notifications{?since,all,participating}", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/labels{/name}", - "releases_url": "https://api.github.com/repos/kanboardapp/webhook/releases{/id}", - "created_at": "2014-10-25T20:10:38Z", - "updated_at": "2014-10-25T20:10:38Z", - "pushed_at": "2014-10-25T22:02:01Z", - "git_url": "git://github.com/kanboardapp/webhook.git", - "ssh_url": "git@github.com:kanboardapp/webhook.git", - "clone_url": "https://github.com/kanboardapp/webhook.git", - "svn_url": "https://github.com/kanboardapp/webhook", - "homepage": null, - "size": 124, - "stargazers_count": 0, - "watchers_count": 0, - "language": null, - "has_issues": true, - "has_downloads": true, - "has_wiki": true, - "has_pages": false, - "forks_count": 0, - "mirror_url": null, - "open_issues_count": 3, - "forks": 0, - "open_issues": 3, - "watchers": 0, - "default_branch": "master" - }, - "organization": { - "login": "kanboardapp", - "id": 8738076, - "url": "https://api.github.com/orgs/kanboardapp", - "repos_url": "https://api.github.com/orgs/kanboardapp/repos", - "events_url": "https://api.github.com/orgs/kanboardapp/events", - "members_url": "https://api.github.com/orgs/kanboardapp/members{/member}", - "public_members_url": "https://api.github.com/orgs/kanboardapp/public_members{/member}", - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "description": null - }, - "sender": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/github_issue_reopened.json b/tests/units/fixtures/github_issue_reopened.json deleted file mode 100644 index 70f9e884..00000000 --- a/tests/units/fixtures/github_issue_reopened.json +++ /dev/null @@ -1,159 +0,0 @@ -{ - "action": "reopened", - "issue": { - "url": "https://api.github.com/repos/kanboardapp/webhook/issues/3", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/labels{/name}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/comments", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/events", - "html_url": "https://github.com/kanboardapp/webhook/issues/3", - "id": 89823399, - "number": 3, - "title": "test with ngrok", - "user": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - }, - "labels": [], - "state": "open", - "locked": false, - "assignee": null, - "milestone": null, - "comments": 0, - "created_at": "2015-06-20T21:58:20Z", - "updated_at": "2015-06-20T22:33:35Z", - "closed_at": null, - "body": "plop" - }, - "repository": { - "id": 25744941, - "name": "webhook", - "full_name": "kanboardapp/webhook", - "owner": { - "login": "kanboardapp", - "id": 8738076, - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/kanboardapp", - "html_url": "https://github.com/kanboardapp", - "followers_url": "https://api.github.com/users/kanboardapp/followers", - "following_url": "https://api.github.com/users/kanboardapp/following{/other_user}", - "gists_url": "https://api.github.com/users/kanboardapp/gists{/gist_id}", - "starred_url": "https://api.github.com/users/kanboardapp/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/kanboardapp/subscriptions", - "organizations_url": "https://api.github.com/users/kanboardapp/orgs", - "repos_url": "https://api.github.com/users/kanboardapp/repos", - "events_url": "https://api.github.com/users/kanboardapp/events{/privacy}", - "received_events_url": "https://api.github.com/users/kanboardapp/received_events", - "type": "Organization", - "site_admin": false - }, - "private": false, - "html_url": "https://github.com/kanboardapp/webhook", - "description": "", - "fork": false, - "url": "https://api.github.com/repos/kanboardapp/webhook", - "forks_url": "https://api.github.com/repos/kanboardapp/webhook/forks", - "keys_url": "https://api.github.com/repos/kanboardapp/webhook/keys{/key_id}", - "collaborators_url": "https://api.github.com/repos/kanboardapp/webhook/collaborators{/collaborator}", - "teams_url": "https://api.github.com/repos/kanboardapp/webhook/teams", - "hooks_url": "https://api.github.com/repos/kanboardapp/webhook/hooks", - "issue_events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/events{/number}", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/events", - "assignees_url": "https://api.github.com/repos/kanboardapp/webhook/assignees{/user}", - "branches_url": "https://api.github.com/repos/kanboardapp/webhook/branches{/branch}", - "tags_url": "https://api.github.com/repos/kanboardapp/webhook/tags", - "blobs_url": "https://api.github.com/repos/kanboardapp/webhook/git/blobs{/sha}", - "git_tags_url": "https://api.github.com/repos/kanboardapp/webhook/git/tags{/sha}", - "git_refs_url": "https://api.github.com/repos/kanboardapp/webhook/git/refs{/sha}", - "trees_url": "https://api.github.com/repos/kanboardapp/webhook/git/trees{/sha}", - "statuses_url": "https://api.github.com/repos/kanboardapp/webhook/statuses/{sha}", - "languages_url": "https://api.github.com/repos/kanboardapp/webhook/languages", - "stargazers_url": "https://api.github.com/repos/kanboardapp/webhook/stargazers", - "contributors_url": "https://api.github.com/repos/kanboardapp/webhook/contributors", - "subscribers_url": "https://api.github.com/repos/kanboardapp/webhook/subscribers", - "subscription_url": "https://api.github.com/repos/kanboardapp/webhook/subscription", - "commits_url": "https://api.github.com/repos/kanboardapp/webhook/commits{/sha}", - "git_commits_url": "https://api.github.com/repos/kanboardapp/webhook/git/commits{/sha}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/comments{/number}", - "issue_comment_url": "https://api.github.com/repos/kanboardapp/webhook/issues/comments{/number}", - "contents_url": "https://api.github.com/repos/kanboardapp/webhook/contents/{+path}", - "compare_url": "https://api.github.com/repos/kanboardapp/webhook/compare/{base}...{head}", - "merges_url": "https://api.github.com/repos/kanboardapp/webhook/merges", - "archive_url": "https://api.github.com/repos/kanboardapp/webhook/{archive_format}{/ref}", - "downloads_url": "https://api.github.com/repos/kanboardapp/webhook/downloads", - "issues_url": "https://api.github.com/repos/kanboardapp/webhook/issues{/number}", - "pulls_url": "https://api.github.com/repos/kanboardapp/webhook/pulls{/number}", - "milestones_url": "https://api.github.com/repos/kanboardapp/webhook/milestones{/number}", - "notifications_url": "https://api.github.com/repos/kanboardapp/webhook/notifications{?since,all,participating}", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/labels{/name}", - "releases_url": "https://api.github.com/repos/kanboardapp/webhook/releases{/id}", - "created_at": "2014-10-25T20:10:38Z", - "updated_at": "2014-10-25T20:10:38Z", - "pushed_at": "2014-10-25T22:02:01Z", - "git_url": "git://github.com/kanboardapp/webhook.git", - "ssh_url": "git@github.com:kanboardapp/webhook.git", - "clone_url": "https://github.com/kanboardapp/webhook.git", - "svn_url": "https://github.com/kanboardapp/webhook", - "homepage": null, - "size": 124, - "stargazers_count": 0, - "watchers_count": 0, - "language": null, - "has_issues": true, - "has_downloads": true, - "has_wiki": true, - "has_pages": false, - "forks_count": 0, - "mirror_url": null, - "open_issues_count": 3, - "forks": 0, - "open_issues": 3, - "watchers": 0, - "default_branch": "master" - }, - "organization": { - "login": "kanboardapp", - "id": 8738076, - "url": "https://api.github.com/orgs/kanboardapp", - "repos_url": "https://api.github.com/orgs/kanboardapp/repos", - "events_url": "https://api.github.com/orgs/kanboardapp/events", - "members_url": "https://api.github.com/orgs/kanboardapp/members{/member}", - "public_members_url": "https://api.github.com/orgs/kanboardapp/public_members{/member}", - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "description": null - }, - "sender": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/github_issue_unassigned.json b/tests/units/fixtures/github_issue_unassigned.json deleted file mode 100644 index 0a578bab..00000000 --- a/tests/units/fixtures/github_issue_unassigned.json +++ /dev/null @@ -1,178 +0,0 @@ -{ - "action": "unassigned", - "issue": { - "url": "https://api.github.com/repos/kanboardapp/webhook/issues/3", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/labels{/name}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/comments", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/events", - "html_url": "https://github.com/kanboardapp/webhook/issues/3", - "id": 89823399, - "number": 3, - "title": "test with ngrok", - "user": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - }, - "labels": [], - "state": "open", - "locked": false, - "assignee": null, - "milestone": null, - "comments": 0, - "created_at": "2015-06-20T21:58:20Z", - "updated_at": "2015-06-20T22:26:05Z", - "closed_at": null, - "body": "plop" - }, - "assignee": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - }, - "repository": { - "id": 25744941, - "name": "webhook", - "full_name": "kanboardapp/webhook", - "owner": { - "login": "kanboardapp", - "id": 8738076, - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/kanboardapp", - "html_url": "https://github.com/kanboardapp", - "followers_url": "https://api.github.com/users/kanboardapp/followers", - "following_url": "https://api.github.com/users/kanboardapp/following{/other_user}", - "gists_url": "https://api.github.com/users/kanboardapp/gists{/gist_id}", - "starred_url": "https://api.github.com/users/kanboardapp/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/kanboardapp/subscriptions", - "organizations_url": "https://api.github.com/users/kanboardapp/orgs", - "repos_url": "https://api.github.com/users/kanboardapp/repos", - "events_url": "https://api.github.com/users/kanboardapp/events{/privacy}", - "received_events_url": "https://api.github.com/users/kanboardapp/received_events", - "type": "Organization", - "site_admin": false - }, - "private": false, - "html_url": "https://github.com/kanboardapp/webhook", - "description": "", - "fork": false, - "url": "https://api.github.com/repos/kanboardapp/webhook", - "forks_url": "https://api.github.com/repos/kanboardapp/webhook/forks", - "keys_url": "https://api.github.com/repos/kanboardapp/webhook/keys{/key_id}", - "collaborators_url": "https://api.github.com/repos/kanboardapp/webhook/collaborators{/collaborator}", - "teams_url": "https://api.github.com/repos/kanboardapp/webhook/teams", - "hooks_url": "https://api.github.com/repos/kanboardapp/webhook/hooks", - "issue_events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/events{/number}", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/events", - "assignees_url": "https://api.github.com/repos/kanboardapp/webhook/assignees{/user}", - "branches_url": "https://api.github.com/repos/kanboardapp/webhook/branches{/branch}", - "tags_url": "https://api.github.com/repos/kanboardapp/webhook/tags", - "blobs_url": "https://api.github.com/repos/kanboardapp/webhook/git/blobs{/sha}", - "git_tags_url": "https://api.github.com/repos/kanboardapp/webhook/git/tags{/sha}", - "git_refs_url": "https://api.github.com/repos/kanboardapp/webhook/git/refs{/sha}", - "trees_url": "https://api.github.com/repos/kanboardapp/webhook/git/trees{/sha}", - "statuses_url": "https://api.github.com/repos/kanboardapp/webhook/statuses/{sha}", - "languages_url": "https://api.github.com/repos/kanboardapp/webhook/languages", - "stargazers_url": "https://api.github.com/repos/kanboardapp/webhook/stargazers", - "contributors_url": "https://api.github.com/repos/kanboardapp/webhook/contributors", - "subscribers_url": "https://api.github.com/repos/kanboardapp/webhook/subscribers", - "subscription_url": "https://api.github.com/repos/kanboardapp/webhook/subscription", - "commits_url": "https://api.github.com/repos/kanboardapp/webhook/commits{/sha}", - "git_commits_url": "https://api.github.com/repos/kanboardapp/webhook/git/commits{/sha}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/comments{/number}", - "issue_comment_url": "https://api.github.com/repos/kanboardapp/webhook/issues/comments{/number}", - "contents_url": "https://api.github.com/repos/kanboardapp/webhook/contents/{+path}", - "compare_url": "https://api.github.com/repos/kanboardapp/webhook/compare/{base}...{head}", - "merges_url": "https://api.github.com/repos/kanboardapp/webhook/merges", - "archive_url": "https://api.github.com/repos/kanboardapp/webhook/{archive_format}{/ref}", - "downloads_url": "https://api.github.com/repos/kanboardapp/webhook/downloads", - "issues_url": "https://api.github.com/repos/kanboardapp/webhook/issues{/number}", - "pulls_url": "https://api.github.com/repos/kanboardapp/webhook/pulls{/number}", - "milestones_url": "https://api.github.com/repos/kanboardapp/webhook/milestones{/number}", - "notifications_url": "https://api.github.com/repos/kanboardapp/webhook/notifications{?since,all,participating}", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/labels{/name}", - "releases_url": "https://api.github.com/repos/kanboardapp/webhook/releases{/id}", - "created_at": "2014-10-25T20:10:38Z", - "updated_at": "2014-10-25T20:10:38Z", - "pushed_at": "2014-10-25T22:02:01Z", - "git_url": "git://github.com/kanboardapp/webhook.git", - "ssh_url": "git@github.com:kanboardapp/webhook.git", - "clone_url": "https://github.com/kanboardapp/webhook.git", - "svn_url": "https://github.com/kanboardapp/webhook", - "homepage": null, - "size": 124, - "stargazers_count": 0, - "watchers_count": 0, - "language": null, - "has_issues": true, - "has_downloads": true, - "has_wiki": true, - "has_pages": false, - "forks_count": 0, - "mirror_url": null, - "open_issues_count": 3, - "forks": 0, - "open_issues": 3, - "watchers": 0, - "default_branch": "master" - }, - "organization": { - "login": "kanboardapp", - "id": 8738076, - "url": "https://api.github.com/orgs/kanboardapp", - "repos_url": "https://api.github.com/orgs/kanboardapp/repos", - "events_url": "https://api.github.com/orgs/kanboardapp/events", - "members_url": "https://api.github.com/orgs/kanboardapp/members{/member}", - "public_members_url": "https://api.github.com/orgs/kanboardapp/public_members{/member}", - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "description": null - }, - "sender": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/github_issue_unlabeled.json b/tests/units/fixtures/github_issue_unlabeled.json deleted file mode 100644 index 47070a91..00000000 --- a/tests/units/fixtures/github_issue_unlabeled.json +++ /dev/null @@ -1,164 +0,0 @@ -{ - "action": "unlabeled", - "issue": { - "url": "https://api.github.com/repos/kanboardapp/webhook/issues/3", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/labels{/name}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/comments", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/3/events", - "html_url": "https://github.com/kanboardapp/webhook/issues/3", - "id": 89823399, - "number": 3, - "title": "test with ngrok", - "user": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - }, - "labels": [], - "state": "open", - "locked": false, - "assignee": null, - "milestone": null, - "comments": 0, - "created_at": "2015-06-20T21:58:20Z", - "updated_at": "2015-06-20T22:43:48Z", - "closed_at": null, - "body": "plop" - }, - "label": { - "url": "https://api.github.com/repos/kanboardapp/webhook/labels/bug", - "name": "bug", - "color": "fc2929" - }, - "repository": { - "id": 25744941, - "name": "webhook", - "full_name": "kanboardapp/webhook", - "owner": { - "login": "kanboardapp", - "id": 8738076, - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/kanboardapp", - "html_url": "https://github.com/kanboardapp", - "followers_url": "https://api.github.com/users/kanboardapp/followers", - "following_url": "https://api.github.com/users/kanboardapp/following{/other_user}", - "gists_url": "https://api.github.com/users/kanboardapp/gists{/gist_id}", - "starred_url": "https://api.github.com/users/kanboardapp/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/kanboardapp/subscriptions", - "organizations_url": "https://api.github.com/users/kanboardapp/orgs", - "repos_url": "https://api.github.com/users/kanboardapp/repos", - "events_url": "https://api.github.com/users/kanboardapp/events{/privacy}", - "received_events_url": "https://api.github.com/users/kanboardapp/received_events", - "type": "Organization", - "site_admin": false - }, - "private": false, - "html_url": "https://github.com/kanboardapp/webhook", - "description": "", - "fork": false, - "url": "https://api.github.com/repos/kanboardapp/webhook", - "forks_url": "https://api.github.com/repos/kanboardapp/webhook/forks", - "keys_url": "https://api.github.com/repos/kanboardapp/webhook/keys{/key_id}", - "collaborators_url": "https://api.github.com/repos/kanboardapp/webhook/collaborators{/collaborator}", - "teams_url": "https://api.github.com/repos/kanboardapp/webhook/teams", - "hooks_url": "https://api.github.com/repos/kanboardapp/webhook/hooks", - "issue_events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/events{/number}", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/events", - "assignees_url": "https://api.github.com/repos/kanboardapp/webhook/assignees{/user}", - "branches_url": "https://api.github.com/repos/kanboardapp/webhook/branches{/branch}", - "tags_url": "https://api.github.com/repos/kanboardapp/webhook/tags", - "blobs_url": "https://api.github.com/repos/kanboardapp/webhook/git/blobs{/sha}", - "git_tags_url": "https://api.github.com/repos/kanboardapp/webhook/git/tags{/sha}", - "git_refs_url": "https://api.github.com/repos/kanboardapp/webhook/git/refs{/sha}", - "trees_url": "https://api.github.com/repos/kanboardapp/webhook/git/trees{/sha}", - "statuses_url": "https://api.github.com/repos/kanboardapp/webhook/statuses/{sha}", - "languages_url": "https://api.github.com/repos/kanboardapp/webhook/languages", - "stargazers_url": "https://api.github.com/repos/kanboardapp/webhook/stargazers", - "contributors_url": "https://api.github.com/repos/kanboardapp/webhook/contributors", - "subscribers_url": "https://api.github.com/repos/kanboardapp/webhook/subscribers", - "subscription_url": "https://api.github.com/repos/kanboardapp/webhook/subscription", - "commits_url": "https://api.github.com/repos/kanboardapp/webhook/commits{/sha}", - "git_commits_url": "https://api.github.com/repos/kanboardapp/webhook/git/commits{/sha}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/comments{/number}", - "issue_comment_url": "https://api.github.com/repos/kanboardapp/webhook/issues/comments{/number}", - "contents_url": "https://api.github.com/repos/kanboardapp/webhook/contents/{+path}", - "compare_url": "https://api.github.com/repos/kanboardapp/webhook/compare/{base}...{head}", - "merges_url": "https://api.github.com/repos/kanboardapp/webhook/merges", - "archive_url": "https://api.github.com/repos/kanboardapp/webhook/{archive_format}{/ref}", - "downloads_url": "https://api.github.com/repos/kanboardapp/webhook/downloads", - "issues_url": "https://api.github.com/repos/kanboardapp/webhook/issues{/number}", - "pulls_url": "https://api.github.com/repos/kanboardapp/webhook/pulls{/number}", - "milestones_url": "https://api.github.com/repos/kanboardapp/webhook/milestones{/number}", - "notifications_url": "https://api.github.com/repos/kanboardapp/webhook/notifications{?since,all,participating}", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/labels{/name}", - "releases_url": "https://api.github.com/repos/kanboardapp/webhook/releases{/id}", - "created_at": "2014-10-25T20:10:38Z", - "updated_at": "2014-10-25T20:10:38Z", - "pushed_at": "2014-10-25T22:02:01Z", - "git_url": "git://github.com/kanboardapp/webhook.git", - "ssh_url": "git@github.com:kanboardapp/webhook.git", - "clone_url": "https://github.com/kanboardapp/webhook.git", - "svn_url": "https://github.com/kanboardapp/webhook", - "homepage": null, - "size": 124, - "stargazers_count": 0, - "watchers_count": 0, - "language": null, - "has_issues": true, - "has_downloads": true, - "has_wiki": true, - "has_pages": false, - "forks_count": 0, - "mirror_url": null, - "open_issues_count": 3, - "forks": 0, - "open_issues": 3, - "watchers": 0, - "default_branch": "master" - }, - "organization": { - "login": "kanboardapp", - "id": 8738076, - "url": "https://api.github.com/orgs/kanboardapp", - "repos_url": "https://api.github.com/orgs/kanboardapp/repos", - "events_url": "https://api.github.com/orgs/kanboardapp/events", - "members_url": "https://api.github.com/orgs/kanboardapp/members{/member}", - "public_members_url": "https://api.github.com/orgs/kanboardapp/public_members{/member}", - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "description": null - }, - "sender": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/github_push.json b/tests/units/fixtures/github_push.json deleted file mode 100644 index 5ae9b766..00000000 --- a/tests/units/fixtures/github_push.json +++ /dev/null @@ -1,165 +0,0 @@ -{ - "ref": "refs/heads/master", - "before": "895598f1baf1ee5fb3f43ebc509aa86e263bde4b", - "after": "98dee3e49ee7aa66ffec1f761af93da5ffd711f6", - "created": false, - "deleted": false, - "forced": false, - "base_ref": null, - "compare": "https://github.com/kanboardapp/webhook/compare/895598f1baf1...98dee3e49ee7", - "commits": [ - { - "id": "98dee3e49ee7aa66ffec1f761af93da5ffd711f6", - "distinct": true, - "message": "Update README to fix #1", - "timestamp": "2015-06-20T18:54:52-04:00", - "url": "https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6", - "author": { - "name": "Frédéric Guillot", - "email": "fred@kanboard.net", - "username": "fguillot" - }, - "committer": { - "name": "Frédéric Guillot", - "email": "fred@kanboard.net", - "username": "fguillot" - }, - "added": [], - "removed": [], - "modified": [ - "README.md" - ] - } - ], - "head_commit": { - "id": "98dee3e49ee7aa66ffec1f761af93da5ffd711f6", - "distinct": true, - "message": "Update README", - "timestamp": "2015-06-20T18:54:52-04:00", - "url": "https://github.com/kanboardapp/webhook/commit/98dee3e49ee7aa66ffec1f761af93da5ffd711f6", - "author": { - "name": "Frédéric Guillot", - "email": "fred@kanboard.net", - "username": "fguillot" - }, - "committer": { - "name": "Frédéric Guillot", - "email": "fred@kanboard.net", - "username": "fguillot" - }, - "added": [], - "removed": [], - "modified": [ - "README.md" - ] - }, - "repository": { - "id": 25744941, - "name": "webhook", - "full_name": "kanboardapp/webhook", - "owner": { - "name": "kanboardapp", - "email": null - }, - "private": false, - "html_url": "https://github.com/kanboardapp/webhook", - "description": "", - "fork": false, - "url": "https://github.com/kanboardapp/webhook", - "forks_url": "https://api.github.com/repos/kanboardapp/webhook/forks", - "keys_url": "https://api.github.com/repos/kanboardapp/webhook/keys{/key_id}", - "collaborators_url": "https://api.github.com/repos/kanboardapp/webhook/collaborators{/collaborator}", - "teams_url": "https://api.github.com/repos/kanboardapp/webhook/teams", - "hooks_url": "https://api.github.com/repos/kanboardapp/webhook/hooks", - "issue_events_url": "https://api.github.com/repos/kanboardapp/webhook/issues/events{/number}", - "events_url": "https://api.github.com/repos/kanboardapp/webhook/events", - "assignees_url": "https://api.github.com/repos/kanboardapp/webhook/assignees{/user}", - "branches_url": "https://api.github.com/repos/kanboardapp/webhook/branches{/branch}", - "tags_url": "https://api.github.com/repos/kanboardapp/webhook/tags", - "blobs_url": "https://api.github.com/repos/kanboardapp/webhook/git/blobs{/sha}", - "git_tags_url": "https://api.github.com/repos/kanboardapp/webhook/git/tags{/sha}", - "git_refs_url": "https://api.github.com/repos/kanboardapp/webhook/git/refs{/sha}", - "trees_url": "https://api.github.com/repos/kanboardapp/webhook/git/trees{/sha}", - "statuses_url": "https://api.github.com/repos/kanboardapp/webhook/statuses/{sha}", - "languages_url": "https://api.github.com/repos/kanboardapp/webhook/languages", - "stargazers_url": "https://api.github.com/repos/kanboardapp/webhook/stargazers", - "contributors_url": "https://api.github.com/repos/kanboardapp/webhook/contributors", - "subscribers_url": "https://api.github.com/repos/kanboardapp/webhook/subscribers", - "subscription_url": "https://api.github.com/repos/kanboardapp/webhook/subscription", - "commits_url": "https://api.github.com/repos/kanboardapp/webhook/commits{/sha}", - "git_commits_url": "https://api.github.com/repos/kanboardapp/webhook/git/commits{/sha}", - "comments_url": "https://api.github.com/repos/kanboardapp/webhook/comments{/number}", - "issue_comment_url": "https://api.github.com/repos/kanboardapp/webhook/issues/comments{/number}", - "contents_url": "https://api.github.com/repos/kanboardapp/webhook/contents/{+path}", - "compare_url": "https://api.github.com/repos/kanboardapp/webhook/compare/{base}...{head}", - "merges_url": "https://api.github.com/repos/kanboardapp/webhook/merges", - "archive_url": "https://api.github.com/repos/kanboardapp/webhook/{archive_format}{/ref}", - "downloads_url": "https://api.github.com/repos/kanboardapp/webhook/downloads", - "issues_url": "https://api.github.com/repos/kanboardapp/webhook/issues{/number}", - "pulls_url": "https://api.github.com/repos/kanboardapp/webhook/pulls{/number}", - "milestones_url": "https://api.github.com/repos/kanboardapp/webhook/milestones{/number}", - "notifications_url": "https://api.github.com/repos/kanboardapp/webhook/notifications{?since,all,participating}", - "labels_url": "https://api.github.com/repos/kanboardapp/webhook/labels{/name}", - "releases_url": "https://api.github.com/repos/kanboardapp/webhook/releases{/id}", - "created_at": 1414267838, - "updated_at": "2014-10-25T20:10:38Z", - "pushed_at": 1434840893, - "git_url": "git://github.com/kanboardapp/webhook.git", - "ssh_url": "git@github.com:kanboardapp/webhook.git", - "clone_url": "https://github.com/kanboardapp/webhook.git", - "svn_url": "https://github.com/kanboardapp/webhook", - "homepage": null, - "size": 124, - "stargazers_count": 0, - "watchers_count": 0, - "language": null, - "has_issues": true, - "has_downloads": true, - "has_wiki": true, - "has_pages": false, - "forks_count": 0, - "mirror_url": null, - "open_issues_count": 3, - "forks": 0, - "open_issues": 3, - "watchers": 0, - "default_branch": "master", - "stargazers": 0, - "master_branch": "master", - "organization": "kanboardapp" - }, - "pusher": { - "name": "fguillot", - "email": "fred@kanboard.net" - }, - "organization": { - "login": "kanboardapp", - "id": 8738076, - "url": "https://api.github.com/orgs/kanboardapp", - "repos_url": "https://api.github.com/orgs/kanboardapp/repos", - "events_url": "https://api.github.com/orgs/kanboardapp/events", - "members_url": "https://api.github.com/orgs/kanboardapp/members{/member}", - "public_members_url": "https://api.github.com/orgs/kanboardapp/public_members{/member}", - "avatar_url": "https://avatars.githubusercontent.com/u/8738076?v=3", - "description": null - }, - "sender": { - "login": "fguillot", - "id": 323546, - "avatar_url": "https://avatars.githubusercontent.com/u/323546?v=3", - "gravatar_id": "", - "url": "https://api.github.com/users/fguillot", - "html_url": "https://github.com/fguillot", - "followers_url": "https://api.github.com/users/fguillot/followers", - "following_url": "https://api.github.com/users/fguillot/following{/other_user}", - "gists_url": "https://api.github.com/users/fguillot/gists{/gist_id}", - "starred_url": "https://api.github.com/users/fguillot/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/fguillot/subscriptions", - "organizations_url": "https://api.github.com/users/fguillot/orgs", - "repos_url": "https://api.github.com/users/fguillot/repos", - "events_url": "https://api.github.com/users/fguillot/events{/privacy}", - "received_events_url": "https://api.github.com/users/fguillot/received_events", - "type": "User", - "site_admin": false - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/gitlab_comment_created.json b/tests/units/fixtures/gitlab_comment_created.json deleted file mode 100644 index b6599419..00000000 --- a/tests/units/fixtures/gitlab_comment_created.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "object_kind": "note", - "user": { - "name": "Fred", - "username": "minicoders", - "avatar_url": "https://secure.gravatar.com/avatar/3c44936e5a56f80711bff14987d2733f?s=40&d=identicon" - }, - "project_id": 320820, - "repository": { - "name": "test-webhook", - "url": "git@gitlab.com:minicoders/test-webhook.git", - "description": "", - "homepage": "https://gitlab.com/minicoders/test-webhook" - }, - "object_attributes": { - "id": 1642761, - "note": "Super comment!", - "noteable_type": "Issue", - "author_id": 74067, - "created_at": "2015-07-17 21:37:48 UTC", - "updated_at": "2015-07-17 21:37:48 UTC", - "project_id": 320820, - "attachment": null, - "line_code": null, - "commit_id": "", - "noteable_id": 355691, - "st_diff": null, - "system": false, - "url": "https://gitlab.com/minicoders/test-webhook/issues/1#note_1642761" - }, - "issue": { - "id": 355691, - "title": "Bug", - "assignee_id": null, - "author_id": 74067, - "project_id": 320820, - "created_at": "2015-07-17 21:31:47 UTC", - "updated_at": "2015-07-17 21:37:48 UTC", - "position": 0, - "branch_name": null, - "description": "There is a bug somewhere.\r\n\r\nBye", - "milestone_id": null, - "state": "opened", - "iid": 1 - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/gitlab_issue_closed.json b/tests/units/fixtures/gitlab_issue_closed.json deleted file mode 100644 index 82500b3c..00000000 --- a/tests/units/fixtures/gitlab_issue_closed.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "object_kind": "issue", - "user": { - "name": "Fred", - "username": "minicoders", - "avatar_url": "https://secure.gravatar.com/avatar/3c44936e5a56f80711bff14987d2733f?s=40&d=identicon" - }, - "object_attributes": { - "id": 355691, - "title": "Bug", - "assignee_id": null, - "author_id": 74067, - "project_id": 320820, - "created_at": "2015-07-17 21:31:47 UTC", - "updated_at": "2015-07-17 22:10:17 UTC", - "position": 0, - "branch_name": null, - "description": "There is a bug somewhere.\r\n\r\nBye", - "milestone_id": null, - "state": "closed", - "iid": 1, - "url": "https://gitlab.com/minicoders/test-webhook/issues/1", - "action": "close" - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/gitlab_issue_opened.json b/tests/units/fixtures/gitlab_issue_opened.json deleted file mode 100644 index 3e75c138..00000000 --- a/tests/units/fixtures/gitlab_issue_opened.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "object_kind": "issue", - "user": { - "name": "Fred", - "username": "minicoders", - "avatar_url": "https://secure.gravatar.com/avatar/3c44936e5a56f80711bff14987d2733f?s=40&d=identicon" - }, - "object_attributes": { - "id": 355691, - "title": "Bug", - "assignee_id": null, - "author_id": 74067, - "project_id": 320820, - "created_at": "2015-07-17 21:31:47 UTC", - "updated_at": "2015-07-17 21:31:47 UTC", - "position": 0, - "branch_name": null, - "description": "There is a bug somewhere.\r\n\r\nBye", - "milestone_id": null, - "state": "opened", - "iid": 1, - "url": "https://gitlab.com/minicoders/test-webhook/issues/1", - "action": "open" - } -}
\ No newline at end of file diff --git a/tests/units/fixtures/gitlab_push.json b/tests/units/fixtures/gitlab_push.json deleted file mode 100644 index ed77f041..00000000 --- a/tests/units/fixtures/gitlab_push.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "object_kind": "push", - "before": "e4ec6156d208a45fc546fae73c28300b5af1692a", - "after": "48aafa75eef9ad253aa254b0c82c987a52ebea78", - "ref": "refs/heads/master", - "checkout_sha": "48aafa75eef9ad253aa254b0c82c987a52ebea78", - "message": null, - "user_id": 74067, - "user_name": "Fred", - "user_email": "f+gitlab@minicoders.com", - "project_id": 320820, - "repository": { - "name": "test-webhook", - "url": "git@gitlab.com:minicoders/test-webhook.git", - "description": "", - "homepage": "https://gitlab.com/minicoders/test-webhook", - "git_http_url": "https://gitlab.com/minicoders/test-webhook.git", - "git_ssh_url": "git@gitlab.com:minicoders/test-webhook.git", - "visibility_level": 0 - }, - "commits": [ - { - "id": "48aafa75eef9ad253aa254b0c82c987a52ebea78", - "message": "Fix bug #2", - "timestamp": "2015-06-21T00:41:41+00:00", - "url": "https://gitlab.com/minicoders/test-webhook/commit/48aafa75eef9ad253aa254b0c82c987a52ebea78", - "author": { - "name": "Fred", - "email": "me@localhost" - } - }, - { - "id": "e4ec6156d208a45fc546fae73c28300b5af1692a", - "message": "test", - "timestamp": "2015-06-21T00:35:55+00:00", - "url": "https://gitlab.com/localhost/test-webhook/commit/e4ec6156d208a45fc546fae73c28300b5af1692a", - "author": { - "name": "Fred", - "email": "me@localhost" - } - } - ], - "total_commits_count": 2 -}
\ No newline at end of file |