public function testGetsAttributesByCategory()
 {
     $attributes = array(new TestCustomAttribute(1, 'label'));
     $categoryId = CustomAttributeCategory::RESERVATION;
     $this->attributeService->expects($this->once())->method('GetByCategory')->with($this->equalTo($categoryId))->will($this->returnValue($attributes));
     $expectedResponse = new CustomAttributesResponse($this->server, $attributes);
     $this->service->GetAttributes($categoryId);
     $this->assertEquals($expectedResponse, $this->server->_LastResponse);
 }
 public function testGetsResourceList()
 {
     $resourceId = 123;
     $resources[] = new FakeBookableResource($resourceId);
     $attributes = new AttributeList();
     $this->repository->expects($this->once())->method('GetResourceList')->will($this->returnValue($resources));
     $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::RESOURCE), $this->equalTo(array($resourceId)))->will($this->returnValue($attributes));
     $this->service->GetAll();
     $this->assertEquals(new ResourcesResponse($this->server, $resources, $attributes), $this->server->_LastResponse);
 }
 public function testCustomAttributesAreValidated()
 {
     $request = ResourceRequest::Example();
     $result = new AttributeServiceValidationResult(false, array('error'));
     $this->attributeService->expects($this->atLeastOnce())->method('Validate')->with($this->equalTo(CustomAttributeCategory::RESOURCE), $this->equalTo(array(new AttributeValue($request->customAttributes[0]->attributeId, $request->customAttributes[0]->attributeValue))))->will($this->returnValue($result));
     $createErrors = $this->validator->ValidateCreateRequest($request);
     $updateErrors = $this->validator->ValidateUpdateRequest(1, $request);
     $this->assertEquals(1, count($createErrors));
     $this->assertEquals(1, count($updateErrors));
 }
 public function testBindsResourceTypes()
 {
     $types = array(new ResourceType(1, 'name', 'desc'));
     $ids = array(1);
     $attributes = $this->getMock('IEntityAttributeList');
     $this->resourceRepository->expects($this->once())->method('GetResourceTypes')->will($this->returnValue($types));
     $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::RESOURCE_TYPE), $this->equalTo($ids))->will($this->returnValue($attributes));
     $this->page->expects($this->once())->method('BindResourceTypes')->with($this->equalTo($types));
     $this->page->expects($this->once())->method('BindAttributeList')->with($this->equalTo($attributes));
     $this->presenter->PageLoad();
 }
 public function testBindsUsersAndAttributesAndGroups()
 {
     $userId = 123;
     $pageNumber = 1;
     $pageSize = 10;
     $result = new UserItemView();
     $result->Id = $userId;
     $results = array($result);
     $userList = new PageableData($results);
     $resourceList = array(new FakeBookableResource(1));
     $attributeList = array(new FakeCustomAttribute(1, '1'));
     $this->page->expects($this->once())->method('GetPageNumber')->will($this->returnValue($pageNumber));
     $this->page->expects($this->once())->method('GetPageSize')->will($this->returnValue($pageSize));
     $this->page->expects($this->once())->method('GetFilterStatusId')->will($this->returnValue(AccountStatus::ALL));
     $this->userRepo->expects($this->once())->method('GetList')->with($this->equalTo($pageNumber), $this->equalTo($pageSize), $this->isNull(), $this->isNull(), $this->isNull(), $this->equalTo(AccountStatus::ALL))->will($this->returnValue($userList));
     $user = new FakeUser();
     $this->userRepo->expects($this->once())->method('LoadById')->with($this->fakeUser->UserId)->will($this->returnValue($user));
     $this->page->expects($this->once())->method('BindUsers')->with($this->equalTo($userList->Results()));
     $this->page->expects($this->once())->method('BindPageInfo')->with($this->equalTo($userList->PageInfo()));
     $this->resourceRepo->expects($this->once())->method('GetResourceList')->will($this->returnValue($resourceList));
     $this->page->expects($this->once())->method('BindResources')->with($this->equalTo($resourceList));
     $this->attributeService->expects($this->once())->method('GetByCategory')->with($this->equalTo(CustomAttributeCategory::USER))->will($this->returnValue($attributeList));
     $this->page->expects($this->once())->method('BindAttributeList')->with($this->equalTo($attributeList));
     $groups = array(new GroupItemView(1, 'gn'));
     $groupList = new PageableData($groups);
     $this->groupViewRepository->expects($this->once())->method('GetList')->will($this->returnValue($groupList));
     $this->page->expects($this->once())->method('BindGroups')->with($this->equalTo($groups));
     $this->presenter->PageLoad();
 }
 public function testFiltersResourceTypeCustomAttributes()
 {
     $attributeId1 = 1;
     $attributeValue1 = 1;
     $attributeId2 = 2;
     $attributeValue2 = 'something';
     $resourceId = 3;
     $resourceTypeId = 4;
     $attributeList = new FakeAttributeList();
     $attributeList->Add($resourceTypeId, new Attribute(new CustomAttribute($attributeId1, '', CustomAttributeTypes::CHECKBOX, CustomAttributeCategory::RESOURCE, '', false, '', 0, $resourceTypeId), $attributeValue1));
     $attributeList->Add($resourceTypeId, new Attribute(new CustomAttribute($attributeId2, '', CustomAttributeTypes::MULTI_LINE_TEXTBOX, CustomAttributeCategory::RESOURCE, '', false, '', 0, $resourceTypeId), $attributeValue2));
     $attributeList->Add(1, new Attribute(new CustomAttribute($attributeId2, '', CustomAttributeTypes::MULTI_LINE_TEXTBOX, CustomAttributeCategory::RESOURCE, '', false, '', 0, 1), $attributeValue2));
     $attributeList->Add(3, new Attribute(new CustomAttribute($attributeId2, '', CustomAttributeTypes::MULTI_LINE_TEXTBOX, CustomAttributeCategory::RESOURCE, '', false, '', 0, 3), $attributeValue2));
     $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::RESOURCE_TYPE), $this->isNull())->will($this->returnValue($attributeList));
     $filter = new ScheduleResourceFilter();
     $filter->ResourceTypeAttributes = array(new AttributeValue($attributeId1, $attributeValue1), new AttributeValue($attributeId2, $attributeValue2));
     $resource1 = new FakeBookableResource(1, 'resource1');
     $resource1->SetResourceTypeId(100);
     $resource2 = new FakeBookableResource(2, 'resource2');
     $resource2->SetResourceTypeId(200);
     $resource3 = new FakeBookableResource($resourceId, 'resource3');
     $resource3->SetResourceTypeId($resourceTypeId);
     $resource4 = new FakeBookableResource(4, 'resource4');
     $resources = array($resource1, $resource2, $resource3, $resource4);
     $resourceIds = $filter->FilterResources($resources, $this->resourceRepository, $this->attributeService);
     $this->assertEquals(1, count($resourceIds));
     $this->assertEquals($resourceId, $resourceIds[0]);
 }
Exemplo n.º 7
0
 public function testGetsResourceTypeCustomAttributes()
 {
     $customAttributes = array(new FakeCustomAttribute(1));
     $this->attributeService->expects($this->once())->method('GetByCategory')->with($this->equalTo(CustomAttributeCategory::RESOURCE_TYPE))->will($this->returnValue($customAttributes));
     $attributes = $this->resourceService->GetResourceTypeAttributes();
     $this->assertEquals(1, count($attributes));
     $this->assertEquals($customAttributes[0]->Id(), $attributes[0]->Id());
 }
Exemplo n.º 8
0
 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 testLoadsASingleReservation()
 {
     $referenceNumber = '12323';
     $reservation = new ReservationView();
     $reservation->StartDate = Date::Now();
     $reservation->EndDate = Date::Now();
     $reservation->ReferenceNumber = $referenceNumber;
     $attributes = array(new FakeCustomAttribute());
     $this->reservationViewRepository->expects($this->once())->method('GetReservationForEditing')->with($this->equalTo($referenceNumber))->will($this->returnValue($reservation));
     $this->attributeService->expects($this->once())->method('GetByCategory')->with($this->equalTo(CustomAttributeCategory::RESERVATION))->will($this->returnValue($attributes));
     $this->service->GetReservation($referenceNumber);
     $expectedResponse = new ReservationResponse($this->server, $reservation, $this->privacyFilter, $attributes);
     $this->assertEquals($expectedResponse, $this->server->_LastResponse);
 }
 public function testUsesTwoWeekSpanWhenNoDateFilterProvided()
 {
     $userTimezone = 'America/Chicago';
     $defaultStart = Date::Now()->AddDays(-7)->ToTimezone($userTimezone)->GetDate();
     $defaultEnd = Date::Now()->AddDays(7)->ToTimezone($userTimezone)->GetDate();
     $searchedScheduleId = 15;
     $searchedResourceId = 105;
     $searchedStatusId = ReservationStatus::Pending;
     $searchedUserId = 111;
     $searchedReferenceNumber = 'abc123';
     $searchedUserName = '******';
     $searchedResourceStatusId = 292;
     $searchedResourceStatusReasonId = 4292;
     /** @var TestCustomAttribute[] $customAttributes */
     $customAttributes = array(new TestCustomAttribute(1, 'something'));
     /** @var Attribute[] $attributes */
     $attributes = array(new Attribute($customAttributes[0], 'value'));
     $this->resourceRepository->expects($this->once())->method('GetStatusReasons')->will($this->returnValue(array()));
     $this->page->expects($this->any())->method('FilterButtonPressed')->will($this->returnValue(true));
     $this->page->expects($this->atLeastOnce())->method('GetStartDate')->will($this->returnValue(null));
     $this->page->expects($this->atLeastOnce())->method('GetEndDate')->will($this->returnValue(null));
     $this->page->expects($this->atLeastOnce())->method('GetScheduleId')->will($this->returnValue($searchedScheduleId));
     $this->page->expects($this->atLeastOnce())->method('GetResourceId')->will($this->returnValue($searchedResourceId));
     $this->page->expects($this->atLeastOnce())->method('GetReservationStatusId')->will($this->returnValue($searchedStatusId));
     $this->page->expects($this->atLeastOnce())->method('GetUserId')->will($this->returnValue($searchedUserId));
     $this->page->expects($this->atLeastOnce())->method('GetUserName')->will($this->returnValue($searchedUserName));
     $this->page->expects($this->atLeastOnce())->method('GetReferenceNumber')->will($this->returnValue($searchedReferenceNumber));
     $this->page->expects($this->atLeastOnce())->method('GetResourceStatusFilterId')->will($this->returnValue($searchedResourceStatusId));
     $this->page->expects($this->atLeastOnce())->method('GetResourceStatusReasonFilterId')->will($this->returnValue($searchedResourceStatusReasonId));
     $this->page->expects($this->atLeastOnce())->method('GetAttributeFilters')->will($this->returnValue(array(new AttributeFormElement($customAttributes[0]->Id(), 'value'))));
     $filter = $this->GetExpectedFilter($defaultStart, $defaultEnd, $searchedReferenceNumber, $searchedScheduleId, $searchedResourceId, $searchedUserId, $searchedStatusId, $searchedResourceStatusId, $searchedResourceStatusReasonId, $attributes);
     $data = new PageableData($this->getReservations());
     $this->reservationsService->expects($this->once())->method('LoadFiltered')->with($this->anything(), $this->anything(), $this->equalTo($filter), $this->equalTo($this->fakeUser))->will($this->returnValue($data));
     $this->attributeService->expects($this->once())->method('GetByCategory')->with($this->equalTo(CustomAttributeCategory::RESERVATION))->will($this->returnValue($customAttributes));
     $this->page->expects($this->once())->method('SetAttributeFilters')->with($attributes);
     $this->page->expects($this->once())->method('SetStartDate')->with($this->equalTo($defaultStart));
     $this->page->expects($this->once())->method('SetEndDate')->with($this->equalTo($defaultEnd));
     $this->page->expects($this->once())->method('SetReferenceNumber')->with($this->equalTo($searchedReferenceNumber));
     $this->page->expects($this->once())->method('SetScheduleId')->with($this->equalTo($searchedScheduleId));
     $this->page->expects($this->once())->method('SetResourceId')->with($this->equalTo($searchedResourceId));
     $this->page->expects($this->once())->method('SetReservationStatusId')->with($this->equalTo($searchedStatusId));
     $this->page->expects($this->once())->method('SetUserId')->with($this->equalTo($searchedUserId));
     $this->page->expects($this->once())->method('SetUserName')->with($this->equalTo($searchedUserName));
     $this->page->expects($this->once())->method('SetUserName')->with($this->equalTo($searchedUserName));
     $this->page->expects($this->once())->method('SetResourceStatusFilterId')->with($this->equalTo($searchedResourceStatusId));
     $this->page->expects($this->once())->method('SetResourceStatusReasonFilterId')->with($this->equalTo($searchedResourceStatusReasonId));
     $this->presenter->PageLoad($userTimezone);
 }
Exemplo n.º 11
0
 private function ExpectAttributeServiceCalled($attributes = array())
 {
     $list = new FakeAttributeList($attributes);
     $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::USER))->will($this->returnValue($list));
 }
Exemplo n.º 12
0
 private function expectsAttributeValidator()
 {
     $this->attributeService->expects($this->any())->method('Validate')->with($this->anything(), $this->anything())->will($this->returnValue(new AttributeServiceValidationResult(true, null)));
 }