예제 #1
0
 public function testRedirectsToActiveIfUserNeedsActivation()
 {
     $this->user->SetStatus(AccountStatus::AWAITING_ACTIVATION);
     $this->postRegistration->HandleSelfRegistration($this->user, $this->page, $this->context);
     $this->assertFalse($this->fakeAuth->_LoginCalled);
     $this->assertTrue($this->activation->_NotifyCalled);
     $this->assertEquals($this->user, $this->activation->_NotifiedUser);
     $this->assertEquals(Pages::ACTIVATION, $this->page->_RedirectDestination);
 }
 public function testIsNotValidWhenTurnedOffForUser()
 {
     $user = new FakeUser();
     $user->DisableSubscription();
     $publicId = uniqid();
     $this->page->expects($this->once())->method('GetUserId')->will($this->returnValue($publicId));
     $this->subscriptionService->expects($this->once())->method('GetUser')->with($this->equalTo($publicId))->will($this->returnValue($user));
     $this->StubSubscriptionKey();
     $isValid = $this->validator->IsValid();
     $this->assertFalse($isValid);
 }
 public function testActivatesAccount()
 {
     $user = new FakeUser(12);
     $activationSuccess = new ActivationResult(true, $user);
     $this->accountActivation->_ActivationResult = $activationSuccess;
     $activationCode = uniqid();
     $this->page->expects($this->once())->method('GetActivationCode')->will($this->returnValue($activationCode));
     $this->page->expects($this->once())->method('Redirect')->with($this->equalTo(Pages::UrlFromId($user->Homepage())));
     $this->presenter->PageLoad();
     $this->assertEquals($activationCode, $this->accountActivation->_LastActivationCode);
     $this->assertTrue($this->auth->_LoginCalled);
     $this->assertEquals($user->EmailAddress(), $this->auth->_LastLogin);
     $this->assertEquals(new WebLoginContext(new LoginData(false, $user->Language())), $this->auth->_LastLoginContext);
 }
예제 #4
0
 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);
 }
예제 #5
0
 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());
 }
예제 #6
0
 public static function getFakeEmail()
 {
     mt_srand(self::make_seed());
     $name = FakeUser::getFirstName(false);
     $lastname = FakeUser::getLastName(false);
     $alphabet = str_shuffle('abcdefghijklmnopqrstuvwxyz0123456789');
     $str = str_shuffle(substr($alphabet, 0, mt_rand(2, 5)));
     return $name . '.' . $lastname . '.' . $str . '@' . self::url();
 }
예제 #7
0
 public function testChecksWhenAtLeastOneGroupApplies()
 {
     $g1 = new UserGroup(1, null);
     $g2 = new UserGroup(2, null);
     $g4 = new UserGroup(4, null);
     $this->user->SetGroups(array($g1, $g2, $g4));
     $groupId = 4;
     $startDate = Date::Parse('2011-07-31 21:30', $this->tz);
     $endDate = Date::Parse('2011-08-01 2:30', $this->tz);
     $quota = new Quota(1, new QuotaDurationDay(), new QuotaLimitCount(0), null, $groupId, null);
     $series = $this->GetHourLongReservation($startDate, $endDate, 101, 102);
     $this->SearchReturns(array());
     $exceeds = $quota->ExceedsQuota($series, $this->user, $this->schedule, $this->reservationViewRepository);
     $this->assertTrue($exceeds);
 }
예제 #8
0
 public function addAuthor($id)
 {
     $user = Users::model()->findByPk($id);
     $fake_user = FakeUser::model()->findByPk($user->fake_name_id);
     if ($fake_user != null) {
         $fake_user_id = qa_db_user_find_by_facebook_id($id);
         if ($fake_user_id == null) {
             $fake_user_id = qa_create_new_user($fake_user->email, "ciaociao123", $fake_user->first_name . $fake_user->last_name, QA_USER_LEVEL_BASIC, true);
             qa_db_user_create_by_fb_id($fake_user_id, $id);
         }
     }
     return $fake_user_id;
 }
예제 #9
0
 public function testWhenNotAllowedToGetUser()
 {
     $sessionUserId = $this->server->GetSession()->UserId;
     $userId = 999;
     $this->HideUsers(true);
     $user = new FakeUser($userId);
     $me = new FakeUser($sessionUserId);
     $me->_SetIsAdminForUser(false);
     $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->userRepository->expects($this->at(1))->method('LoadById')->with($this->equalTo($sessionUserId))->will($this->returnValue($me));
     $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::USER), $this->equalTo(array($userId)))->will($this->returnValue($attributes));
     $this->service->GetUser($userId);
     $this->assertEquals(RestResponse::Unauthorized(), $this->server->_LastResponse);
     $this->assertEquals(RestResponse::UNAUTHORIZED_CODE, $this->server->_LastResponseCode);
 }
예제 #10
0
 public function testAddsAndRemovesUserFromGroups()
 {
     $userId = 23;
     $user = new FakeUser($userId);
     $user->WithGroups(array(new UserGroup(1, '1'), new UserGroup(4, '4')));
     $groupids = array(1, 2, 3);
     $group1 = new FakeGroup(1);
     $group1->WithUser($userId);
     $group2 = new FakeGroup(2);
     $group3 = new FakeGroup(3);
     $group4 = new FakeGroup(4);
     $group4->WithUser($userId);
     $this->groupRepo->expects($this->at(0))->method('LoadById')->with($this->equalTo(2))->will($this->returnValue($group2));
     $this->groupRepo->expects($this->at(2))->method('LoadById')->with($this->equalTo(3))->will($this->returnValue($group3));
     $this->groupRepo->expects($this->at(4))->method('LoadById')->with($this->equalTo(4))->will($this->returnValue($group4));
     $this->service->ChangeGroups($user, $groupids);
     $this->assertTrue(in_array($userId, $group2->AddedUsers()));
     $this->assertTrue(in_array($userId, $group3->AddedUsers()));
     $this->assertTrue(in_array($userId, $group4->RemovedUsers()));
 }
 public function testGetsSelectedResourcesFromPageAndAssignsPermission()
 {
     $resourcesThatShouldRemainUnchanged = array(5, 10);
     $allowedResourceIds = array(1, 2, 4, 20, 30);
     $submittedResourceIds = array(1, 4);
     $currentResourceIds = array(1, 20, 30);
     $expectedResourceIds = array(1, 4, 5, 10);
     $allResourceIds = array_unique(array_merge($resourcesThatShouldRemainUnchanged, $allowedResourceIds, $submittedResourceIds, $currentResourceIds));
     $resources = array();
     foreach ($allResourceIds as $rid) {
         $resources[] = new FakeBookableResource($rid);
     }
     $userId = 9928;
     $adminUserId = $this->fakeUser->UserId;
     $user = new FakeUser();
     $user->WithPermissions(array_merge($resourcesThatShouldRemainUnchanged, $currentResourceIds));
     $adminUser = new FakeUser();
     $adminUser->_ResourceAdminResourceIds = $allowedResourceIds;
     $adminUser->_IsResourceAdmin = false;
     $this->page->expects($this->atLeastOnce())->method('GetUserId')->will($this->returnValue($userId));
     $this->page->expects($this->atLeastOnce())->method('GetAllowedResourceIds')->will($this->returnValue($submittedResourceIds));
     $this->resourceRepo->expects($this->once())->method('GetResourceList')->will($this->returnValue($resources));
     $this->userRepo->expects($this->at(0))->method('LoadById')->with($this->equalTo($adminUserId))->will($this->returnValue($adminUser));
     $this->userRepo->expects($this->at(1))->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user));
     $this->userRepo->expects($this->once())->method('Update')->with($this->equalTo($user));
     $this->presenter->ChangePermissions();
     $actual = $user->AllowedResourceIds();
     $this->assertEquals(sort($expectedResourceIds), sort($actual));
 }
예제 #12
0
 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');
 }