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());
 }
Exemplo n.º 2
0
 /**
  * @param $attachmentFile ReservationAttachment
  * @return int
  */
 public function AddReservationAttachment(ReservationAttachment $attachmentFile)
 {
     $command = new AddReservationAttachmentCommand($attachmentFile->FileName(), $attachmentFile->FileType(), $attachmentFile->FileSize(), $attachmentFile->FileExtension(), $attachmentFile->SeriesId());
     $id = ServiceLocator::GetDatabase()->ExecuteInsert($command);
     $extension = $attachmentFile->FileExtension();
     $attachmentFile->WithFileId($id);
     $fileSystem = ServiceLocator::GetFileSystem();
     $fileSystem->Add($fileSystem->GetReservationAttachmentsPath(), "{$id}.{$extension}", $attachmentFile->FileContents());
     return $id;
 }
Exemplo n.º 3
0
 public function BuildReservation()
 {
     $userId = $this->_page->GetUserId();
     $primaryResourceId = $this->_page->GetResourceId();
     $resource = $this->_resourceRepository->LoadById($primaryResourceId);
     $title = $this->_page->GetTitle();
     $description = $this->_page->GetDescription();
     $roFactory = new RepeatOptionsFactory();
     $repeatOptions = $roFactory->CreateFromComposite($this->_page, $this->userSession->Timezone);
     $duration = $this->GetReservationDuration();
     $reservationSeries = ReservationSeries::Create($userId, $resource, $title, $description, $duration, $repeatOptions, $this->userSession);
     $resourceIds = $this->_page->GetResources();
     foreach ($resourceIds as $resourceId) {
         if ($primaryResourceId != $resourceId) {
             $reservationSeries->AddResource($this->_resourceRepository->LoadById($resourceId));
         }
     }
     $accessories = $this->_page->GetAccessories();
     foreach ($accessories as $accessory) {
         $reservationSeries->AddAccessory(new ReservationAccessory($accessory->Id, $accessory->Quantity, $accessory->Name));
     }
     $attributes = $this->_page->GetAttributes();
     foreach ($attributes as $attribute) {
         $reservationSeries->AddAttributeValue(new AttributeValue($attribute->Id, $attribute->Value));
     }
     $participantIds = $this->_page->GetParticipants();
     $reservationSeries->ChangeParticipants($participantIds);
     $inviteeIds = $this->_page->GetInvitees();
     $reservationSeries->ChangeInvitees($inviteeIds);
     $attachments = $this->_page->GetAttachments();
     foreach ($attachments as $attachment) {
         if ($attachment != null) {
             if ($attachment->IsError()) {
                 Log::Error('Error attaching file %s. %s', $attachment->OriginalName(), $attachment->Error());
             } else {
                 $att = ReservationAttachment::Create($attachment->OriginalName(), $attachment->MimeType(), $attachment->Size(), $attachment->Contents(), $attachment->Extension(), 0);
                 $reservationSeries->AddAttachment($att);
             }
         }
     }
     if ($this->_page->HasStartReminder()) {
         $reservationSeries->AddStartReminder(new ReservationReminder($this->_page->GetStartReminderValue(), $this->_page->GetStartReminderInterval()));
     }
     if ($this->_page->HasEndReminder()) {
         $reservationSeries->AddEndReminder(new ReservationReminder($this->_page->GetEndReminderValue(), $this->_page->GetEndReminderInterval()));
     }
     return $reservationSeries;
 }
Exemplo n.º 4
0
 /**
  * @param ReservationAttachment $attachment
  * @return void
  */
 public function BindAttachment(ReservationAttachment $attachment)
 {
     header('Content-Type: ' . $attachment->FileType());
     header('Content-Disposition: attachment; filename="' . $attachment->FileName() . '"');
     ob_clean();
     flush();
     echo $attachment->FileContents();
 }
Exemplo n.º 5
0
 /**
  * @return ExistingReservationSeries
  */
 public function BuildReservation()
 {
     $referenceNumber = $this->page->GetReferenceNumber();
     $existingSeries = $this->persistenceService->LoadByReferenceNumber($referenceNumber);
     $existingSeries->ApplyChangesTo($this->page->GetSeriesUpdateScope());
     $resourceId = $this->page->GetResourceId();
     $additionalResourceIds = $this->page->GetResources();
     if (empty($resourceId)) {
         // the first additional resource will become the primary if the primary is removed
         $resourceId = array_shift($additionalResourceIds);
     }
     $resource = $this->resourceRepository->LoadById($resourceId);
     $existingSeries->Update($this->page->GetUserId(), $resource, $this->page->GetTitle(), $this->page->GetDescription(), $this->userSession);
     $existingSeries->UpdateDuration($this->GetReservationDuration());
     $roFactory = new RepeatOptionsFactory();
     $existingSeries->Repeats($roFactory->CreateFromComposite($this->page, $this->userSession->Timezone));
     $additionalResources = array();
     foreach ($additionalResourceIds as $additionalResourceId) {
         if ($additionalResourceId != $resourceId) {
             $additionalResources[] = $this->resourceRepository->LoadById($additionalResourceId);
         }
     }
     $existingSeries->ChangeResources($additionalResources);
     $existingSeries->ChangeParticipants($this->page->GetParticipants());
     $existingSeries->ChangeInvitees($this->page->GetInvitees());
     $existingSeries->ChangeAccessories($this->GetAccessories());
     $existingSeries->ChangeAttributes($this->GetAttributes());
     $attachments = $this->page->GetAttachments();
     foreach ($attachments as $attachment) {
         if ($attachment != null) {
             if ($attachment->IsError()) {
                 Log::Error('Error attaching file %s. %s', $attachment->OriginalName(), $attachment->Error());
             } else {
                 Log::Debug('Attaching file %s to series %s', $attachment->OriginalName(), $existingSeries->SeriesId());
                 $att = ReservationAttachment::Create($attachment->OriginalName(), $attachment->MimeType(), $attachment->Size(), $attachment->Contents(), $attachment->Extension(), $existingSeries->SeriesId());
                 $existingSeries->AddAttachment($att);
             }
         }
     }
     foreach ($this->page->GetRemovedAttachmentIds() as $fileId) {
         $existingSeries->RemoveAttachment($fileId);
     }
     if ($this->page->HasStartReminder()) {
         $existingSeries->AddStartReminder(new ReservationReminder($this->page->GetStartReminderValue(), $this->page->GetStartReminderInterval()));
     } else {
         $existingSeries->RemoveStartReminder();
     }
     if ($this->page->HasEndReminder()) {
         $existingSeries->AddEndReminder(new ReservationReminder($this->page->GetEndReminderValue(), $this->page->GetEndReminderInterval()));
     } else {
         $existingSeries->RemoveEndReminder();
     }
     return $existingSeries;
 }
 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 testAddAttachmentToExistingReservation()
 {
     $seriesId = 10;
     $builder = new ExistingReservationSeriesBuilder();
     $series = $builder->WithId($seriesId)->Build();
     $expectedFileId = 5346;
     $fileName = 'fn';
     $fileType = 'doc';
     $fileSize = 100;
     $fileContent = 'contents';
     $fileExtension = 'doc';
     $attachment = ReservationAttachment::Create($fileName, $fileType, $fileSize, $fileContent, $fileExtension, $seriesId);
     $series->AddAttachment($attachment);
     $command = new AddReservationAttachmentCommand($fileName, $fileType, $fileSize, $fileExtension, $seriesId);
     $this->db->_ExpectedInsertId = $expectedFileId;
     $this->repository->Update($series);
     $this->assertEquals($command, $this->db->_LastCommand);
     $this->assertEquals($expectedFileId, $attachment->FileId());
 }