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)); }
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']); }