public function testWhenInitializing()
 {
     $accessories = array();
     $this->resourceRepository->expects($this->once())->method('GetAccessoryList')->will($this->returnValue($accessories));
     $this->page->expects($this->once())->method('BindAccessories')->with($this->equalTo($accessories));
     $this->presenter->PageLoad();
 }
 public function testGetsResourceByPublicId()
 {
     $expected = new FakeBookableResource(123);
     $publicId = uniqid();
     $this->resourceRepo->expects($this->once())->method('LoadByPublicId')->with($this->equalTo($publicId))->will($this->returnValue($expected));
     $actual = $this->service->GetResource($publicId);
     $this->assertEquals($expected, $actual);
 }
 public function testGetsAllAccessories()
 {
     $accessories = array(new AccessoryDto(1, 'name', 23));
     $this->resourceRepository->expects($this->once())->method('GetAccessoryList')->will($this->returnValue($accessories));
     $this->service->GetAll();
     $this->assertEquals(new AccessoriesResponse($this->server, $accessories), $this->server->_LastResponse);
     $this->assertEquals(RestResponse::OK_CODE, $this->server->_LastResponseCode);
 }
 public function testUpdatesReservationResourceStatuses()
 {
     $resourceStatusId = ResourceStatus::HIDDEN;
     $resourceStatusReasonId = 111;
     $referenceNumber = 'abc123';
     $reservations = array(new TestReservationItemView(1, Date::Now(), Date::Now(), 1), new TestReservationItemView(1, Date::Now(), Date::Now(), 2));
     $pageableReservations = new PageableData($reservations);
     $resource1 = new FakeBookableResource(1);
     $resource1->ChangeStatus(ResourceStatus::AVAILABLE, null);
     $resource2 = new FakeBookableResource(2);
     $resource2->ChangeStatus(ResourceStatus::AVAILABLE, null);
     $this->page->expects($this->once())->method('CanUpdateResourceStatuses')->will($this->returnValue(true));
     $this->page->expects($this->once())->method('GetResourceStatus')->will($this->returnValue($resourceStatusId));
     $this->page->expects($this->once())->method('GetUpdateScope')->will($this->returnValue('all'));
     $this->page->expects($this->once())->method('GetResourceStatusReason')->will($this->returnValue($resourceStatusReasonId));
     $this->page->expects($this->once())->method('GetResourceStatusReferenceNumber')->will($this->returnValue($referenceNumber));
     $this->reservationsService->expects($this->once())->method('LoadFiltered')->with($this->isNull(), $this->isNull(), $this->equalTo(new ReservationFilter(null, null, $referenceNumber, null, null, null, null, null)), $this->equalTo($this->fakeUser))->will($this->returnValue($pageableReservations));
     $this->resourceRepository->expects($this->at(0))->method('LoadById')->with(1)->will($this->returnValue($resource1));
     $this->resourceRepository->expects($this->at(2))->method('LoadById')->with(2)->will($this->returnValue($resource2));
     $this->resourceRepository->expects($this->at(1))->method('Update')->with($this->anything());
     $this->resourceRepository->expects($this->at(3))->method('Update')->with($this->anything());
     $this->presenter->UpdateResourceStatus();
     $this->assertEquals($resourceStatusId, $resource1->GetStatusId());
     $this->assertEquals($resourceStatusReasonId, $resource1->GetStatusReasonId());
 }
 public function testWhenInitializing()
 {
     $groups = array();
     $bookableResources = array();
     $schedules = array();
     $groupResult = new PageableData($groups);
     $quotaList = array();
     $this->resourceRepository->expects($this->once())->method('GetResourceList')->will($this->returnValue($bookableResources));
     $this->page->expects($this->once())->method('BindResources')->with($this->equalTo($bookableResources));
     $this->groupRepository->expects($this->once())->method('GetList')->will($this->returnValue($groupResult));
     $this->page->expects($this->once())->method('BindGroups')->with($this->equalTo($groups));
     $this->scheduleRepository->expects($this->once())->method('GetAll')->will($this->returnValue($schedules));
     $this->page->expects($this->once())->method('BindSchedules')->with($this->equalTo($schedules));
     $this->quotaRepository->expects($this->once())->method('GetAll')->will($this->returnValue($quotaList));
     $this->presenter->PageLoad();
 }
 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));
 }
 public function testMovesGroupNode()
 {
     $nodeId = 1;
     $targetId = 2;
     $nodeType = ResourceGroup::GROUP_TYPE;
     $previousNodeId = 3;
     $group = new ResourceGroup($nodeId, 'name', $previousNodeId);
     $group->MoveTo($targetId);
     $this->page->expects($this->atLeastOnce())->method('GetNodeId')->will($this->returnValue($nodeId));
     $this->page->expects($this->atLeastOnce())->method('GetTargetNodeId')->will($this->returnValue($targetId));
     $this->page->expects($this->atLeastOnce())->method('GetNodeType')->will($this->returnValue($nodeType));
     $this->page->expects($this->atLeastOnce())->method('GetPreviousNodeId')->will($this->returnValue($previousNodeId));
     $this->resourceRepository->expects($this->once())->method('LoadResourceGroup')->with($this->equalTo($nodeId))->will($this->returnValue($group));
     $this->resourceRepository->expects($this->once())->method('UpdateResourceGroup')->with($group);
     $this->presenter->MoveNode();
 }
 public function testAddsNewBlackoutTimeForSchedule()
 {
     $startDate = '1/1/2011';
     $endDate = '1/2/2011';
     $startTime = '01:30 PM';
     $endTime = '12:15 AM';
     $timezone = $this->fakeUser->Timezone;
     $dr = DateRange::Create($startDate . ' ' . $startTime, $endDate . ' ' . $endTime, $timezone);
     $title = 'out of service';
     $conflictAction = ReservationConflictResolution::Delete;
     $conflictResolution = ReservationConflictResolution::Create($conflictAction);
     $endDateString = '2012-01-01';
     $repeatType = RepeatType::Daily;
     $repeatInterval = 1;
     $repeatDays = array(1, 2);
     $repeatMonthlyType = RepeatMonthlyType::DayOfMonth;
     $roFactory = new RepeatOptionsFactory();
     $repeatEndDate = Date::Parse($endDateString, $timezone);
     $repeatOptions = $roFactory->Create($repeatType, $repeatInterval, $repeatEndDate, $repeatDays, $repeatMonthlyType);
     $this->ExpectPageToReturnCommonBlackoutInfo($startDate, $startTime, $endDate, $endTime, $title, $conflictAction);
     $this->ExpectPageToReturnRepeatInfo($repeatType, $repeatInterval, $endDateString, $repeatDays, $repeatMonthlyType);
     $scheduleId = 123;
     $this->page->expects($this->once())->method('GetBlackoutScheduleId')->will($this->returnValue($scheduleId));
     $this->page->expects($this->once())->method('GetApplyBlackoutToAllResources')->will($this->returnValue(true));
     $resources = array(new FakeBookableResource(1), new FakeBookableResource(2), new FakeBookableResource(3));
     $this->resourceRepository->expects($this->once())->method('GetScheduleResources')->with($this->equalTo($scheduleId))->will($this->returnValue($resources));
     $result = $this->getMock('IBlackoutValidationResult');
     $this->blackoutsService->expects($this->once())->method('Add')->with($this->equalTo($dr), $this->equalTo(array(1, 2, 3)), $this->equalTo($title), $this->equalTo($conflictResolution), $this->equalTo($repeatOptions))->will($this->returnValue($result));
     $this->presenter->AddBlackout();
 }
 public function testDeletesResourceType()
 {
     $id = 9919;
     $this->page->expects($this->once())->method('GetId')->will($this->returnValue($id));
     $this->resourceRepository->expects($this->once())->method('RemoveResourceType')->with($this->equalTo($id));
     $this->presenter->Delete();
 }
Exemplo n.º 10
0
 public function testFiltersResourcesWhenGettingResourceGroups()
 {
     $scheduleId = 18;
     $expectedGroups = new FakeResourceGroupTree();
     $expectedGroups->AddGroup(new ResourceGroup(1, 'g'));
     $this->resourceRepository->expects($this->once())->method('GetResourceGroups')->with($this->equalTo($scheduleId), $this->anything())->will($this->returnValue($expectedGroups));
     $groups = $this->resourceService->GetResourceGroups($scheduleId, $this->fakeUser);
     $this->assertEquals($expectedGroups, $groups);
 }
 public function testFiltersByGroupId()
 {
     $scheduleId = 122;
     $groupId = 10;
     $resourceId = 4;
     $groups = $this->getMock('ResourceGroupTree');
     $resource1 = new FakeBookableResource(1, 'resource1');
     $resource2 = new FakeBookableResource(2, 'resource2');
     $resource3 = new FakeBookableResource(3, 'resource3');
     $resource4 = new FakeBookableResource($resourceId, 'resource4');
     $resources = array($resource1, $resource2, $resource3, $resource4);
     $this->resourceRepository->expects($this->once())->method('GetResourceGroups')->with($this->equalTo($scheduleId))->will($this->returnValue($groups));
     $groups->expects($this->once())->method('GetResourceIds')->with($this->equalTo($groupId))->will($this->returnValue(array($resourceId)));
     $filter = new ScheduleResourceFilter($scheduleId);
     $filter->GroupId = $groupId;
     $resourceIds = $filter->FilterResources($resources, $this->resourceRepository, $this->attributeService);
     $this->assertEquals(1, count($resourceIds));
     $this->assertEquals($resourceId, $resourceIds[0]);
 }
 public function testDeletesResource()
 {
     $resourceId = 998;
     $resource = new FakeBookableResource($resourceId);
     $this->validator->expects($this->once())->method('ValidateDeleteRequest')->with($this->equalTo($resourceId))->will($this->returnValue(array()));
     $this->repository->expects($this->once())->method('LoadById')->with($this->equalTo($resourceId))->will($this->returnValue($resource));
     $this->repository->expects($this->once())->method('Delete')->with($this->equalTo($resource));
     $response = $this->controller->Delete($resourceId, $this->session);
     $this->assertTrue($response->WasSuccessful());
     $this->assertEquals($resourceId, $response->ResourceId());
     $this->assertEmpty($response->Errors());
 }
 public function testCreationBuildsReservationFromPageData()
 {
     $timezone = $this->user->Timezone;
     $userId = $this->page->GetUserId();
     $resourceId = $this->page->GetResourceId();
     $title = $this->page->GetTitle();
     $description = $this->page->GetDescription();
     $startDate = $this->page->GetStartDate();
     $endDate = $this->page->GetEndDate();
     $startTime = $this->page->GetStartTime();
     $endTime = $this->page->GetEndTime();
     $additionalResources = $this->page->GetResources();
     $pageAccessories = $this->page->GetAccessories();
     $pageAttributes = $this->page->GetAttributes();
     $roFactory = new RepeatOptionsFactory();
     $repeatOptions = $roFactory->CreateFromComposite($this->page, $timezone);
     $participants = $this->page->GetParticipants();
     $invitees = $this->page->GetInvitees();
     $attachment = new FakeUploadedFile();
     $this->page->attachment = $attachment;
     $resource = new FakeBookableResource($resourceId, 'r1');
     $additionalResource1 = new FakeBookableResource($additionalResources[0], 'r2');
     $additionalResource2 = new FakeBookableResource($additionalResources[1], 'r3');
     $accessories = array();
     foreach ($pageAccessories as $pa) {
         $accessories[] = new ReservationAccessory($pa->Id, $pa->Quantity, $pa->Name);
     }
     $expectedAttributes = array();
     foreach ($pageAttributes as $attr) {
         $expectedAttributes[] = new AttributeValue($attr->Id, $attr->Value);
     }
     $startReminder = new ReservationReminder($this->page->GetStartReminderValue(), $this->page->GetStartReminderInterval());
     $endReminder = new ReservationReminder($this->page->GetEndReminderValue(), $this->page->GetEndReminderInterval());
     $this->resourceRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($resourceId))->will($this->returnValue($resource));
     $this->resourceRepository->expects($this->at(1))->method('LoadById')->with($this->equalTo($additionalResources[0]))->will($this->returnValue($additionalResource1));
     $this->resourceRepository->expects($this->at(2))->method('LoadById')->with($this->equalTo($additionalResources[1]))->will($this->returnValue($additionalResource2));
     $duration = DateRange::Create($startDate . ' ' . $startTime, $endDate . ' ' . $endTime, $timezone);
     $actualReservation = $this->presenter->BuildReservation();
     $this->assertEquals($userId, $actualReservation->UserId());
     $this->assertEquals($resourceId, $actualReservation->ResourceId());
     $this->assertEquals($title, $actualReservation->Title());
     $this->assertEquals($description, $actualReservation->Description());
     $this->assertEquals($duration, $actualReservation->CurrentInstance()->Duration());
     $this->assertEquals($repeatOptions, $actualReservation->RepeatOptions());
     $this->assertEquals($participants, $actualReservation->CurrentInstance()->AddedParticipants());
     $this->assertEquals($invitees, $actualReservation->CurrentInstance()->AddedInvitees());
     $this->assertEquals($accessories, $actualReservation->Accessories());
     $this->assertTrue(in_array($expectedAttributes[0], $actualReservation->AttributeValues()));
     $expectedAttachment = ReservationAttachment::Create($attachment->OriginalName(), $attachment->MimeType(), $attachment->Size(), $attachment->Contents(), $attachment->Extension(), 0);
     $this->assertEquals(array($expectedAttachment), $actualReservation->AddedAttachments());
     $this->assertEquals($startReminder, $actualReservation->GetStartReminder());
     $this->assertEquals($endReminder, $actualReservation->GetEndReminder());
 }
 public function testUsesFirstAdditionalResourceIfPrimaryIsRemoved()
 {
     $referenceNumber = $this->page->existingReferenceNumber;
     $builder = new ExistingReservationSeriesBuilder();
     $builder->WithPrimaryResource(new FakeBookableResource(100));
     $expectedSeries = $builder->Build();
     $additionalId = 5;
     $this->page->resourceId = null;
     $this->page->resourceIds = array($additionalId);
     $resource = new FakeBookableResource($additionalId);
     $this->persistenceService->expects($this->once())->method('LoadByReferenceNumber')->with($this->equalTo($referenceNumber))->will($this->returnValue($expectedSeries));
     $this->resourceRepository->expects($this->once())->method('LoadById')->with($this->equalTo($additionalId))->will($this->returnValue($resource));
     $existingSeries = $this->presenter->BuildReservation();
     $this->assertEquals($resource, $existingSeries->Resource());
 }
Exemplo n.º 15
0
 public function testGetsSingleResourceAvailabilityForARequestTime()
 {
     $date = Date::Parse('2014-01-01 04:30:00', 'America/Chicago');
     $this->server->SetQueryString(WebServiceQueryStringKeys::DATE_TIME, $date->ToIso());
     $resourceId1 = 1;
     $startTime = $date->AddHours(-1);
     $endTime = $date->AddHours(1);
     $resource = new FakeBookableResource($resourceId1);
     $this->repository->expects($this->once())->method('LoadById')->with($this->equalTo($resourceId1))->will($this->returnValue($resource));
     $conflicting = new TestReservationItemView(1, $startTime, $endTime, $resourceId1);
     $upcoming = new TestReservationItemView(2, $endTime, $endTime->AddHours(3), $resourceId1);
     $upcoming2 = new TestReservationItemView(3, $endTime->AddHours(3), $endTime->AddHours(4), $resourceId1);
     $upcoming3 = new TestReservationItemView(4, $endTime->AddHours(5), $endTime->AddHours(6), $resourceId1);
     $reservations = array($conflicting, $upcoming, $upcoming2, $upcoming3);
     $endDate = $date->AddDays(7);
     $this->reservationRepository->expects($this->once())->method('GetReservationList')->with($this->equalTo($date->AddDays(-1)->ToUtc()), $this->equalTo($endDate->ToUtc()), $this->isEmpty(), $this->isEmpty(), $this->isEmpty(), $this->equalTo($resourceId1))->will($this->returnValue($reservations));
     $this->service->GetAvailability($resourceId1);
     $resources = array(new ResourceAvailabilityResponse($this->server, $resource, $conflicting, $upcoming, $endTime->AddHours(4), $endDate));
     $this->assertEquals(new ResourcesAvailabilityResponse($this->server, $resources), $this->server->_LastResponse);
 }