public function PageLoad() { $this->page->BindResources($this->resourceRepo->GetResourceList()); $this->page->BindAccessories($this->resourceRepo->GetAccessoryList()); $this->page->BindSchedules($this->scheduleRepo->GetAll()); $this->page->BindGroups($this->groupRepo->GetList()->Results()); }
/** * @name GetGroup * @description Loads a specific group by id * @response GroupResponse * @param int $groupId * @return void */ public function GetGroup($groupId) { $group = $this->groupRepository->LoadById($groupId); if ($group != null) { $this->server->WriteResponse(new GroupResponse($this->server, $group)); } else { $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE); } }
public function testWhenGroupIsNotFound() { $groupId = 999; $this->groupRepository->expects($this->once())->method('LoadById')->with($this->equalTo($groupId))->will($this->returnValue(null)); $expectedResponse = RestResponse::NotFound(); $this->service->GetGroup($groupId); $this->assertEquals($expectedResponse, $this->server->_LastResponse); $this->assertEquals(RestResponse::NOT_FOUND_CODE, $this->server->_LastResponseCode); }
public function ChangeGroups($user, $groupIds) { if ($groupIds == null) { return; } $existingGroupIds = array(); foreach ($user->Groups() as $group) { $existingGroupIds[] = $group->GroupId; } foreach ($groupIds as $targetGroupId) { if (!in_array($targetGroupId, $existingGroupIds)) { // add group $group = $this->groupRepository->LoadById($targetGroupId); $group->AddUser($user->Id()); $this->groupRepository->Update($group); } } foreach ($existingGroupIds as $existingId) { if (!in_array($existingId, $groupIds)) { // remove user $group = $this->groupRepository->LoadById($existingId); $group->RemoveUser($user->Id()); $this->groupRepository->Update($group); } } }
public function testAddsUser() { $fname = 'f'; $lname = 'l'; $username = '******'; $email = '*****@*****.**'; $timezone = 'America/Chicago'; $lang = 'foo'; $password = '******'; $attributeId = 1; $attributeValue = 'value'; $attributeFormElements = array(new AttributeFormElement($attributeId, $attributeValue)); $userId = 1090; $groupId = 111; $user = new FakeUser($userId); $group = new Group($groupId, 'name'); $group->AddUser($userId); $this->fakeConfig->SetKey(ConfigKeys::LANGUAGE, $lang); $this->page->expects($this->once())->method('GetFirstName')->will($this->returnValue($fname)); $this->page->expects($this->once())->method('GetLastName')->will($this->returnValue($lname)); $this->page->expects($this->once())->method('GetUserName')->will($this->returnValue($username)); $this->page->expects($this->once())->method('GetEmail')->will($this->returnValue($email)); $this->page->expects($this->once())->method('GetTimezone')->will($this->returnValue($timezone)); $this->page->expects($this->once())->method('GetPassword')->will($this->returnValue($password)); $this->page->expects($this->once())->method('GetAttributes')->will($this->returnValue($attributeFormElements)); $this->page->expects($this->once())->method('GetUserGroup')->will($this->returnValue($groupId)); $this->manageUsersService->expects($this->once())->method('AddUser')->with($this->equalTo($username), $this->equalTo($email), $this->equalTo($fname), $this->equalTo($lname), $this->equalTo($password), $this->equalTo($timezone), $this->equalTo($lang), $this->equalTo(Pages::DEFAULT_HOMEPAGE_ID), $this->equalTo(array()), $this->equalTo(array(new AttributeValue($attributeId, $attributeValue))))->will($this->returnValue($user)); $this->groupRepository->expects($this->once())->method('LoadById')->with($this->equalTo($groupId))->will($this->returnValue($group)); $this->groupRepository->expects($this->once())->method('Update')->with($this->equalTo($group)); $this->presenter->AddUser(); }
public function AddUser() { $userId = $this->manageUsersService->AddUser($this->page->GetUserName(), $this->page->GetEmail(), $this->page->GetFirstName(), $this->page->GetLastName(), $this->page->GetPassword(), $this->page->GetTimezone(), Configuration::Instance()->GetKey(ConfigKeys::LANGUAGE), Pages::DEFAULT_HOMEPAGE_ID, array(), $this->GetAttributeValues()); $groupId = $this->page->GetUserGroup(); if (!empty($groupId)) { $group = $this->groupRepository->LoadById($groupId); $group->AddUser($userId); $this->groupRepository->Update($group); } }
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())); }