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));
 }
Beispiel #2
0
 public function testDisablePublicAccess()
 {
     $p = new Project($this->registry);
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
     $this->assertTrue($p->enablePublicAccess(1));
     $this->assertTrue($p->disablePublicAccess(1));
     $project = $p->getById(1);
     $this->assertNotEmpty($project);
     $this->assertEquals(0, $project['is_public']);
     $this->assertEmpty($project['token']);
     $this->assertFalse($p->disablePublicAccess(123));
 }
 public function testCloneProjectWithCategories()
 {
     $p = new Project($this->container);
     $c = new Category($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'P1')));
     $this->assertEquals(1, $c->create(array('name' => 'C1', 'project_id' => 1)));
     $this->assertEquals(2, $c->create(array('name' => 'C2', 'project_id' => 1)));
     $this->assertEquals(3, $c->create(array('name' => 'C3', 'project_id' => 1)));
     $this->assertEquals(2, $p->duplicate(1));
     $project = $p->getById(2);
     $this->assertNotEmpty($project);
     $this->assertEquals('P1 (Clone)', $project['name']);
     $categories = $c->getAll(2);
     $this->assertNotempty($categories);
     $this->assertEquals(3, count($categories));
     $this->assertEquals(4, $categories[0]['id']);
     $this->assertEquals('C1', $categories[0]['name']);
     $this->assertEquals(5, $categories[1]['id']);
     $this->assertEquals('C2', $categories[1]['name']);
     $this->assertEquals(6, $categories[2]['id']);
     $this->assertEquals('C3', $categories[2]['name']);
 }
 public function testRemove()
 {
     $u = new User($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $s = new Subtask($this->container);
     $c = new Comment($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)));
     $this->assertEquals(1, $s->create(array('title' => 'Subtask #1', 'user_id' => 2, 'task_id' => 1)));
     $this->assertEquals(1, $c->create(array('comment' => 'foobar', 'user_id' => 2, 'task_id' => 1)));
     $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 assigned subtasks are unassigned after removing the user
     $subtask = $s->getById(1);
     $this->assertEquals(1, $subtask['id']);
     $this->assertEquals(0, $subtask['user_id']);
     // Make sure that comments are not related to the user anymore
     $comment = $c->getById(1);
     $this->assertEquals(1, $comment['id']);
     $this->assertEquals(0, $comment['user_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));
 }
Beispiel #5
0
$language = $config->get('language', 'en_US');
if ($language !== 'en_US') {
    Translator::load($language);
}
$server = new Server();
$server->authentication(array('jsonrpc' => $config->get('api_token')));
/**
 * Project procedures
 */
$server->register('createProject', function ($name) use($project) {
    $values = array('name' => $name);
    list($valid, ) = $project->validateCreation($values);
    return $valid && $project->create($values);
});
$server->register('getProjectById', function ($project_id) use($project) {
    return $project->getById($project_id);
});
$server->register('getProjectByName', function ($name) use($project) {
    return $project->getByName($name);
});
$server->register('getAllProjects', function () use($project) {
    return $project->getAll();
});
$server->register('updateProject', function ($id, $name, $is_active = null, $is_public = null, $token = null) use($project) {
    $values = array('id' => $id, 'name' => $name, 'is_active' => $is_active, 'is_public' => $is_public, 'token' => $token);
    foreach ($values as $key => $value) {
        if (is_null($value)) {
            unset($values[$key]);
        }
    }
    list($valid, ) = $project->validateModification($values);
Beispiel #6
0
 public function testIdentifier()
 {
     $p = new Project($this->container);
     // Creation
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
     $this->assertEquals(2, $p->create(array('name' => 'UnitTest2')));
     $project = $p->getById(1);
     $this->assertNotEmpty($project);
     $this->assertEquals('TEST1', $project['identifier']);
     $project = $p->getById(2);
     $this->assertNotEmpty($project);
     $this->assertEquals('', $project['identifier']);
     // Update
     $this->assertTrue($p->update(array('id' => '2', 'identifier' => 'test2')));
     $project = $p->getById(2);
     $this->assertNotEmpty($project);
     $this->assertEquals('TEST2', $project['identifier']);
     $project = $p->getByIdentifier('test1');
     $this->assertNotEmpty($project);
     $this->assertEquals('TEST1', $project['identifier']);
     $project = $p->getByIdentifier('');
     $this->assertFalse($project);
     // Validation rules
     $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'TEST1'));
     $this->assertFalse($r[0]);
     $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test1'));
     $this->assertFalse($r[0]);
     $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1'));
     $this->assertTrue($r[0]);
     $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3'));
     $this->assertTrue($r[0]);
     $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => ''));
     $this->assertTrue($r[0]);
     $r = $p->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2'));
     $this->assertFalse($r[0]);
     $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'a-b-c'));
     $this->assertFalse($r[0]);
     $r = $p->validateCreation(array('name' => 'test', 'identifier' => 'test 123'));
     $this->assertFalse($r[0]);
 }