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']);
 }
Ejemplo n.º 2
0
 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));
 }
Ejemplo n.º 4
0
 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'));
 }
Ejemplo n.º 5
0
 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']);
 }
Ejemplo n.º 6
0
 public function testSendWithoutEmailAddress()
 {
     $en = new Mail($this->container);
     $p = new Project($this->container);
     $tf = new TaskFinder($this->container);
     $tc = new TaskCreation($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)));
     $this->container['emailClient'] = $this->getMockBuilder('\\Kanboard\\Core\\Mail\\Client')->setConstructorArgs(array($this->container))->setMethods(array('send'))->getMock();
     $this->container['emailClient']->expects($this->never())->method('send');
     $en->notifyUser($u->getById(1), Task::EVENT_CREATE, array('task' => $tf->getDetails(1)));
 }
Ejemplo n.º 7
0
 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());
 }
Ejemplo n.º 8
0
 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 testNotifyUserWithWebhookNotConfigured()
 {
     $this->container['userMetadata']->save(1, array('rocketchat_webhook_url' => ''));
     $this->container['httpClient']->expects($this->never())->method('postForm');
     $userModel = new User($this->container);
     $projectModel = new Project($this->container);
     $taskCreationModel = new TaskCreation($this->container);
     $taskFinderModel = new TaskFinder($this->container);
     $handler = new RocketChat($this->container);
     $this->assertEquals(1, $projectModel->create(array('name' => 'test')));
     $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test')));
     $user = $userModel->getById(1);
     $task = $taskFinderModel->getDetails(1);
     $event = array('task' => $task);
     $event['task']['task_id'] = $task['id'];
     $handler->notifyUser($user, Task::EVENT_MOVE_COLUMN, $event);
 }
 public function testSuccess()
 {
     $userModel = new User($this->container);
     $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')));
     $this->assertTrue($userModel->update(array('id' => 1, 'email' => 'admin@localhost')));
     $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2));
     $action = new TaskEmail($this->container);
     $action->setProjectId(1);
     $action->setParam('column_id', 2);
     $action->setParam('user_id', 1);
     $action->setParam('subject', 'My email subject');
     $this->container['emailClient']->expects($this->once())->method('send')->with($this->equalTo('admin@localhost'), $this->equalTo('admin'), $this->equalTo('My email subject'), $this->stringContains('test'));
     $this->assertTrue($action->execute($event, Task::EVENT_CLOSE));
 }
 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 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);
 }
Ejemplo n.º 13
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 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']);
 }
Ejemplo n.º 15
0
 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 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 testIcalEventsWithAssigneeAndDueDate()
 {
     $dp = new DateParser($this->container);
     $p = new Project($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFilterICalendarFormatter($this->container);
     $u = new User($this->container);
     $c = new Config($this->container);
     $this->assertNotFalse($c->save(array('application_url' => 'http://kb/')));
     $this->assertEquals('http://kb/', $c->get('application_url'));
     $this->assertNotFalse($u->update(array('id' => 1, 'email' => 'bob@localhost')));
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1', 'owner_id' => 1, 'date_due' => $dp->getTimestampFromIsoFormat('+5 days'))));
     $ics = $tf->create()->filterByDueDateRange(strtotime('-1 month'), strtotime('+1 month'))->setFullDay()->setCalendar(new Calendar('Kanboard'))->setColumns('date_due')->addFullDayEvents()->format();
     $this->assertContains('UID:task-#1-date_due', $ics);
     $this->assertContains('DTSTART;TZID=UTC;VALUE=DATE:' . date('Ymd', strtotime('+5 days')), $ics);
     $this->assertContains('DTEND;TZID=UTC;VALUE=DATE:' . date('Ymd', strtotime('+5 days')), $ics);
     $this->assertContains('URL:http://kb/?controller=task&action=show&task_id=1&project_id=1', $ics);
     $this->assertContains('SUMMARY:#1 task1', $ics);
     $this->assertContains('ORGANIZER;CN=admin:MAILTO:bob@localhost', $ics);
     $this->assertContains('X-MICROSOFT-CDO-ALLDAYEVENT:TRUE', $ics);
 }
 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));
 }
Ejemplo n.º 19
0
 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']);
 }
Ejemplo n.º 20
0
 public function testTaskClose()
 {
     $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);
     $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
     $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 2);
     // 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'));
     // Our event should be executed
     $this->assertTrue($action->execute(new GenericEvent($event)));
 }
Ejemplo n.º 21
0
 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));
 }
Ejemplo n.º 22
0
 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));
 }
Ejemplo n.º 23
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']);
 }
Ejemplo n.º 24
0
 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));
 }
Ejemplo n.º 25
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)));
 }
Ejemplo n.º 26
0
 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);
 }
Ejemplo n.º 27
0
 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));
 }
Ejemplo n.º 28
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));
 }
Ejemplo n.º 29
0
 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']);
 }
Ejemplo n.º 30
0
 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']);
 }