public function setup()
 {
     parent::setup();
     $this->rule = new ResourceParticipationRule();
     $this->resourceLimit10 = new FakeBookableResource(1, 'name1');
     $this->resourceLimit10->SetMaxParticipants(10);
     $this->resourceLimit20 = new FakeBookableResource(2, 'name2');
     $this->resourceLimit20->SetMaxParticipants(20);
 }
 public function testGetsResourceById()
 {
     $resourceId = 8282;
     $resource = new FakeBookableResource($resourceId);
     $resource->SetBufferTime(3600);
     $attributes = new AttributeList();
     $this->repository->expects($this->once())->method('LoadById')->with($this->equalTo($resourceId))->will($this->returnValue($resource));
     $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::RESOURCE), $this->equalTo(array($resourceId)))->will($this->returnValue($attributes));
     $this->service->GetResource($resourceId);
     $this->assertEquals(new ResourceResponse($this->server, $resource, $attributes), $this->server->_LastResponse);
 }
 public function testDoesNotMarkAsRequiringApprovalIfUserCanApproveForResource()
 {
     $series = new TestReservationSeries();
     $resource = new FakeBookableResource(1);
     $resource->RequiresApproval(true);
     $series->WithResource($resource);
     $series->WithBookedBy($this->fakeUser);
     $this->authorizationService->expects($this->once())->method('CanApproveForResource')->with($this->equalTo($this->fakeUser), $this->equalTo($resource))->will($this->returnValue(true));
     $this->rule->Validate($series);
     $this->assertFalse($series->RequiresApproval());
 }
 public function testIsNotValidWhenTurnedOffForResource()
 {
     $resource = new FakeBookableResource(12);
     $resource->DisableSubscription();
     $publicId = uniqid();
     $this->page->expects($this->once())->method('GetResourceId')->will($this->returnValue($publicId));
     $this->subscriptionService->expects($this->once())->method('GetResource')->with($this->equalTo($publicId))->will($this->returnValue($resource));
     $this->StubSubscriptionKey();
     $isValid = $this->validator->IsValid();
     $this->assertFalse($isValid);
 }
 public function testOkIfLatestInstanceIsBeforeTheMaximumNoticeTime()
 {
     $resource = new FakeBookableResource(1, "2");
     $resource->SetMaxNotice("1h00m");
     $reservation = new TestReservationSeries();
     $reservation->WithResource($resource);
     $duration = new DateRange(Date::Now(), Date::Now());
     $reservation->WithDuration($duration);
     $rule = new ResourceMaximumNoticeRule();
     $result = $rule->Validate($reservation);
     $this->assertTrue($result->IsValid());
 }
 public function testOkIfReservationIsShorterThanTheMaximumDuration()
 {
     $resource = new FakeBookableResource(1, "2");
     $resource->SetMaxLength("25h00m");
     $reservation = new TestReservationSeries();
     $reservation->WithResource($resource);
     $duration = new DateRange(Date::Now(), Date::Now()->AddDays(1));
     $reservation->WithDuration($duration);
     $rule = new ResourceMaximumDurationRule();
     $result = $rule->Validate($reservation);
     $this->assertTrue($result->IsValid());
 }
Exemplo n.º 7
0
 public function testSucceedsWhenStartAndEndTimeMatchPeriods()
 {
     $date = Date::Now();
     $dates = new DateRange($date, $date);
     $scheduleId = 1232;
     $resource = new FakeBookableResource(1);
     $resource->SetScheduleId($scheduleId);
     $series = ReservationSeries::Create(1, $resource, null, null, $dates, new RepeatNone(), $this->fakeUser);
     $this->scheduleRepository->expects($this->once())->method('GetLayout')->with($this->equalTo($scheduleId), $this->equalTo(new ScheduleLayoutFactory($this->fakeUser->Timezone)))->will($this->returnValue($this->layout));
     $period = new SchedulePeriod($date, $date);
     $this->layout->expects($this->at(0))->method('GetPeriod')->with($this->equalTo($series->CurrentInstance()->StartDate()))->will($this->returnValue($period));
     $this->layout->expects($this->at(1))->method('GetPeriod')->with($this->equalTo($series->CurrentInstance()->EndDate()))->will($this->returnValue($period));
     $result = $this->rule->Validate($series);
     $this->assertTrue($result->IsValid());
 }
 public function testDoesNotUpdateResourceIfUserDoesNotHaveAccess()
 {
     $user = $this->getMock('User');
     $this->userRepository->expects($this->once())->method('LoadById')->with($this->equalTo($this->fakeUser->UserId))->will($this->returnValue($user));
     $repo = new ResourceAdminResourceRepository($this->userRepository, $this->fakeUser);
     $resource = new FakeBookableResource(1);
     $resource->SetAdminGroupId(2);
     $user->expects($this->at(0))->method('IsResourceAdminFor')->with($this->equalTo($resource))->will($this->returnValue(false));
     $actualEx = null;
     try {
         $repo->Update($resource);
     } catch (Exception $ex) {
         $actualEx = $ex;
     }
     $this->assertNotEmpty($actualEx, "should have thrown an exception");
 }
 public function testRuleIsInValidIfReservationCrossesDayInScheduleTimezone()
 {
     $start = Date::Now();
     $end = Date::Now()->AddDays(1);
     $reservation = new TestReservationSeries();
     $reservation->WithCurrentInstance(new TestReservation('1', new DateRange($start, $end)));
     $resource = new FakeBookableResource(1);
     $resource->SetAllowMultiday(true);
     $resource2 = new FakeBookableResource(2);
     $resource2->SetAllowMultiday(false);
     $reservation->WithResource($resource);
     $reservation->AddResource($resource2);
     $this->scheduleRepository->expects($this->once())->method('LoadById')->with($this->equalTo($reservation->ScheduleId()))->will($this->returnValue($this->schedule));
     $rule = new ResourceCrossDayRule($this->scheduleRepository);
     $result = $rule->Validate($reservation);
     $this->assertFalse($result->IsValid());
 }
 public function testGetsConflictingReservationTimesForSingleDateSingleResourceWithBufferTimes()
 {
     $startDate = Date::Parse('2010-04-04 06:00', 'UTC');
     $endDate = Date::Parse('2010-04-04 07:00', 'UTC');
     $bufferTime = 60 * 60;
     $reservation = new TestReservationSeries();
     $resource1 = new FakeBookableResource(100, null);
     $resource1->SetBufferTime($bufferTime);
     $reservation->WithDuration(new DateRange($startDate, $endDate));
     $reservation->WithResource($resource1);
     $conflict1 = new TestReservationItemView(2, Date::Parse('2010-04-04 04:00', 'UTC'), Date::Parse('2010-04-04 05:30', 'UTC'), $resource1->GetId());
     $conflict1->WithBufferTime($bufferTime);
     $conflict2 = new TestReservationItemView(3, Date::Parse('2010-04-04 07:30', 'UTC'), Date::Parse('2010-04-04 08:00', 'UTC'), $resource1->GetId());
     $conflict2->WithBufferTime($bufferTime);
     $nonConflict1 = new TestReservationItemView(4, Date::Parse('2010-04-04 06:00', 'UTC'), Date::Parse('2010-04-04 07:30', 'UTC'), 2);
     $nonConflict1->WithBufferTime($bufferTime);
     $nonConflict2 = new TestReservationItemView(5, Date::Parse('2010-04-04 02:30', 'UTC'), Date::Parse('2010-04-04 05:00', 'UTC'), $resource1->GetId());
     $nonConflict2->WithBufferTime($bufferTime);
     $nonConflict3 = new TestReservationItemView(6, Date::Parse('2010-04-04 08:00', 'UTC'), Date::Parse('2010-04-04 09:00', 'UTC'), $resource1->GetId());
     $nonConflict3->WithBufferTime($bufferTime);
     $strategy = $this->getMock('IResourceAvailabilityStrategy');
     $strategy->expects($this->once())->method('GetItemsBetween')->with($this->equalTo($startDate->AddMinutes(-60)), $this->equalTo($endDate->AddMinutes(60)))->will($this->returnValue(array($conflict1, $conflict2, $nonConflict1, $nonConflict2, $nonConflict3)));
     $rule = new ExistingResourceAvailabilityRule($strategy, 'UTC');
     $result = $rule->Validate($reservation);
     $this->assertFalse($result->IsValid());
 }
 public function testApplicationAdminsAreExcludedFromBufferConstraints()
 {
     $startDate = Date::Parse('2010-04-04 06:00', 'UTC');
     $endDate = Date::Parse('2010-04-04 07:00', 'UTC');
     $bufferTime = 60 * 60;
     $reservation = new TestReservationSeries();
     $resource1 = new FakeBookableResource(100, null);
     $resource1->SetBufferTime($bufferTime);
     $reservation->WithDuration(new DateRange($startDate, $endDate));
     $reservation->WithResource($resource1);
     $reservation->WithBookedBy(new FakeUserSession(true));
     $conflict1 = new TestReservationItemView(2, Date::Parse('2010-04-04 04:00', 'UTC'), Date::Parse('2010-04-04 06:00', 'UTC'), $resource1->GetId());
     $conflict1->WithBufferTime($bufferTime);
     $strategy = $this->getMock('IResourceAvailabilityStrategy');
     $strategy->expects($this->once())->method('GetItemsBetween')->with($this->equalTo($startDate), $this->equalTo($endDate))->will($this->returnValue(array($conflict1)));
     $rule = new ResourceAvailabilityRule($strategy, 'UTC');
     $result = $rule->Validate($reservation);
     $this->assertTrue($result->IsValid());
 }
Exemplo n.º 12
0
 public function testChecksStatusOfEachResourceWhenGettingAll()
 {
     $scheduleId = 100;
     $session = $this->fakeUser;
     $user = new FakeUser();
     $user->_IsResourceAdmin = false;
     $resource1 = new FakeBookableResource(1, 'resource1');
     $resource1->ChangeStatus(ResourceStatus::UNAVAILABLE);
     $resources = array($resource1);
     $this->resourceRepository->expects($this->any())->method('GetScheduleResources')->with($this->equalTo($scheduleId))->will($this->returnValue($resources));
     $this->permissionService->expects($this->at(0))->method('CanAccessResource')->with($this->equalTo($resource1), $this->equalTo($session))->will($this->returnValue(true));
     $this->userRepository->expects($this->any())->method('LoadById')->with($this->equalTo($session->UserId))->will($this->returnValue($user));
     $resourceDto1 = new ResourceDto(1, 'resource1', false, $resource1->GetScheduleId(), $resource1->GetMinLength());
     $expected = array($resourceDto1);
     $actualInclusive = $this->resourceService->GetScheduleResources($scheduleId, true, $session);
     $this->assertEquals($expected, $actualInclusive);
     $actualExcluded = $this->resourceService->GetScheduleResources($scheduleId, false, $session);
     $this->assertEquals(array(), $actualExcluded);
 }
 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.º 14
0
 public function testWhenUserIsInAdminGroupForResourcesSchedule()
 {
     $adminGroupId = 223;
     $resource = new FakeBookableResource(1, 'n');
     $resource->SetScheduleAdminGroupId($adminGroupId);
     $adminUser = new User();
     $regularUser = new User();
     $adminGroup = new UserGroup($adminGroupId, 'admin', null, RoleLevel::SCHEDULE_ADMIN);
     $group1 = new UserGroup(1, 'random group');
     $group2 = new UserGroup(2, 'group with admin');
     $adminUserGroups = array($group1, $adminGroup);
     $userGroups = array($group1, $group2);
     $adminUser->WithGroups($adminUserGroups);
     $regularUser->WithGroups($userGroups);
     $this->assertTrue($adminUser->IsResourceAdminFor($resource));
     $this->assertFalse($regularUser->IsResourceAdminFor($resource));
 }
 public function testWhenUserJoinsAllAndThereIsNotSpace()
 {
     $invitationAction = InvitationAction::JoinAll;
     $currentUserId = 1029;
     $referenceNumber = 'abc123';
     $builder = new ExistingReservationSeriesBuilder();
     $instance = new TestReservation();
     $instance->WithParticipants(array(1));
     $instance->WithInvitee($currentUserId);
     $resource = new FakeBookableResource(1);
     $resource->SetMaxParticipants(1);
     $builder->WithCurrentInstance($instance)->WithPrimaryResource($resource);
     $series = $builder->Build();
     $this->page->expects($this->once())->method('GetResponseType')->will($this->returnValue('json'));
     $this->page->expects($this->once())->method('GetInvitationAction')->will($this->returnValue($invitationAction));
     $this->page->expects($this->once())->method('GetInvitationReferenceNumber')->will($this->returnValue($referenceNumber));
     $this->page->expects($this->once())->method('GetUserId')->will($this->returnValue($currentUserId));
     $this->reservationRepo->expects($this->once())->method('LoadByReferenceNumber')->with($this->equalTo($referenceNumber))->will($this->returnValue($series));
     $this->page->expects($this->once())->method('DisplayResult')->with($this->stringContains('ParticipationNotAllowed'));
     $this->presenter->PageLoad();
 }
Exemplo n.º 16
0
 public function testFirstQuotaExceeded()
 {
     $scheduleId = 971243;
     $timezone = 'America/New_York';
     $userId = 10;
     $groupId1 = 8287;
     $groupId2 = 102;
     $user = new FakeUser();
     $user->SetGroups(array($groupId1, $groupId2));
     $schedule = new Schedule(1, null, null, null, null, $timezone);
     $resource = new FakeBookableResource(20);
     $resource->SetScheduleId($scheduleId);
     $series = ReservationSeries::Create($userId, $resource, null, null, new TestDateRange(), new RepeatNone(), new FakeUserSession());
     $series->AddResource(new FakeBookableResource(22));
     $quota1 = $this->mockQuota('IQuota');
     $quota2 = $this->mockQuota('IQuota');
     $quotas = array($quota1, $quota2);
     $this->quotaRepository->expects($this->once())->method('LoadAll')->will($this->returnValue($quotas));
     $this->userRepository->expects($this->once())->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user));
     $this->scheduleRepository->expects($this->once())->method('LoadById')->with($this->equalTo($scheduleId))->will($this->returnValue($schedule));
     $this->ChecksAgainstQuota($quota1, $series, $this->reservationViewRepository, $schedule, $user, true);
     $quota2->expects($this->never())->method('ExceedsQuota');
     $rule = new QuotaRule($this->quotaRepository, $this->reservationViewRepository, $this->userRepository, $this->scheduleRepository);
     $result = $rule->Validate($series);
     $this->assertFalse($result->IsValid(), 'first quotas was exceeded');
 }
 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());
 }
Exemplo n.º 18
0
 private function GetHourLongReservation($startDate, $endDate, $resourceId1 = null, $resourceId2 = null, $scheduleId = null)
 {
     $userId = 12;
     $resource1 = empty($resourceId1) ? 13 : $resourceId1;
     $resource2 = empty($resourceId2) ? 14 : $resourceId2;
     $schedule = empty($scheduleId) ? 1 : $scheduleId;
     $hourLongReservation = new DateRange($startDate, $endDate, $this->tz);
     $resource = new FakeBookableResource($resource1);
     $resource->SetScheduleId($schedule);
     $series = ReservationSeries::Create($userId, $resource, null, null, $hourLongReservation, new RepeatNone(), new FakeUserSession());
     $series->AddResource(new FakeBookableResource($resource2));
     return $series;
 }
Exemplo n.º 19
0
 public function testUpdatesAttributes()
 {
     $id = 11;
     $unchanged = new AttributeValue(1, 'value');
     $toChange = new AttributeValue(2, 'value');
     $toAdd = new AttributeValue(3, 'value');
     $resource = new FakeBookableResource($id);
     $resource->WithAttribute($unchanged);
     $resource->WithAttribute(new AttributeValue(100, 'should be removed'));
     $resource->WithAttribute(new AttributeValue(2, 'new value'));
     $attributes = array($unchanged, $toChange, $toAdd);
     $resource->ChangeAttributes($attributes);
     $this->repository->Update($resource);
     $addNewCommand = new AddAttributeValueCommand($toAdd->AttributeId, $toAdd->Value, $id, CustomAttributeCategory::RESOURCE);
     $removeOldCommand = new RemoveAttributeValueCommand(100, $id);
     $removeUpdated = new RemoveAttributeValueCommand($toChange->AttributeId, $id);
     $addUpdated = new AddAttributeValueCommand($toChange->AttributeId, $toChange->Value, $id, CustomAttributeCategory::RESOURCE);
     $this->assertEquals($removeOldCommand, $this->db->_Commands[1]);
     $this->assertEquals($removeUpdated, $this->db->_Commands[2], "need to remove before adding to make sure changed values are not immediately deleted");
     $this->assertEquals($addUpdated, $this->db->_Commands[3]);
     $this->assertEquals($addNewCommand, $this->db->_Commands[4]);
 }