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)); }
public function testHandlePayload() { $w = new EmailHandler($this->container); $p = new Project($this->container); $pp = new ProjectUserRole($this->container); $u = new User($this->container); $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $this->assertEquals(2, $u->create(array('username' => 'me', 'email' => 'me@localhost'))); $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(2, $p->create(array('name' => 'test2', 'identifier' => 'TEST1'))); // Empty payload $this->assertFalse($w->receiveEmail(array())); // Unknown user $this->assertFalse($w->receiveEmail(array('sender' => 'a@b.c', 'subject' => 'Email task', 'recipient' => 'foobar', 'stripped-text' => 'boo'))); // Project not found $this->assertFalse($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test@localhost', 'stripped-text' => 'boo'))); // User is not member $this->assertFalse($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); $this->assertTrue($pp->addUser(2, 2, Role::PROJECT_MEMBER)); // The task must be created $this->assertTrue($w->receiveEmail(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-html' => '<strong>boo</strong>'))); $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(2, $task['project_id']); $this->assertEquals('Email task', $task['title']); $this->assertEquals('**boo**', $task['description']); $this->assertEquals(2, $task['creator_id']); }
public function testGetAll() { $u = new User($this->container); $p = new Project($this->container); $cf = new CustomFilter($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest 1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest 2'))); $this->assertEquals(2, $u->create(array('username' => 'user 2'))); $this->assertEquals(1, $cf->create(array('name' => 'My filter 1', 'filter' => 'color:blue', 'project_id' => 1, 'user_id' => 1))); $this->assertEquals(2, $cf->create(array('name' => 'My filter 2', 'filter' => 'color:red', 'project_id' => 1, 'user_id' => 1, 'is_shared' => 1))); $this->assertEquals(3, $cf->create(array('name' => 'My filter 3', 'filter' => 'color:green', 'project_id' => 1, 'user_id' => 2, 'is_shared' => 1))); $this->assertEquals(4, $cf->create(array('name' => 'My filter 4', 'filter' => 'color:brown', 'project_id' => 1, 'user_id' => 2, 'is_shared' => 0))); $this->assertEquals(5, $cf->create(array('name' => 'My filter 5', 'filter' => 'color:grey', 'project_id' => 2, 'user_id' => 2))); // Get filters for the project 1 and user 1 $filters = $cf->getAll(1, 1); $this->assertCount(3, $filters); $this->assertEquals(1, $filters[0]['id']); $this->assertEquals('My filter 1', $filters[0]['name']); $this->assertEquals('color:blue', $filters[0]['filter']); $this->assertEquals(1, $filters[0]['project_id']); $this->assertEquals(1, $filters[0]['user_id']); $this->assertEquals(0, $filters[0]['is_shared']); $this->assertEquals('', $filters[0]['owner_name']); $this->assertEquals('admin', $filters[0]['owner_username']); $this->assertEquals(2, $filters[1]['id']); $this->assertEquals('My filter 2', $filters[1]['name']); $this->assertEquals('color:red', $filters[1]['filter']); $this->assertEquals(1, $filters[1]['project_id']); $this->assertEquals(1, $filters[1]['user_id']); $this->assertEquals(1, $filters[1]['is_shared']); $this->assertEquals('', $filters[1]['owner_name']); $this->assertEquals('admin', $filters[1]['owner_username']); $this->assertEquals(3, $filters[2]['id']); $this->assertEquals('My filter 3', $filters[2]['name']); $this->assertEquals('color:green', $filters[2]['filter']); $this->assertEquals(1, $filters[2]['project_id']); $this->assertEquals(2, $filters[2]['user_id']); $this->assertEquals(1, $filters[2]['is_shared']); $this->assertEquals('', $filters[2]['owner_name']); $this->assertEquals('user 2', $filters[2]['owner_username']); // Get filters for the project 1 and user 2 $filters = $cf->getAll(1, 2); $this->assertCount(3, $filters); $this->assertEquals(2, $filters[0]['id']); $this->assertEquals('My filter 2', $filters[0]['name']); $this->assertEquals(3, $filters[1]['id']); $this->assertEquals('My filter 3', $filters[1]['name']); $this->assertEquals(4, $filters[2]['id']); $this->assertEquals('My filter 4', $filters[2]['name']); // Get filters for the project 2 and user 1 $filters = $cf->getAll(2, 1); $this->assertCount(0, $filters); // Get filters for the project 2 and user 2 $filters = $cf->getAll(2, 2); $this->assertCount(1, $filters); $this->assertEquals(5, $filters[0]['id']); $this->assertEquals('My filter 5', $filters[0]['name']); $this->assertEquals(0, $filters[0]['is_shared']); }
public function testUnlink() { $userModel = new User($this->container); $provider = new GoogleAuth($this->container); $this->assertEquals(2, $userModel->create(array('username' => 'test', 'google_id' => '1234'))); $this->assertNotEmpty($userModel->getByExternalId('google_id', 1234)); $this->assertTrue($provider->unlink(2)); $this->assertEmpty($userModel->getByExternalId('google_id', 1234)); }
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 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()); }
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)); }
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']); }
public function testWithNoComment() { $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')); }
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]); }
public function testOperations() { $m = new UserMetadata($this->container); $u = new User($this->container); $this->assertEquals(2, $u->create(array('username' => 'foobar'))); $this->assertTrue($m->save(1, array('key1' => 'value1'))); $this->assertTrue($m->save(1, array('key1' => 'value2'))); $this->assertTrue($m->save(2, array('key1' => 'value1'))); $this->assertTrue($m->save(2, array('key2' => 'value2'))); $this->assertEquals('value2', $m->get(1, 'key1')); $this->assertEquals('value1', $m->get(2, 'key1')); $this->assertEquals('', $m->get(2, 'key3')); $this->assertEquals('default', $m->get(2, 'key3', 'default')); $this->assertTrue($m->exists(2, 'key1')); $this->assertFalse($m->exists(2, 'key3')); $this->assertEquals(array('key1' => 'value2'), $m->getAll(1)); $this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $m->getAll(2)); }
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)); }
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 testThatProjectCreatorAreAlsoOwner() { $projectModel = new Project($this->container); $userModel = new User($this->container); $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'))); $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']); $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']); }
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 testCloneProjectWithUsers() { $p = new Project($this->container); $c = new Category($this->container); $pp = new ProjectPermission($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(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->assertEquals(2, $pd->duplicate(1)); $project = $p->getById(2); $this->assertNotEmpty($project); $this->assertEquals('P1 (Clone)', $project['name']); $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)); }
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)); }
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 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 ProjectUserRole($this->container); $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); $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 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)); }
public function testDuplicateMixedResults() { $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'))); $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->assertTrue($pp->addMember(1, 2)); $this->assertEquals(1, $a->create(array('project_id' => 1, 'event_name' => Task::EVENT_CREATE_UPDATE, 'action_name' => 'TaskAssignSpecificUser', 'params' => array('column_id' => 1, 'user_id' => 2)))); $action = $a->getById(1); $this->assertNotEmpty($action); $this->assertNotEmpty($action['params']); $this->assertEquals(2, $a->create(array('project_id' => 1, 'event_name' => Task::EVENT_CREATE_UPDATE, 'action_name' => 'TaskAssignCategoryColor', 'params' => array('color_id' => 'blue', 'category_id' => 1)))); $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']); $actions = $a->getAllByProject(1); $this->assertNotEmpty($actions); $this->assertCount(2, $actions); $this->assertTrue($a->duplicate(1, 2)); $actions = $a->getAllByProject(2); $this->assertNotEmpty($actions); $this->assertCount(1, $actions); $actions = $a->getAll(); $this->assertNotEmpty($actions); $this->assertCount(3, $actions); $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']); }
public function testMoveAnotherProjectWithForbiddenUser() { $td = new TaskDuplication($this->container); $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 $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(2, $p->create(array('name' => 'test2'))); // 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)); // We create a task $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 2, 'owner_id' => 3))); // We move our task to the 2nd project $this->assertTrue($td->moveToProject(1, 2)); // Check the values of the moved task $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['position']); $this->assertEquals(0, $task['owner_id']); $this->assertEquals(2, $task['project_id']); $this->assertEquals(6, $task['column_id']); }
public function testIsProjectManagementAllowedForProjectManager() { $h = new User($this->container); $p = new Project($this->container); $pp = new ProjectPermission($this->container); $u = new UserModel($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 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 $this->container['sessionStorage']->user = array('id' => 2, 'is_admin' => false, 'is_project_admin' => false); $this->assertTrue($h->isProjectManagementAllowed(1)); }
public function testGetUsersWithNotificationsWhenEverybodyAllowed() { $u = new User($this->container); $p = new Project($this->container); $n = new UserNotification($this->container); $pp = new ProjectPermission($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'is_everybody_allowed' => 1))); $this->assertTrue($pp->isEverybodyAllowed(1)); // Email + Notifications enabled $this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); // No email + Notifications enabled $this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); // Email + Notifications enabled $this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1))); // No email + notifications disabled $this->assertNotFalse($u->create(array('username' => 'user4'))); $users = $n->getUsersWithNotificationEnabled(1); $this->assertNotEmpty($users); $this->assertCount(3, $users); $this->assertEquals('user1@here', $users[0]['email']); $this->assertEquals('', $users[1]['email']); $this->assertEquals('user3@here', $users[2]['email']); }
public function testDuplicateWithUserParameterButNotAvailable() { $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->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 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 testPrepareCreation() { $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $tp = new TaskPermission($this->container); $p = new Project($this->container); $u = new User($this->container); $us = new UserSession($this->container); $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456'))); $this->assertNotFalse($u->create(array('username' => 'toto2', 'password' => '123456'))); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'creator_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'creator_id' => 2))); $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 1, 'creator_id' => 3))); $this->assertEquals(4, $tc->create(array('title' => 'Task #4', 'project_id' => 1))); // User #1 can remove everything $user = $u->getbyId(1); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(1); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); // User #2 can't remove the task #1 $user = $u->getbyId(2); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(1); $this->assertNotEmpty($task); $this->assertFalse($tp->canRemoveTask($task)); // User #1 can remove everything $user = $u->getbyId(1); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(2); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); // User #2 can remove his own task $user = $u->getbyId(2); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(2); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); // User #1 can remove everything $user = $u->getbyId(1); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(3); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); // User #2 can't remove the task #3 $user = $u->getbyId(2); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(3); $this->assertNotEmpty($task); $this->assertFalse($tp->canRemoveTask($task)); // User #1 can remove everything $user = $u->getbyId(1); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(4); $this->assertNotEmpty($task); $this->assertTrue($tp->canRemoveTask($task)); // User #2 can't remove the task #4 $user = $u->getbyId(2); $this->assertNotEmpty($user); $us->refresh($user); $task = $tf->getbyId(4); $this->assertNotEmpty($task); $this->assertFalse($tp->canRemoveTask($task)); }
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 testHasProjectAccessForProjectViewers() { $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, 'role' => Role::APP_USER); $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)); }
public function testCloneProjectWithUsers() { $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' => '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(1, $p->create(array('name' => 'P1'))); $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_MANAGER)); $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(1, 2)); $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(1, 3)); $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(1, 4)); $this->assertEquals(2, $pd->duplicate(1)); $project = $p->getById(2); $this->assertNotEmpty($project); $this->assertEquals('P1 (Clone)', $project['name']); $this->assertEquals(3, count($pp->getUsers(2))); $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(2, 2)); $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(2, 3)); $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 4)); }