public function testValidateModification()
 {
     $validator = new ProjectValidator($this->container);
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'identifier' => 'test1')));
     $this->assertEquals(2, $p->create(array('name' => 'UnitTest2', 'identifier' => 'TEST2')));
     $project = $p->getById(1);
     $this->assertNotEmpty($project);
     $this->assertEquals('TEST1', $project['identifier']);
     $project = $p->getById(2);
     $this->assertNotEmpty($project);
     $this->assertEquals('TEST2', $project['identifier']);
     $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST1'));
     $this->assertTrue($r[0]);
     $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'test3'));
     $this->assertTrue($r[0]);
     $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => ''));
     $this->assertTrue($r[0]);
     $r = $validator->validateModification(array('id' => 1, 'name' => 'test', 'identifier' => 'TEST2'));
     $this->assertFalse($r[0]);
 }
 public function testNotifyProjectWithWebhookNotConfigured()
 {
     $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')));
     $this->container['projectMetadata']->save(1, array('rocketchat_webhook_url' => ''));
     $project = $projectModel->getById(1);
     $task = $taskFinderModel->getDetails(1);
     $event = array('task' => $task);
     $event['task']['task_id'] = $task['id'];
     $handler->notifyProject($project, Task::EVENT_MOVE_COLUMN, $event);
 }
示例#3
0
 public function testPriority()
 {
     $projectModel = new Project($this->container);
     $this->assertEquals(1, $projectModel->create(array('name' => 'My project 2')));
     $project = $projectModel->getById(1);
     $this->assertNotEmpty($project);
     $this->assertEquals(0, $project['priority_default']);
     $this->assertEquals(0, $project['priority_start']);
     $this->assertEquals(3, $project['priority_end']);
     $this->assertTrue($projectModel->update(array('id' => 1, 'priority_start' => 2, 'priority_end' => 5, 'priority_default' => 4)));
     $project = $projectModel->getById(1);
     $this->assertNotEmpty($project);
     $this->assertEquals(4, $project['priority_default']);
     $this->assertEquals(2, $project['priority_start']);
     $this->assertEquals(5, $project['priority_end']);
 }
 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));
 }
示例#5
0
 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));
 }
 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);
 }
示例#7
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]);
 }
 public function testCloneProjectWithUsers()
 {
     $p = new Project($this->container);
     $c = new Category($this->container);
     $pp = new ProjectUserRole($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->addUser(1, 2, Role::PROJECT_MEMBER));
     $this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER));
     $this->assertTrue($pp->addUser(1, 4, Role::PROJECT_MANAGER));
     $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(1, 2));
     $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(1, 3));
     $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(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->getUsers(2)));
     $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(2, 2));
     $this->assertEquals(Role::PROJECT_MEMBER, $pp->getUserRole(2, 3));
     $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 4));
 }
 public function testCloneTeamProjectToPrivatProject()
 {
     $p = new Project($this->container);
     $c = new Category($this->container);
     $pp = new ProjectUserRole($this->container);
     $u = new User($this->container);
     $pd = new ProjectDuplication($this->container);
     $this->assertEquals(2, $u->create(array('username' => 'user1')));
     $this->assertEquals(3, $u->create(array('username' => 'user2')));
     $this->assertEquals(1, $p->create(array('name' => 'P1'), 2));
     $project = $p->getById(1);
     $this->assertEquals(2, $project['owner_id']);
     $this->assertEquals(0, $project['is_private']);
     $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MANAGER));
     $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER));
     $this->assertEquals(2, $pd->duplicate(1, array('projectPermission'), 3, 'My private project', true));
     $this->assertCount(1, $pp->getUsers(2));
     $this->assertEquals(Role::PROJECT_MANAGER, $pp->getUserRole(2, 3));
     $project = $p->getById(2);
     $this->assertEquals(3, $project['owner_id']);
     $this->assertEquals(1, $project['is_private']);
 }