public function testLoadsExistingReservationAndUpdatesData() { $seriesId = 109809; $expectedSeries = new ExistingReservationSeries(); $currentDuration = new DateRange(Date::Now()->AddDays(1), Date::Now()->AddDays(2), 'UTC'); $removedResourceId = 190; $resource = new FakeBookableResource(1); $additionalId1 = $this->page->resourceIds[0]; $additionalId2 = $this->page->resourceIds[1]; $additional1 = new FakeBookableResource($additionalId1); $additional2 = new FakeBookableResource($additionalId2); $reservation = new Reservation($expectedSeries, $currentDuration); $expectedSeries->WithId($seriesId); $expectedSeries->WithCurrentInstance($reservation); $expectedSeries->WithPrimaryResource($resource); $expectedSeries->WithResource(new FakeBookableResource($removedResourceId)); $expectedSeries->WithAttribute(new AttributeValue(100, 'to be removed')); $referenceNumber = $this->page->existingReferenceNumber; $timezone = $this->user->Timezone; $this->persistenceService->expects($this->once())->method('LoadByReferenceNumber')->with($this->equalTo($referenceNumber))->will($this->returnValue($expectedSeries)); $this->resourceRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($this->page->resourceId))->will($this->returnValue($resource)); $this->resourceRepository->expects($this->at(1))->method('LoadById')->with($this->equalTo($additionalId1))->will($this->returnValue($additional1)); $this->resourceRepository->expects($this->at(2))->method('LoadById')->with($this->equalTo($additionalId2))->will($this->returnValue($additional2)); $this->page->repeatType = RepeatType::Daily; $roFactory = new RepeatOptionsFactory(); $repeatOptions = $roFactory->CreateFromComposite($this->page, $this->user->Timezone); $expectedDuration = DateRange::Create($this->page->GetStartDate() . " " . $this->page->GetStartTime(), $this->page->GetEndDate() . " " . $this->page->GetEndTime(), $timezone); $attachment = new FakeUploadedFile(); $this->page->attachment = $attachment; $this->page->hasEndReminder = false; $existingSeries = $this->presenter->BuildReservation(); $expectedAccessories = array(new ReservationAccessory(1, 2, 'accessoryname')); $expectedAttributes = array(1 => new AttributeValue(1, 'something')); $this->assertEquals($seriesId, $existingSeries->SeriesId()); $this->assertEquals($this->page->seriesUpdateScope, $existingSeries->SeriesUpdateScope()); $this->assertEquals($this->page->title, $existingSeries->Title()); $this->assertEquals($this->page->description, $existingSeries->Description()); $this->assertEquals($this->page->userId, $existingSeries->UserId()); $this->assertEquals($resource, $existingSeries->Resource()); $this->assertEquals($repeatOptions, $existingSeries->RepeatOptions()); $this->assertEquals(array($additional1, $additional2), $existingSeries->AdditionalResources()); $this->assertEquals($this->page->participants, $existingSeries->CurrentInstance()->AddedParticipants()); $this->assertEquals($this->page->invitees, $existingSeries->CurrentInstance()->AddedInvitees()); $this->assertTrue($expectedDuration->Equals($existingSeries->CurrentInstance()->Duration()), "Expected: {$expectedDuration} Actual: {$existingSeries->CurrentInstance()->Duration()}"); $this->assertEquals($this->user, $expectedSeries->BookedBy()); $this->assertEquals($expectedAccessories, $existingSeries->Accessories()); $this->assertEquals($expectedAttributes, $existingSeries->AttributeValues()); $expectedAttachment = ReservationAttachment::Create($attachment->OriginalName(), $attachment->MimeType(), $attachment->Size(), $attachment->Contents(), $attachment->Extension(), $seriesId); $this->assertEquals(array($expectedAttachment), $expectedSeries->AddedAttachments()); $this->assertEquals($this->page->removedFileIds, $existingSeries->RemovedAttachmentIds()); $this->assertEquals(new ReservationReminder($this->page->GetStartReminderValue(), $this->page->GetStartReminderInterval()), $existingSeries->GetStartReminder()); $this->assertEquals(ReservationReminder::None(), $existingSeries->GetEndReminder()); }
/** * @return ExistingReservationSeries */ public function Build() { $this->series->WithId($this->id); $this->series->WithCurrentInstance($this->currentInstance); $this->series->WithRepeatOptions($this->repeatOptions); foreach ($this->instances as $reservation) { $this->series->WithInstance($reservation); } foreach ($this->events as $event) { $this->series->AddEvent($event); } $this->series->WithPrimaryResource($this->resource); $this->series->Update(1, $this->resource, 'title', 'description', $this->bookedBy); return $this->series; }
/** * @param IReader $reader * @return ExistingReservationSeries */ private function BuildSeries($reader) { $series = new ExistingReservationSeries(); if ($row = $reader->GetRow()) { $repeatType = $row[ColumnNames::REPEAT_TYPE]; $configurationString = $row[ColumnNames::REPEAT_OPTIONS]; $repeatOptions = $this->BuildRepeatOptions($repeatType, $configurationString); $series->WithRepeatOptions($repeatOptions); $seriesId = $row[ColumnNames::SERIES_ID]; $title = $row[ColumnNames::RESERVATION_TITLE]; $description = $row[ColumnNames::RESERVATION_DESCRIPTION]; $series->WithId($seriesId); $series->WithTitle($title); $series->WithDescription($description); $series->WithOwner($row[ColumnNames::RESERVATION_OWNER]); $series->WithStatus($row[ColumnNames::RESERVATION_STATUS]); $series->AllowParticipation($row[ColumnNames::RESERVATION_ALLOW_PARTICIPATION]); $startDate = Date::FromDatabase($row[ColumnNames::RESERVATION_START]); $endDate = Date::FromDatabase($row[ColumnNames::RESERVATION_END]); $duration = new DateRange($startDate, $endDate); $instance = new Reservation($series, $duration, $row[ColumnNames::RESERVATION_INSTANCE_ID], $row[ColumnNames::REFERENCE_NUMBER]); $series->WithCurrentInstance($instance); } $reader->Free(); return $series; }
public function testNoConflictsIfReservationExistsAtSameTimeForDifferentResource() { $resourceId1 = 1; $resourceId2 = 2; $resourceId3 = 3; $currentId = 19; $currentDate = new DateRange(Date::Now()->AddDays(10), Date::Now()->AddDays(15)); $current = new TestReservation('ref', $currentDate); $current->SetReservationId($currentId); $series = new ExistingReservationSeries(); $series->WithPrimaryResource(new FakeBookableResource($resourceId1)); $series->WithResource(new FakeBookableResource($resourceId2)); $series->WithCurrentInstance($current); $reservations = array(new TestReservationItemView($currentId + 1, Date::Now(), Date::Now(), $resourceId3)); $this->strategy->expects($this->once())->method('GetItemsBetween')->with($this->anything(), $this->anything())->will($this->returnValue($reservations)); $rule = new ExistingResourceAvailabilityRule($this->strategy, $this->timezone); $ruleResult = $rule->Validate($series); $this->assertTrue($ruleResult->IsValid()); }
public function testLoadByIdFullyHydratesReservationSeriesObject() { $seriesId = 10; $reservationId = 1; $referenceNumber = 'currentInstanceRefNum'; $ownerId = 10; $resourceId = 100; $scheduleId = 1000; $title = 'title'; $description = 'description'; $resourceId1 = 99; $resourceId2 = 999; $begin = '2010-01-05 12:30:00'; $end = '2010-01-05 18:30:00'; $duration = DateRange::Create($begin, $end, 'UTC'); $interval = 3; $repeatType = RepeatType::Daily; $terminationDateString = '2010-01-20 12:30:00'; $terminationDate = Date::FromDatabase($terminationDateString); $repeatOptions = new RepeatDaily($interval, $terminationDate); $instance1Invitees = array(1, 2, 3); $instance1Participants = array(4, 5); $instance2Invitees = array(6); $instance2Participants = array(7, 8, 9); $resourceName = 'primary resource'; $location = 'l'; $contact = 'c'; $notes = 'notes'; $minLength = '3:00'; $maxLength = null; $autoAssign = true; $requiresApproval = false; $allowMultiDay = true; $maxParticipants = 100; $minNotice = '2:10'; $maxNotice = null; $statusId = ReservationStatus::Pending; $accessoryId1 = 8111; $accessoryId2 = 8222; $quantity1 = 11; $quantity2 = 22; $attributeId1 = 908; $attributeValue1 = 'custom1'; $attributeId2 = 999; $attributeValue2 = 'custom2'; $fileId = 100; $startReminderMinutes = 25; $endReminderMinutes = 120; $allowParticipation = true; $expected = new ExistingReservationSeries(); $expected->WithId($seriesId); $expected->WithOwner($ownerId); $expected->WithPrimaryResource(new BookableResource($resourceId, $resourceName, $location, $contact, $notes, $minLength, $maxLength, $autoAssign, $requiresApproval, $allowMultiDay, $maxParticipants, $minNotice, $maxNotice, null, $scheduleId)); $expected->WithTitle($title); $expected->WithDescription($description); $expected->WithResource(new BookableResource($resourceId1, $resourceName, $location, $contact, $notes, $minLength, $maxLength, $autoAssign, $requiresApproval, $allowMultiDay, $maxParticipants, $minNotice, $maxNotice, null, $scheduleId)); $expected->WithResource(new BookableResource($resourceId2, $resourceName, $location, $contact, $notes, $minLength, $maxLength, $autoAssign, $requiresApproval, $allowMultiDay, $maxParticipants, $minNotice, $maxNotice, null, $scheduleId)); $expected->WithRepeatOptions($repeatOptions); $expected->WithStatus($statusId); $expected->WithAccessory(new ReservationAccessory($accessoryId1, $quantity1)); $expected->WithAccessory(new ReservationAccessory($accessoryId2, $quantity2)); $expected->WithAttribute(new AttributeValue($attributeId1, $attributeValue1)); $expected->WithAttribute(new AttributeValue($attributeId2, $attributeValue2)); $expected->WithAttachment($fileId, 'doc'); $expected->AllowParticipation($allowParticipation); $instance1 = new Reservation($expected, $duration->AddDays(10)); $instance1->SetReferenceNumber('instance1'); $instance1->SetReservationId(909); $instance1->WithInvitees($instance1Invitees); $instance1->WithParticipants($instance1Participants); $instance2 = new Reservation($expected, $duration->AddDays(20)); $instance2->SetReferenceNumber('instance2'); $instance2->SetReservationId(1909); $instance2->WithInvitees($instance2Invitees); $instance2->WithParticipants($instance2Participants); $expected->WithInstance($instance1); $expected->WithInstance($instance2); $expectedInstance = new Reservation($expected, $duration); $expectedInstance->SetReferenceNumber($referenceNumber); $expectedInstance->SetReservationId($reservationId); $expected->WithCurrentInstance($expectedInstance); $expected->WithStartReminder(new ReservationReminder($startReminderMinutes, ReservationReminderInterval::Minutes)); $expected->WithEndReminder(new ReservationReminder($endReminderMinutes / 60, ReservationReminderInterval::Hours)); $reservationRow = new ReservationRow($reservationId, $begin, $end, $title, $description, $repeatType, $repeatOptions->ConfigurationString(), $referenceNumber, $seriesId, $ownerId, $statusId, $allowParticipation); $reservationInstanceRow = new ReservationInstanceRow($seriesId); $reservationInstanceRow->WithInstance($instance1->ReservationId(), $instance1->ReferenceNumber(), $instance1->Duration())->WithInstance($instance2->ReservationId(), $instance2->ReferenceNumber(), $instance2->Duration())->WithInstance($reservationId, $expectedInstance->ReferenceNumber(), $expectedInstance->Duration()); $reservationResourceRow = new ReservationResourceRow($reservationId, $resourceName, $location, $contact, $notes, $minLength, $maxLength, $autoAssign, $requiresApproval, $allowMultiDay, $maxParticipants, $minNotice, $maxNotice, $scheduleId); $reservationResourceRow->WithPrimary($resourceId)->WithAdditional($resourceId1)->WithAdditional($resourceId2); $reservationUserRow = new ReservationUserRow(); $reservationUserRow->WithParticipants($instance1, $instance1Participants)->WithParticipants($instance2, $instance2Participants)->WithInvitees($instance1, $instance1Invitees)->WithInvitees($instance2, $instance2Invitees); $reservationAccessoryRow = new ReservationAccessoryRow(); $reservationAccessoryRow->WithAccessory($accessoryId1, $quantity1)->WithAccessory($accessoryId2, $quantity2); $attributeValueRow = new CustomAttributeValueRow(); $attributeValueRow->With($attributeId1, $attributeValue1)->With($attributeId2, $attributeValue2); $attachmentRow = new ReservationAttachmentItemRow(); $attachmentRow->With($fileId, $seriesId, null, 'doc'); $reminderRow = new ReservationReminderRow(); $reminderRow->With(1, $seriesId, $startReminderMinutes, ReservationReminderType::Start)->With(2, $seriesId, $endReminderMinutes, ReservationReminderType::End); $this->db->SetRow(0, $reservationRow->Rows()); $this->db->SetRow(1, $reservationInstanceRow->Rows()); $this->db->SetRow(2, $reservationResourceRow->Rows()); $this->db->SetRow(3, $reservationUserRow->Rows()); $this->db->SetRow(4, $reservationAccessoryRow->Rows()); $this->db->SetRow(5, $attributeValueRow->Rows()); $this->db->SetRow(6, $attachmentRow->Rows()); $this->db->SetRow(7, $reminderRow->Rows()); $actualReservation = $this->repository->LoadById($reservationId); $this->assertEquals($expected, $actualReservation); $getReservation = new GetReservationByIdCommand($reservationId); $getInstances = new GetReservationSeriesInstances($seriesId); $getResources = new GetReservationResourcesCommand($seriesId); $getParticipants = new GetReservationSeriesParticipantsCommand($seriesId); $getAccessories = new GetReservationAccessoriesCommand($seriesId); $getAttributeValues = new GetAttributeValuesCommand($seriesId, CustomAttributeCategory::RESERVATION); $getAttachments = new GetReservationAttachmentsCommand($seriesId); $getReminders = new GetReservationReminders($seriesId); $this->assertTrue($this->db->ContainsCommand($getReservation)); $this->assertTrue($this->db->ContainsCommand($getInstances)); $this->assertTrue($this->db->ContainsCommand($getResources)); $this->assertTrue($this->db->ContainsCommand($getParticipants)); $this->assertTrue($this->db->ContainsCommand($getAccessories)); $this->assertTrue($this->db->ContainsCommand($getAttributeValues)); $this->assertTrue($this->db->ContainsCommand($getAttachments)); $this->assertTrue($this->db->ContainsCommand($getReminders)); }
public function testUpdateSingleInstanceToAnEarlierTime() { $now = Date::Now(); $newStart = Date::Parse('2010-01-01 04:00:00', 'UTC'); $start = Date::Parse('2010-01-01 05:00:00', 'UTC'); $end = Date::Parse('2010-01-01 07:00:00', 'UTC'); $future1 = new TestReservation('1', new DateRange($now->AddDays(5), $now->AddDays(5))); $future2 = new TestReservation('2', new DateRange($now->AddDays(6), $now->AddDays(6))); $current = new TestReservation('3', new DateRange($start, $end)); $existing = new ExistingReservationSeries(); $existing->WithInstance($future1); $existing->WithInstance($future2); $existing->WithCurrentInstance($current); $existing->ApplyChangesTo(SeriesUpdateScope::ThisInstance); $existing->UpdateDuration(new DateRange($newStart, $end)); $newCurrent = $existing->CurrentInstance(); $this->assertTrue($newCurrent->StartDate()->Equals($newStart)); $this->assertTrue($newCurrent->EndDate()->Equals($end)); }