function setup() { parent::setup(); $this->username = '******'; $this->password = '******'; $this->id = 191; $this->fname = 'Test'; $this->lname = 'Name'; $this->email = '*****@*****.**'; $this->isAdmin = true; $this->timezone = "US/Central"; $this->lastLogin = time(); $this->homepageId = 2; $this->languageCode = 'en_us'; $this->publicId = 'public_id'; $this->scheduleId = 111; $this->groups = array(new UserGroup(999, '1'), new UserGroup(888, '2')); $this->user = new FakeUser(); $this->user->WithId($this->id); $this->user->ChangeName($this->fname, $this->lname); $this->user->ChangeEmailAddress($this->email); $this->user->ChangeTimezone($this->timezone); $this->user->ChangeDefaultHomePage($this->homepageId); $this->user->SetLanguage($this->languageCode); $this->user->WithPublicId($this->publicId); $this->user->Activate(); $this->user->WithDefaultSchedule($this->scheduleId); $this->user->WithGroups($this->groups); $this->fakePassword = new FakePassword(); $this->fakeMigration = new FakeMigration(); $this->fakeMigration->_Password = $this->fakePassword; $this->authorization = $this->getMock('IRoleService'); $this->userRepository = $this->getMock('IUserRepository'); $this->auth = new Authentication($this->authorization, $this->userRepository); $this->auth->SetMigration($this->fakeMigration); $this->loginContext = new WebLoginContext(new LoginData()); }
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())); }