public function PageLoad()
 {
     $referenceNumber = $this->page->GetReferenceNumber();
     Log::Debug('User: %s, Approving reservation with reference number %s', $this->userSession->UserId, $referenceNumber);
     $series = $this->persistenceService->LoadByReferenceNumber($referenceNumber);
     if ($this->authorization->CanApprove(new ReservationViewAdapter($series), $this->userSession)) {
         $series->Approve($this->userSession);
         $this->handler->Handle($series, $this->page);
     }
 }
 public function testLoadAndApprovesReservationSendingNotifications()
 {
     $referenceNumber = 'rn';
     $builder = new ExistingReservationSeriesBuilder();
     $reservation = $builder->Build();
     $this->page->expects($this->once())->method('GetReferenceNumber')->will($this->returnValue($referenceNumber));
     $this->persistence->expects($this->once())->method('LoadByReferenceNumber')->with($this->equalTo($referenceNumber))->will($this->returnValue($reservation));
     $this->handler->expects($this->once())->method('Handle')->with($this->equalTo($reservation), $this->equalTo($this->page))->will($this->returnValue(true));
     $this->auth->expects($this->once())->method('CanApprove')->with($this->equalTo(new ReservationViewAdapter($reservation)), $this->equalTo($this->fakeUser))->will($this->returnValue(true));
     $this->presenter->PageLoad();
     $this->assertTrue(in_array(new SeriesApprovedEvent($reservation), $reservation->GetEvents()));
 }
 public function testUpdatesReservationAttributeIfTheUserCanEdit()
 {
     $referenceNumber = 'rn';
     $id = 111;
     $value = 'new attribute value';
     $user = $this->fakeUser;
     $resultCollector = new ManageReservationsUpdateAttributeResultCollector();
     $reservation = new ExistingReservationSeries();
     $reservation->UpdateBookedBy($user);
     $reservation->AddAttributeValue(new AttributeValue($id, $value));
     $this->persistenceService->expects($this->once())->method('LoadByReferenceNumber')->with($this->equalTo($referenceNumber))->will($this->returnValue($reservation));
     $this->reservationHandler->expects($this->once())->method('Handle')->with($this->equalTo($reservation), $this->equalTo($resultCollector));
     $result = $this->service->UpdateAttribute($referenceNumber, $id, $value, $user);
 }
 /**
  * @param string $referenceNumber
  * @param int $attributeId
  * @param string $attributeValue
  * @param UserSession $userSession
  * @return string[] Any errors that were returned during reservation update
  */
 public function UpdateAttribute($referenceNumber, $attributeId, $attributeValue, $userSession)
 {
     $reservation = $this->persistenceService->LoadByReferenceNumber($referenceNumber);
     $reservation->UpdateBookedBy($userSession);
     $attributeValues = $reservation->AttributeValues();
     $attributeValues[$attributeId] = $attributeValue;
     $reservation->ChangeAttribute(new AttributeValue($attributeId, $attributeValue));
     $collector = new ManageReservationsUpdateAttributeResultCollector();
     $this->reservationHandler->Handle($reservation, $collector);
     return $collector->errors;
 }
 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());
 }