public function testDoesNotUpdateResourceIfUserDoesNotHaveAccess() { $user = $this->getMock('User'); $this->userRepository->expects($this->once())->method('LoadById')->with($this->equalTo($this->fakeUser->UserId))->will($this->returnValue($user)); $repo = new ResourceAdminResourceRepository($this->userRepository, $this->fakeUser); $resource = new FakeBookableResource(1); $resource->SetAdminGroupId(2); $user->expects($this->at(0))->method('IsResourceAdminFor')->with($this->equalTo($resource))->will($this->returnValue(false)); $actualEx = null; try { $repo->Update($resource); } catch (Exception $ex) { $actualEx = $ex; } $this->assertNotEmpty($actualEx, "should have thrown an exception"); }
public function testWhenUserIsInAdminGroupForResource() { $adminGroupId = 223; $resource = new FakeBookableResource(1, 'n'); $resource->SetAdminGroupId($adminGroupId); $adminUser = new User(); $regularUser = new User(); $adminGroup = new UserGroup($adminGroupId, 'admin', null, RoleLevel::RESOURCE_ADMIN); $group1 = new UserGroup(1, 'random group'); $group2 = new UserGroup(2, 'group with admin'); $adminUserGroups = array($group1, $adminGroup); $userGroups = array($group1, $group2); $adminUser->WithGroups($adminUserGroups); $regularUser->WithGroups($userGroups); $this->assertTrue($adminUser->IsResourceAdminFor($resource)); $this->assertFalse($regularUser->IsResourceAdminFor($resource)); }