예제 #1
0
 public function testGetProjectMembersWithNotifications()
 {
     $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')));
     // 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')));
     // Nobody is member of any projects
     $this->assertEmpty($pp->getMembers(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->assertNotEmpty($pp->getMembers(1));
     $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']);
 }
예제 #2
0
 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']);
 }
예제 #3
0
 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));
 }
예제 #4
0
 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)));
 }
예제 #5
0
 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());
 }
예제 #6
0
 public function testIsProjectManagementAllowedForProjectMember()
 {
     $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->addMember(1, 2));
     $this->assertTrue($pp->isMember(1, 2));
     $this->assertFalse($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->assertFalse($h->isProjectManagementAllowed(1));
 }
예제 #7
0
 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']);
 }
예제 #8
0
 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));
 }
예제 #9
0
 public function testUsersList()
 {
     $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));
     // We allow only the regular user
     $this->assertTrue($pp->addMember(1, 2));
     $this->assertEquals(array(0 => 'Unassigned', 2 => 'unittest'), $pp->getMemberList(1));
     // We allow the admin user
     $this->assertTrue($pp->addMember(1, 1));
     $this->assertEquals(array(0 => 'Unassigned', 1 => 'admin', 2 => 'unittest'), $pp->getMemberList(1));
     // We revoke only the regular user
     $this->assertTrue($pp->revokeMember(1, 2));
     $this->assertEquals(array(0 => 'Unassigned', 1 => 'admin'), $pp->getMemberList(1));
     // We revoke only the admin user, we should have everybody
     $this->assertTrue($pp->revokeMember(1, 1));
     $this->assertEquals(array(0 => 'Unassigned'), $pp->getMemberList(1));
 }