public function __construct()
 {
     $series = new ExistingReservationSeries();
     $this->currentInstance = new Reservation($series, new DateRange(Date::Now(), Date::Now()));
     $this->repeatOptions = new RepeatNone();
     $this->instances = array();
     $this->events = array();
     $series->WithDescription('description');
     $series->WithOwner(1);
     $this->resource = new FakeBookableResource(2);
     $series->WithResource(new FakeBookableResource(3));
     $series->WithTitle('title');
     $series->WithStatus(ReservationStatus::Created);
     $this->bookedBy = new FakeUserSession();
     $this->series = $series;
 }
 public function testSendsReservationDeletedEmailIfUserWantsIt()
 {
     $event = new ReservationDeletedEvent();
     $ownerId = 100;
     $resourceId = 200;
     $resource = new FakeBookableResource($resourceId, 'name');
     $reservation = new ExistingReservationSeries();
     $reservation->WithOwner($ownerId);
     $reservation->WithPrimaryResource($resource);
     $userRepo = $this->getMock('IUserRepository');
     $attributeRepo = $this->getMock('IAttributeRepository');
     $user = $this->LoadsUser($userRepo, $ownerId);
     $this->AsksUser($user, $event);
     $notification = new OwnerEmailDeletedNotification($userRepo, $attributeRepo);
     $notification->Notify($reservation);
     $expectedMessage = new ReservationDeletedEmail($user, $reservation, null, $attributeRepo);
     $lastMessage = $this->fakeEmailService->_LastMessage;
     $this->assertInstanceOf('ReservationDeletedEmail', $lastMessage);
 }
 /**
  * @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 testSendsReservationDeletedEmailIfAdminWantsIt()
 {
     $ownerId = 100;
     $resourceId = 200;
     $resource = new FakeBookableResource($resourceId, 'name');
     $reservation = new ExistingReservationSeries();
     $reservation->WithOwner($ownerId);
     $reservation->WithPrimaryResource($resource);
     $owner = new FakeUser($ownerId);
     $admin1 = new UserDto(1, 'f', 'l', 'e');
     $admin2 = new UserDto(2, 'f', 'l', 'e');
     $admin3 = new UserDto(3, 'f', 'l', 'e');
     $admin4 = new UserDto(4, 'f', 'l', 'e');
     $admin5 = new UserDto(5, 'f', 'l', 'e');
     $admin6 = new UserDto(6, 'f', 'l', 'e');
     $resourceAdmins = array($admin1, $admin2, $admin3);
     $appAdmins = array($admin3, $admin4, $admin1);
     $groupAdmins = array($admin5, $admin6, $admin2);
     $attributeRepo = $this->getMock('IAttributeRepository');
     $userRepo = $this->getMock('IUserRepository');
     $userRepo->expects($this->once())->method('LoadById')->with($this->equalTo($ownerId))->will($this->returnValue($owner));
     $userRepo->expects($this->once())->method('GetResourceAdmins')->with($this->equalTo($resourceId))->will($this->returnValue($resourceAdmins));
     $userRepo->expects($this->once())->method('GetApplicationAdmins')->will($this->returnValue($appAdmins));
     $userRepo->expects($this->once())->method('GetGroupAdmins')->with($this->equalTo($ownerId))->will($this->returnValue($groupAdmins));
     $this->EnableNotifyFor(ConfigKeys::NOTIFY_DELETE_RESOURCE_ADMINS);
     $this->EnableNotifyFor(ConfigKeys::NOTIFY_DELETE_APPLICATION_ADMINS);
     $this->EnableNotifyFor(ConfigKeys::NOTIFY_DELETE_GROUP_ADMINS);
     $notification = new AdminEmailDeletedNotification($userRepo, $userRepo, $attributeRepo);
     $notification->Notify($reservation);
     $expectedMessage1 = new ReservationDeletedEmailAdmin($admin1, $owner, $reservation, $resource, $attributeRepo);
     $this->assertEquals(6, count($this->fakeEmailService->_Messages), "send one per person, no duplicates");
     $this->isInstanceOf('ReservationDeletedEmailAdmin', $this->fakeEmailService->_Messages[0]);
     $this->isInstanceOf('ReservationDeletedEmailAdmin', $this->fakeEmailService->_Messages[1]);
 }
 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));
 }