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 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 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())); }