public function testGetsUserByPublicId() { $expected = new FakeUser(); $publicId = uniqid(); $this->userRepo->expects($this->once())->method('LoadByPublicId')->with($this->equalTo($publicId))->will($this->returnValue($expected)); $actual = $this->service->GetUser($publicId); $this->assertEquals($expected, $actual); }
public function testBindsUserData() { $userDto = new UserDto($this->userId, 'f', 'l', 'email'); $this->initializer->expects($this->any())->method('CurrentUser')->will($this->returnValue($this->fakeUser)); $this->initializer->expects($this->once())->method('GetOwnerId')->will($this->returnValue($this->userId)); $this->initializer->expects($this->once())->method('CurrentUser')->will($this->returnValue($this->fakeUser)); $this->userRepository->expects($this->once())->method('GetById')->with($this->equalTo($this->userId))->will($this->returnValue($userDto)); $this->reservationAuthorization->expects($this->once())->method('CanChangeUsers')->with($this->fakeUser)->will($this->returnValue(true)); $this->fakeConfig->SetSectionKey(ConfigSection::PRIVACY, ConfigKeys::PRIVACY_HIDE_USER_DETAILS, 'true'); $this->initializer->expects($this->once())->method('SetShowParticipation')->with($this->equalTo(false)); $this->initializer->expects($this->once())->method('SetCanChangeUser')->with($this->equalTo(true)); $this->initializer->expects($this->once())->method('SetReservationUser')->with($this->equalTo($userDto)); $binder = new ReservationUserBinder($this->userRepository, $this->reservationAuthorization); $binder->Bind($this->initializer); }
public function testGetsScheduleResourcesUserHasAdminRightsTo() { $scheduleId = 100; $user = $this->getMock('User'); $this->userRepository->expects($this->once())->method('LoadById')->with($this->equalTo($this->fakeUser->UserId))->will($this->returnValue($user)); $ra = new FakeResourceAccess(); $this->db->SetRows($ra->GetRows()); $user->expects($this->at(0))->method('IsResourceAdminFor')->with($this->equalTo($ra->_Resources[0]))->will($this->returnValue(false)); $user->expects($this->at(1))->method('IsResourceAdminFor')->with($this->equalTo($ra->_Resources[1]))->will($this->returnValue(true)); $repo = new ResourceAdminResourceRepository($this->userRepository, $this->fakeUser); $resources = $repo->GetScheduleResources($scheduleId); $this->assertTrue($this->db->ContainsCommand(new GetScheduleResourcesCommand($scheduleId))); $this->assertEquals(1, count($resources)); $this->assertEquals(2, $resources[0]->GetId()); }
public function testLoadsFilteredResultsAndChecksAuthorizationAgainstPendingReservations() { $pageNumber = 1; $pageSize = 40; $groups = array(new UserGroup(1, '1'), new UserGroup(5, '5'), new UserGroup(9, '9'), new UserGroup(22, '22')); $myGroups = array(1, 5, 9, 22); $this->userRepository->expects($this->once())->method('LoadGroups')->with($this->equalTo($this->fakeUser->UserId), $this->equalTo(RoleLevel::RESOURCE_ADMIN))->will($this->returnValue($groups)); $filter = new ReservationFilter(); $expectedFilter = $filter->GetFilter(); $expectedFilter->_And(new SqlFilterIn(new SqlFilterColumn(TableNames::RESOURCES, ColumnNames::RESOURCE_ADMIN_GROUP_ID), $myGroups)); $data = new PageableData(); $this->reservationViewRepository->expects($this->once())->method('GetList')->with($pageNumber, $pageSize, null, null, $expectedFilter)->will($this->returnValue($data)); $actualData = $this->service->LoadFiltered($pageNumber, $pageSize, $filter, $this->fakeUser); $this->assertEquals($data, $actualData); }
public function testDoesNotUpdateScheduleIfUserDoesNotHaveAccess() { $user = $this->getMock('User'); $this->userRepository->expects($this->once())->method('LoadById')->with($this->equalTo($this->fakeUser->UserId))->will($this->returnValue($user)); $schedule = new FakeSchedule(1); $schedule->SetAdminGroupId(2); $user->expects($this->at(0))->method('IsScheduleAdminFor')->with($this->equalTo($schedule))->will($this->returnValue(false)); $actualEx = null; try { $this->repo->Update($schedule); } catch (Exception $ex) { $actualEx = $ex; } $this->assertNotEmpty($actualEx, "should have thrown an exception"); }
function testLoginGetsUserDataFromDatabase() { $language = 'en_gb'; $this->userRepository->expects($this->once())->method('LoadByUsername')->with($this->equalTo($this->username))->will($this->returnValue($this->user)); LoginTime::$Now = time(); $this->user->Login(LoginTime::Now(), $language); $this->userRepository->expects($this->once())->method('Update')->with($this->equalTo($this->user)); $this->authorization->expects($this->once())->method('IsApplicationAdministrator')->with($this->equalTo($this->user))->will($this->returnValue(true)); $this->authorization->expects($this->once())->method('IsGroupAdministrator')->with($this->equalTo($this->user))->will($this->returnValue(true)); $this->authorization->expects($this->once())->method('IsResourceAdministrator')->with($this->equalTo($this->user))->will($this->returnValue(true)); $this->authorization->expects($this->once())->method('IsScheduleAdministrator')->with($this->equalTo($this->user))->will($this->returnValue(true)); $context = new WebLoginContext(new LoginData(false, $language)); $actualSession = $this->auth->Login($this->username, $context); $user = new UserSession($this->id); $user->FirstName = $this->fname; $user->LastName = $this->lname; $user->Email = $this->email; $user->Timezone = $this->timezone; $user->HomepageId = $this->homepageId; $user->IsAdmin = true; $user->IsGroupAdmin = true; $user->IsResourceAdmin = true; $user->IsScheduleAdmin = true; $user->LanguageCode = $language; $user->LoginTime = LoginTime::Now(); $user->PublicId = $this->publicId; $user->ScheduleId = $this->scheduleId; foreach ($this->groups as $group) { $user->Groups[] = $group->GroupId; } $this->assertEquals($user, $actualSession); }
public function testConflictHandlerReportsConflictingReservationAndDoesNotUpdateBlackout() { $userId = $this->fakeUser->UserId; $start = Date::Parse('2011-01-01 01:01:01'); $end = Date::Parse('2011-02-02 02:02:02'); $date = new DateRange($start, $end); $resourceId = 2; $resourceIds = array($resourceId); $title = 'title'; $seriesId = 111; $blackoutInstanceId = 10; $series = BlackoutSeries::Create(1, 'old title', new TestDateRange()); $series->WithId($seriesId); $user = $this->getMock('User'); $user->expects($this->any())->method('IsResourceAdminFor')->with($this->anything())->will($this->returnValue(true)); $this->userRepository->expects($this->once())->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user)); $this->reservationViewRepository->expects($this->once())->method('GetBlackoutsWithin')->with($this->equalTo($date))->will($this->returnValue(array())); $reservation1 = new TestReservationItemView(1, $start, $end, 2); $reservation2 = new TestReservationItemView(2, $start, $end, 2); $this->reservationViewRepository->expects($this->once())->method('GetReservationList')->with($this->equalTo($start), $this->equalTo($end))->will($this->returnValue(array($reservation1, $reservation2))); $this->conflictHandler->expects($this->at(0))->method('Handle')->with($this->equalTo($reservation1))->will($this->returnValue(false)); $this->conflictHandler->expects($this->at(1))->method('Handle')->with($this->equalTo($reservation2))->will($this->returnValue(false)); $this->blackoutRepository->expects($this->never())->method('Update'); $this->blackoutRepository->expects($this->once())->method('LoadByBlackoutId')->with($this->equalTo($blackoutInstanceId))->will($this->returnValue($series)); $result = $this->service->Update($blackoutInstanceId, $date, $resourceIds, $title, $this->conflictHandler, new RepeatNone(), SeriesUpdateScope::FullSeries); $this->assertFalse($result->WasSuccessful()); }
public function testUpdatesUser() { $user = new User(); $userId = 1029380; $fname = 'f'; $lname = 'l'; $username = '******'; $email = '*****@*****.**'; $timezone = 'America/Chicago'; $phone = '123-123-1234'; $organization = 'ou'; $position = 'position'; $extraAttributes = array(UserAttribute::Organization => $organization, UserAttribute::Phone => $phone, UserAttribute::Position => $position); $this->userRepo->expects($this->once())->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user)); $this->userRepo->expects($this->once())->method('Update')->with($this->equalTo($user)); $updatedUser = $this->service->UpdateUser($userId, $username, $email, $fname, $lname, $timezone, $extraAttributes); $this->assertEquals($user, $updatedUser); $this->assertEquals($fname, $user->FirstName()); $this->assertEquals($lname, $user->LastName()); $this->assertEquals($timezone, $user->Timezone()); $this->assertEquals($username, $user->Username()); $this->assertEquals($email, $user->EmailAddress()); $this->assertEquals($phone, $user->GetAttribute(UserAttribute::Phone)); $this->assertEquals($organization, $user->GetAttribute(UserAttribute::Organization)); $this->assertEquals($position, $user->GetAttribute(UserAttribute::Position)); }
public function testFirstQuotaExceeded() { $scheduleId = 971243; $timezone = 'America/New_York'; $userId = 10; $groupId1 = 8287; $groupId2 = 102; $user = new FakeUser(); $user->SetGroups(array($groupId1, $groupId2)); $schedule = new Schedule(1, null, null, null, null, $timezone); $resource = new FakeBookableResource(20); $resource->SetScheduleId($scheduleId); $series = ReservationSeries::Create($userId, $resource, null, null, new TestDateRange(), new RepeatNone(), new FakeUserSession()); $series->AddResource(new FakeBookableResource(22)); $quota1 = $this->mockQuota('IQuota'); $quota2 = $this->mockQuota('IQuota'); $quotas = array($quota1, $quota2); $this->quotaRepository->expects($this->once())->method('LoadAll')->will($this->returnValue($quotas)); $this->userRepository->expects($this->once())->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user)); $this->scheduleRepository->expects($this->once())->method('LoadById')->with($this->equalTo($scheduleId))->will($this->returnValue($schedule)); $this->ChecksAgainstQuota($quota1, $series, $this->reservationViewRepository, $schedule, $user, true); $quota2->expects($this->never())->method('ExceedsQuota'); $rule = new QuotaRule($this->quotaRepository, $this->reservationViewRepository, $this->userRepository, $this->scheduleRepository); $result = $rule->Validate($series); $this->assertFalse($result->IsValid(), 'first quotas was exceeded'); }
public function testWhenActivationCodeIsValid() { $userId = 11; $homepage = Pages::CALENDAR; $user = new FakeUser($userId); $user->ChangeDefaultHomePage($homepage); $user->SetStatus(AccountStatus::AWAITING_ACTIVATION); $activationCode = uniqid(); $this->activationRepo->expects($this->once())->method('FindUserIdByCode')->with($this->equalTo($activationCode))->will($this->returnValue($userId)); $this->activationRepo->expects($this->once())->method('DeleteActivation')->with($this->equalTo($activationCode)); $this->userRepo->expects($this->once())->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user)); $this->userRepo->expects($this->once())->method('Update')->with($this->equalTo($user)); $result = $this->activation->Activate($activationCode); $this->assertTrue($result->Activated()); $this->assertEquals($user, $result->User()); $this->assertEquals(AccountStatus::ACTIVE, $user->StatusId()); }
public function testIfUserIsAdminForReservationUserReturnTrue() { $this->fakeUser->IsAdmin = false; $this->fakeUser->IsGroupAdmin = true; $adminUser = $this->getMock('User'); $reservationUser = $this->getMock('User'); $this->userRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($this->fakeUser->UserId))->will($this->returnValue($adminUser)); $this->userRepository->expects($this->at(1))->method('LoadById')->with($this->equalTo($this->reservationSeries->UserId()))->will($this->returnValue($reservationUser)); $adminUser->expects($this->once())->method('IsAdminFor')->with($this->equalTo($reservationUser))->will($this->returnValue(true)); $result = $this->rule->Validate($this->reservationSeries); $this->assertTrue($result->IsValid()); }
public function testCanApproveReservationOnResourceIfUserIsAdminOfThatResource() { $userId = 1234; $userSession = new UserSession($userId); $userSession->IsResourceAdmin = true; $groupAdmin = $this->getMock('User'); $resource = $this->getMock('IResource'); $this->userRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($groupAdmin)); $groupAdmin->expects($this->once())->method('IsResourceAdminFor')->with($this->equalTo($resource))->will($this->returnValue(true)); $canApprove = $this->authorizationService->CanApproveForResource($userSession, $resource); $this->assertTrue($canApprove, "should be able to approve because user is in admin group"); }
public function testWhenNotHidingUserDetails() { $this->HideUsers(false); $userId = 999; $user = new FakeUser($userId); $attributes = $this->getMock('IEntityAttributeList'); $this->userRepositoryFactory->expects($this->once())->method('Create')->with($this->equalTo($this->server->GetSession()))->will($this->returnValue($this->userRepository)); $this->userRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user)); $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::USER), $this->equalTo(array($userId)))->will($this->returnValue($attributes)); $expectedResponse = new UserResponse($this->server, $user, $attributes); $this->service->GetUser($userId); $this->assertEquals($expectedResponse, $this->server->_LastResponse); }
public function testChecksStatusOfEachResourceWhenGettingAll() { $scheduleId = 100; $session = $this->fakeUser; $user = new FakeUser(); $user->_IsResourceAdmin = false; $resource1 = new FakeBookableResource(1, 'resource1'); $resource1->ChangeStatus(ResourceStatus::UNAVAILABLE); $resources = array($resource1); $this->resourceRepository->expects($this->any())->method('GetScheduleResources')->with($this->equalTo($scheduleId))->will($this->returnValue($resources)); $this->permissionService->expects($this->at(0))->method('CanAccessResource')->with($this->equalTo($resource1), $this->equalTo($session))->will($this->returnValue(true)); $this->userRepository->expects($this->any())->method('LoadById')->with($this->equalTo($session->UserId))->will($this->returnValue($user)); $resourceDto1 = new ResourceDto(1, 'resource1', false, $resource1->GetScheduleId(), $resource1->GetMinLength()); $expected = array($resourceDto1); $actualInclusive = $this->resourceService->GetScheduleResources($scheduleId, true, $session); $this->assertEquals($expected, $actualInclusive); $actualExcluded = $this->resourceService->GetScheduleResources($scheduleId, false, $session); $this->assertEquals(array(), $actualExcluded); }
public function testSynchronizeRegistersNewUser() { $username = '******'; $email = 'em'; $fname = 'fn'; $lname = 'ln'; $phone = 'ph'; $inst = 'or'; $title = 'title'; $langCode = 'en_US'; $timezone = 'UTC'; $groups = array(new UserGroup(1, 'group1'), new UserGroup(2, 'g2')); $encryptedPassword = $this->fakeEncryption->_Encrypted; $salt = $this->fakeEncryption->_Salt; $user = new AuthenticatedUser($username, $email, $fname, $lname, 'password', $langCode, $timezone, $phone, $inst, $title, $groups); $expectedUser = User::Create($fname, $lname, $email, $username, $langCode, $timezone, $encryptedPassword, $salt, Pages::DEFAULT_HOMEPAGE_ID); $expectedUser->ChangeAttributes($phone, $inst, $title); $expectedUser->WithGroups($groups); $this->userRepository->expects($this->once())->method('UserExists')->with($this->equalTo($email), $this->equalTo($username))->will($this->returnValue(null)); $this->userRepository->expects($this->once())->method('Add')->with($this->equalTo($expectedUser)); $this->registration->Synchronize($user); }