public function testBuildsViewObjectFromDatabase()
 {
     $referenceNumber = "12345";
     $reservationId = 187;
     $resourceId = 12;
     $scheduleId = 73;
     $startDate = new Date('2010-01-01 05:00', 'UTC');
     $endDate = new Date('2010-01-01 12:00', 'UTC');
     $dateCreated = new Date('2010-01-01', 'UTC');
     $ownerId = 92;
     $title = 'ti';
     $description = 'de';
     $repeatType = RepeatType::Yearly;
     $repeatOptions = 'interval=5';
     $seriesId = 1000;
     $ownerFirst = 'f';
     $ownerLast = 'l';
     $statusId = ReservationStatus::Pending;
     $resourceName = 'resource';
     $resourceId1 = 88;
     $resourceName1 = 'r1';
     $adminGroupId1 = 1239;
     $scheduleAdminGroupId = 992323;
     $resourceId2 = 99;
     $resourceName2 = 'r2';
     $userId1 = 87;
     $fname1 = 'f1';
     $lname1 = 'l1';
     $email1 = 'e1';
     $userId2 = 97;
     $fname2 = 'f2';
     $lname2 = 'l2';
     $email2 = 'e2';
     $userId3 = 98;
     $fname3 = 'f3';
     $lname3 = 'l3';
     $email3 = 'e3';
     $email = '*****@*****.**';
     $allowParticipation = 1;
     $ownerLevel = ReservationUserLevel::OWNER;
     $participantLevel = ReservationUserLevel::PARTICIPANT;
     $inviteeLevel = ReservationUserLevel::INVITEE;
     $getReservationForEditingCommand = new GetReservationForEditingCommand($referenceNumber);
     $getReservationResources = new GetReservationResourcesCommand($seriesId);
     $getParticipants = new GetReservationParticipantsCommand($reservationId);
     $getAccessories = new GetReservationAccessoriesCommand($seriesId);
     $getAttributes = new GetAttributeValuesCommand($seriesId, CustomAttributeCategory::RESERVATION);
     $getAttachments = new GetReservationAttachmentsCommand($seriesId);
     $getReminders = new GetReservationReminders($seriesId);
     $reservationRow = array(ColumnNames::RESERVATION_INSTANCE_ID => $reservationId, ColumnNames::REFERENCE_NUMBER => $referenceNumber, ColumnNames::RESOURCE_ID => $resourceId, ColumnNames::SCHEDULE_ID => $scheduleId, ColumnNames::RESERVATION_START => $startDate->ToDatabase(), ColumnNames::RESERVATION_END => $endDate->ToDatabase(), ColumnNames::USER_ID => $ownerId, ColumnNames::RESERVATION_TITLE => $title, ColumnNames::RESERVATION_DESCRIPTION => $description, ColumnNames::REPEAT_TYPE => $repeatType, ColumnNames::REPEAT_OPTIONS => $repeatOptions, ColumnNames::SERIES_ID => $seriesId, ColumnNames::FIRST_NAME => $ownerFirst, ColumnNames::LAST_NAME => $ownerLast, ColumnNames::RESERVATION_STATUS => $statusId, ColumnNames::RESERVATION_CREATED => $dateCreated->ToDatabase(), ColumnNames::RESOURCE_NAME => $resourceName, ColumnNames::EMAIL => $email, ColumnNames::RESERVATION_MODIFIED => Date::Now()->ToDatabase(), ColumnNames::RESERVATION_ALLOW_PARTICIPATION => $allowParticipation);
     $resourceRows = array($this->GetResourceRow($reservationId, $resourceId1, $resourceName1, $adminGroupId1, $scheduleId, $scheduleAdminGroupId), $this->GetResourceRow($reservationId, $resourceId2, $resourceName2, null, $scheduleId, $scheduleAdminGroupId));
     $participantRows = array($this->GetParticipantRow($reservationId, $userId1, $fname1, $lname1, $email1, $ownerLevel), $this->GetParticipantRow($reservationId, $userId2, $fname2, $lname2, $email2, $participantLevel), $this->GetParticipantRow($reservationId, $userId3, $fname3, $lname3, $email3, $inviteeLevel));
     $accessory1 = 123;
     $accessory2 = 1232;
     $quantity1 = 123;
     $quantity2 = 1232;
     $accessoryName1 = 'a1';
     $accessoryName2 = 'a2';
     $accessoryQuantity1 = 111;
     $accessoryQuantity2 = 222;
     $attributeId1 = 9292;
     $attributeId2 = 884;
     $attributeValue1 = 'v1';
     $attributeValue2 = 'v1';
     $attributeLabel1 = 'al1';
     $attributeLabel2 = 'al2';
     $startReminderMinutes = 25;
     $endReminderMinutes = 120;
     $accessoryRows = new ReservationAccessoryRow();
     $accessoryRows->WithAccessory($accessory1, $quantity1, $accessoryName1, $accessoryQuantity1)->WithAccessory($accessory2, $quantity2, $accessoryName2, $accessoryQuantity2);
     $attributeRows = new CustomAttributeValueRow();
     $attributeRows->With($attributeId1, $attributeValue1, $attributeLabel1)->With($attributeId2, $attributeValue2, $attributeLabel2);
     $reminderRows = new ReservationReminderRow();
     $reminderRows->With(1, $seriesId, $startReminderMinutes, ReservationReminderType::Start)->With(2, $seriesId, $endReminderMinutes, ReservationReminderType::End);
     $fileId1 = 1;
     $fileName1 = 'fn1';
     $fileId2 = 2;
     $fileName2 = 'fn2';
     $attachmentRows = new ReservationAttachmentItemRow();
     $attachmentRows->With($fileId1, $seriesId, $fileName1)->With($fileId2, $seriesId, $fileName2);
     $this->db->SetRow(0, array($reservationRow));
     $this->db->SetRow(1, $resourceRows);
     $this->db->SetRow(2, $participantRows);
     $this->db->SetRow(3, $accessoryRows->Rows());
     $this->db->SetRow(4, $attributeRows->Rows());
     $this->db->SetRow(5, $attachmentRows->Rows());
     $this->db->SetRow(6, $reminderRows->Rows());
     $reservationView = $this->repository->GetReservationForEditing($referenceNumber);
     $commands = $this->db->_Commands;
     $this->assertEquals(7, count($commands));
     $this->assertEquals($getReservationForEditingCommand, $commands[0]);
     $this->assertEquals($getReservationResources, $commands[1]);
     $this->assertEquals($getParticipants, $commands[2]);
     $this->assertEquals($getAccessories, $commands[3]);
     $this->assertEquals($getAttributes, $commands[4]);
     $this->assertEquals($getAttachments, $commands[5]);
     $this->assertEquals($getReminders, $commands[6]);
     $expectedView = new ReservationView();
     $expectedView->AdditionalResourceIds = array($resourceId1, $resourceId2);
     $expectedView->Description = $description;
     $expectedView->EndDate = $endDate;
     $expectedView->OwnerId = $ownerId;
     $expectedView->ReferenceNumber = $referenceNumber;
     $expectedView->ReservationId = $reservationId;
     $expectedView->ResourceId = $resourceId;
     $expectedView->ResourceName = $resourceName;
     $expectedView->DateCreated = $dateCreated;
     $expectedView->ScheduleId = $scheduleId;
     $expectedView->StartDate = $startDate;
     $expectedView->Title = $title;
     $expectedView->RepeatType = $repeatType;
     $expectedView->RepeatInterval = '5';
     $expectedView->SeriesId = $seriesId;
     $expectedView->OwnerFirstName = $ownerFirst;
     $expectedView->OwnerLastName = $ownerLast;
     $expectedView->StatusId = $statusId;
     $expectedView->OwnerEmailAddress = $email;
     $expectedView->DateModified = Date::Now()->ToUtc();
     $expectedView->Participants = array(new ReservationUserView($userId2, $fname2, $lname2, $email2, $participantLevel));
     $expectedView->Invitees = array(new ReservationUserView($userId3, $fname3, $lname3, $email3, $inviteeLevel));
     $expectedView->Resources = array(new ReservationResourceView($resourceId1, $resourceName1, $adminGroupId1, $scheduleId, $scheduleAdminGroupId, ResourceStatus::AVAILABLE), new ReservationResourceView($resourceId2, $resourceName2, null, $scheduleId, $scheduleAdminGroupId, ResourceStatus::AVAILABLE));
     $expectedView->Accessories = array(new ReservationAccessoryView($accessory1, $quantity1, $accessoryName1, $accessoryQuantity1), new ReservationAccessoryView($accessory2, $quantity2, $accessoryName2, $accessoryQuantity2));
     $expectedView->AddAttribute(new AttributeValue($attributeId1, $attributeValue1, $attributeLabel1));
     $expectedView->AddAttribute(new AttributeValue($attributeId2, $attributeValue2, $attributeLabel2));
     $expectedView->AddAttachment(new ReservationAttachmentView($fileId1, $seriesId, $fileName1));
     $expectedView->AddAttachment(new ReservationAttachmentView($fileId2, $seriesId, $fileName2));
     $expectedView->StartReminder = new ReservationReminderView($startReminderMinutes);
     $expectedView->EndReminder = new ReservationReminderView($endReminderMinutes);
     $expectedView->AllowParticipation = true;
     $this->assertEquals($expectedView, $reservationView);
 }
Exemplo n.º 2
0
 public function testLoadsResourceType()
 {
     $rows = new ResourceTypeRow();
     $rows->With(1, 'resourcetype1', 'description');
     $car = new CustomAttributeValueRow();
     $car->With(1, 'value')->With(2, 'value2');
     $this->db->SetRow(0, $rows->Rows());
     $this->db->SetRow(1, $car->Rows());
     $resourceType = $this->repository->LoadResourceType(123);
     $this->assertEquals(1, $resourceType->Id());
     $this->assertEquals('resourcetype1', $resourceType->Name());
     $this->assertTrue($this->db->ContainsCommand(new GetResourceTypeCommand(123)));
     $this->assertTrue($this->db->ContainsCommand(new GetAttributeValuesCommand(123, CustomAttributeCategory::RESOURCE_TYPE)));
     $this->assertEquals('value', $resourceType->GetAttributeValue(1));
     $this->assertEquals('value2', $resourceType->GetAttributeValue(2));
 }
 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));
 }
Exemplo n.º 4
0
 private function GetAttributeRows()
 {
     $car = new CustomAttributeValueRow();
     $car->With(1, 'value')->With(2, 'value2');
     return $car->Rows();
 }