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 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(); /*EXPERIMENT*/ $experiment = $this->_page->getExperiment(); $reservationSeries = ReservationSeries::Create($userId, $resource, $title, $description, $duration, $repeatOptions, $this->userSession, $experiment); $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); $reservationSeries->AllowParticipation($this->_page->GetAllowParticipation()); $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; }