public function testCloneProjectWithUsers() { $p = new Project($this->container); $c = new Category($this->container); $pp = new ProjectPermission($this->container); $u = new User($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, $p->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)); }
function add() { $app = get_app(); //GET if ($app->request()->isGet()) { render_with_layout('misc.php', 'Users/add.php'); } //POST if ($app->request()->isPost()) { $password_1 = $app->request()->post('password_1'); $password_2 = $app->request()->post('password_2'); if ($password_1 != $password_2) { $app->flashNow('errors', array('您两次输入的密码不一致!')); render_with_layout('misc.php', 'Users/add.php'); } else { $post = $app->request()->post(); $post['password'] = !empty($password_1) && strlen($password_1) >= 8 ? md5($password_1) : $password_1; $post['team_id'] = 0; unset($post['password_1']); unset($post['password_2']); $user = User::create($post); if (!$user->is_valid()) { $app->flashNow('errors', $user->errors); render_with_layout('misc.php', 'Users/add.php'); } else { $user->save(); $app->flash('success', '用户创建成功!'); redirect('/users'); } } } }
public function testHandlePayload() { $w = new MailgunWebhook($this->container); $p = new Project($this->container); $pp = new ProjectPermission($this->container); $u = new User($this->container); $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $this->assertEquals(2, $u->create(array('name' => '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->parsePayload(array())); // Unknown user $this->assertFalse($w->parsePayload(array('sender' => 'a@b.c', 'subject' => 'Email task', 'recipient' => 'foobar', 'stripped-text' => 'boo'))); // Project not found $this->assertFalse($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test@localhost', 'stripped-text' => 'boo'))); // User is not member $this->assertFalse($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); $this->assertTrue($pp->addMember(2, 2)); // The task must be created $this->assertTrue($w->parsePayload(array('sender' => 'me@localhost', 'subject' => 'Email task', 'recipient' => 'foo+test1@localhost', 'stripped-text' => 'boo'))); $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 testHtml2Markdown() { $w = new Postmark($this->container); $p = new Project($this->container); $pp = new ProjectPermission($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' => 'test2', 'identifier' => 'TEST1'))); $this->assertTrue($pp->addMember(1, 2)); $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => 'boo', 'HtmlBody' => '<p><strong>boo</strong></p>'))); $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['project_id']); $this->assertEquals('Email task', $task['title']); $this->assertEquals('**boo**', $task['description']); $this->assertEquals(2, $task['creator_id']); $this->assertTrue($w->receiveEmail(array('From' => 'me@localhost', 'Subject' => 'Email task', 'MailboxHash' => 'test1', 'TextBody' => '**boo**', 'HtmlBody' => ''))); $task = $tf->getById(2); $this->assertNotEmpty($task); $this->assertEquals(1, $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']); }
/** * POST /register.json */ public function register($f3, $params) { // Create user $data = ['username' => $f3->get('POST.username'), 'fingerprint' => $f3->get('POST.keypair-fingerprint'), 'name' => $f3->get('POST.name'), 'password_salt' => $f3->get('POST.password-salt'), 'password_hash' => password_hash($f3->get('POST.password-hash'), PASSWORD_DEFAULT, ['cost' => \App::config()['security']['bcrypt_cost']]), 'private_key' => $f3->get('POST.keypair-private'), 'public_key' => $f3->get('POST.keypair-public'), 'symmetric_key' => $f3->get('POST.symmkey')]; $user = \Model\User::create($data); // Log in user and return stssion token $token = \Helper\Security::generateToken($user->id); $this->_json(['user_id' => $user->id, 'token' => $token]); }
public function testGetUserList() { $u = new User($this->registry); $p = new Project($this->registry); $n = new Notification($this->registry); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); // Email + Notifications enabled $this->assertTrue($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); // No email + Notifications enabled $this->assertTrue($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); // Email + Notifications enabled $this->assertTrue($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1))); // No email + notifications disabled $this->assertTrue($u->create(array('username' => 'user4'))); $users = $n->getUsersList(1); $this->assertNotEmpty($users); $this->assertEquals(2, count($users)); $this->assertEquals('user1@here', $users[0]['email']); $this->assertEquals('user3@here', $users[1]['email']); $users = $n->getUsersList(2); $this->assertNotEmpty($users); $this->assertEquals(2, count($users)); $this->assertEquals('user1@here', $users[0]['email']); $this->assertEquals('user3@here', $users[1]['email']); // User 3 choose to receive notification only for project 2 $n->saveSettings(4, array('notifications_enabled' => 1, 'projects' => array(2 => true))); $users = $n->getUsersList(1); $this->assertNotEmpty($users); $this->assertEquals(1, count($users)); $this->assertEquals('user1@here', $users[0]['email']); $users = $n->getUsersList(2); $this->assertNotEmpty($users); $this->assertEquals(2, count($users)); $this->assertEquals('user1@here', $users[0]['email']); $this->assertEquals('user3@here', $users[1]['email']); // User 1 excluded $users = $n->getUsersList(1, array(2)); $this->assertEmpty($users); $users = $n->getUsersList(2, array(2)); $this->assertNotEmpty($users); $this->assertEquals(1, count($users)); $this->assertEquals('user3@here', $users[0]['email']); }
public function testHandlePayload() { $w = new Sendgrid($this->container); $p = new Project($this->container); $pp = new ProjectPermission($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('envelope' => '{"to":["a@b.c"],"from":"a.b.c"}', 'subject' => 'Email task'))); // Project not found $this->assertFalse($w->receiveEmail(array('envelope' => '{"to":["a@b.c"],"from":"me@localhost"}', 'subject' => 'Email task'))); // User is not member $this->assertFalse($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task'))); $this->assertTrue($pp->addMember(2, 2)); // The task must be created $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task'))); $task = $tf->getById(1); $this->assertNotEmpty($task); $this->assertEquals(2, $task['project_id']); $this->assertEquals('Email task', $task['title']); $this->assertEquals('', $task['description']); $this->assertEquals(2, $task['creator_id']); // Html content $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'html' => '<strong>bold</strong> text'))); $task = $tf->getById(2); $this->assertNotEmpty($task); $this->assertEquals(2, $task['project_id']); $this->assertEquals('Email task', $task['title']); $this->assertEquals('**bold** text', $task['description']); $this->assertEquals(2, $task['creator_id']); // Text content $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'text' => '**bold** text'))); $task = $tf->getById(3); $this->assertNotEmpty($task); $this->assertEquals(2, $task['project_id']); $this->assertEquals('Email task', $task['title']); $this->assertEquals('**bold** text', $task['description']); $this->assertEquals(2, $task['creator_id']); // Text + html content $this->assertTrue($w->receiveEmail(array('envelope' => '{"to":["something+test1@localhost"],"from":"me@localhost"}', 'subject' => 'Email task', 'html' => '<strong>bold</strong> html', 'text' => '**bold** text'))); $task = $tf->getById(4); $this->assertNotEmpty($task); $this->assertEquals(2, $task['project_id']); $this->assertEquals('Email task', $task['title']); $this->assertEquals('**bold** html', $task['description']); $this->assertEquals(2, $task['creator_id']); }
/** * Test setup */ public function setUp() { // Create Environment $db = $this->getDb(); $db->selectCollection(Bucket::$collection); // Empty Database $this->emptyDb(); // Create user $user = User::create(array('email' => '*****@*****.**')); $apikey = $user->createApiKey(); $apikeys = array_keys($user->apikeys); $this->apikey = $apikeys[0]; }
/** * Create CLI User (Requires API Key Access) */ public function assertCliUser() { $this->user = User::findOne(array('email' => '*****@*****.**')); if (!$this->user) { $this->user = User::create(array('email' => '*****@*****.**')); $this->user->createApiKey(); } $apikeys = array_keys($this->user->apikeys); $this->apikey = isset($apikeys[0]) ? $apikeys[0] : false; if (!$this->apikey) { $this->user->createApiKey(); $this->assertCliUser(); } }
public function testRemove() { $u = new User($this->registry); $t = new Task($this->registry); $p = new Project($this->registry); $this->assertTrue($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $t->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2))); $task = $t->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(2, $task['owner_id']); $this->assertTrue($u->remove(1)); $this->assertTrue($u->remove(2)); $this->assertFalse($u->remove(2)); $this->assertFalse($u->remove(55)); // Make sure that assigned tasks are unassigned after removing the user $task = $t->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(0, $task['owner_id']); }
}); $server->register('closeTask', function ($task_id) use($task) { return $task->close($task_id); }); $server->register('removeTask', function ($task_id) use($task) { return $task->remove($task_id); }); $server->register('moveTaskPosition', function ($project_id, $task_id, $column_id, $position) use($task) { return $task->movePosition($project_id, $task_id, $column_id, $position); }); /** * User procedures */ $server->register('createUser', function (array $values) use($user) { list($valid, ) = $user->validateCreation($values); return $valid && $user->create($values); }); $server->register('getUser', function ($user_id) use($user) { return $user->getById($user_id); }); $server->register('getAllUsers', function () use($user) { return $user->getAll(); }); $server->register('updateUser', function ($values) use($user) { list($valid, ) = $user->validateModification($values); return $valid && $user->update($values); }); $server->register('removeUser', function ($user_id) use($user) { return $user->remove($user_id); }); /**
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 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 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 testIsProjectManagementAllowedForProjectManager() { $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('id' => 2, 'is_admin' => false, 'is_project_admin' => false); $this->assertTrue($h->isProjectManagementAllowed(1)); }
public function testMoveToAnotherProject() { $t = new Task($this->registry); $p = new Project($this->registry); $user = new User($this->registry); // We create a regular user $user->create(array('username' => 'unittest1', 'password' => 'unittest')); $user->create(array('username' => 'unittest2', 'password' => 'unittest')); // We create 2 projects $this->assertEquals(1, $p->create(array('name' => 'test1'))); $this->assertEquals(2, $p->create(array('name' => 'test2'))); // We create a task $this->assertEquals(1, $t->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1, 'category_id' => 10, 'position' => 333))); $this->assertEquals(2, $t->create(array('title' => 'test2', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 3, 'category_id' => 10, 'position' => 333))); // We duplicate our task to the 2nd project $task = $t->getById(1); $this->assertEquals(1, $t->moveToAnotherProject(2, $task)); //$this->assertTrue($this->registry->event->isEventTriggered(Task::EVENT_CREATE)); // Check the values of the duplicated task $task = $t->getById(1); $this->assertNotEmpty($task); $this->assertEquals(1, $task['owner_id']); $this->assertEquals(0, $task['category_id']); $this->assertEquals(2, $task['project_id']); $this->assertEquals(5, $task['column_id']); $this->assertEquals(1, $task['position']); $this->assertEquals('test', $task['title']); // We allow only one user on the second project $this->assertTrue($p->allowUser(2, 2)); // The owner should be reseted $task = $t->getById(2); $this->assertEquals(2, $t->moveToAnotherProject(2, $task)); $task = $t->getById(2); $this->assertNotEmpty($task); $this->assertEquals(0, $task['owner_id']); }
public function testGetUserList() { $u = new User($this->container); $p = new Project($this->container); $pp = new ProjectPermission($this->container); $n = new Notification($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); $this->assertEquals(3, $p->create(array('name' => 'UnitTest3', 'is_everybody_allowed' => 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'))); // We allow all users to be member of our projects $this->assertTrue($pp->allowUser(1, 1)); $this->assertTrue($pp->allowUser(1, 2)); $this->assertTrue($pp->allowUser(1, 3)); $this->assertTrue($pp->allowUser(1, 4)); $this->assertTrue($pp->allowUser(2, 1)); $this->assertTrue($pp->allowUser(2, 2)); $this->assertTrue($pp->allowUser(2, 3)); $this->assertTrue($pp->allowUser(2, 4)); $users = $n->getUsersList(1); $this->assertNotEmpty($users); $this->assertEquals(2, count($users)); $this->assertEquals('user1@here', $users[0]['email']); $this->assertEquals('user3@here', $users[1]['email']); $users = $n->getUsersList(2); $this->assertNotEmpty($users); $this->assertEquals(2, count($users)); $this->assertEquals('user1@here', $users[0]['email']); $this->assertEquals('user3@here', $users[1]['email']); // User 3 choose to receive notification only for project 2 $n->saveSettings(4, array('notifications_enabled' => 1, 'projects' => array(2 => true))); $users = $n->getUsersList(1); $this->assertNotEmpty($users); $this->assertEquals(1, count($users)); $this->assertEquals('user1@here', $users[0]['email']); $users = $n->getUsersList(2); $this->assertNotEmpty($users); $this->assertEquals(2, count($users)); $this->assertEquals('user1@here', $users[0]['email']); $this->assertEquals('user3@here', $users[1]['email']); // User 1 excluded $users = $n->getUsersList(1, array(2)); $this->assertEmpty($users); $users = $n->getUsersList(2, array(2)); $this->assertNotEmpty($users); $this->assertEquals(1, count($users)); $this->assertEquals('user3@here', $users[0]['email']); // Project #3 allow everybody $users = $n->getUsersList(3); $this->assertNotEmpty($users); $this->assertEquals(1, count($users)); $this->assertEquals('user1@here', $users[0]['email']); $users = $n->getUsersWithNotification(3); $this->assertNotEmpty($users); $this->assertEquals(2, count($users)); $this->assertEquals('user1@here', $users[0]['email']); $this->assertEquals('user3@here', $users[1]['email']); }
public function testRemove() { $u = new User($this->container); $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); $this->assertEquals(1, $p->create(array('name' => 'Project #1'))); $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2))); $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(2, $task['owner_id']); $this->assertTrue($u->remove(1)); $this->assertTrue($u->remove(2)); $this->assertFalse($u->remove(2)); $this->assertFalse($u->remove(55)); // Make sure that assigned tasks are unassigned after removing the user $task = $tf->getById(1); $this->assertEquals(1, $task['id']); $this->assertEquals(0, $task['owner_id']); // Make sure that private projects are also removed $user_id1 = $u->create(array('username' => 'toto1', 'password' => '123456', 'name' => 'Toto')); $user_id2 = $u->create(array('username' => 'toto2', 'password' => '123456', 'name' => 'Toto')); $this->assertNotFalse($user_id1); $this->assertNotFalse($user_id2); $this->assertEquals(2, $p->create(array('name' => 'Private project #1', 'is_private' => 1), $user_id1, true)); $this->assertEquals(3, $p->create(array('name' => 'Private project #2', 'is_private' => 1), $user_id2, true)); $this->assertTrue($u->remove($user_id1)); $this->assertNotEmpty($p->getById(1)); $this->assertNotEmpty($p->getById(3)); $this->assertEmpty($p->getById(2)); }
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 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 testSendNotificationsToNotMember() { $u = new User($this->container); $p = new Project($this->container); $n = new Notification($this->container); $pp = new ProjectPermission($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); $this->container['emailClient']->expects($this->never())->method('send'); $n->sendNotifications('task.open', array('task' => array('id' => 2, 'title' => 'blah', 'project_name' => 'test', 'project_id' => 1, 'owner_id' => 0, 'creator_id' => 2))); }
public function testFilterUserWithBothFilterAndProjectSelected() { $u = new User($this->container); $n = new Notification($this->container); $nf = new NotificationFilter($this->container); $p = new Project($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); $this->assertEquals(2, $p->create(array('name' => 'UnitTest2'))); $this->assertEquals(2, $u->create(array('username' => 'user2', 'notifications_filter' => NotificationFilter::FILTER_BOTH))); $n->saveSettings(2, array('notifications_enabled' => 1, 'notification_projects' => array(2 => true))); $this->assertFalse($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 2, 'owner_id' => 3)))); $this->assertFalse($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 1, 'creator_id' => 0, 'owner_id' => 2)))); $this->assertTrue($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 2, 'owner_id' => 3)))); $this->assertTrue($nf->shouldReceiveNotification($u->getById(2), array('task' => array('project_id' => 2, 'creator_id' => 0, 'owner_id' => 2)))); }
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(5, $task['column_id']); }
public function testSearchWithAssigneeIncludingSubtasks() { $p = new Project($this->container); $u = new User($this->container); $tc = new TaskCreation($this->container); $s = new Subtask($this->container); $tf = new TaskFilter($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(2, $u->create(array('username' => 'bob', 'name' => 'Paul Ryan'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'task1', 'owner_id' => 2))); $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'status' => 1, 'user_id' => 0))); $this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'task2', 'owner_id' => 0))); $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 2, 'status' => 1, 'user_id' => 2))); $this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'task3', 'owner_id' => 0))); $this->assertEquals(3, $s->create(array('title' => 'subtask #3', 'task_id' => 3, 'user_id' => 1))); $tf->search('assignee:bob'); $tasks = $tf->findAll(); $this->assertNotEmpty($tasks); $this->assertCount(2, $tasks); $this->assertEquals('task1', $tasks[0]['title']); $this->assertEquals('task2', $tasks[1]['title']); $tf->search('assignee:"Paul Ryan"'); $tasks = $tf->findAll(); $this->assertNotEmpty($tasks); $this->assertCount(2, $tasks); $this->assertEquals('task1', $tasks[0]['title']); $this->assertEquals('task2', $tasks[1]['title']); $tf->search('assignee:nobody'); $tasks = $tf->findAll(); $this->assertNotEmpty($tasks); $this->assertCount(2, $tasks); $this->assertEquals('task2', $tasks[0]['title']); $this->assertEquals('task3', $tasks[1]['title']); $tf->search('assignee:admin'); $tasks = $tf->findAll(); $this->assertNotEmpty($tasks); $this->assertCount(1, $tasks); $this->assertEquals('task3', $tasks[0]['title']); }
public function testSearchWithAssignee() { $p = new Project($this->container); $u = new User($this->container); $tc = new TaskCreation($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', 'owner_id' => 1))); $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'my task title is amazing', 'owner_id' => 0))); $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'Bob at work', 'owner_id' => 2))); $tf->search('assignee:john'); $tasks = $tf->findAll(); $this->assertEmpty($tasks); $tf->search('assignee:admin my task title'); $tasks = $tf->findAll(); $this->assertNotEmpty($tasks); $this->assertCount(1, $tasks); $this->assertEquals('my task title is awesome', $tasks[0]['title']); $tf->search('my task title'); $tasks = $tf->findAll(); $this->assertNotEmpty($tasks); $this->assertCount(2, $tasks); $this->assertEquals('my task title is awesome', $tasks[0]['title']); $this->assertEquals('my task title is amazing', $tasks[1]['title']); $tf->search('my task title assignee:nobody'); $tasks = $tf->findAll(); $this->assertNotEmpty($tasks); $this->assertCount(1, $tasks); $this->assertEquals('my task title is amazing', $tasks[0]['title']); $tf->search('assignee:"Bob ryan" assignee:nobody'); $tasks = $tf->findAll(); $this->assertNotEmpty($tasks); $this->assertCount(2, $tasks); $this->assertEquals('my task title is amazing', $tasks[0]['title']); $this->assertEquals('Bob at work', $tasks[1]['title']); }
public function testEnableDisablePublicAccess() { $u = new User($this->container); $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456'))); $user = $u->getById(2); $this->assertNotEmpty($user); $this->assertEquals('toto', $user['username']); $this->assertEmpty($user['token']); $this->assertTrue($u->enablePublicAccess(2)); $user = $u->getById(2); $this->assertNotEmpty($user); $this->assertEquals('toto', $user['username']); $this->assertNotEmpty($user['token']); $this->assertTrue($u->disablePublicAccess(2)); $user = $u->getById(2); $this->assertNotEmpty($user); $this->assertEquals('toto', $user['username']); $this->assertEmpty($user['token']); }
#!/usr/bin/env php <?php require __DIR__ . '/../app/common.php'; use Model\TaskCreation; use Model\SubTask; use Model\Project; use Model\ProjectPermission; use Model\User; $task_per_column = 200; $userModel = new User($container); $projectModel = new Project($container); $permissionModel = new ProjectPermission($container); $taskModel = new TaskCreation($container); $subtaskModel = new SubTask($container); $project_id = $projectModel->create(array('name' => 'Project #1')); $permissionModel->addMember($project_id, 1); for ($i = 0; $i <= 5; $i++) { $userModel->create(array('username' => 'user' . $i, 'password' => 'password' . $i, 'name' => 'User #' . $i, 'email' => 'user' . $i . '@localhost')); } foreach (array(1, 2, 3, 4) as $column_id) { for ($i = 1; $i <= $task_per_column; $i++) { $task = array('title' => 'Task #' . $i . '-' . $column_id, 'project_id' => 1, 'column_id' => $column_id, 'owner_id' => 1, 'color_id' => mt_rand(0, 1) === 0 ? 'green' : 'purple', 'score' => mt_rand(0, 21), 'is_active' => mt_rand(0, 1)); $id = $taskModel->create($task); $subtaskModel->create(array('title' => 'Subtask of task #' . $id, 'user_id' => 1, 'status' => mt_rand(0, 2), 'task_id' => $id)); } }
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)); }
public function testGetUsersWithNotificationsWhenEverybodyAllowed() { $u = new User($this->container); $p = new Project($this->container); $n = new Notification($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']); }