Esempio n. 1
0
 public function testGetUsersWithNotification()
 {
     $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')));
     // 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')));
     // Nobody is member of any projects
     $this->assertEmpty($pp->getMembers(1));
     $this->assertEmpty($n->getUsersWithNotification(1));
     // 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->assertNotEmpty($pp->getMembers(1));
     $users = $n->getUsersWithNotification(1);
     $this->assertNotEmpty($users);
     $this->assertEquals(2, count($users));
     $this->assertEquals('user1@here', $users[0]['email']);
     $this->assertEquals('user3@here', $users[1]['email']);
 }
 public function testClonePrivateProject()
 {
     $p = new Project($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'Private', 'is_private' => 1), 1, true));
     $this->assertEquals(2, $p->duplicate(1));
     $project = $p->getById(2);
     $this->assertNotEmpty($project);
     $this->assertEquals('Private (Clone)', $project['name']);
     $this->assertEquals(1, $project['is_private']);
     $this->assertEquals(0, $project['is_public']);
     $this->assertEmpty($project['token']);
     $pp = new ProjectPermission($this->container);
     $this->assertEquals(array(1 => 'admin'), $pp->getMembers(1));
     $this->assertEquals(array(1 => 'admin'), $pp->getMembers(2));
 }
 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));
 }
Esempio n. 4
0
 public function testRevokeUser()
 {
     $p = new Project($this->container);
     $pp = new ProjectPermission($this->container);
     $user = new User($this->container);
     $user->create(array('username' => 'unittest', 'password' => 'unittest'));
     // We create a project
     $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
     // We revoke our admin user (not existing row)
     $this->assertFalse($pp->revokeMember(1, 1));
     // We should have nobody in the users list
     $this->assertEmpty($pp->getMembers(1));
     // Only admin is allowed
     $this->assertTrue($pp->isUserAllowed(1, 1));
     $this->assertFalse($pp->isUserAllowed(1, 2));
     // We allow only the regular user
     $this->assertTrue($pp->addMember(1, 2));
     // All users should be allowed (admin and regular)
     $this->assertTrue($pp->isUserAllowed(1, 1));
     $this->assertTrue($pp->isUserAllowed(1, 2));
     // However, we should have only our regular user in the list
     $this->assertEquals(array('2' => 'unittest'), $pp->getMembers(1));
     // We allow our admin, we should have both in the list
     $this->assertTrue($pp->addMember(1, 1));
     $this->assertEquals(array('1' => 'admin', '2' => 'unittest'), $pp->getMembers(1));
     $this->assertTrue($pp->isUserAllowed(1, 1));
     $this->assertTrue($pp->isUserAllowed(1, 2));
     // We revoke the regular user
     $this->assertTrue($pp->revokeMember(1, 2));
     // Only admin should be allowed
     $this->assertTrue($pp->isUserAllowed(1, 1));
     $this->assertFalse($pp->isUserAllowed(1, 2));
     // We should have only admin in the list
     $this->assertEquals(array('1' => 'admin'), $pp->getMembers(1));
     // We revoke the admin user
     $this->assertTrue($pp->revokeMember(1, 1));
     $this->assertEmpty($pp->getMembers(1));
     // Only admin should be allowed again
     $this->assertTrue($pp->isUserAllowed(1, 1));
     $this->assertFalse($pp->isUserAllowed(1, 2));
 }