コード例 #1
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->allowUser(1, 2));
     $this->assertTrue($pp->allowUser(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']);
 }
コード例 #2
0
#!/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 = 50;
$userModel = new User($container);
$projectModel = new Project($container);
$permissionModel = new ProjectPermission($container);
$taskModel = new TaskCreation($container);
$subtaskModel = new SubTask($container);
for ($i = 0; $i <= 100; $i++) {
    $id = $projectModel->create(array('name' => 'Project #' . $i));
    $permissionModel->allowUser($id, 1);
}
for ($i = 0; $i <= 500; $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' => mt_rand(1, 100), '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));
    }
}
コード例 #3
0
 public function testUsersList()
 {
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $user = new User($this->container);
     $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->allowUser(1, 2));
     $this->assertEquals(array(0 => 'Unassigned', 2 => 'unittest'), $pp->getMemberList(1));
     // We allow the admin user
     $this->assertTrue($pp->allowUser(1, 1));
     $this->assertEquals(array(0 => 'Unassigned', 1 => 'admin', 2 => 'unittest'), $pp->getMemberList(1));
     // We revoke only the regular user
     $this->assertTrue($pp->revokeUser(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->revokeUser(1, 1));
     $this->assertEquals(array(0 => 'Unassigned'), $pp->getMemberList(1));
 }
コード例 #4
0
 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']);
 }